mirror of https://github.com/procxx/kepka.git
				
				
				
			Improve disabled Ui::Checkbox layout.
This commit is contained in:
		
							parent
							
								
									9e73e22e13
								
							
						
					
					
						commit
						7cc38f8f6a
					
				|  | @ -368,8 +368,12 @@ void Checkbox::paintEvent(QPaintEvent *e) { | ||||||
| 
 | 
 | ||||||
| 	auto realCheckRect = myrtlrect(_checkRect); | 	auto realCheckRect = myrtlrect(_checkRect); | ||||||
| 	if (realCheckRect.intersects(e->rect())) { | 	if (realCheckRect.intersects(e->rect())) { | ||||||
|  | 		if (isDisabled()) { | ||||||
|  | 			p.drawPixmapLeft(_checkRect.left(), _checkRect.top(), width(), _checkCache); | ||||||
|  | 		} else { | ||||||
| 			_check->paint(p, _checkRect.left(), _checkRect.top(), width()); | 			_check->paint(p, _checkRect.left(), _checkRect.top(), width()); | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 	if (realCheckRect.contains(e->rect())) return; | 	if (realCheckRect.contains(e->rect())) return; | ||||||
| 
 | 
 | ||||||
| 	auto textWidth = qMax(width() - (_checkRect.width() + _st.textPosition.x() + _st.textPosition.x()), 1); | 	auto textWidth = qMax(width() - (_checkRect.width() + _st.textPosition.x() + _st.textPosition.x()), 1); | ||||||
|  | @ -378,14 +382,27 @@ void Checkbox::paintEvent(QPaintEvent *e) { | ||||||
| 	_text.drawLeftElided(p, _st.margin.left() + _checkRect.width() + _st.textPosition.x(), _st.margin.top() + _st.textPosition.y(), textWidth, width()); | 	_text.drawLeftElided(p, _st.margin.left() + _checkRect.width() + _st.textPosition.x(), _st.margin.top() + _st.textPosition.y(), textWidth, width()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | QPixmap Checkbox::grabCheckCache() const { | ||||||
|  | 	auto image = QImage(_checkRect.size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); | ||||||
|  | 	image.fill(Qt::transparent); | ||||||
|  | 	image.setDevicePixelRatio(cRetinaFactor()); | ||||||
|  | 	{ | ||||||
|  | 		Painter p(&image); | ||||||
|  | 		_check->paint(p, 0, 0, _checkRect.width()); | ||||||
|  | 	} | ||||||
|  | 	return App::pixmapFromImageInPlace(std::move(image)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void Checkbox::onStateChanged(State was, StateChangeSource source) { | void Checkbox::onStateChanged(State was, StateChangeSource source) { | ||||||
| 	RippleButton::onStateChanged(was, source); | 	RippleButton::onStateChanged(was, source); | ||||||
| 
 | 
 | ||||||
| 	if (isDisabled() && !(was & StateFlag::Disabled)) { | 	if (isDisabled() && !(was & StateFlag::Disabled)) { | ||||||
| 		setCursor(style::cur_default); | 		setCursor(style::cur_default); | ||||||
| 		finishAnimations(); | 		finishAnimations(); | ||||||
|  | 		_checkCache = grabCheckCache(); | ||||||
| 	} else if (!isDisabled() && (was & StateFlag::Disabled)) { | 	} else if (!isDisabled() && (was & StateFlag::Disabled)) { | ||||||
| 		setCursor(style::cur_pointer); | 		setCursor(style::cur_pointer); | ||||||
|  | 		_checkCache = QPixmap(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	auto now = state(); | 	auto now = state(); | ||||||
|  |  | ||||||
|  | @ -154,9 +154,11 @@ protected: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| 	void resizeToText(); | 	void resizeToText(); | ||||||
|  | 	QPixmap grabCheckCache() const; | ||||||
| 
 | 
 | ||||||
| 	const style::Checkbox &_st; | 	const style::Checkbox &_st; | ||||||
| 	std::unique_ptr<AbstractCheckView> _check; | 	std::unique_ptr<AbstractCheckView> _check; | ||||||
|  | 	QPixmap _checkCache; | ||||||
| 
 | 
 | ||||||
| 	Text _text; | 	Text _text; | ||||||
| 	QRect _checkRect; | 	QRect _checkRect; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue