Changeset View
Changeset View
Standalone View
Standalone View
kstyle/breezehelper.cpp
Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Line(s) | 167 | { | |||
---|---|---|---|---|---|
190 | 190 | | |||
191 | } | 191 | } | ||
192 | 192 | | |||
193 | return outline; | 193 | return outline; | ||
194 | 194 | | |||
195 | } | 195 | } | ||
196 | 196 | | |||
197 | //____________________________________________________________________ | 197 | //____________________________________________________________________ | ||
198 | QColor Helper::buttonOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | 198 | QColor Helper::buttonOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode ) const | ||
199 | { | 199 | { | ||
200 | 200 | | |||
201 | const QColor focus( focusColor( palette ) ); | ||||
201 | QColor outline( KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.3 ) ); | 202 | QColor outline( KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.3 ) ); | ||
202 | if( mode == AnimationHover ) | 203 | if( mode == AnimationFocus ) { | ||
203 | { | | |||
204 | | ||||
205 | if( hasFocus ) | | |||
206 | { | | |||
207 | const QColor focus( buttonFocusOutlineColor( palette ) ); | | |||
208 | const QColor hover( buttonHoverOutlineColor( palette ) ); | | |||
209 | outline = KColorUtils::mix( focus, hover, opacity ); | | |||
210 | | ||||
211 | } else { | | |||
212 | | ||||
213 | const QColor hover( hoverColor( palette ) ); | | |||
214 | outline = KColorUtils::mix( outline, hover, opacity ); | | |||
215 | | ||||
216 | } | | |||
217 | | ||||
218 | } else if( mouseOver ) { | | |||
219 | 204 | | |||
220 | if( hasFocus ) outline = buttonHoverOutlineColor( palette ); | | |||
221 | else outline = hoverColor( palette ); | | |||
222 | | ||||
223 | } else if( mode == AnimationFocus ) { | | |||
224 | | ||||
225 | const QColor focus( buttonFocusOutlineColor( palette ) ); | | |||
226 | outline = KColorUtils::mix( outline, focus, opacity ); | 205 | outline = KColorUtils::mix( outline, focus, opacity ); | ||
227 | 206 | | |||
228 | } else if( hasFocus ) { | 207 | } else if( hasFocus ) { | ||
229 | 208 | | |||
230 | outline = buttonFocusOutlineColor( palette ); | 209 | outline = focus; | ||
231 | 210 | | |||
232 | } | 211 | } | ||
233 | 212 | | |||
234 | return outline; | 213 | return outline; | ||
235 | 214 | | |||
236 | } | 215 | } | ||
237 | 216 | | |||
238 | //____________________________________________________________________ | 217 | //____________________________________________________________________ | ||
239 | QColor Helper::buttonBackgroundColor( const QPalette& palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode ) const | 218 | QColor Helper::buttonBackgroundColor( const QPalette& palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode ) const | ||
240 | { | 219 | { | ||
241 | 220 | | |||
242 | QColor background( sunken ? | 221 | QColor background = sunken ? | ||
243 | KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.2 ): | 222 | KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.2 ) : | ||
244 | palette.color( QPalette::Button ) ); | 223 | palette.color( QPalette::Button ); | ||
224 | const bool hasLightBg = palette.color( QPalette::Button ).lightness() > palette.color( QPalette::ButtonText ).lightness(); | ||||
225 | const QColor hover = hasLightBg ? KColorUtils::lighten(background, 0.5) : KColorUtils::darken(background, 0.5); | ||||
226 | const QColor focus( focusColor( palette, background, 0.4 ) ); | ||||
227 | const QColor hoverFocus( KColorUtils::mix( hover, focus, 0.4 ) ); | ||||
245 | 228 | | |||
246 | if( mode == AnimationHover ) | 229 | if( mode == AnimationHover ) | ||
247 | { | 230 | { | ||
248 | 231 | | |||
249 | const QColor focus( focusColor( palette ) ); | 232 | if( hasFocus ) background = KColorUtils::mix( focus, hoverFocus, opacity ); | ||
250 | const QColor hover( hoverColor( palette ) ); | 233 | else background = KColorUtils::mix( background, hover, opacity ); | ||
251 | if( hasFocus ) background = KColorUtils::mix( focus, hover, opacity ); | | |||
252 | 234 | | |||
253 | } else if( mouseOver && hasFocus ) { | 235 | } else if( mouseOver ) { | ||
254 | 236 | | |||
255 | background = hoverColor( palette ); | 237 | if( hasFocus ) background = hoverFocus; | ||
238 | else background = hover; | ||||
256 | 239 | | |||
257 | } else if( mode == AnimationFocus ) { | 240 | } else if( mode == AnimationFocus ) { | ||
258 | 241 | | |||
259 | const QColor focus( focusColor( palette ) ); | | |||
260 | background = KColorUtils::mix( background, focus, opacity ); | 242 | background = KColorUtils::mix( background, focus, opacity ); | ||
261 | 243 | | |||
262 | } else if( hasFocus ) { | 244 | } else if( hasFocus ) { | ||
263 | 245 | | |||
264 | background = focusColor( palette ); | 246 | background = focus; | ||
265 | 247 | | |||
266 | } | 248 | } | ||
267 | 249 | | |||
268 | return background; | 250 | return background; | ||
269 | 251 | | |||
270 | } | 252 | } | ||
271 | 253 | | |||
272 | //____________________________________________________________________ | 254 | //____________________________________________________________________ | ||
▲ Show 20 Lines • Show All 344 Lines • ▼ Show 20 Line(s) | 588 | } else { | |||
617 | 599 | | |||
618 | painter->drawRect( frameRect ); | 600 | painter->drawRect( frameRect ); | ||
619 | 601 | | |||
620 | } | 602 | } | ||
621 | 603 | | |||
622 | } | 604 | } | ||
623 | 605 | | |||
624 | //______________________________________________________________________________ | 606 | //______________________________________________________________________________ | ||
625 | void Helper::renderButtonFrame( | 607 | void Helper::renderButton( | ||
626 | QPainter* painter, const QRect& rect, | 608 | QPainter* painter, const QRect& rect, | ||
627 | const QColor& color, const QColor& outline, const QColor& shadow, | 609 | const QColor& color, const QColor& outline, const QColor& shadow, | ||
628 | bool hasFocus, bool sunken ) const | 610 | bool hasFocus, bool sunken ) const | ||
629 | { | 611 | { | ||
630 | 612 | | |||
631 | // setup painter | 613 | // setup painter | ||
632 | painter->setRenderHint( QPainter::Antialiasing, true ); | 614 | painter->setRenderHint( QPainter::Antialiasing, true ); | ||
633 | 615 | | |||
634 | // copy rect | 616 | // copy rect | ||
635 | QRectF frameRect( rect ); | 617 | QRectF frameRect( rect ); | ||
636 | frameRect.adjust( 1, 1, -1, -1 ); | 618 | frameRect.adjust( 1, 1, -1, -1 ); | ||
637 | qreal radius( frameRadius() ); | 619 | qreal radius( frameRadius() ); | ||
638 | 620 | | |||
639 | // shadow | 621 | // shadow | ||
640 | if( sunken ) { | 622 | if( shadow.isValid() ) { | ||
641 | | ||||
642 | frameRect.translate( 1, 1 ); | | |||
643 | | ||||
644 | } else if( shadow.isValid() ) { | | |||
645 | 623 | | |||
646 | const qreal shadowRadius = qMax( radius - 1, qreal( 0.0 ) ); | 624 | const qreal shadowRadius = qMax( radius - 1, qreal( 0.0 ) ); | ||
647 | painter->setPen( QPen( shadow, 2 ) ); | 625 | painter->setPen( QPen( shadow, 2 ) ); | ||
648 | painter->setBrush( Qt::NoBrush ); | 626 | painter->setBrush( Qt::NoBrush ); | ||
649 | painter->drawRoundedRect( shadowRect( frameRect ), shadowRadius, shadowRadius ); | 627 | painter->drawRoundedRect( shadowRect( frameRect ), shadowRadius, shadowRadius ); | ||
650 | 628 | | |||
651 | } | 629 | } | ||
652 | 630 | | |||
653 | if( outline.isValid() ) | 631 | if( outline.isValid() ) | ||
654 | { | 632 | { | ||
655 | 633 | | |||
656 | QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); | 634 | painter->setPen( outline ); | ||
657 | gradient.setColorAt( 0, outline.lighter( hasFocus ? 103:101 ) ); | | |||
658 | gradient.setColorAt( 1, outline.darker( hasFocus ? 110:103 ) ); | | |||
659 | painter->setPen( QPen( QBrush( gradient ), 1.0 ) ); | | |||
660 | 635 | | |||
661 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | 636 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | ||
662 | radius = qMax( radius - 1, qreal( 0.0 ) ); | 637 | radius = qMax( radius - 1, qreal( 0.0 ) ); | ||
663 | 638 | | |||
664 | } else painter->setPen( Qt::NoPen ); | 639 | } else painter->setPen( Qt::NoPen ); | ||
665 | 640 | | |||
666 | // content | 641 | // content | ||
667 | if( color.isValid() ) | 642 | if( color.isValid() ) | ||
668 | { | 643 | { | ||
669 | 644 | | |||
670 | QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); | 645 | painter->setBrush( color ); | ||
671 | gradient.setColorAt( 0, color.lighter( hasFocus ? 103:101 ) ); | | |||
672 | gradient.setColorAt( 1, color.darker( hasFocus ? 110:103 ) ); | | |||
673 | painter->setBrush( gradient ); | | |||
674 | 646 | | |||
675 | } else painter->setBrush( Qt::NoBrush ); | 647 | } else painter->setBrush( Qt::NoBrush ); | ||
676 | 648 | | |||
677 | // render | 649 | // render | ||
678 | painter->drawRoundedRect( frameRect, radius, radius ); | 650 | painter->drawRoundedRect( frameRect, radius, radius ); | ||
679 | 651 | | |||
680 | } | 652 | } | ||
681 | 653 | | |||
▲ Show 20 Lines • Show All 928 Lines • Show Last 20 Lines |