Back to index

salome-gui  6.5.0
Style_Tools.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File   : Style_Tools.cxx
00021 // Author : Natalia Ermolaeva, Open CASCADE S.A.S.
00022 //
00023 #include "Style_Tools.h"
00024 
00025 #include <QPainter>
00026 #include <QPainterPath>
00027 #include <QRect>
00028 #include <QColor>
00029 #include <QSize>
00030 #include <QTabWidget>
00031 
00042 QPainterPath Style_Tools::painterPath( const QRect& r )
00043 {
00044   QPainterPath res;
00045   double x = r.x(), y = r.y(), right = r.right(), bottom = r.bottom();
00046   res.moveTo( x, y );
00047   res.lineTo( right, y );
00048   res.lineTo( right, bottom );
00049   res.lineTo( x, bottom );
00050   res.closeSubpath();
00051   return res;
00052 }
00053 
00061 QPainterPath Style_Tools::substractPath( const QPainterPath& fromPath,
00062                                          const QPainterPath& path )
00063 {
00064   QPainterPath res;
00065   QRegion aFromRegion( fromPath.toFillPolygon().toPolygon() );
00066   QRegion aRegion( path.toFillPolygon().toPolygon() );
00067   aFromRegion -= aRegion;
00068   res.addRegion( aFromRegion );
00069   return res;
00070 }
00071 
00081 QPainterPath Style_Tools::roundRect( const QRect& r, const double rad, int type,
00082                                      int shType )
00083 {
00084   QPainterPath res;
00085   if ( type & None )
00086     return painterPath( r );
00087   double x = r.x(), y = r.y(), right = r.right(), bottom = r.bottom();
00088   int aRad = getMaxRect( r, (int)rad );
00089 
00090   if ( shType == WholePath || shType == TopPath ) {
00091     if ( type & ( All | Left | BottomLeft ) ) {
00092       res.moveTo( x+aRad, bottom );
00093       res.arcTo( x, bottom-2*aRad, 2*aRad, 2*aRad, 270, -90 );
00094     }
00095     else
00096       res.moveTo( x, bottom );
00097     res.lineTo( x, y+aRad );
00098     if ( type & (All | Left | TopLeft ) )
00099       res.arcTo( x, y, 2*aRad, 2*aRad, 180, -90 );
00100     else
00101       res.lineTo( x, y );
00102     res.lineTo( right-aRad, y );
00103     if ( type & ( All | Right | TopRight ) )
00104       res.arcTo( right-2*aRad, y, 2*aRad, 2*aRad, 90, -90 );
00105     else
00106       res.lineTo( right, y );
00107   }
00108   if ( shType == WholePath || shType == BottomPath ) {
00109     if ( shType == BottomPath ) {
00110       if ( type & ( All | Right | TopRight ) )
00111         res.moveTo( right, y+aRad );
00112       else
00113         res.moveTo( right, y );
00114     }
00115     res.lineTo( right, bottom-aRad );
00116     if ( type & ( All | Right | BottomRight ) )
00117       res.arcTo( right-2*aRad, bottom-2*aRad, 2*aRad, 2*aRad, 0, -90 );
00118     else
00119       res.lineTo( right, bottom );
00120 
00121     if ( type & ( All | Left | BottomLeft ) )
00122       res.lineTo( x+aRad, bottom );
00123     else
00124       res.lineTo( x, bottom ); 
00125   }
00126   if ( shType == WholePath )
00127     res.closeSubpath();
00128   return res;
00129 }
00130 
00142 void Style_Tools::roundRect( QPainter* p, const QRect& r, const double rad, const int type,
00143                              const QColor& c1, const QColor& c2, bool fill, bool antial )
00144 {
00145   if ( antial )
00146     p->setRenderHint( QPainter::Antialiasing );
00147 
00148   QPainterPath path = roundRect( r, rad, type );
00149 
00150   if ( fill ) {
00151     QLinearGradient gr( r.x(), r.y(), r.x(), r.bottom() );
00152     gr.setColorAt( 0.0, c1 );
00153     gr.setColorAt( 0.5, c1 );
00154     gr.setColorAt( 1.0, c2 );
00155     p->fillPath( path, gr );
00156   }
00157   p->strokePath( path, QPen( c2, Qt::SolidLine ) );
00158 }
00159 
00177 void Style_Tools::shadowRect( QPainter* p, const QRect& r, const double rad, const double marg,
00178                               const int shad, int type, const QColor& light, const QColor& dark,
00179                               const QColor& border_top, const QColor& border_bot, const bool antialize,
00180                               const bool isButton, const bool btnOn, const bool fill )
00181 {
00182   QColor aLight = light, aDark = dark, aBrdTop = border_top, aBrdBot = border_bot;
00183   if ( isButton && btnOn ) {
00184     aLight = dark;
00185     aDark = light;
00186     aBrdTop = border_bot;
00187     aBrdBot = border_top;
00188   }
00189 
00190   // gradients
00191   QLinearGradient
00192     gr1( r.x(), r.y(), r.right(), r.y() ),
00193     gr2( r.x(), r.y(), r.x(), r.bottom() );
00194   if ( fill ) {
00195     if ( isButton ) {
00196       gr2.setColorAt( 0.0, aLight );
00197       if ( marg > 0 )
00198         gr2.setColorAt( marg / r.height(), aLight );
00199       gr2.setColorAt( 1.0, aDark );
00200     }
00201     else {
00202       QColor _c1 = aLight; _c1.setAlpha( 0 );
00203       QColor _c2 = aDark;
00204       gr1.setColorAt( 0.0, _c2 );
00205       if ( marg > 0 )
00206         gr1.setColorAt( marg / r.width(), _c1 );
00207       gr1.setColorAt( 1.0, _c1 );
00208       gr2.setColorAt( 0.0, _c2 );
00209       if ( marg > 0 )
00210         gr2.setColorAt( marg / r.height(), _c1 );
00211       gr2.setColorAt( 1.0, _c1 );
00212     }
00213   }
00214   // paths
00215   int x = r.x(), y = r.y(), right = r.right(), bottom = r.bottom();
00216   // main path
00217   QRect rCont;
00218   if ( antialize )
00219    rCont = QRect( QPoint( x+shad, y+shad ), QPoint( right-shad, bottom-shad ) );
00220   else
00221     rCont = QRect( QPoint( x, y ), QPoint( right, bottom ) );
00222 
00223   QPainterPath path = roundRect( rCont, rad, type );
00224 
00225   // draw paths
00226   p->save();
00227   if ( antialize )
00228     p->setRenderHint( QPainter::Antialiasing, true );
00229   else
00230     p->setRenderHint( QPainter::Antialiasing, false );
00231 
00232   if( fill ) {
00233     p->fillPath( path, aLight );
00234     if ( !isButton )
00235       p->fillPath( path, gr1 );
00236     p->fillPath( path, gr2 );
00237   }
00238   if ( antialize )
00239     p->strokePath( path, QPen( aBrdBot, Qt::SolidLine ) );
00240 
00241   QPainterPath bottomPath = roundRect( rCont, rad, type, BottomPath ),
00242                topPath = roundRect( rCont, rad, type, TopPath );
00243   p->strokePath( bottomPath, aBrdBot );
00244   p->strokePath( topPath, aBrdTop );
00245 
00246   if ( antialize )
00247       p->setRenderHint( QPainter::Antialiasing, false );
00248   p->restore();
00249 }
00250 
00262 void Style_Tools::shadowCheck( QPainter* p, const QRect& r, const double rad, const int type,
00263                                const QColor& light, const QColor& dark,
00264                                const QColor& border_top, const QColor& border_bot  )
00265 {
00266   // main path
00267   QPainterPath path = roundRect( r, rad, type );
00268 
00269   QLinearGradient gr( r.x(), r.y(), r.right(), r.bottom() );
00270   gr.setColorAt( 0.0, dark );
00271   gr.setColorAt( 1.0, light );
00272  
00273   p->fillPath( path, gr ); //fill
00274 
00275   QPainterPath bottomPath = roundRect( r, rad, type, BottomPath ),
00276                topPath = roundRect( r, rad, type, TopPath );
00277   p->strokePath( bottomPath, border_bot );
00278   p->strokePath( topPath, border_top );
00279 }
00280 
00289 void Style_Tools::arrowRect( QPainter* p, const QRect& re, const QColor& frame,
00290                              const QColor& gr1, const QColor& gr2 )
00291 {
00292   QPainterPath path;
00293   const int r = 4;
00294   const double d = re.height()/2;
00295 
00296   path.moveTo( re.x()+r,            re.y() );
00297   path.lineTo( re.x()+re.width(),   re.y() );
00298   path.lineTo( re.x()+re.width()+d, re.y()+d );
00299   path.lineTo( re.x()+re.width(),   re.y()+re.height() );
00300   path.lineTo( re.x()+r,            re.y()+re.height() );
00301   path.arcTo ( re.x(),              re.y()+2*d-2*r, 2*r, 2*r, 270, -90 );
00302   path.lineTo( re.x(),              re.y()+r );
00303   path.arcTo ( re.x(),              re.y(), 2*r, 2*r, 180, -90 );
00304   path.closeSubpath();
00305 
00306   QLinearGradient gr( re.x(), re.y(), re.x(), re.y()+re.height() );
00307   gr.setColorAt( 0.0, gr1 );
00308   gr.setColorAt( 0.4, gr2 );
00309   gr.setColorAt( 0.6, gr2 );
00310   gr.setColorAt( 1.0, gr1 );
00311 
00312   p->fillPath( path, gr );
00313   p->strokePath( path, QPen( frame, Qt::SolidLine ) );
00314 }
00315 
00323 void Style_Tools::fillRect( QPainter* p, const QRect& re, const QColor& c1,
00324                             const QColor& c2, const int alpha )
00325 {
00326   QLinearGradient gr( re.x(), re.y(), re.x()+re.width(), re.y()+re.height() );
00327   QColor cc1 = c1, cc2 = c2;
00328   cc1.setAlpha( alpha );
00329   cc2.setAlpha( alpha );
00330   gr.setColorAt( 0.0, cc1 );
00331   gr.setColorAt( 1.0, cc2 );
00332   p->fillRect( re, gr );
00333 }
00334 
00343 void Style_Tools::drawArrow( QStyle::PrimitiveElement type, QPainter* p, const QRect& r,
00344                              const QColor& pen, const QColor& brush )
00345 {
00346   p->save();
00347   QPainterPath arrow1;
00348   int x = r.x(), y = r.y(), w = r.right()-x, h = r.bottom()-y;
00349   int x11 = 0, x12 = 0, y11 = 0, y12 = 0;
00350   int aDelta = qMin( (int)(w/3.5), (int)(h/3.5) );
00351   int deltaX = aDelta, deltaY = aDelta;
00352   QLineF line( 0, 0, 1, 0 );
00353   int xc = r.center().x(), yc = r.center().y();
00354   p->translate( xc, yc );
00355   bool correct = false;
00356   switch( type ) {
00357     case QStyle::PE_IndicatorArrowDown:
00358       correct = true;
00359     case QStyle::PE_IndicatorArrowUp: {
00360       int widthArr2 = (int)(deltaX/3.);
00361       if ( correct )
00362         deltaY = -deltaY; // change arrow direction
00363       arrow1.moveTo(  0,          deltaY );
00364       arrow1.lineTo(  widthArr2,  deltaY );
00365       arrow1.lineTo(  widthArr2,  0 );
00366       arrow1.lineTo(  deltaX,     0 );
00367       arrow1.lineTo(  0,          -deltaY );
00368       arrow1.lineTo( -deltaX,     0. );
00369       arrow1.lineTo( -widthArr2,  0 );
00370       arrow1.lineTo( -widthArr2, deltaY );
00371       arrow1.lineTo(  0,         deltaY );
00372       if ( correct )
00373         deltaX = -deltaX;
00374       x11 = -deltaX; y11 = -deltaY; x12 = deltaX; y12 = deltaY;
00375       break;
00376     }
00377     case QStyle::PE_IndicatorArrowLeft: // to change
00378       correct = true;
00379     case QStyle::PE_IndicatorArrowRight: {
00380       int widthArr2 = (int)(deltaX/3.);
00381       if ( correct )
00382         deltaX = -deltaX; // change arrow direction
00383       arrow1.moveTo( -deltaX,  0 );
00384       arrow1.lineTo( -deltaX,  widthArr2 );
00385       arrow1.lineTo(  0,       widthArr2 );
00386       arrow1.lineTo(  0,       deltaY );
00387       arrow1.lineTo(  deltaX,  0 );
00388       arrow1.lineTo(  0,      -deltaY );
00389       arrow1.lineTo(  0,      -widthArr2 );
00390       arrow1.lineTo( -deltaX, -widthArr2 );
00391       arrow1.lineTo( -deltaX,  0 );
00392       x11 = deltaX; y11 = deltaY; x12 = -deltaX; y12 = -deltaY;
00393       break;
00394     }
00395     case QStyle::PE_IndicatorSpinDown:
00396       correct = true;
00397     case QStyle::PE_IndicatorSpinUp: {
00398       aDelta = (int)(deltaY/2);
00399       if ( correct ) {
00400         aDelta = (int)(-aDelta/2);
00401         deltaY = -deltaY;
00402       }
00403       arrow1.moveTo(  deltaX,     -aDelta );
00404       arrow1.lineTo(  0,          -aDelta-deltaY );
00405       arrow1.lineTo( -deltaX,     -aDelta );
00406       arrow1.lineTo(  deltaX,     -aDelta );
00407       if ( correct )
00408         deltaX = -deltaX;
00409       x11 = -deltaX, y11 = -deltaY, x12 = deltaX, y12 = 0;
00410       break;
00411     }
00412     default:
00413       p->restore();
00414       return;
00415   }
00416   p->setPen( pen );
00417   p->setBrush( brush );
00418 
00419   QLinearGradient gr( x11, y11, x12, y12 );
00420   gr.setColorAt( 0.0, pen );                // grayer
00421   gr.setColorAt( 1.0, brush);               // lighter
00422   p->fillPath( arrow1, gr );
00423   p->strokePath( arrow1, QPen( pen, Qt::SolidLine ) );
00424 
00425   p->restore();
00426 }
00427 
00436 void Style_Tools::drawSign( QStyle::PrimitiveElement type, QPainter* p, const QRect& r,
00437                             const QColor& pen, const QColor& brush )
00438 {
00439   p->save();
00440   QPainterPath sign;
00441   int x = r.x(), y = r.y(), w = r.right()-x, h = r.bottom()-y;
00442   int x11 = 0, x12 = 0, y11 = 0, y12 = 0;
00443   int aDelta = qMin( (int)(w/3.5), (int)(h/3.5) );
00444   int deltaX = aDelta, deltaY = aDelta;
00445   QLineF line( 0, 0, 1, 0 );
00446   int xc = r.center().x(), yc = r.center().y();
00447   p->translate( xc, yc );
00448   bool correct = false;
00449   switch( type ) {
00450     case QStyle::PE_IndicatorSpinMinus:
00451       correct = true;
00452     case QStyle::PE_IndicatorSpinPlus: {
00453       aDelta = (int)(deltaY/2);
00454       if ( correct ) {
00455         aDelta = -aDelta;
00456         deltaY = -deltaY;
00457       }
00458       if ( correct ) 
00459         sign.moveTo(  deltaY/2,   -aDelta/2-(deltaY/2-aDelta/3) );
00460       else {
00461         sign.moveTo(  aDelta/3,   -aDelta/2 );
00462         sign.lineTo(  aDelta/3,   -aDelta/2-(deltaY/2-aDelta/3) );
00463         sign.lineTo(  deltaY/2,   -aDelta/2-(deltaY/2-aDelta/3) );
00464       }
00465       
00466       sign.lineTo(    deltaY/2,   -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
00467       
00468       if ( !correct ) {
00469         sign.lineTo(  aDelta/3,   -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
00470         sign.lineTo(  aDelta/3,   -aDelta/2-deltaY );
00471         sign.lineTo( -aDelta/3,   -aDelta/2-deltaY );
00472         sign.lineTo( -aDelta/3,   -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
00473       }
00474       
00475       sign.lineTo(   -deltaY/2,   -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 );
00476       sign.lineTo(   -deltaY/2,   -aDelta/2-(deltaY/2-aDelta/3) );
00477 
00478       if ( correct ) 
00479         sign.lineTo(  deltaY/2,   -aDelta/2-(deltaY/2-aDelta/3) );
00480       else {
00481         sign.lineTo( -aDelta/3,   -aDelta/2-(deltaY/2-aDelta/3) );
00482         sign.lineTo( -aDelta/3,   -aDelta/2 );
00483         sign.lineTo(  aDelta/3,   -aDelta/2);
00484       }
00485 
00486       if ( correct )
00487         deltaX = -deltaX;
00488       x11 = -deltaX, y11 = -deltaY, x12 = deltaX, y12 = 0;
00489       break;
00490     }
00491     default:
00492       p->restore();
00493       return;
00494   }
00495   p->setPen( pen );
00496   p->setBrush( brush );
00497 
00498   QLinearGradient gr( x11, y11, x12, y12 );
00499   gr.setColorAt( 0.0, pen );                // grayer
00500   gr.setColorAt( 1.0, brush);               // lighter
00501   p->fillPath( sign, gr );
00502   p->strokePath( sign, QPen( pen, Qt::SolidLine ) );
00503 
00504   p->restore();
00505 }
00506 
00525 QPainterPath Style_Tools::tabRect( QPainter* p, const QRect& r, const int position, const double rad,
00526                                    const double delta, const QColor& light, const QColor& dark,
00527                                    const QColor& border_top, const QColor& border_bot,
00528                                    const bool selected, const bool isLast,  const bool isHover,
00529                                    const bool focusRect, const bool draw )
00530 {
00531   // paths
00532   int x = r.x()+1, y = r.y()+1, right = r.right()+1, left = r.left()-1,
00533       bottom = r.bottom()-1, top = r.top()+1;
00534   int aDelta;
00535   if ( position == QTabWidget::North || position == QTabWidget::South )
00536     aDelta = (int)((bottom - top)*delta/2);
00537   else
00538     aDelta = (int)((right-left)*delta/2);  
00539 
00540   int aRad = getMaxRect( r, (int)rad );
00541 
00542   // main path
00543   QPainterPath path, strokePath;
00544   switch ( position ) {
00545     case QTabWidget::North: {
00546       path.moveTo( x, bottom );
00547       path.lineTo( x, y+aRad );
00548       path.arcTo( x, y, 2*aRad, 2*aRad, 180, -90 );
00549       if ( isLast )
00550         right = right - aDelta;
00551       path.lineTo( right-aDelta, y );
00552       path.lineTo( right+aDelta, bottom );
00553       strokePath.moveTo( x, bottom );
00554       strokePath.lineTo( right+aDelta, bottom );
00555       break;
00556     }
00557     case QTabWidget::South: {
00558       path.moveTo( x, y );
00559       path.lineTo( x, bottom-aRad );
00560       path.arcTo( x, bottom-2*aRad, 2*aRad, 2*aRad, 180, 90 );
00561       if ( isLast )
00562         right = right - aDelta;
00563       path.lineTo( right-aDelta, bottom );
00564       path.lineTo( right+aDelta, y );
00565       strokePath.moveTo( x, y );
00566       strokePath.lineTo( right+aDelta, y );
00567       break;
00568     }
00569     case QTabWidget::West: {
00570       path.moveTo( right, y );
00571       path.lineTo( x+aRad, y );
00572       path.arcTo( x, y, 2*aRad, 2*aRad, 90, 90 );
00573       if ( isLast )
00574         bottom = bottom - aDelta;
00575       path.lineTo( x, bottom-aDelta );
00576       path.lineTo( right, bottom+aDelta );
00577       strokePath.moveTo( right, y );
00578       strokePath.lineTo( right, bottom+aDelta );
00579       break;
00580     }
00581     case QTabWidget::East: {
00582       path.moveTo( x, y );
00583       path.lineTo( right-aRad, y );
00584       path.arcTo( right-2*aRad, y, 2*aRad, 2*aRad, 90, -90 );
00585       if ( isLast )
00586         bottom = bottom - aDelta;
00587       path.lineTo( right, bottom-aDelta );
00588       path.lineTo( x, bottom+aDelta );
00589       strokePath.moveTo( x, y );
00590       strokePath.lineTo( x, bottom+aDelta );
00591       break;
00592     }
00593   }
00594   if ( !draw )
00595     return path;
00596 
00597   // draw path
00598   p->save();
00599   p->setRenderHint( QPainter::Antialiasing, true );
00600   if ( focusRect ) {
00601     path.closeSubpath();
00602     drawFocus( p, path, dark, false );
00603   }
00604   else {
00605     QLinearGradient gr( x, y, x, bottom );
00606     if ( selected ) {
00607       gr.setColorAt( 0.0, light );
00608       gr.setColorAt( 1.0, light );
00609     }
00610     else if ( isHover ) {
00611       gr.setColorAt( 0.0, dark );
00612       gr.setColorAt( 0.2, light );
00613       gr.setColorAt( 0.8, light );
00614       gr.setColorAt( 1.0, dark );
00615       QLinearGradient gr_1( x, y, right, y );
00616       QColor aLight = light;
00617       aLight.setAlpha( 0 );
00618       gr_1.setColorAt( 0.0, dark );
00619       gr_1.setColorAt( 0.2, aLight );
00620       gr_1.setColorAt( 0.7, aLight );
00621       gr_1.setColorAt( 1.0, dark );
00622       p->fillPath( path, gr );
00623       p->fillPath( path, gr_1 );
00624     }
00625     else {
00626       gr.setColorAt( 0.0, light );
00627       gr.setColorAt( 0.3, dark );
00628       gr.setColorAt( 0.7, dark );
00629       gr.setColorAt( 1.0, light );
00630     }
00631     if ( !isHover || selected )
00632       p->fillPath( path, gr );
00633 
00634     QColor bordCol = border_top;
00635     if ( position == QTabWidget::South || position == QTabWidget::East )
00636       bordCol = border_bot;
00637     else
00638       bordCol = border_top;
00639     p->strokePath( path, QPen( bordCol, Qt::SolidLine ) );
00640     p->setRenderHint( QPainter::Antialiasing, false );
00641     p->strokePath( strokePath, QPen( selected ? light : bordCol, Qt::SolidLine ) );
00642   }
00643   p->restore();
00644   return path;
00645 }
00646 
00655 void Style_Tools::drawFocus( QPainter* p, const QRect& aRect, const double rad, const int type,
00656                              const QColor& border )
00657 {
00658   QPainterPath path = Style_Tools::roundRect( aRect, rad, type );
00659 
00660   drawFocus( p, path, border );
00661 }
00662 
00670 void Style_Tools::drawFocus( QPainter* p, const QPainterPath& path, const QColor& border,
00671                              const bool line )
00672 {
00673   QPen oldPen = p->pen();
00674   QPen aPen = oldPen;
00675   aPen.setColor( border );
00676   if ( !line )
00677     aPen.setStyle( Qt::DotLine );
00678   p->setPen( aPen );
00679 
00680   p->drawPath( path );
00681   p->setPen( oldPen );
00682 }
00683 
00695 void Style_Tools::drawSlider( QPainter* p, const QRect& r, const double rad,
00696                               SliderType type, const QColor& light, const QColor& dark,
00697                               const QColor& border_top, const QColor& border_bot )
00698 {
00699   p->save();
00700   QPainterPath path, bottomPath;
00701   if ( rad == 0 )
00702     type = SlNone;
00703   int aRad = getMaxRect( r, (int)rad );
00704   int w = r.width(), h = r.height();
00705   int xc = r.center().x(), yc = r.center().y();
00706   p->translate( xc, yc );
00707   QLinearGradient gr;
00708   switch ( type ) {
00709     case SlUp:
00710     case SlDown: {
00711       int aDeltaX = (int)(w/2), aDeltaY = (int)(h/4), aDeltaArr = (int)(aDeltaY/2);
00712       if ( type == SlDown )
00713         p->rotate( 180 );
00714       path.moveTo(  0,       -2*aDeltaY );
00715       path.lineTo(  aDeltaX, -aDeltaY+aDeltaArr );
00716       path.lineTo(  aDeltaX, 2*aDeltaY-aRad );
00717       path.arcTo(   aDeltaX-2*aRad, 2*aDeltaY-2*aRad, 2*aRad, 2*aRad, 0, -90 );
00718       path.lineTo( -aDeltaX+aRad, 2*aDeltaY );
00719       path.arcTo(  -aDeltaX,  2*aDeltaY-2*aRad, 2*aRad, 2*aRad, 270, -90 );
00720       path.lineTo( -aDeltaX, -aDeltaY+aDeltaArr );
00721       path.lineTo( 0,       -2*aDeltaY );
00722       bottomPath = path;
00723       gr.setStart( 0, -2*aDeltaY );
00724       gr.setFinalStop( 0, 2*aDeltaY );
00725       break;
00726     }
00727     case SlLeft:
00728     case SlRight: {
00729       int aDeltaX = (int)(w/4), aDeltaY = (int)(h/2), aDeltaArr = (int)(aDeltaX/2);
00730       if ( type == SlRight )
00731         p->rotate( 180 );
00732       path.moveTo( -2*aDeltaX,        0 );
00733       path.lineTo( -aDeltaX+aDeltaArr,aDeltaY );
00734       path.lineTo(  2*aDeltaX-aRad,   aDeltaY );
00735       path.arcTo(   2*aDeltaX-2*aRad, aDeltaY-2*aRad, 2*aRad, 2*aRad, 270, 90 );
00736       path.lineTo(  2*aDeltaX,       -aDeltaY+aRad );
00737       path.arcTo(   2*aDeltaX-2*aRad, -aDeltaY, 2*aRad, 2*aRad, 0, 90 );
00738       path.lineTo( -aDeltaX+aDeltaArr,-aDeltaY );
00739       path.lineTo( -2*aDeltaX,       0 );
00740       gr.setStart( -2*aDeltaX, 0 );
00741       gr.setFinalStop( 2*aDeltaX, 0 );
00742       bottomPath = path;
00743       break;
00744     }
00745     case SlNone: {
00746       p->translate( -xc, -yc );
00747       path = Style_Tools::roundRect( r, rad, Style_Tools::All );
00748       bottomPath = path;
00749       gr.setStart( r.x(), r.y() );
00750       gr.setFinalStop( r.x(), r.bottom() );
00751       break;
00752     }
00753     default:
00754       return;
00755   }
00756   p->setRenderHint( QPainter::Antialiasing );
00757   gr.setColorAt( 0.0, light );
00758   gr.setColorAt( 1.0, dark );
00759   p->fillPath( path, gr );
00760 
00761   QColor bottomShadow = border_bot;
00762   p->strokePath( bottomPath, bottomShadow );
00763   p->setRenderHint( QPainter::Antialiasing, false );
00764   p->restore();
00765 }
00766 
00778 void Style_Tools::highlightRect( QPainter* p, const QRect& rect, const double rad, const int type,
00779                                  const double marg, const QColor& center, const QColor& out_center,
00780                                  const QColor& border )
00781 {
00782   QPainterPath path = Style_Tools::roundRect( rect, rad, type );
00783   QLinearGradient gr_h( rect.x(), rect.y(), rect.right(), rect.y() ),
00784                   gr_v( rect.x(), rect.y(), rect.x(), rect.bottom() );
00785   double aXDelta = marg > 0 ? marg/rect.width() : 0.5;
00786   double aYDelta = marg > 0 ? marg/rect.height() : 0.5;
00787   if ( aYDelta > 0.5 )
00788     aYDelta = 0.25;
00789   gr_v.setColorAt( 0.0, out_center );
00790   gr_v.setColorAt( aYDelta, center );
00791   gr_v.setColorAt( 1-aYDelta, center );
00792   gr_v.setColorAt( 1.0, out_center );
00793 
00794   QColor aCenter = center;
00795   aCenter.setAlpha( 0 );
00796   if ( aXDelta > 0.5 )
00797     aXDelta = 0.25;
00798   gr_h.setColorAt( 0.0, out_center );
00799   gr_h.setColorAt( aXDelta, aCenter );
00800   gr_h.setColorAt( 1-aXDelta, aCenter );
00801   gr_h.setColorAt( 1.0, out_center );
00802 
00803   p->fillPath( path, gr_v );
00804   if ( marg > 0 )
00805     p->fillPath( path, gr_h );
00806   p->strokePath( path, border );
00807 }
00808 
00816 int Style_Tools::getMinDelta( const QRect& rect, const QSize& size, const int defDelta )
00817 {
00818   int aDelta = defDelta;
00819   aDelta = qMin( aDelta, ( rect.height() - size.height() ) / 2 );
00820   aDelta = qMin( aDelta, ( rect.width()  - size.width() )  / 2 );
00821   return aDelta;
00822 }
00823 
00830 int Style_Tools::getMaxRect( const QRect& rect, const int defRect )
00831 {
00832   int aRect = defRect;
00833   aRect = qMin( aRect, rect.height() / 2 );
00834   aRect = qMin( aRect, rect.width()  / 2 );
00835   return aRect;
00836 }