Changeset View
Changeset View
Standalone View
Standalone View
kstyle/breezehelper.cpp
Show All 16 Lines | |||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
18 | *************************************************************************/ | 18 | *************************************************************************/ | ||
19 | 19 | | |||
20 | #include "breezehelper.h" | 20 | #include "breezehelper.h" | ||
21 | 21 | | |||
22 | #include "breeze.h" | 22 | #include "breeze.h" | ||
23 | #include "breezestyleconfigdata.h" | 23 | #include "breezestyleconfigdata.h" | ||
24 | 24 | | |||
25 | #include <KColorUtils> | | |||
26 | #include <KWindowSystem> | 25 | #include <KWindowSystem> | ||
27 | 26 | | |||
28 | #include <QApplication> | 27 | #include <QApplication> | ||
29 | #include <QPainter> | 28 | #include <QPainter> | ||
30 | 29 | | |||
31 | #if BREEZE_HAVE_X11 && QT_VERSION < 0x050000 | 30 | #if BREEZE_HAVE_X11 && QT_VERSION < 0x050000 | ||
32 | #include <X11/Xlib-xcb.h> | 31 | #include <X11/Xlib-xcb.h> | ||
33 | #endif | 32 | #endif | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 37 | { | |||
111 | QColor Helper::focusOutlineColor( const QPalette& palette ) const | 110 | QColor Helper::focusOutlineColor( const QPalette& palette ) const | ||
112 | { return KColorUtils::mix( focusColor( palette ), palette.color( QPalette::WindowText ), 0.15 ); } | 111 | { return KColorUtils::mix( focusColor( palette ), palette.color( QPalette::WindowText ), 0.15 ); } | ||
113 | 112 | | |||
114 | //____________________________________________________________________ | 113 | //____________________________________________________________________ | ||
115 | QColor Helper::hoverOutlineColor( const QPalette& palette ) const | 114 | QColor Helper::hoverOutlineColor( const QPalette& palette ) const | ||
116 | { return KColorUtils::mix( hoverColor( palette ), palette.color( QPalette::WindowText ), 0.15 ); } | 115 | { return KColorUtils::mix( hoverColor( palette ), palette.color( QPalette::WindowText ), 0.15 ); } | ||
117 | 116 | | |||
118 | //____________________________________________________________________ | 117 | //____________________________________________________________________ | ||
119 | QColor Helper::buttonFocusOutlineColor( const QPalette& palette ) const | | |||
120 | { return KColorUtils::mix( focusColor( palette ), palette.color( QPalette::ButtonText ), 0.15 ); } | | |||
121 | | ||||
122 | //____________________________________________________________________ | | |||
123 | QColor Helper::buttonHoverOutlineColor( const QPalette& palette ) const | | |||
124 | { return KColorUtils::mix( hoverColor( palette ), palette.color( QPalette::ButtonText ), 0.15 ); } | | |||
125 | | ||||
126 | //____________________________________________________________________ | | |||
127 | QColor Helper::sidePanelOutlineColor( const QPalette& palette, bool hasFocus, qreal opacity, AnimationMode mode ) const | 118 | QColor Helper::sidePanelOutlineColor( const QPalette& palette, bool hasFocus, qreal opacity, AnimationMode mode ) const | ||
128 | { | 119 | { | ||
129 | 120 | | |||
130 | QColor outline( palette.color( QPalette::Inactive, QPalette::Highlight ) ); | 121 | QColor outline( palette.color( QPalette::Inactive, QPalette::Highlight ) ); | ||
131 | const QColor &focus = palette.color( QPalette::Active, QPalette::Highlight ); | 122 | const QColor &focus = palette.color( QPalette::Active, QPalette::Highlight ); | ||
132 | 123 | | |||
133 | if( mode == AnimationFocus ) | 124 | if( mode == AnimationFocus ) | ||
134 | { | 125 | { | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 178 | } else if( hasFocus ) { | |||
189 | outline = focusColor( palette ); | 180 | outline = focusColor( palette ); | ||
190 | 181 | | |||
191 | } | 182 | } | ||
192 | 183 | | |||
193 | return outline; | 184 | return outline; | ||
194 | 185 | | |||
195 | } | 186 | } | ||
196 | 187 | | |||
197 | //____________________________________________________________________ | | |||
198 | QColor Helper::buttonOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | | |||
199 | { | | |||
200 | | ||||
201 | QColor outline( KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.3 ) ); | | |||
202 | if( mode == AnimationHover ) | | |||
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 | | ||||
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 ); | | |||
227 | | ||||
228 | } else if( hasFocus ) { | | |||
229 | | ||||
230 | outline = buttonFocusOutlineColor( palette ); | | |||
231 | | ||||
232 | } | | |||
233 | | ||||
234 | return outline; | | |||
235 | | ||||
236 | } | | |||
237 | | ||||
238 | //____________________________________________________________________ | | |||
239 | QColor Helper::buttonBackgroundColor( const QPalette& palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode ) const | | |||
240 | { | | |||
241 | | ||||
242 | QColor background( sunken ? | | |||
243 | KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.2 ): | | |||
244 | palette.color( QPalette::Button ) ); | | |||
245 | | ||||
246 | if( mode == AnimationHover ) | | |||
247 | { | | |||
248 | | ||||
249 | const QColor focus( focusColor( palette ) ); | | |||
250 | const QColor hover( hoverColor( palette ) ); | | |||
251 | if( hasFocus ) background = KColorUtils::mix( focus, hover, opacity ); | | |||
252 | | ||||
253 | } else if( mouseOver && hasFocus ) { | | |||
254 | | ||||
255 | background = hoverColor( palette ); | | |||
256 | | ||||
257 | } else if( mode == AnimationFocus ) { | | |||
258 | | ||||
259 | const QColor focus( focusColor( palette ) ); | | |||
260 | background = KColorUtils::mix( background, focus, opacity ); | | |||
261 | | ||||
262 | } else if( hasFocus ) { | | |||
263 | | ||||
264 | background = focusColor( palette ); | | |||
265 | | ||||
266 | } | | |||
267 | | ||||
268 | return background; | | |||
269 | | ||||
270 | } | | |||
271 | | ||||
272 | //____________________________________________________________________ | | |||
273 | QColor Helper::toolButtonColor( const QPalette& palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode ) const | | |||
274 | { | | |||
275 | | ||||
276 | QColor outline; | | |||
277 | const QColor hoverColor( this->hoverColor( palette ) ); | | |||
278 | const QColor focusColor( this->focusColor( palette ) ); | | |||
279 | const QColor sunkenColor = alphaColor( palette.color( QPalette::WindowText ), 0.2 ); | | |||
280 | | ||||
281 | // hover takes precedence over focus | | |||
282 | if( mode == AnimationHover ) | | |||
283 | { | | |||
284 | | ||||
285 | if( hasFocus ) outline = KColorUtils::mix( focusColor, hoverColor, opacity ); | | |||
286 | else if( sunken ) outline = sunkenColor; | | |||
287 | else outline = alphaColor( hoverColor, opacity ); | | |||
288 | | ||||
289 | } else if( mouseOver ) { | | |||
290 | | ||||
291 | outline = hoverColor; | | |||
292 | | ||||
293 | } else if( mode == AnimationFocus ) { | | |||
294 | | ||||
295 | if( sunken ) outline = KColorUtils::mix( sunkenColor, focusColor, opacity ); | | |||
296 | else outline = alphaColor( focusColor, opacity ); | | |||
297 | | ||||
298 | } else if( hasFocus ) { | | |||
299 | | ||||
300 | outline = focusColor; | | |||
301 | | ||||
302 | } else if( sunken ) { | | |||
303 | | ||||
304 | outline = sunkenColor; | | |||
305 | | ||||
306 | } | | |||
307 | | ||||
308 | return outline; | | |||
309 | | ||||
310 | } | | |||
311 | | ||||
312 | //____________________________________________________________________ | | |||
313 | QColor Helper::sliderOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | | |||
314 | { | | |||
315 | | ||||
316 | QColor outline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.4 ) ); | | |||
317 | | ||||
318 | // hover takes precedence over focus | | |||
319 | if( mode == AnimationHover ) | | |||
320 | { | | |||
321 | | ||||
322 | const QColor hover( hoverColor( palette ) ); | | |||
323 | const QColor focus( focusColor( palette ) ); | | |||
324 | if( hasFocus ) outline = KColorUtils::mix( focus, hover, opacity ); | | |||
325 | else outline = KColorUtils::mix( outline, hover, opacity ); | | |||
326 | | ||||
327 | } else if( mouseOver ) { | | |||
328 | | ||||
329 | outline = hoverColor( palette ); | | |||
330 | | ||||
331 | } else if( mode == AnimationFocus ) { | | |||
332 | | ||||
333 | const QColor focus( focusColor( palette ) ); | | |||
334 | outline = KColorUtils::mix( outline, focus, opacity ); | | |||
335 | | ||||
336 | } else if( hasFocus ) { | | |||
337 | | ||||
338 | outline = focusColor( palette ); | | |||
339 | | ||||
340 | } | | |||
341 | | ||||
342 | return outline; | | |||
343 | | ||||
344 | } | | |||
345 | | ||||
346 | //____________________________________________________________________ | | |||
347 | QColor Helper::scrollBarHandleColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | | |||
348 | { | | |||
349 | | ||||
350 | QColor color( alphaColor( palette.color( QPalette::WindowText ), 0.5 ) ); | | |||
351 | | ||||
352 | // hover takes precedence over focus | | |||
353 | if( mode == AnimationHover ) | | |||
354 | { | | |||
355 | | ||||
356 | const QColor hover( hoverColor( palette ) ); | | |||
357 | const QColor focus( focusColor( palette ) ); | | |||
358 | if( hasFocus ) color = KColorUtils::mix( focus, hover, opacity ); | | |||
359 | else color = KColorUtils::mix( color, hover, opacity ); | | |||
360 | | ||||
361 | } else if( mouseOver ) { | | |||
362 | | ||||
363 | color = hoverColor( palette ); | | |||
364 | | ||||
365 | } else if( mode == AnimationFocus ) { | | |||
366 | | ||||
367 | const QColor focus( focusColor( palette ) ); | | |||
368 | color = KColorUtils::mix( color, focus, opacity ); | | |||
369 | | ||||
370 | } else if( hasFocus ) { | | |||
371 | | ||||
372 | color = focusColor( palette ); | | |||
373 | | ||||
374 | } | | |||
375 | | ||||
376 | return color; | | |||
377 | | ||||
378 | } | | |||
379 | | ||||
380 | //______________________________________________________________________________ | | |||
381 | QColor Helper::checkBoxIndicatorColor( const QPalette& palette, bool mouseOver, bool active, qreal opacity, AnimationMode mode ) const | | |||
382 | { | | |||
383 | | ||||
384 | QColor color( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.6 ) ); | | |||
385 | if( mode == AnimationHover ) | | |||
386 | { | | |||
387 | | ||||
388 | const QColor focus( focusColor( palette ) ); | | |||
389 | const QColor hover( hoverColor( palette ) ); | | |||
390 | if( active ) color = KColorUtils::mix( focus, hover, opacity ); | | |||
391 | else color = KColorUtils::mix( color, hover, opacity ); | | |||
392 | | ||||
393 | } else if( mouseOver ) { | | |||
394 | | ||||
395 | color = hoverColor( palette ); | | |||
396 | | ||||
397 | } else if( active ) { | | |||
398 | | ||||
399 | color = focusColor( palette ); | | |||
400 | | ||||
401 | } | | |||
402 | | ||||
403 | return color; | | |||
404 | | ||||
405 | } | | |||
406 | | ||||
407 | //______________________________________________________________________________ | 188 | //______________________________________________________________________________ | ||
408 | QColor Helper::separatorColor( const QPalette& palette ) const | 189 | QColor Helper::separatorColor( const QPalette& palette ) const | ||
409 | { return KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ); } | 190 | { return KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ); } | ||
410 | 191 | | |||
411 | //______________________________________________________________________________ | 192 | //______________________________________________________________________________ | ||
412 | QPalette Helper::disabledPalette( const QPalette& source, qreal ratio ) const | 193 | QPalette Helper::disabledPalette( const QPalette& source, qreal ratio ) const | ||
413 | { | 194 | { | ||
414 | 195 | | |||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 280 | { | |||
522 | else painter->setBrush( Qt::NoBrush ); | 303 | else painter->setBrush( Qt::NoBrush ); | ||
523 | 304 | | |||
524 | // render | 305 | // render | ||
525 | painter->drawRoundedRect( frameRect, radius, radius ); | 306 | painter->drawRoundedRect( frameRect, radius, radius ); | ||
526 | 307 | | |||
527 | } | 308 | } | ||
528 | 309 | | |||
529 | //______________________________________________________________________________ | 310 | //______________________________________________________________________________ | ||
530 | void Helper::renderSidePanelFrame( QPainter* painter, const QRect& rect, const QColor& outline, Side side ) const | 311 | void Helper::renderSeparator( | ||
531 | { | | |||
532 | | ||||
533 | // check color | | |||
534 | if( !outline.isValid() ) return; | | |||
535 | | ||||
536 | // adjust rect | | |||
537 | QRectF frameRect( rect ); | | |||
538 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | | |||
539 | | ||||
540 | // setup painter | | |||
541 | painter->setRenderHint( QPainter::Antialiasing ); | | |||
542 | painter->setPen( outline ); | | |||
543 | | ||||
544 | // render | | |||
545 | switch( side ) | | |||
546 | { | | |||
547 | default: | | |||
548 | case SideLeft: | | |||
549 | painter->drawLine( frameRect.topRight(), frameRect.bottomRight() ); | | |||
550 | break; | | |||
551 | | ||||
552 | case SideTop: | | |||
553 | painter->drawLine( frameRect.topLeft(), frameRect.topRight() ); | | |||
554 | break; | | |||
555 | | ||||
556 | case SideRight: | | |||
557 | painter->drawLine( frameRect.topLeft(), frameRect.bottomLeft() ); | | |||
558 | break; | | |||
559 | | ||||
560 | case SideBottom: | | |||
561 | painter->drawLine( frameRect.bottomLeft(), frameRect.bottomRight() ); | | |||
562 | break; | | |||
563 | | ||||
564 | case AllSides: | | |||
565 | { | | |||
566 | const qreal radius( frameRadius( -1.0 ) ); | | |||
567 | painter->drawRoundedRect( frameRect, radius, radius ); | | |||
568 | break; | | |||
569 | } | | |||
570 | | ||||
571 | } | | |||
572 | | ||||
573 | } | | |||
574 | | ||||
575 | //______________________________________________________________________________ | | |||
576 | void Helper::renderMenuFrame( | | |||
577 | QPainter* painter, const QRect& rect, | 312 | QPainter* painter, const QRect& rect, | ||
578 | const QColor& color, const QColor& outline, bool roundCorners ) const | 313 | const QColor& color, bool vertical ) const | ||
579 | { | | |||
580 | | ||||
581 | | ||||
582 | // set brush | | |||
583 | if( color.isValid() ) painter->setBrush( color ); | | |||
584 | else painter->setBrush( Qt::NoBrush ); | | |||
585 | | ||||
586 | if( roundCorners ) | | |||
587 | { | 314 | { | ||
588 | 315 | | |||
589 | painter->setRenderHint( QPainter::Antialiasing ); | 316 | painter->setRenderHint( QPainter::Antialiasing, false ); | ||
590 | QRectF frameRect( rect ); | 317 | painter->setBrush( Qt::NoBrush ); | ||
591 | qreal radius( frameRadius() ); | 318 | painter->setPen( color ); | ||
592 | 319 | | |||
593 | // set pen | 320 | if( vertical ) | ||
594 | if( outline.isValid() ) | | |||
595 | { | 321 | { | ||
596 | 322 | | |||
597 | painter->setPen( outline ); | 323 | painter->translate( rect.width()/2, 0 ); | ||
598 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | 324 | painter->drawLine( rect.topLeft(), rect.bottomLeft() ); | ||
599 | radius = qMax( radius - 1, qreal( 0.0 ) ); | | |||
600 | | ||||
601 | } else painter->setPen( Qt::NoPen ); | | |||
602 | | ||||
603 | // render | | |||
604 | painter->drawRoundedRect( frameRect, radius, radius ); | | |||
605 | 325 | | |||
606 | } else { | 326 | } else { | ||
607 | 327 | | |||
608 | painter->setRenderHint( QPainter::Antialiasing, false ); | 328 | painter->translate( 0, rect.height()/2 ); | ||
609 | QRect frameRect( rect ); | 329 | painter->drawLine( rect.topLeft(), rect.topRight() ); | ||
610 | if( outline.isValid() ) | | |||
611 | { | | |||
612 | | ||||
613 | painter->setPen( outline ); | | |||
614 | frameRect.adjust( 0, 0, -1, -1 ); | | |||
615 | | ||||
616 | } else painter->setPen( Qt::NoPen ); | | |||
617 | | ||||
618 | painter->drawRect( frameRect ); | | |||
619 | 330 | | |||
620 | } | | |||
621 | 331 | | |||
622 | } | 332 | } | ||
623 | 333 | | |||
624 | //______________________________________________________________________________ | | |||
625 | void Helper::renderButtonFrame( | | |||
626 | QPainter* painter, const QRect& rect, | | |||
627 | const QColor& color, const QColor& outline, const QColor& shadow, | | |||
628 | bool hasFocus, bool sunken ) const | | |||
629 | { | | |||
630 | | ||||
631 | // setup painter | | |||
632 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
633 | | ||||
634 | // copy rect | | |||
635 | QRectF frameRect( rect ); | | |||
636 | frameRect.adjust( 1, 1, -1, -1 ); | | |||
637 | qreal radius( frameRadius() ); | | |||
638 | | ||||
639 | // shadow | | |||
640 | if( sunken ) { | | |||
641 | | ||||
642 | frameRect.translate( 1, 1 ); | | |||
643 | | ||||
644 | } else if( shadow.isValid() ) { | | |||
645 | | ||||
646 | const qreal shadowRadius = qMax( radius - 1, qreal( 0.0 ) ); | | |||
647 | painter->setPen( QPen( shadow, 2 ) ); | | |||
648 | painter->setBrush( Qt::NoBrush ); | | |||
649 | painter->drawRoundedRect( shadowRect( frameRect ), shadowRadius, shadowRadius ); | | |||
650 | 334 | | |||
651 | } | 335 | } | ||
652 | 336 | | |||
653 | if( outline.isValid() ) | 337 | //______________________________________________________________________________ | ||
338 | void Helper::renderArrow( QPainter* painter, const QRect& rect, const QColor& color, ArrowOrientation orientation ) const | ||||
654 | { | 339 | { | ||
655 | 340 | // define polygon | |||
656 | QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); | 341 | QPolygonF arrow; | ||
657 | gradient.setColorAt( 0, outline.lighter( hasFocus ? 103:101 ) ); | 342 | switch( orientation ) | ||
658 | gradient.setColorAt( 1, outline.darker( hasFocus ? 110:103 ) ); | | |||
659 | painter->setPen( QPen( QBrush( gradient ), 1.0 ) ); | | |||
660 | | ||||
661 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | | |||
662 | radius = qMax( radius - 1, qreal( 0.0 ) ); | | |||
663 | | ||||
664 | } else painter->setPen( Qt::NoPen ); | | |||
665 | | ||||
666 | // content | | |||
667 | if( color.isValid() ) | | |||
668 | { | 343 | { | ||
669 | 344 | case ArrowUp: arrow = QVector<QPointF>{QPointF( -4, 2 ), QPointF( 0, -2 ), QPointF( 4, 2 )}; break; | |||
670 | QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); | 345 | case ArrowDown: arrow = QVector<QPointF>{QPointF( -4, -2 ), QPointF( 0, 2 ), QPointF( 4, -2 )}; break; | ||
671 | gradient.setColorAt( 0, color.lighter( hasFocus ? 103:101 ) ); | 346 | case ArrowLeft: arrow = QVector<QPointF>{QPointF( 2, -4 ), QPointF( -2, 0 ), QPointF( 2, 4 )}; break; | ||
672 | gradient.setColorAt( 1, color.darker( hasFocus ? 110:103 ) ); | 347 | case ArrowRight: arrow = QVector<QPointF>{QPointF( -2, -4 ), QPointF( 2, 0 ), QPointF( -2, 4 )}; break; | ||
673 | painter->setBrush( gradient ); | 348 | default: break; | ||
674 | | ||||
675 | } else painter->setBrush( Qt::NoBrush ); | | |||
676 | | ||||
677 | // render | | |||
678 | painter->drawRoundedRect( frameRect, radius, radius ); | | |||
679 | | ||||
680 | } | | |||
681 | | ||||
682 | //______________________________________________________________________________ | | |||
683 | void Helper::renderToolButtonFrame( | | |||
684 | QPainter* painter, const QRect& rect, | | |||
685 | const QColor& color, bool sunken ) const | | |||
686 | { | | |||
687 | | ||||
688 | // do nothing for invalid color | | |||
689 | if( !color.isValid() ) return; | | |||
690 | | ||||
691 | // setup painter | | |||
692 | painter->setRenderHints( QPainter::Antialiasing ); | | |||
693 | | ||||
694 | const QRectF baseRect( rect ); | | |||
695 | | ||||
696 | if( sunken ) | | |||
697 | { | | |||
698 | | ||||
699 | const qreal radius( frameRadius() ); | | |||
700 | | ||||
701 | painter->setPen( Qt::NoPen ); | | |||
702 | painter->setBrush( color ); | | |||
703 | | ||||
704 | const QRectF contentRect( baseRect.adjusted( 1, 1, -1, -1 ) ); | | |||
705 | painter->drawRoundedRect( contentRect, radius, radius ); | | |||
706 | | ||||
707 | } else { | | |||
708 | | ||||
709 | const qreal radius( frameRadius(-0.5) ); | | |||
710 | | ||||
711 | painter->setPen( color ); | | |||
712 | painter->setBrush( Qt::NoBrush ); | | |||
713 | const QRectF outlineRect( baseRect.adjusted( 1.5, 1.5, -1.5, -1.5 ) ); | | |||
714 | painter->drawRoundedRect( outlineRect, radius, radius ); | | |||
715 | | ||||
716 | } | | |||
717 | | ||||
718 | } | | |||
719 | | ||||
720 | //______________________________________________________________________________ | | |||
721 | void Helper::renderToolBoxFrame( | | |||
722 | QPainter* painter, const QRect& rect, int tabWidth, | | |||
723 | const QColor& outline ) const | | |||
724 | { | | |||
725 | | ||||
726 | if( !outline.isValid() ) return; | | |||
727 | | ||||
728 | // round radius | | |||
729 | const qreal radius( frameRadius() ); | | |||
730 | const QSizeF cornerSize( 2*radius, 2*radius ); | | |||
731 | | ||||
732 | // if rect - tabwidth is even, need to increase tabWidth by 1 unit | | |||
733 | // for anti aliasing | | |||
734 | if( !((rect.width() - tabWidth)%2) ) ++tabWidth; | | |||
735 | | ||||
736 | // adjust rect for antialiasing | | |||
737 | QRectF baseRect( rect ); | | |||
738 | baseRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | | |||
739 | | ||||
740 | // create path | | |||
741 | QPainterPath path; | | |||
742 | path.moveTo( 0, baseRect.height()-1 ); | | |||
743 | path.lineTo( ( baseRect.width() - tabWidth )/2 - radius, baseRect.height()-1 ); | | |||
744 | path.arcTo( QRectF( QPointF( ( baseRect.width() - tabWidth )/2 - 2*radius, baseRect.height()-1 - 2*radius ), cornerSize ), 270, 90 ); | | |||
745 | path.lineTo( ( baseRect.width() - tabWidth )/2, radius ); | | |||
746 | path.arcTo( QRectF( QPointF( ( baseRect.width() - tabWidth )/2, 0 ), cornerSize ), 180, -90 ); | | |||
747 | path.lineTo( ( baseRect.width() + tabWidth )/2 -1 - radius, 0 ); | | |||
748 | path.arcTo( QRectF( QPointF( ( baseRect.width() + tabWidth )/2 - 1 - 2*radius, 0 ), cornerSize ), 90, -90 ); | | |||
749 | path.lineTo( ( baseRect.width() + tabWidth )/2 -1, baseRect.height()-1 - radius ); | | |||
750 | path.arcTo( QRectF( QPointF( ( baseRect.width() + tabWidth )/2 -1, baseRect.height()-1 - 2*radius ), cornerSize ), 180, 90 ); | | |||
751 | path.lineTo( baseRect.width()-1, baseRect.height()-1 ); | | |||
752 | | ||||
753 | // render | | |||
754 | painter->setRenderHints( QPainter::Antialiasing ); | | |||
755 | painter->setBrush( Qt::NoBrush ); | | |||
756 | painter->setPen( outline ); | | |||
757 | painter->translate( baseRect.topLeft() ); | | |||
758 | painter->drawPath( path ); | | |||
759 | | ||||
760 | } | | |||
761 | | ||||
762 | //______________________________________________________________________________ | | |||
763 | void Helper::renderTabWidgetFrame( | | |||
764 | QPainter* painter, const QRect& rect, | | |||
765 | const QColor& color, const QColor& outline, Corners corners ) const | | |||
766 | { | | |||
767 | | ||||
768 | painter->setRenderHint( QPainter::Antialiasing ); | | |||
769 | | ||||
770 | QRectF frameRect( rect.adjusted( 1, 1, -1, -1 ) ); | | |||
771 | qreal radius( frameRadius() ); | | |||
772 | | ||||
773 | // set pen | | |||
774 | if( outline.isValid() ) | | |||
775 | { | | |||
776 | | ||||
777 | painter->setPen( outline ); | | |||
778 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | | |||
779 | radius = qMax( radius-1, qreal( 0.0 ) ); | | |||
780 | | ||||
781 | } else painter->setPen( Qt::NoPen ); | | |||
782 | | ||||
783 | // set brush | | |||
784 | if( color.isValid() ) painter->setBrush( color ); | | |||
785 | else painter->setBrush( Qt::NoBrush ); | | |||
786 | | ||||
787 | // render | | |||
788 | QPainterPath path( roundedPath( frameRect, corners, radius ) ); | | |||
789 | painter->drawPath( path ); | | |||
790 | | ||||
791 | } | | |||
792 | | ||||
793 | | ||||
794 | //______________________________________________________________________________ | | |||
795 | void Helper::renderSelection( | | |||
796 | QPainter* painter, const QRect& rect, | | |||
797 | const QColor& color ) const | | |||
798 | { | | |||
799 | | ||||
800 | painter->setRenderHint( QPainter::Antialiasing ); | | |||
801 | painter->setPen( Qt::NoPen ); | | |||
802 | painter->setBrush( color ); | | |||
803 | painter->drawRect( rect ); | | |||
804 | | ||||
805 | } | | |||
806 | | ||||
807 | //______________________________________________________________________________ | | |||
808 | void Helper::renderSeparator( | | |||
809 | QPainter* painter, const QRect& rect, | | |||
810 | const QColor& color, bool vertical ) const | | |||
811 | { | | |||
812 | | ||||
813 | painter->setRenderHint( QPainter::Antialiasing, false ); | | |||
814 | painter->setBrush( Qt::NoBrush ); | | |||
815 | painter->setPen( color ); | | |||
816 | | ||||
817 | if( vertical ) | | |||
818 | { | | |||
819 | | ||||
820 | painter->translate( rect.width()/2, 0 ); | | |||
821 | painter->drawLine( rect.topLeft(), rect.bottomLeft() ); | | |||
822 | | ||||
823 | } else { | | |||
824 | | ||||
825 | painter->translate( 0, rect.height()/2 ); | | |||
826 | painter->drawLine( rect.topLeft(), rect.topRight() ); | | |||
827 | | ||||
828 | | ||||
829 | } | | |||
830 | | ||||
831 | | ||||
832 | } | | |||
833 | | ||||
834 | //______________________________________________________________________________ | | |||
835 | void Helper::renderCheckBoxBackground( | | |||
836 | QPainter* painter, const QRect& rect, | | |||
837 | const QColor& color, bool sunken ) const | | |||
838 | { | | |||
839 | | ||||
840 | // setup painter | | |||
841 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
842 | | ||||
843 | // copy rect and radius | | |||
844 | QRectF frameRect( rect ); | | |||
845 | frameRect.adjust( 3, 3, -3, -3 ); | | |||
846 | | ||||
847 | if( sunken ) frameRect.translate(1, 1); | | |||
848 | | ||||
849 | painter->setPen( Qt::NoPen ); | | |||
850 | painter->setBrush( color ); | | |||
851 | painter->drawRect( frameRect ); | | |||
852 | | ||||
853 | } | | |||
854 | | ||||
855 | //______________________________________________________________________________ | | |||
856 | void Helper::renderCheckBox( | | |||
857 | QPainter* painter, const QRect& rect, | | |||
858 | const QColor& color, const QColor& shadow, | | |||
859 | bool sunken, CheckBoxState state, qreal animation ) const | | |||
860 | { | | |||
861 | | ||||
862 | // setup painter | | |||
863 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
864 | | ||||
865 | // copy rect and radius | | |||
866 | QRectF frameRect( rect ); | | |||
867 | frameRect.adjust( 2, 2, -2, -2 ); | | |||
868 | qreal radius( frameRadius() ); | | |||
869 | | ||||
870 | // shadow | | |||
871 | if( sunken ) | | |||
872 | { | | |||
873 | | ||||
874 | frameRect.translate(1, 1); | | |||
875 | | ||||
876 | } else { | | |||
877 | | ||||
878 | painter->setPen( QPen( shadow, 1 ) ); | | |||
879 | painter->setBrush( Qt::NoBrush ); | | |||
880 | | ||||
881 | const qreal shadowRadius( radius + 0.5 ); | | |||
882 | painter->drawRoundedRect( shadowRect( frameRect ).adjusted( -0.5, -0.5, 0.5, 0.5 ), shadowRadius, shadowRadius ); | | |||
883 | | ||||
884 | } | | |||
885 | | ||||
886 | // content | | |||
887 | { | | |||
888 | | ||||
889 | painter->setPen( QPen( color, 1 ) ); | | |||
890 | painter->setBrush( Qt::NoBrush ); | | |||
891 | | ||||
892 | radius = qMax( radius-1, qreal( 0.0 ) ); | | |||
893 | const QRectF contentRect( frameRect.adjusted( 0.5, 0.5, -0.5, -0.5 ) ); | | |||
894 | painter->drawRoundedRect( contentRect, radius, radius ); | | |||
895 | | ||||
896 | } | | |||
897 | | ||||
898 | // mark | | |||
899 | if( state == CheckOn ) | | |||
900 | { | | |||
901 | | ||||
902 | painter->setBrush( color ); | | |||
903 | painter->setPen( Qt::NoPen ); | | |||
904 | | ||||
905 | const QRectF markerRect( frameRect.adjusted( 3, 3, -3, -3 ) ); | | |||
906 | painter->drawRect( markerRect ); | | |||
907 | | ||||
908 | } else if( state == CheckPartial ) { | | |||
909 | | ||||
910 | QPen pen( color, 2 ); | | |||
911 | pen.setJoinStyle( Qt::MiterJoin ); | | |||
912 | painter->setPen( pen ); | | |||
913 | | ||||
914 | const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) ); | | |||
915 | painter->drawRect( markerRect ); | | |||
916 | | ||||
917 | painter->setPen( Qt::NoPen ); | | |||
918 | painter->setBrush( color ); | | |||
919 | painter->setRenderHint( QPainter::Antialiasing, false ); | | |||
920 | | ||||
921 | QPainterPath path; | | |||
922 | path.moveTo( markerRect.topLeft() ); | | |||
923 | path.lineTo( markerRect.right() - 1, markerRect.top() ); | | |||
924 | path.lineTo( markerRect.left(), markerRect.bottom()-1 ); | | |||
925 | painter->drawPath( path ); | | |||
926 | | ||||
927 | } else if( state == CheckAnimated ) { | | |||
928 | | ||||
929 | const QRectF markerRect( frameRect.adjusted( 3, 3, -3, -3 ) ); | | |||
930 | QPainterPath path; | | |||
931 | path.moveTo( markerRect.topRight() ); | | |||
932 | path.lineTo( markerRect.center() + animation*( markerRect.topLeft() - markerRect.center() ) ); | | |||
933 | path.lineTo( markerRect.bottomLeft() ); | | |||
934 | path.lineTo( markerRect.center() + animation*( markerRect.bottomRight() - markerRect.center() ) ); | | |||
935 | path.closeSubpath(); | | |||
936 | | ||||
937 | painter->setBrush( color ); | | |||
938 | painter->setPen( Qt::NoPen ); | | |||
939 | painter->drawPath( path ); | | |||
940 | | ||||
941 | } | | |||
942 | | ||||
943 | } | | |||
944 | | ||||
945 | //______________________________________________________________________________ | | |||
946 | void Helper::renderRadioButtonBackground( QPainter* painter, const QRect& rect, const QColor& color, bool sunken ) const | | |||
947 | { | | |||
948 | | ||||
949 | // setup painter | | |||
950 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
951 | | ||||
952 | // copy rect | | |||
953 | QRectF frameRect( rect ); | | |||
954 | frameRect.adjust( 3, 3, -3, -3 ); | | |||
955 | if( sunken ) frameRect.translate(1, 1); | | |||
956 | | ||||
957 | painter->setPen( Qt::NoPen ); | | |||
958 | painter->setBrush( color ); | | |||
959 | painter->drawEllipse( frameRect ); | | |||
960 | | ||||
961 | } | | |||
962 | | ||||
963 | //______________________________________________________________________________ | | |||
964 | void Helper::renderRadioButton( | | |||
965 | QPainter* painter, const QRect& rect, | | |||
966 | const QColor& color, const QColor& shadow, | | |||
967 | bool sunken, RadioButtonState state, qreal animation ) const | | |||
968 | { | | |||
969 | | ||||
970 | // setup painter | | |||
971 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
972 | | ||||
973 | // copy rect | | |||
974 | QRectF frameRect( rect ); | | |||
975 | frameRect.adjust( 2, 2, -2, -2 ); | | |||
976 | | ||||
977 | // shadow | | |||
978 | if( sunken ) | | |||
979 | { | | |||
980 | | ||||
981 | frameRect.translate( 1, 1 ); | | |||
982 | | ||||
983 | } else { | | |||
984 | | ||||
985 | painter->setPen( QPen( shadow, 1 ) ); | | |||
986 | painter->setBrush( Qt::NoBrush ); | | |||
987 | painter->drawEllipse( shadowRect( frameRect ).adjusted( -0.5, -0.5, 0.5, 0.5 ) ); | | |||
988 | | ||||
989 | } | | |||
990 | | ||||
991 | // content | | |||
992 | { | | |||
993 | | ||||
994 | painter->setPen( QPen( color, 1 ) ); | | |||
995 | painter->setBrush( Qt::NoBrush ); | | |||
996 | | ||||
997 | const QRectF contentRect( frameRect.adjusted( 0.5, 0.5, -0.5, -0.5 ) ); | | |||
998 | painter->drawEllipse( contentRect ); | | |||
999 | | ||||
1000 | } | | |||
1001 | | ||||
1002 | // mark | | |||
1003 | if( state == RadioOn ) | | |||
1004 | { | | |||
1005 | | ||||
1006 | painter->setBrush( color ); | | |||
1007 | painter->setPen( Qt::NoPen ); | | |||
1008 | | ||||
1009 | const QRectF markerRect( frameRect.adjusted( 3, 3, -3, -3 ) ); | | |||
1010 | painter->drawEllipse( markerRect ); | | |||
1011 | | ||||
1012 | } else if( state == RadioAnimated ) { | | |||
1013 | | ||||
1014 | painter->setBrush( color ); | | |||
1015 | painter->setPen( Qt::NoPen ); | | |||
1016 | QRectF markerRect( frameRect.adjusted( 3, 3, -3, -3 ) ); | | |||
1017 | | ||||
1018 | painter->translate( markerRect.center() ); | | |||
1019 | painter->rotate( 45 ); | | |||
1020 | | ||||
1021 | markerRect.setWidth( markerRect.width()*animation ); | | |||
1022 | markerRect.translate( -markerRect.center() ); | | |||
1023 | painter->drawEllipse( markerRect ); | | |||
1024 | | ||||
1025 | } | | |||
1026 | | ||||
1027 | } | | |||
1028 | | ||||
1029 | //______________________________________________________________________________ | | |||
1030 | void Helper::renderSliderGroove( | | |||
1031 | QPainter* painter, const QRect& rect, | | |||
1032 | const QColor& color ) const | | |||
1033 | { | | |||
1034 | | ||||
1035 | // setup painter | | |||
1036 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1037 | | ||||
1038 | const QRectF baseRect( rect ); | | |||
1039 | const qreal radius( 0.5*Metrics::Slider_GrooveThickness ); | | |||
1040 | | ||||
1041 | // content | | |||
1042 | if( color.isValid() ) | | |||
1043 | { | | |||
1044 | painter->setPen( Qt::NoPen ); | | |||
1045 | painter->setBrush( color ); | | |||
1046 | painter->drawRoundedRect( baseRect, radius, radius ); | | |||
1047 | } | | |||
1048 | | ||||
1049 | | ||||
1050 | } | | |||
1051 | | ||||
1052 | //______________________________________________________________________________ | | |||
1053 | void Helper::renderDialGroove( | | |||
1054 | QPainter* painter, const QRect& rect, | | |||
1055 | const QColor& color, | | |||
1056 | qreal first, qreal last ) const | | |||
1057 | { | | |||
1058 | | ||||
1059 | // setup painter | | |||
1060 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1061 | | ||||
1062 | const QRectF baseRect( rect ); | | |||
1063 | | ||||
1064 | // content | | |||
1065 | if( color.isValid() ) | | |||
1066 | { | | |||
1067 | const qreal penWidth( Metrics::Slider_GrooveThickness ); | | |||
1068 | const QRectF grooveRect( rect.adjusted( penWidth/2, penWidth/2, -penWidth/2, -penWidth/2 ) ); | | |||
1069 | | ||||
1070 | // setup angles | | |||
1071 | const int angleStart( first * 180 * 16 / M_PI ); | | |||
1072 | const int angleSpan( (last - first ) * 180 * 16 / M_PI ); | | |||
1073 | | ||||
1074 | // setup pen | | |||
1075 | if( angleSpan != 0 ) | | |||
1076 | { | | |||
1077 | QPen pen( color, penWidth ); | | |||
1078 | pen.setCapStyle( Qt::RoundCap ); | | |||
1079 | painter->setPen( pen ); | | |||
1080 | painter->setBrush( Qt::NoBrush ); | | |||
1081 | painter->drawArc( grooveRect, angleStart, angleSpan ); | | |||
1082 | } | | |||
1083 | } | | |||
1084 | | ||||
1085 | | ||||
1086 | } | | |||
1087 | | ||||
1088 | //______________________________________________________________________________ | | |||
1089 | void Helper::renderDialContents( | | |||
1090 | QPainter* painter, const QRect& rect, | | |||
1091 | const QColor& color, | | |||
1092 | qreal first, qreal second ) const | | |||
1093 | { | | |||
1094 | | ||||
1095 | // setup painter | | |||
1096 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1097 | | ||||
1098 | const QRectF baseRect( rect ); | | |||
1099 | | ||||
1100 | // content | | |||
1101 | if( color.isValid() ) | | |||
1102 | { | | |||
1103 | | ||||
1104 | // setup groove rect | | |||
1105 | const qreal penWidth( Metrics::Slider_GrooveThickness ); | | |||
1106 | const QRectF grooveRect( rect.adjusted( penWidth/2, penWidth/2, -penWidth/2, -penWidth/2 ) ); | | |||
1107 | | ||||
1108 | // setup angles | | |||
1109 | const int angleStart( first * 180 * 16 / M_PI ); | | |||
1110 | const int angleSpan( (second - first ) * 180 * 16 / M_PI ); | | |||
1111 | | ||||
1112 | // setup pen | | |||
1113 | if( angleSpan != 0 ) | | |||
1114 | { | | |||
1115 | QPen pen( color, penWidth ); | | |||
1116 | pen.setCapStyle( Qt::RoundCap ); | | |||
1117 | painter->setPen( pen ); | | |||
1118 | painter->setBrush( Qt::NoBrush ); | | |||
1119 | painter->drawArc( grooveRect, angleStart, angleSpan ); | | |||
1120 | } | | |||
1121 | | ||||
1122 | } | | |||
1123 | | ||||
1124 | | ||||
1125 | } | | |||
1126 | | ||||
1127 | //______________________________________________________________________________ | | |||
1128 | void Helper::renderSliderHandle( | | |||
1129 | QPainter* painter, const QRect& rect, | | |||
1130 | const QColor& color, | | |||
1131 | const QColor& outline, | | |||
1132 | const QColor& shadow, | | |||
1133 | bool sunken ) const | | |||
1134 | { | | |||
1135 | | ||||
1136 | // setup painter | | |||
1137 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1138 | | ||||
1139 | // copy rect | | |||
1140 | QRectF frameRect( rect ); | | |||
1141 | frameRect.adjust( 1, 1, -1, -1 ); | | |||
1142 | | ||||
1143 | // shadow | | |||
1144 | if( shadow.isValid() && !sunken ) | | |||
1145 | { | | |||
1146 | | ||||
1147 | painter->setPen( QPen( shadow, 2 ) ); | | |||
1148 | painter->setBrush( Qt::NoBrush ); | | |||
1149 | painter->drawEllipse( shadowRect( frameRect ) ); | | |||
1150 | | ||||
1151 | } | | |||
1152 | | ||||
1153 | // set pen | | |||
1154 | if( outline.isValid() ) | | |||
1155 | { | | |||
1156 | | ||||
1157 | painter->setPen( outline ); | | |||
1158 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | | |||
1159 | | ||||
1160 | } else painter->setPen( Qt::NoPen ); | | |||
1161 | | ||||
1162 | // set brush | | |||
1163 | if( color.isValid() ) painter->setBrush( color ); | | |||
1164 | else painter->setBrush( Qt::NoBrush ); | | |||
1165 | | ||||
1166 | // render | | |||
1167 | painter->drawEllipse( frameRect ); | | |||
1168 | | ||||
1169 | } | | |||
1170 | | ||||
1171 | //______________________________________________________________________________ | | |||
1172 | void Helper::renderProgressBarGroove( | | |||
1173 | QPainter* painter, const QRect& rect, | | |||
1174 | const QColor& color ) const | | |||
1175 | { | | |||
1176 | | ||||
1177 | // setup painter | | |||
1178 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1179 | | ||||
1180 | const QRectF baseRect( rect ); | | |||
1181 | const qreal radius( 0.5*Metrics::ProgressBar_Thickness ); | | |||
1182 | | ||||
1183 | // content | | |||
1184 | if( color.isValid() ) | | |||
1185 | { | | |||
1186 | painter->setPen( Qt::NoPen ); | | |||
1187 | painter->setBrush( color ); | | |||
1188 | painter->drawRoundedRect( baseRect, radius, radius ); | | |||
1189 | } | | |||
1190 | | ||||
1191 | | ||||
1192 | } | | |||
1193 | | ||||
1194 | | ||||
1195 | //______________________________________________________________________________ | | |||
1196 | void Helper::renderProgressBarBusyContents( | | |||
1197 | QPainter* painter, const QRect& rect, | | |||
1198 | const QColor& first, | | |||
1199 | const QColor& second, | | |||
1200 | bool horizontal, | | |||
1201 | bool reverse, | | |||
1202 | int progress | | |||
1203 | ) const | | |||
1204 | { | | |||
1205 | | ||||
1206 | // setup painter | | |||
1207 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1208 | | ||||
1209 | const QRectF baseRect( rect ); | | |||
1210 | const qreal radius( 0.5*Metrics::ProgressBar_Thickness ); | | |||
1211 | | ||||
1212 | // setup brush | | |||
1213 | QPixmap pixmap( horizontal ? 2*Metrics::ProgressBar_BusyIndicatorSize : 1, horizontal ? 1:2*Metrics::ProgressBar_BusyIndicatorSize ); | | |||
1214 | pixmap.fill( second ); | | |||
1215 | if( horizontal ) | | |||
1216 | { | | |||
1217 | | ||||
1218 | QPainter painter( &pixmap ); | | |||
1219 | painter.setBrush( first ); | | |||
1220 | painter.setPen( Qt::NoPen ); | | |||
1221 | | ||||
1222 | progress %= 2*Metrics::ProgressBar_BusyIndicatorSize; | | |||
1223 | if( reverse ) progress = 2*Metrics::ProgressBar_BusyIndicatorSize - progress - 1; | | |||
1224 | painter.drawRect( QRect( 0, 0, Metrics::ProgressBar_BusyIndicatorSize, 1 ).translated( progress, 0 ) ); | | |||
1225 | | ||||
1226 | if( progress > Metrics::ProgressBar_BusyIndicatorSize ) | | |||
1227 | { painter.drawRect( QRect( 0, 0, Metrics::ProgressBar_BusyIndicatorSize, 1 ).translated( progress - 2*Metrics::ProgressBar_BusyIndicatorSize, 0 ) ); } | | |||
1228 | | ||||
1229 | } else { | | |||
1230 | | ||||
1231 | QPainter painter( &pixmap ); | | |||
1232 | painter.setBrush( first ); | | |||
1233 | painter.setPen( Qt::NoPen ); | | |||
1234 | | ||||
1235 | progress %= 2*Metrics::ProgressBar_BusyIndicatorSize; | | |||
1236 | progress = 2*Metrics::ProgressBar_BusyIndicatorSize - progress - 1; | | |||
1237 | painter.drawRect( QRect( 0, 0, 1, Metrics::ProgressBar_BusyIndicatorSize ).translated( 0, progress ) ); | | |||
1238 | | ||||
1239 | if( progress > Metrics::ProgressBar_BusyIndicatorSize ) | | |||
1240 | { painter.drawRect( QRect( 0, 0, 1, Metrics::ProgressBar_BusyIndicatorSize ).translated( 0, progress - 2*Metrics::ProgressBar_BusyIndicatorSize ) ); } | | |||
1241 | | ||||
1242 | } | | |||
1243 | | ||||
1244 | painter->setPen( Qt::NoPen ); | | |||
1245 | painter->setBrush( pixmap ); | | |||
1246 | painter->drawRoundedRect( baseRect, radius, radius ); | | |||
1247 | | ||||
1248 | } | | |||
1249 | | ||||
1250 | //______________________________________________________________________________ | | |||
1251 | void Helper::renderScrollBarHandle( | | |||
1252 | QPainter* painter, const QRect& rect, | | |||
1253 | const QColor& color ) const | | |||
1254 | { | | |||
1255 | | ||||
1256 | // setup painter | | |||
1257 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1258 | | ||||
1259 | const QRectF baseRect( rect ); | | |||
1260 | const qreal radius( 0.5 * std::min({baseRect.width(), baseRect.height(), (qreal)Metrics::ScrollBar_SliderWidth}) ); | | |||
1261 | | ||||
1262 | // content | | |||
1263 | if( color.isValid() ) | | |||
1264 | { | | |||
1265 | painter->setPen( Qt::NoPen ); | | |||
1266 | painter->setBrush( color ); | | |||
1267 | painter->drawRoundedRect( baseRect, radius, radius ); | | |||
1268 | } | | |||
1269 | | ||||
1270 | | ||||
1271 | } | | |||
1272 | | ||||
1273 | //______________________________________________________________________________ | | |||
1274 | void Helper::renderTabBarTab( QPainter* painter, const QRect& rect, const QColor& color, const QColor& outline, Corners corners ) const | | |||
1275 | { | | |||
1276 | | ||||
1277 | // setup painter | | |||
1278 | painter->setRenderHint( QPainter::Antialiasing, true ); | | |||
1279 | | ||||
1280 | QRectF frameRect( rect ); | | |||
1281 | qreal radius( frameRadius() ); | | |||
1282 | | ||||
1283 | // pen | | |||
1284 | if( outline.isValid() ) | | |||
1285 | { | | |||
1286 | | ||||
1287 | painter->setPen( outline ); | | |||
1288 | frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); | | |||
1289 | radius = qMax( radius-1, qreal( 0.0 ) ); | | |||
1290 | | ||||
1291 | } else painter->setPen( Qt::NoPen ); | | |||
1292 | | ||||
1293 | | ||||
1294 | // brush | | |||
1295 | if( color.isValid() ) painter->setBrush( color ); | | |||
1296 | else painter->setBrush( Qt::NoBrush ); | | |||
1297 | | ||||
1298 | // render | | |||
1299 | QPainterPath path( roundedPath( frameRect, corners, radius ) ); | | |||
1300 | painter->drawPath( path ); | | |||
1301 | | ||||
1302 | } | | |||
1303 | | ||||
1304 | //______________________________________________________________________________ | | |||
1305 | void Helper::renderArrow( QPainter* painter, const QRect& rect, const QColor& color, ArrowOrientation orientation ) const | | |||
1306 | { | | |||
1307 | // define polygon | | |||
1308 | QPolygonF arrow; | | |||
1309 | switch( orientation ) | | |||
1310 | { | | |||
1311 | case ArrowUp: arrow = QVector<QPointF>{QPointF( -4, 2 ), QPointF( 0, -2 ), QPointF( 4, 2 )}; break; | | |||
1312 | case ArrowDown: arrow = QVector<QPointF>{QPointF( -4, -2 ), QPointF( 0, 2 ), QPointF( 4, -2 )}; break; | | |||
1313 | case ArrowLeft: arrow = QVector<QPointF>{QPointF( 2, -4 ), QPointF( -2, 0 ), QPointF( 2, 4 )}; break; | | |||
1314 | case ArrowRight: arrow = QVector<QPointF>{QPointF( -2, -4 ), QPointF( 2, 0 ), QPointF( -2, 4 )}; break; | | |||
1315 | default: break; | | |||
1316 | } | 349 | } | ||
1317 | 350 | | |||
1318 | painter->save(); | 351 | painter->save(); | ||
1319 | painter->setRenderHints( QPainter::Antialiasing ); | 352 | painter->setRenderHints( QPainter::Antialiasing ); | ||
1320 | painter->translate( QRectF( rect ).center() ); | 353 | painter->translate( QRectF( rect ).center() ); | ||
1321 | painter->setBrush( Qt::NoBrush ); | 354 | painter->setBrush( Qt::NoBrush ); | ||
1322 | painter->setPen( QPen( color, 1.1 ) ); | 355 | painter->setPen( QPen( color, 1.1 ) ); | ||
1323 | painter->drawPolyline( arrow ); | 356 | painter->drawPolyline( arrow ); | ||
1324 | painter->restore(); | 357 | painter->restore(); | ||
1325 | } | 358 | } | ||
1326 | 359 | | |||
1327 | //______________________________________________________________________________ | 360 | //______________________________________________________________________________ | ||
1328 | void Helper::renderDecorationButton( QPainter* painter, const QRect& rect, const QColor& color, ButtonType buttonType, bool inverted ) const | | |||
1329 | { | | |||
1330 | | ||||
1331 | painter->save(); | | |||
1332 | painter->setViewport( rect ); | | |||
1333 | painter->setWindow( 0, 0, 18, 18 ); | | |||
1334 | painter->setRenderHints( QPainter::Antialiasing ); | | |||
1335 | | ||||
1336 | // initialize pen | | |||
1337 | QPen pen; | | |||
1338 | pen.setCapStyle( Qt::RoundCap ); | | |||
1339 | pen.setJoinStyle( Qt::MiterJoin ); | | |||
1340 | | ||||
1341 | if( inverted ) | | |||
1342 | { | | |||
1343 | // render circle | | |||
1344 | painter->setPen( Qt::NoPen ); | | |||
1345 | painter->setBrush( color ); | | |||
1346 | painter->drawEllipse( QRectF( 0, 0, 18, 18 ) ); | | |||
1347 | | ||||
1348 | // take out the inner part | | |||
1349 | painter->setCompositionMode( QPainter::CompositionMode_DestinationOut ); | | |||
1350 | painter->setBrush( Qt::NoBrush ); | | |||
1351 | pen.setColor( Qt::black ); | | |||
1352 | | ||||
1353 | } else { | | |||
1354 | | ||||
1355 | painter->setBrush( Qt::NoBrush ); | | |||
1356 | pen.setColor( color ); | | |||
1357 | | ||||
1358 | } | | |||
1359 | | ||||
1360 | pen.setCapStyle( Qt::RoundCap ); | | |||
1361 | pen.setJoinStyle( Qt::MiterJoin ); | | |||
1362 | pen.setWidthF( 1.1*qMax(1.0, 18.0/rect.width() ) ); | | |||
1363 | painter->setPen( pen ); | | |||
1364 | | ||||
1365 | switch( buttonType ) | | |||
1366 | { | | |||
1367 | case ButtonClose: | | |||
1368 | { | | |||
1369 | painter->drawLine( QPointF( 5, 5 ), QPointF( 13, 13 ) ); | | |||
1370 | painter->drawLine( 13, 5, 5, 13 ); | | |||
1371 | break; | | |||
1372 | } | | |||
1373 | | ||||
1374 | case ButtonMaximize: | | |||
1375 | { | | |||
1376 | painter->drawPolyline( QVector<QPointF>{ | | |||
1377 | QPointF( 4, 11 ), | | |||
1378 | QPointF( 9, 6 ), | | |||
1379 | QPointF( 14, 11 )}); | | |||
1380 | break; | | |||
1381 | } | | |||
1382 | | ||||
1383 | case ButtonMinimize: | | |||
1384 | { | | |||
1385 | | ||||
1386 | painter->drawPolyline(QVector<QPointF>{ | | |||
1387 | QPointF( 4, 7 ), | | |||
1388 | QPointF( 9, 12 ), | | |||
1389 | QPointF( 14, 7 )} ); | | |||
1390 | break; | | |||
1391 | } | | |||
1392 | | ||||
1393 | case ButtonRestore: | | |||
1394 | { | | |||
1395 | pen.setJoinStyle( Qt::RoundJoin ); | | |||
1396 | painter->setPen( pen ); | | |||
1397 | painter->drawPolygon( QVector<QPointF>{ | | |||
1398 | QPointF( 4.5, 9 ), | | |||
1399 | QPointF( 9, 4.5 ), | | |||
1400 | QPointF( 13.5, 9 ), | | |||
1401 | QPointF( 9, 13.5 )}); | | |||
1402 | break; | | |||
1403 | } | | |||
1404 | | ||||
1405 | default: break; | | |||
1406 | } | | |||
1407 | | ||||
1408 | painter->restore(); | | |||
1409 | | ||||
1410 | } | | |||
1411 | | ||||
1412 | //______________________________________________________________________________ | | |||
1413 | bool Helper::isX11() | 361 | bool Helper::isX11() | ||
1414 | { | 362 | { | ||
1415 | #if BREEZE_HAVE_X11 | 363 | #if BREEZE_HAVE_X11 | ||
1416 | #if QT_VERSION >= 0x050000 | 364 | #if QT_VERSION >= 0x050000 | ||
1417 | static const bool s_isX11 = KWindowSystem::isPlatformX11(); | 365 | static const bool s_isX11 = KWindowSystem::isPlatformX11(); | ||
1418 | return s_isX11; | 366 | return s_isX11; | ||
1419 | #else | 367 | #else | ||
1420 | return true; | 368 | return true; | ||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |