1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : Style_Tools.cxx
21 // Author : Natalia Ermolaeva, Open CASCADE S.A.S.
23 #include "Style_Tools.h"
26 #include <QPainterPath>
34 \brief A set of utility functions used by SALOME style to draw widgets
38 \brief Create painter path for specified rectangle
39 \param r rectangle on which painter path is build
40 \return resulting painter path
42 QPainterPath Style_Tools::painterPath( const QRect& r )
45 double x = r.x(), y = r.y(), right = r.right(), bottom = r.bottom();
47 res.lineTo( right, y );
48 res.lineTo( right, bottom );
49 res.lineTo( x, bottom );
55 \brief Create painter path by subtracting painter path \a path from another
56 painter path \a fromPath
57 \param fromPath initial painter path
58 \param path painter path being subtracted from \a fromPath
59 \return resulting painter path
61 QPainterPath Style_Tools::substractPath( const QPainterPath& fromPath,
62 const QPainterPath& path )
65 QRegion aFromRegion( fromPath.toFillPolygon().toPolygon() );
66 QRegion aRegion( path.toFillPolygon().toPolygon() );
67 aFromRegion -= aRegion;
68 res.addRegion( aFromRegion );
73 \brief Create painter path basing on specified rectangle \a r with rounded corners
74 specified by radius \a r, operation \a type and shadow type \a shType.
75 \param r initial rectangle
76 \param rad rounding radius
77 \param type rounding type operation (Style_Tools::RoundType)
78 \param shType shadow type (Style_Tools::ShadowType)
79 \return resulting painter path
81 QPainterPath Style_Tools::roundRect( const QRect& r, const double rad, int type,
86 return painterPath( r );
87 double x = r.x(), y = r.y(), right = r.right(), bottom = r.bottom();
88 int aRad = getMaxRect( r, (int)rad );
90 if ( shType == WholePath || shType == TopPath ) {
91 if ( type & ( All | Left | BottomLeft ) ) {
92 res.moveTo( x+aRad, bottom );
93 res.arcTo( x, bottom-2*aRad, 2*aRad, 2*aRad, 270, -90 );
96 res.moveTo( x, bottom );
97 res.lineTo( x, y+aRad );
98 if ( type & (All | Left | TopLeft ) )
99 res.arcTo( x, y, 2*aRad, 2*aRad, 180, -90 );
102 res.lineTo( right-aRad, y );
103 if ( type & ( All | Right | TopRight ) )
104 res.arcTo( right-2*aRad, y, 2*aRad, 2*aRad, 90, -90 );
106 res.lineTo( right, y );
108 if ( shType == WholePath || shType == BottomPath ) {
109 if ( shType == BottomPath ) {
110 if ( type & ( All | Right | TopRight ) )
111 res.moveTo( right, y+aRad );
113 res.moveTo( right, y );
115 res.lineTo( right, bottom-aRad );
116 if ( type & ( All | Right | BottomRight ) )
117 res.arcTo( right-2*aRad, bottom-2*aRad, 2*aRad, 2*aRad, 0, -90 );
119 res.lineTo( right, bottom );
121 if ( type & ( All | Left | BottomLeft ) )
122 res.lineTo( x+aRad, bottom );
124 res.lineTo( x, bottom );
126 if ( shType == WholePath )
132 \brief Draw rectangle with rounded corners.
134 \param r drawing rectangle
135 \param rad corner rounding radius
136 \param type rounding type operation (Style_Tools::RoundType)
137 \param c1 first gradient color
138 \param c2 second gradient color
139 \param fill if \c true rectangle is filled with gradiented background according to \a c1 and \a c2
140 \param antial if \c true, rectangle corners are anti-aliased
142 void Style_Tools::roundRect( QPainter* p, const QRect& r, const double rad, const int type,
143 const QColor& c1, const QColor& c2, bool fill, bool antial )
146 p->setRenderHint( QPainter::Antialiasing );
148 QPainterPath path = roundRect( r, rad, type );
151 QLinearGradient gr( r.x(), r.y(), r.x(), r.bottom() );
152 gr.setColorAt( 0.0, c1 );
153 gr.setColorAt( 0.5, c1 );
154 gr.setColorAt( 1.0, c2 );
155 p->fillPath( path, gr );
157 p->strokePath( path, QPen( c2, Qt::SolidLine ) );
161 \brief Draw rectangle with rounded corners and shadow.
163 \param r drawing rectangle
164 \param rad corner rounding radius
165 \param marg drawing margin
166 \param shad shadow size
167 \param type rounding type operation (Style_Tools::RoundType)
168 \param light background's first gradient color
169 \param dark background's second gradient color
170 \param border_top top-left border's color
171 \param border_bot bottom-right border's color
172 \param antialize if \c true, rectangle corners are anti-aliased
173 \param isButton \c true if button is drawn
174 \param btnOn \c true if button is drawn and it is pressed
175 \param fill if \c true rectangle is filled with gradiented background according to \a light and \a dark
177 void Style_Tools::shadowRect( QPainter* p, const QRect& r, const double rad, const double marg,
178 const int shad, int type, const QColor& light, const QColor& dark,
179 const QColor& border_top, const QColor& border_bot, const bool antialize,
180 const bool isButton, const bool btnOn, const bool fill )
182 QColor aLight = light, aDark = dark, aBrdTop = border_top, aBrdBot = border_bot;
183 if ( isButton && btnOn ) {
186 aBrdTop = border_bot;
187 aBrdBot = border_top;
192 gr1( r.x(), r.y(), r.right(), r.y() ),
193 gr2( r.x(), r.y(), r.x(), r.bottom() );
196 gr2.setColorAt( 0.0, aLight );
198 gr2.setColorAt( marg / r.height(), aLight );
199 gr2.setColorAt( 1.0, aDark );
202 QColor _c1 = aLight; _c1.setAlpha( 0 );
204 gr1.setColorAt( 0.0, _c2 );
206 gr1.setColorAt( marg / r.width(), _c1 );
207 gr1.setColorAt( 1.0, _c1 );
208 gr2.setColorAt( 0.0, _c2 );
210 gr2.setColorAt( marg / r.height(), _c1 );
211 gr2.setColorAt( 1.0, _c1 );
215 int x = r.x(), y = r.y(), right = r.right(), bottom = r.bottom();
219 rCont = QRect( QPoint( x+shad, y+shad ), QPoint( right-shad, bottom-shad ) );
221 rCont = QRect( QPoint( x, y ), QPoint( right, bottom ) );
223 QPainterPath path = roundRect( rCont, rad, type );
228 p->setRenderHint( QPainter::Antialiasing, true );
230 p->setRenderHint( QPainter::Antialiasing, false );
233 p->fillPath( path, aLight );
235 p->fillPath( path, gr1 );
236 p->fillPath( path, gr2 );
239 p->strokePath( path, QPen( aBrdBot, Qt::SolidLine ) );
241 QPainterPath bottomPath = roundRect( rCont, rad, type, BottomPath ),
242 topPath = roundRect( rCont, rad, type, TopPath );
243 p->strokePath( bottomPath, aBrdBot );
244 p->strokePath( topPath, aBrdTop );
247 p->setRenderHint( QPainter::Antialiasing, false );
252 \brief Draw shadow of the check-mark
254 \param r drawing rectangle
255 \param rad corner rounding radius
256 \param type rounding type operation (Style_Tools::RoundType)
257 \param light background's first gradient color
258 \param dark background's second gradient color
259 \param border_top top-left border's color
260 \param border_bot bottom-right border's color
262 void Style_Tools::shadowCheck( QPainter* p, const QRect& r, const double rad, const int type,
263 const QColor& light, const QColor& dark,
264 const QColor& border_top, const QColor& border_bot )
267 QPainterPath path = roundRect( r, rad, type );
269 QLinearGradient gr( r.x(), r.y(), r.right(), r.bottom() );
270 gr.setColorAt( 0.0, dark );
271 gr.setColorAt( 1.0, light );
273 p->fillPath( path, gr ); //fill
275 QPainterPath bottomPath = roundRect( r, rad, type, BottomPath ),
276 topPath = roundRect( r, rad, type, TopPath );
277 p->strokePath( bottomPath, border_bot );
278 p->strokePath( topPath, border_top );
282 \brief Draw rectnagle arrow
284 \param re drawing rectangle
285 \param frame frame color
286 \param gr1 background's first gradient color
287 \param gr2 background's second gradient color
289 void Style_Tools::arrowRect( QPainter* p, const QRect& re, const QColor& frame,
290 const QColor& gr1, const QColor& gr2 )
294 const double d = re.height()/2;
296 path.moveTo( re.x()+r, re.y() );
297 path.lineTo( re.x()+re.width(), re.y() );
298 path.lineTo( re.x()+re.width()+d, re.y()+d );
299 path.lineTo( re.x()+re.width(), re.y()+re.height() );
300 path.lineTo( re.x()+r, re.y()+re.height() );
301 path.arcTo ( re.x(), re.y()+2*d-2*r, 2*r, 2*r, 270, -90 );
302 path.lineTo( re.x(), re.y()+r );
303 path.arcTo ( re.x(), re.y(), 2*r, 2*r, 180, -90 );
306 QLinearGradient gr( re.x(), re.y(), re.x(), re.y()+re.height() );
307 gr.setColorAt( 0.0, gr1 );
308 gr.setColorAt( 0.4, gr2 );
309 gr.setColorAt( 0.6, gr2 );
310 gr.setColorAt( 1.0, gr1 );
312 p->fillPath( path, gr );
313 p->strokePath( path, QPen( frame, Qt::SolidLine ) );
317 \brief Fill rectangle with gradiented background
319 \param re drawing rectangle
320 \param c1 background's first gradient color
321 \param c2 background's second gradient color
323 void Style_Tools::fillRect( QPainter* p, const QRect& re, const QColor& c1,
324 const QColor& c2, const int alpha )
326 QLinearGradient gr( re.x(), re.y(), re.x()+re.width(), re.y()+re.height() );
327 QColor cc1 = c1, cc2 = c2;
328 cc1.setAlpha( alpha );
329 cc2.setAlpha( alpha );
330 gr.setColorAt( 0.0, cc1 );
331 gr.setColorAt( 1.0, cc2 );
332 p->fillRect( re, gr );
336 \brief Draw arrow (for example, for combo-box drop-down menu button)
337 \param type primitive type
339 \param r drawing rectangle
340 \param pen foreground painter pen
341 \param brush background painter brush
343 void Style_Tools::drawArrow( QStyle::PrimitiveElement type, QPainter* p, const QRect& r,
344 const QColor& pen, const QColor& brush )
348 int x = r.x(), y = r.y(), w = r.right()-x, h = r.bottom()-y;
349 int x11 = 0, x12 = 0, y11 = 0, y12 = 0;
350 int aDelta = qMin( (int)(w/3.5), (int)(h/3.5) );
351 int deltaX = aDelta, deltaY = aDelta;
352 QLineF line( 0, 0, 1, 0 );
353 int xc = r.center().x(), yc = r.center().y();
354 p->translate( xc, yc );
355 bool correct = false;
357 case QStyle::PE_IndicatorArrowDown:
359 case QStyle::PE_IndicatorArrowUp: {
360 int widthArr2 = (int)(deltaX/3.);
362 deltaY = -deltaY; // change arrow direction
363 arrow1.moveTo( 0, deltaY );
364 arrow1.lineTo( widthArr2, deltaY );
365 arrow1.lineTo( widthArr2, 0 );
366 arrow1.lineTo( deltaX, 0 );
367 arrow1.lineTo( 0, -deltaY );
368 arrow1.lineTo( -deltaX, 0. );
369 arrow1.lineTo( -widthArr2, 0 );
370 arrow1.lineTo( -widthArr2, deltaY );
371 arrow1.lineTo( 0, deltaY );
374 x11 = -deltaX; y11 = -deltaY; x12 = deltaX; y12 = deltaY;
377 case QStyle::PE_IndicatorArrowLeft: // to change
379 case QStyle::PE_IndicatorArrowRight: {
380 int widthArr2 = (int)(deltaX/3.);
382 deltaX = -deltaX; // change arrow direction
383 arrow1.moveTo( -deltaX, 0 );
384 arrow1.lineTo( -deltaX, widthArr2 );
385 arrow1.lineTo( 0, widthArr2 );
386 arrow1.lineTo( 0, deltaY );
387 arrow1.lineTo( deltaX, 0 );
388 arrow1.lineTo( 0, -deltaY );
389 arrow1.lineTo( 0, -widthArr2 );
390 arrow1.lineTo( -deltaX, -widthArr2 );
391 arrow1.lineTo( -deltaX, 0 );
392 x11 = deltaX; y11 = deltaY; x12 = -deltaX; y12 = -deltaY;
395 case QStyle::PE_IndicatorSpinDown:
397 case QStyle::PE_IndicatorSpinUp: {
398 aDelta = (int)(deltaY/2);
400 aDelta = (int)(-aDelta/2);
403 arrow1.moveTo( deltaX, -aDelta );
404 arrow1.lineTo( 0, -aDelta-deltaY );
405 arrow1.lineTo( -deltaX, -aDelta );
406 arrow1.lineTo( deltaX, -aDelta );
409 x11 = -deltaX, y11 = -deltaY, x12 = deltaX, y12 = 0;
417 p->setBrush( brush );
419 QLinearGradient gr( x11, y11, x12, y12 );
420 gr.setColorAt( 0.0, pen ); // grayer
421 gr.setColorAt( 1.0, brush); // lighter
422 p->fillPath( arrow1, gr );
423 p->strokePath( arrow1, QPen( pen, Qt::SolidLine ) );
429 \brief Draw indicator (for example, for spin box's increment/decrement buttons)
430 \param type primitive type
432 \param r drawing rectangle
433 \param pen foreground painter pen
434 \param brush background painter brush
436 void Style_Tools::drawSign( QStyle::PrimitiveElement type, QPainter* p, const QRect& r,
437 const QColor& pen, const QColor& brush )
441 int x = r.x(), y = r.y(), w = r.right()-x, h = r.bottom()-y;
442 int x11 = 0, x12 = 0, y11 = 0, y12 = 0;
443 int aDelta = qMin( (int)(w/3.5), (int)(h/3.5) );
444 int deltaX = aDelta, deltaY = aDelta;
445 QLineF line( 0, 0, 1, 0 );
446 int xc = r.center().x(), yc = r.center().y();
447 p->translate( xc, yc );
448 bool correct = false;
450 case QStyle::PE_IndicatorSpinMinus:
452 case QStyle::PE_IndicatorSpinPlus: {
453 aDelta = (int)(deltaY/2);
459 sign.moveTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) );
461 sign.moveTo( aDelta/3, -aDelta/2 );
462 sign.lineTo( aDelta/3, -aDelta/2-(deltaY/2-aDelta/3) );
463 sign.lineTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) );
466 sign.lineTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
469 sign.lineTo( aDelta/3, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
470 sign.lineTo( aDelta/3, -aDelta/2-deltaY );
471 sign.lineTo( -aDelta/3, -aDelta/2-deltaY );
472 sign.lineTo( -aDelta/3, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
475 sign.lineTo( -deltaY/2, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
476 sign.lineTo( -deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) );
479 sign.lineTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) );
481 sign.lineTo( -aDelta/3, -aDelta/2-(deltaY/2-aDelta/3) );
482 sign.lineTo( -aDelta/3, -aDelta/2 );
483 sign.lineTo( aDelta/3, -aDelta/2);
488 x11 = -deltaX, y11 = -deltaY, x12 = deltaX, y12 = 0;
496 p->setBrush( brush );
498 QLinearGradient gr( x11, y11, x12, y12 );
499 gr.setColorAt( 0.0, pen ); // grayer
500 gr.setColorAt( 1.0, brush); // lighter
501 p->fillPath( sign, gr );
502 p->strokePath( sign, QPen( pen, Qt::SolidLine ) );
508 \brief Create painter path for tab bar and optionally draw it
510 \param r drawing rectangle
511 \param position tab position
512 \param rad rounding radius
513 \param delta gap between tabs
514 \param light background's first gradient color
515 \param dark background's second gradient color
516 \param border_top top-left border's color
517 \param border_bot bottom-right border's color
518 \param selected \c true if tab is selected
519 \param isLast \c true if tab is last in the tabs list
520 \param isHover \c true if tab is hovered
521 \param focusRect focus rectangle
522 \param draw if \c true, tab bar is drawn
523 \return tab bar's painter path
525 QPainterPath Style_Tools::tabRect( QPainter* p, const QRect& r, const int position, const double rad,
526 const double delta, const QColor& light, const QColor& dark,
527 const QColor& border_top, const QColor& border_bot,
528 const bool selected, const bool isLast, const bool isHover,
529 const bool focusRect, const bool draw )
532 int x = r.x()+1, y = r.y()+1, right = r.right()+1, left = r.left()-1,
533 bottom = r.bottom()-1, top = r.top()+1;
535 if ( position == QTabWidget::North || position == QTabWidget::South )
536 aDelta = (int)((bottom - top)*delta/2);
538 aDelta = (int)((right-left)*delta/2);
540 int aRad = getMaxRect( r, (int)rad );
543 QPainterPath path, strokePath;
544 switch ( position ) {
545 case QTabWidget::North: {
546 path.moveTo( x, bottom );
547 path.lineTo( x, y+aRad );
548 path.arcTo( x, y, 2*aRad, 2*aRad, 180, -90 );
550 right = right - aDelta;
551 path.lineTo( right-aDelta, y );
552 path.lineTo( right+aDelta, bottom );
553 strokePath.moveTo( x, bottom );
554 strokePath.lineTo( right+aDelta, bottom );
557 case QTabWidget::South: {
559 path.lineTo( x, bottom-aRad );
560 path.arcTo( x, bottom-2*aRad, 2*aRad, 2*aRad, 180, 90 );
562 right = right - aDelta;
563 path.lineTo( right-aDelta, bottom );
564 path.lineTo( right+aDelta, y );
565 strokePath.moveTo( x, y );
566 strokePath.lineTo( right+aDelta, y );
569 case QTabWidget::West: {
570 path.moveTo( right, y );
571 path.lineTo( x+aRad, y );
572 path.arcTo( x, y, 2*aRad, 2*aRad, 90, 90 );
574 bottom = bottom - aDelta;
575 path.lineTo( x, bottom-aDelta );
576 path.lineTo( right, bottom+aDelta );
577 strokePath.moveTo( right, y );
578 strokePath.lineTo( right, bottom+aDelta );
581 case QTabWidget::East: {
583 path.lineTo( right-aRad, y );
584 path.arcTo( right-2*aRad, y, 2*aRad, 2*aRad, 90, -90 );
586 bottom = bottom - aDelta;
587 path.lineTo( right, bottom-aDelta );
588 path.lineTo( x, bottom+aDelta );
589 strokePath.moveTo( x, y );
590 strokePath.lineTo( x, bottom+aDelta );
599 p->setRenderHint( QPainter::Antialiasing, true );
602 drawFocus( p, path, dark, false );
605 QLinearGradient gr( x, y, x, bottom );
607 gr.setColorAt( 0.0, light );
608 gr.setColorAt( 1.0, light );
610 else if ( isHover ) {
611 gr.setColorAt( 0.0, dark );
612 gr.setColorAt( 0.2, light );
613 gr.setColorAt( 0.8, light );
614 gr.setColorAt( 1.0, dark );
615 QLinearGradient gr_1( x, y, right, y );
616 QColor aLight = light;
617 aLight.setAlpha( 0 );
618 gr_1.setColorAt( 0.0, dark );
619 gr_1.setColorAt( 0.2, aLight );
620 gr_1.setColorAt( 0.7, aLight );
621 gr_1.setColorAt( 1.0, dark );
622 p->fillPath( path, gr );
623 p->fillPath( path, gr_1 );
626 gr.setColorAt( 0.0, light );
627 gr.setColorAt( 0.3, dark );
628 gr.setColorAt( 0.7, dark );
629 gr.setColorAt( 1.0, light );
631 if ( !isHover || selected )
632 p->fillPath( path, gr );
634 QColor bordCol = border_top;
635 if ( position == QTabWidget::South || position == QTabWidget::East )
636 bordCol = border_bot;
638 bordCol = border_top;
639 p->strokePath( path, QPen( bordCol, Qt::SolidLine ) );
640 p->setRenderHint( QPainter::Antialiasing, false );
641 p->strokePath( strokePath, QPen( selected ? light : bordCol, Qt::SolidLine ) );
648 \brief Draw widget's focus
650 \param aRect drawing rectangle
651 \param rad rounding radius
652 \param type rounding operation type
653 \param border focus rectangle color
655 void Style_Tools::drawFocus( QPainter* p, const QRect& aRect, const double rad, const int type,
656 const QColor& border )
658 QPainterPath path = Style_Tools::roundRect( aRect, rad, type );
660 drawFocus( p, path, border );
664 \brief Draw widget's focus
666 \param path drawing painter path
667 \param border focus rectangle color
668 \param line if \c true, focus is drawn as dotted line
670 void Style_Tools::drawFocus( QPainter* p, const QPainterPath& path, const QColor& border,
673 QPen oldPen = p->pen();
675 aPen.setColor( border );
677 aPen.setStyle( Qt::DotLine );
687 \param r drawing rectangle
688 \param rad rounding radius
689 \param slider slider type
690 \param light background's first gradient color
691 \param dark background's second gradient color
692 \param border_top top-left border's color
693 \param border_bot bottom-right border's color
695 void Style_Tools::drawSlider( QPainter* p, const QRect& r, const double rad,
696 SliderType type, const QColor& light, const QColor& dark,
697 const QColor& border_top, const QColor& border_bot )
700 QPainterPath path, bottomPath;
703 int aRad = getMaxRect( r, (int)rad );
704 int w = r.width(), h = r.height();
705 int xc = r.center().x(), yc = r.center().y();
706 p->translate( xc, yc );
711 int aDeltaX = (int)(w/2), aDeltaY = (int)(h/4), aDeltaArr = (int)(aDeltaY/2);
712 if ( type == SlDown )
714 path.moveTo( 0, -2*aDeltaY );
715 path.lineTo( aDeltaX, -aDeltaY+aDeltaArr );
716 path.lineTo( aDeltaX, 2*aDeltaY-aRad );
717 path.arcTo( aDeltaX-2*aRad, 2*aDeltaY-2*aRad, 2*aRad, 2*aRad, 0, -90 );
718 path.lineTo( -aDeltaX+aRad, 2*aDeltaY );
719 path.arcTo( -aDeltaX, 2*aDeltaY-2*aRad, 2*aRad, 2*aRad, 270, -90 );
720 path.lineTo( -aDeltaX, -aDeltaY+aDeltaArr );
721 path.lineTo( 0, -2*aDeltaY );
723 gr.setStart( 0, -2*aDeltaY );
724 gr.setFinalStop( 0, 2*aDeltaY );
729 int aDeltaX = (int)(w/4), aDeltaY = (int)(h/2), aDeltaArr = (int)(aDeltaX/2);
730 if ( type == SlRight )
732 path.moveTo( -2*aDeltaX, 0 );
733 path.lineTo( -aDeltaX+aDeltaArr,aDeltaY );
734 path.lineTo( 2*aDeltaX-aRad, aDeltaY );
735 path.arcTo( 2*aDeltaX-2*aRad, aDeltaY-2*aRad, 2*aRad, 2*aRad, 270, 90 );
736 path.lineTo( 2*aDeltaX, -aDeltaY+aRad );
737 path.arcTo( 2*aDeltaX-2*aRad, -aDeltaY, 2*aRad, 2*aRad, 0, 90 );
738 path.lineTo( -aDeltaX+aDeltaArr,-aDeltaY );
739 path.lineTo( -2*aDeltaX, 0 );
740 gr.setStart( -2*aDeltaX, 0 );
741 gr.setFinalStop( 2*aDeltaX, 0 );
746 p->translate( -xc, -yc );
747 path = Style_Tools::roundRect( r, rad, Style_Tools::All );
749 gr.setStart( r.x(), r.y() );
750 gr.setFinalStop( r.x(), r.bottom() );
756 p->setRenderHint( QPainter::Antialiasing );
757 gr.setColorAt( 0.0, light );
758 gr.setColorAt( 1.0, dark );
759 p->fillPath( path, gr );
761 QColor bottomShadow = border_bot;
762 p->strokePath( bottomPath, bottomShadow );
763 p->setRenderHint( QPainter::Antialiasing, false );
768 \brief Draw highlighted rectangle
770 \param rect drawing rectangle
771 \param rad rounding radius
772 \param type rounding operation type
773 \parma marg margin size
774 \param center background's center gradient color
775 \param out_center background's second color
776 \param border border color
778 void Style_Tools::highlightRect( QPainter* p, const QRect& rect, const double rad, const int type,
779 const double marg, const QColor& center, const QColor& out_center,
780 const QColor& border )
782 QPainterPath path = Style_Tools::roundRect( rect, rad, type );
783 QLinearGradient gr_h( rect.x(), rect.y(), rect.right(), rect.y() ),
784 gr_v( rect.x(), rect.y(), rect.x(), rect.bottom() );
785 double aXDelta = marg > 0 ? marg/rect.width() : 0.5;
786 double aYDelta = marg > 0 ? marg/rect.height() : 0.5;
789 gr_v.setColorAt( 0.0, out_center );
790 gr_v.setColorAt( aYDelta, center );
791 gr_v.setColorAt( 1-aYDelta, center );
792 gr_v.setColorAt( 1.0, out_center );
794 QColor aCenter = center;
795 aCenter.setAlpha( 0 );
798 gr_h.setColorAt( 0.0, out_center );
799 gr_h.setColorAt( aXDelta, aCenter );
800 gr_h.setColorAt( 1-aXDelta, aCenter );
801 gr_h.setColorAt( 1.0, out_center );
803 p->fillPath( path, gr_v );
805 p->fillPath( path, gr_h );
806 p->strokePath( path, border );
810 \brief Get minimal delta value (the minimum between \a rect and \a size dimensions)
811 \param rect rectangle
813 \param defDelta default minimum delta
814 \return resulting minimum value
816 int Style_Tools::getMinDelta( const QRect& rect, const QSize& size, const int defDelta )
818 int aDelta = defDelta;
819 aDelta = qMin( aDelta, ( rect.height() - size.height() ) / 2 );
820 aDelta = qMin( aDelta, ( rect.width() - size.width() ) / 2 );
825 \brief Get halved size of the quadrangle covering specified rectangle
826 \param rect rectangle
827 \param defRect default quadranle size value
828 \return resulting value
830 int Style_Tools::getMaxRect( const QRect& rect, const int defRect )
833 aRect = qMin( aRect, rect.height() / 2 );
834 aRect = qMin( aRect, rect.width() / 2 );