Back to index

salome-gui  6.5.0
Style_Salome.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_Salome.cxx
00021 // Author : Natalia Ermolaeva, Open CASCADE S.A.S.
00022 //
00023 #include "Style_Salome.h"
00024 #include "Style_Tools.h"
00025 #include "Style_Model.h"
00026 
00027 #include <QApplication>
00028 #include <QPainter>
00029 #include <QMap>
00030 #include <QPainterPath>
00031 #include <QWidget>
00032 #include <QComboBox>
00033 #include <QStyleOptionFrame>
00034 #include <QStyleOptionComplex>
00035 #include <QStyleOptionSpinBox>
00036 #include <QStyleOptionButton>
00037 #include <QStyleOptionTab>
00038 #include <QStyleOptionToolButton>
00039 #include <QStyleOptionFocusRect>
00040 #include <QStyleOption>
00041 #include <QSize>
00042 #include <QToolBar>
00043 #include <QMenuBar>
00044 #include <QToolButton>
00045 #include <QTabWidget>
00046 #include <QTabBar>
00047 #include <QToolTip>
00048 #include <QDockWidget>
00049 #include <QTextEdit>
00050 #include <QTreeView>
00051 #include <QListView>
00052 #include <QHeaderView>
00053 #include <QRadioButton>
00054 #include <QCheckBox>
00055 #include <QPushButton>
00056 #include <QAbstractSpinBox>
00057 #include <QLineEdit>
00058 #include <QScrollBar>
00059 #include <QSlider>
00060 #include <QMainWindow>
00061 #include <QPixmapCache>
00062 
00063 #include <limits.h>
00064 
00065 #define SHADOW          1
00066 #define LINE_GR_MARGIN  10
00067 #define HIGH_WDG_MARGIN 10
00068 
00069 #define BUT_PERCENT_COL 125
00070 #define BUT_PERCENT_ON  115
00071 
00072 #define DELTA_H_TAB     1
00073 #define DELTA_SLIDER    3
00074 
00075 static const char* const hole_xpm[] = {
00076 "3 3 3 1",
00077 ". c None",
00078 "a c #999999",
00079 "b c #FFFFFF",
00080 "aa.",
00081 "aab",
00082 ".bb"
00083 };
00084 
00085 static const char* const cross_xpm[] = {
00086 "12 12 4 1",
00087 ". c None",
00088 "a c #000000",
00089 "b c #FFFFFF",
00090 "c c #666666",
00091 "............",
00092 "............",
00093 "............",
00094 ".aaaa..aaaa.",
00095 "..abbaabba..",
00096 "...abbbba...",
00097 "....abba....",
00098 "...abbbba...",
00099 "..abbaabba..",
00100 ".aaaa..aaaa.",
00101 "............",
00102 "............"
00103 };
00104 
00105 static const char* const maximize_xpm[] = {
00106 "12 12 4 1",
00107 ". c None",
00108 "a c #000000",
00109 "b c #FFFFFF",
00110 "c c #666666",
00111 "............",
00112 ".aaaaaaaaaa.",
00113 ".acccccccca.",
00114 ".acccccccca.",
00115 ".abbbbbbbba.",
00116 ".abbbbbbbba.",
00117 ".abbbbbbbba.",
00118 ".abbbbbbbba.",
00119 ".abbbbbbbba.",
00120 ".abbbbbbbba.",
00121 ".aaaaaaaaaa.",
00122 "............"
00123 };
00124 
00125 static const char* const normal_xpm[] = {
00126 "12 12 4 1",
00127 ". c None",
00128 "a c #000000",
00129 "b c #FFFFFF",
00130 "c c #666666",
00131 "............",
00132 "...aaaaaaaa.",
00133 "...acccccca.",
00134 "...abbbbbba.",
00135 "...aaaaaaba.",
00136 ".aaaaaaaaba.",
00137 ".accccccaba.",
00138 ".abbbbbbaaa.",
00139 ".abbbbbba...",
00140 ".abbbbbba...",
00141 ".aaaaaaaa...",
00142 "............"
00143 };
00144 
00145 static const char* const minimize_xpm[] = {
00146 "12 12 4 1",
00147 ". c None",
00148 "a c #000000",
00149 "b c #FFFFFF",
00150 "c c #666666",
00151 "............",
00152 "............",
00153 "............",
00154 "............",
00155 "............",
00156 "............",
00157 "............",
00158 "............",
00159 "aaaaaaaaaaaa",
00160 "abbbbbbbbbba",
00161 "aaaaaaaaaaaa",
00162 "............"
00163 };
00164 
00166 // FOR debug purposes only!!!
00167 //
00168 int DEBUG_LEVEL = 0;
00169 
00170 static bool checkDebugLevel( int level )
00171 {
00172   return DEBUG_LEVEL == level || DEBUG_LEVEL == -1;
00173 }
00174 //
00176 
00177 Style_Model* Style_Salome::myModel = 0;
00178 
00205 Style_Salome::Style_Salome()
00206   : QWindowsStyle()
00207 {
00208   // initialize SALOME style resources
00209   Q_INIT_RESOURCE( Style );
00210 }
00211 
00215 Style_Salome::~Style_Salome()
00216 {
00217 }
00218 
00219 
00237 void Style_Salome::initialize( QtxResourceMgr* resMgr, const QString& section )
00238 {
00239   model()->fromResources( resMgr, section );
00240 }
00241 
00246 void Style_Salome::apply()
00247 {
00248   // application object is not created yet
00249   if ( !QApplication::instance() )
00250     return;
00251 
00252   // update model (from the resources manager if needed)
00253   model()->update();
00254 
00255   // check if SALOME style is already set to the application
00256   if ( !isActive() ) {
00257     // set SALOME style
00258     QApplication::style()->setParent( 0 );           // avoid deleting original application style
00259     QApplication::setStyle( new Style_Salome() );    // set style
00260     QApplication::setDesktopSettingsAware(false);    // prevent the style changing from another tools
00261   }
00262   update();                                          // update style
00263 }
00264 
00269 void Style_Salome::restore()
00270 {
00271   // application object is not created yet
00272   if ( !QApplication::instance() )
00273     return;
00274   // check if SALOME style is set to the application
00275   if ( !isActive() )
00276     return;
00277 
00278   QApplication::setDesktopSettingsAware(true);
00279 
00280   // restore previous style
00281   model()->restore();
00282 }
00283 
00288 bool Style_Salome::isActive()
00289 {
00290   return QApplication::instance() != 0 && qobject_cast<Style_Salome*>( QApplication::style() ) != 0;
00291 }
00292 
00296 void Style_Salome::update()
00297 {
00298   // application object is not created yet
00299   if ( !QApplication::instance() )
00300     return;
00301   // check if SALOME style is set to the application
00302   if ( Style_Salome* style = qobject_cast<Style_Salome*>( QApplication::style() ) )
00303     style->polish( qobject_cast<QApplication*>( QApplication::instance() ) );
00304 }
00305 
00310 Style_Model* Style_Salome::model()
00311 {
00312   if ( !myModel )
00313     myModel = new Style_Model();
00314   return myModel;
00315 }
00316 
00324 void Style_Salome::polish ( QApplication* app )
00325 {
00326   QWindowsStyle::polish( app );
00327 
00328   if ( checkDebugLevel(1) ) {
00329     return;
00330   }
00331 
00332   updatePaletteColors();
00333   app->setFont( model()->applicationFont() );
00334   updateAllWidgets( app );
00335 }
00336 
00345 void Style_Salome::polish ( QWidget* w )
00346 {
00347   if ( checkDebugLevel(2) ) {
00348     QWindowsStyle::polish( w );
00349     return;
00350   }
00351 
00352   if ( w && hasHover() ) {
00353     if ( qobject_cast<QPushButton*>(w) || qobject_cast<QToolButton*>(w)      ||
00354          qobject_cast<QCheckBox*>(w)   || qobject_cast<QRadioButton*>(w)     ||
00355          qobject_cast<QComboBox*>(w)   || qobject_cast<QAbstractSpinBox*>(w) ||
00356          qobject_cast<QLineEdit*>(w)   || qobject_cast<QScrollBar*>(w)       ||
00357          qobject_cast<QTabBar*>(w)     || qobject_cast<QSlider*>(w)          ||
00358          qobject_cast<QMenuBar*>(w)    || qobject_cast<QDockWidget*>(w) )
00359       w->setAttribute( Qt::WA_Hover );
00360   }
00361 
00362   QWindowsStyle::polish( w );
00363 }
00364 
00375 void Style_Salome::unpolish( QWidget* w )
00376 {
00377   if ( checkDebugLevel(3) ) {
00378     QWindowsStyle::unpolish( w );
00379     return;
00380   }
00381 
00382   if ( w && hasHover() ) {
00383     if ( qobject_cast<QPushButton*>(w) || qobject_cast<QToolButton*>(w)||
00384          qobject_cast<QCheckBox*>(w) || qobject_cast<QRadioButton*>(w) ||
00385          qobject_cast<QComboBox*>(w) || qobject_cast<QAbstractSpinBox*>(w) ||
00386          qobject_cast<QLineEdit*>(w) || qobject_cast<QScrollBar*>(w) ||
00387          qobject_cast<QTabBar*>(w) || qobject_cast<QSlider*>(w) ||
00388          qobject_cast<QMenuBar*>(w) || qobject_cast<QDockWidget*>(w) )
00389       w->setAttribute( Qt::WA_Hover, false );
00390   }
00391 
00392   QWindowsStyle::unpolish( w );
00393 }
00394 
00402 void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComplex* opt,
00403                                        QPainter* p, const QWidget* w ) const
00404 {
00405   if ( checkDebugLevel(4) ) {
00406     QWindowsStyle::drawComplexControl( cc, opt, p, w );
00407     return;
00408   }
00409 
00410   const QPalette& pal = w->palette();
00411   switch( cc ) {
00412     case CC_SpinBox:
00413       if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
00414         bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
00415         QRect optr = opt->rect, arUp =   subControlRect( cc, spin, SC_SpinBoxUp, w );
00416         if (spin->buttonSymbols != QAbstractSpinBox::NoButtons)
00417           optr.setWidth( arUp.x()-optr.x()+1 );
00418         double aRad = model()->widgetRounding( Style_Model::EditRadius );
00419         bool antialized = model()->antialiasing();
00420         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
00421         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
00422         if ( hover )
00423           drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
00424         else
00425           Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left,
00426                                    model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr,
00427                                    model()->color( Style_Model::FieldDark ),  // Style_Model::fld_dark_clr,
00428                                    aBrdTopCol, aBrdBotCol, antialized, false );
00429         QRect aBtnRect = QRect( QPoint( arUp.x(), optr.y() ), QPoint( arUp.right(), optr.bottom() ) );
00430         QColor aBtnCol = opt->palette.color( QPalette::Button );
00431         bool aStateOn = opt->state & ( State_Sunken | State_On );
00432         if ( hover )
00433           drawHoverRect(p, aBtnRect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
00434         else
00435           Style_Tools::shadowRect( p, aBtnRect, aRad, 0.0, SHADOW, Style_Tools::Right,
00436                                   aBtnCol.light( BUT_PERCENT_COL ), aBtnCol.dark( BUT_PERCENT_COL ),
00437                                   aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
00438         QStyleOptionSpinBox copy;
00439         PrimitiveElement pe;
00440         if (spin->subControls & SC_SpinBoxUp) {
00441           copy.subControls = SC_SpinBoxUp;
00442           QPalette pal2 = spin->palette;
00443           if (!(spin->stepEnabled & QAbstractSpinBox::StepUpEnabled) ||
00444               !(spin->state & State_Enabled)) {
00445             pal2.setCurrentColorGroup(QPalette::Disabled);
00446             copy.state &= ~State_Enabled;
00447           }
00448           else
00449             copy.state |= State_Enabled;
00450           copy.palette = pal2;
00451           if ( spin->activeSubControls == SC_SpinBoxUp && ( spin->state & State_Sunken ) ) {
00452             copy.state |= State_On;
00453             copy.state |= State_Sunken;
00454           } else {
00455             copy.state |= State_Raised;
00456             copy.state &= ~State_Sunken;
00457           }
00458           pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
00459                : PE_IndicatorSpinUp);
00460           copy.rect = aBtnRect;
00461           drawPrimitive(pe, &copy, p, w);
00462         }
00463         if (spin->subControls & SC_SpinBoxDown) {
00464           copy.subControls = SC_SpinBoxDown;
00465           copy.state = spin->state;
00466           QPalette pal2 = spin->palette;
00467           if (!(spin->stepEnabled & QAbstractSpinBox::StepDownEnabled) ||
00468                !(spin->state & State_Enabled)) {
00469             pal2.setCurrentColorGroup(QPalette::Disabled);
00470             copy.state &= ~State_Enabled;
00471           }
00472           else
00473             copy.state |= State_Enabled;
00474           copy.palette = pal2;
00475           if (spin->activeSubControls == SC_SpinBoxDown && (spin->state & State_Sunken)) {
00476              copy.state |= State_On;
00477              copy.state |= State_Sunken;
00478           } else {
00479             copy.state |= State_Raised;
00480             copy.state &= ~State_Sunken;
00481           }
00482           pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
00483                : PE_IndicatorSpinDown);
00484           copy.rect = aBtnRect;
00485           drawPrimitive(pe, &copy, p, w);
00486         }
00487         break;
00488      }
00489      case CC_ComboBox: {
00490       if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
00491         bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
00492         QRect optr = opt->rect,
00493               ar = subControlRect( cc, cmb, SC_ComboBoxArrow, w );
00494         optr.setY( ar.y() );
00495         optr.setHeight( ar.height() );
00496         optr.setWidth( ar.x()-optr.x()+1 );
00497         bool antialized = model()->antialiasing();
00498         double aRad = model()->widgetRounding( Style_Model::EditRadius );
00499         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
00500         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
00501         if ( hover )
00502           drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
00503         else
00504           Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left,
00505                                    model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr,
00506                                    model()->color( Style_Model::FieldDark ),  // Style_Model::fld_dark_clr,
00507                                    aBrdTopCol, aBrdBotCol, antialized, false );
00508         if (cmb->subControls & SC_ComboBoxArrow) {
00509           State flags = State_None;
00510           QColor aBtnCol = opt->palette.color( QPalette::Button );
00511           bool aStateOn = opt->state & ( State_Sunken | State_On );
00512           if ( hover )
00513             drawHoverRect(p, ar, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
00514           else
00515             Style_Tools::shadowRect( p, ar, aRad, 0.0, SHADOW, Style_Tools::Right,
00516                                      aBtnCol.light( BUT_PERCENT_COL ), aBtnCol.dark( BUT_PERCENT_COL ),
00517                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
00518           if (opt->state & State_Enabled)
00519             flags |= State_Enabled;
00520           if (cmb->activeSubControls == SC_ComboBoxArrow)
00521             flags |= State_Sunken;
00522           QStyleOption arrowOpt(0);
00523           arrowOpt.rect = ar;
00524           arrowOpt.palette = cmb->palette;
00525           arrowOpt.state = flags;
00526           drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
00527         }
00528         if (cmb->subControls & SC_ComboBoxEditField) {
00529           bool hi = cmb->state & State_HasFocus && !cmb->editable;
00530           if( hi ) {
00531             Style_Tools::shadowRect( p, optr, aRad, 0.0, SHADOW, Style_Tools::Left,
00532                                      pal.color( QPalette::Highlight ),
00533                                      pal.color( QPalette::Highlight ), aBrdTopCol, aBrdBotCol,
00534                                      antialized, false );
00535             p->setPen(cmb->palette.highlightedText().color());
00536           }
00537           else
00538             p->setPen(cmb->palette.text().color());
00539         }
00540         break;
00541       }
00542     }
00543     case CC_Slider: {
00544         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
00545             QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, w);
00546             QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, w);
00547 
00548             if( hasHover() && (slider->state & State_Enabled) &&
00549                          (slider->state & State_MouseOver) ) {
00550               QRect moderated = w->rect();
00551                 drawHoverRect(p, moderated, opt->palette.color( QPalette::Window ),
00552                               model()->widgetRounding( Style_Model::ButtonRadius ), Style_Tools::All, false);
00553             }
00554 
00555             if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
00556               QStyleOptionSlider tmpSlider = *slider;
00557               tmpSlider.subControls = SC_SliderGroove;
00558               QWindowsStyle::drawComplexControl(cc, &tmpSlider, p, w);
00559             }
00560             if (slider->subControls & SC_SliderTickmarks) {
00561               QStyleOptionSlider tmpSlider = *slider;
00562               tmpSlider.subControls = SC_SliderTickmarks;
00563               QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w);
00564             }
00565             if (slider->subControls & SC_SliderHandle) {
00566               if (slider->state & State_HasFocus) {
00567                 QStyleOptionFocusRect fropt;
00568                 fropt.QStyleOption::operator=(*slider);
00569                 fropt.rect = subElementRect(SE_SliderFocusRect, slider, w);
00570                 drawPrimitive(PE_FrameFocusRect, &fropt, p, w);
00571               }
00572               int x = handle.x(), y = handle.y(), wi = handle.width(), he = handle.height();
00573               bool horiz = slider->orientation == Qt::Horizontal;
00574               bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
00575               bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
00576               QColor aBtnCol = model()->color( Style_Model::Slider );          // Style_Model::slider_clr
00577               QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
00578               QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
00579               // rect was changed on +/-DELTA_SLIDER value for correct painting Antialised border of slider
00580               int aDelta = DELTA_SLIDER-1;
00581               QRect slRect = QRect(x+aDelta, y+aDelta, wi-aDelta, he-aDelta);
00582               int aXAdd = (int)(slRect.width()/6), aYAdd = (int)(slRect.height()/6);
00583               Style_Tools::SliderType type = Style_Tools::SlNone;
00584               if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow))
00585                 type = Style_Tools::SlNone;
00586               else {
00587                 if (horiz)
00588                   if (tickAbove) {
00589                     type = Style_Tools::SlUp;
00590                     slRect.setTop( slRect.top()-aYAdd );
00591                   }
00592                   else {
00593                     type = Style_Tools::SlDown;
00594                     slRect.setBottom( slRect.bottom()+aYAdd );
00595                   }
00596                 else
00597                   if (tickAbove) {
00598                     type = Style_Tools::SlLeft;
00599                     slRect.setLeft( slRect.left()-aXAdd );
00600                   }
00601                   else {
00602                     type = Style_Tools::SlRight;
00603                     slRect.setRight( slRect.right()+aXAdd );
00604                  }
00605               }
00606               Style_Tools::drawSlider( p, slRect, model()->widgetRounding( Style_Model::SliderRadius ), type,
00607                                        aBtnCol.light( BUT_PERCENT_COL ),
00608                                        aBtnCol.dark( BUT_PERCENT_COL ), aBrdTopCol, aBrdBotCol );
00609               QRect aHRect = handle;
00610               int aXRect = (int)(aHRect.width()/5),
00611                   aYRect = (int)(aHRect.height()/5);
00612               aHRect = QRect( aHRect.x()+aXRect, aHRect.y()+aYRect,
00613                               aHRect.width()-2*aXRect, aHRect.height()-2*aYRect );
00614               drawHandle( p, aHRect, horiz );
00615             }
00616             break;
00617         }
00618     }
00619     case CC_ToolButton: {
00620       if (const QStyleOptionToolButton *toolbutton
00621            = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
00622         QRect button, menuArea;
00623         button = subControlRect(cc, toolbutton, SC_ToolButton, w);
00624         menuArea = subControlRect(cc, toolbutton, SC_ToolButtonMenu, w);
00625 
00626         if (w && ( qobject_cast<QToolBar *>(w->parentWidget() ) || 
00627                    ( toolbutton->state & State_AutoRaise && !( toolbutton->state & State_MouseOver ) ) )
00628             ) {
00629           QWindowsStyle::drawComplexControl( cc, opt, p, w );
00630           return;
00631         }
00632         int aMinDelta = (int)model()->widgetRounding( Style_Model::ButtonRadius );
00633         if ( !toolbutton->icon.isNull() )
00634           aMinDelta = Style_Tools::getMinDelta( toolbutton->rect, toolbutton->iconSize, aMinDelta );
00635         bool aStateOn = opt->state & ( State_Sunken | State_On );
00636         QColor aBtnCol = opt->palette.color( QPalette::Button ),
00637                top    = aBtnCol.light( BUT_PERCENT_COL ),
00638                bottom = aBtnCol.dark( BUT_PERCENT_COL );
00639         bool isMenuBtn = toolbutton->features == QStyleOptionToolButton::Menu;
00640         bool antialized = model()->antialiasing();
00641         bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
00642         bool isHighWdg     = model()->widgetEffect() == Style_Model::HighlightEffect;
00643         bool hover = hasHover() && (opt->state & State_Enabled) && ( opt->state & State_MouseOver );
00644         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
00645         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
00646         QRect aRect = button;
00647         int aType = isMenuBtn ? Style_Tools::Left : Style_Tools::All;
00648         if ( toolbutton->subControls & SC_ToolButton ) {
00649           if ( isAutoRaising && hover && !aStateOn )
00650             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, bottom, top, aBrdTopCol,
00651                                      aBrdBotCol, antialized, true, aStateOn );
00652           else if ( isHighWdg && hover && !aStateOn )
00653             drawHoverRect( p, aRect, opt->palette.color( QPalette::Window ), aMinDelta, aType, true );
00654           else
00655             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, top, bottom,
00656                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
00657         }
00658         if (toolbutton->subControls & SC_ToolButtonMenu) {
00659           p->save();
00660           if ( aMinDelta > menuArea.height()/2 )
00661             aMinDelta = menuArea.height()/2;
00662           if ( aMinDelta > menuArea.width()/2 )
00663             aMinDelta = menuArea.width()/2;
00664           aRect = menuArea;
00665           aType = isMenuBtn ? Style_Tools::Right : Style_Tools::All;
00666           if ( isAutoRaising && hover && !aStateOn )
00667             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, bottom, top,
00668                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
00669           else if ( isHighWdg && hover && !aStateOn )
00670             drawHoverRect( p, aRect, opt->palette.color( QPalette::Window ), aMinDelta, aType, true );
00671           else
00672             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, top, bottom,
00673                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
00674           QStyleOption tool(0);
00675           tool.palette = toolbutton->palette;
00676           tool.rect = menuArea;
00677           State bflags = toolbutton->state;
00678           if (bflags & State_AutoRaise) {
00679               if (!(bflags & State_MouseOver)) {
00680                   bflags &= ~State_Raised;
00681               }
00682           }
00683           State mflags = bflags;
00684             if (toolbutton->activeSubControls & SC_ToolButton)
00685                 bflags |= State_Sunken;
00686             if (toolbutton->activeSubControls & SC_ToolButtonMenu)
00687                 mflags |= State_Sunken;
00688           tool.state = mflags;
00689           drawPrimitive(PE_IndicatorArrowDown, &tool, p, w);
00690           p->restore();
00691         }
00692 
00693         if (toolbutton->state & State_HasFocus) {
00694           QStyleOptionFocusRect fr;
00695           fr.QStyleOption::operator=(*toolbutton);
00696           fr.rect.adjust(3, 3, -3, -3);
00697           if (toolbutton->features & QStyleOptionToolButton::Menu)
00698             fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, w), 0);
00699           Style_Tools::drawFocus( p, fr.rect, aMinDelta-1,  isMenuBtn ? Style_Tools::Left :
00700                                   Style_Tools::All, aBrdBotCol );
00701         }
00702         QStyleOptionToolButton label = *toolbutton;
00703         int fw = pixelMetric( PM_DefaultFrameWidth, opt, w );
00704         label.rect = button.adjusted( fw, fw, -fw, -fw );
00705         drawControl( CE_ToolButtonLabel, &label, p, w );
00706 
00707         break;
00708       }
00709     }
00710     case CC_TitleBar: {
00711       QWindowsStyle::drawComplexControl( cc, opt, p, w );
00712       break;
00713     }
00714     case CC_GroupBox:
00715       if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const 
00716                                                  QStyleOptionGroupBox *>(opt)) {
00717         // Draw frame
00718         QRect textRect = subControlRect( cc, opt, SC_GroupBoxLabel, w );
00719         QRect checkBoxRect = subControlRect( cc, opt, SC_GroupBoxCheckBox, w);
00720         if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
00721           QRect aRect = subControlRect( cc, opt, SC_GroupBoxFrame, w);
00722           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
00723           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
00724           Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::FrameRadius ), 0.,
00725                                    SHADOW, Style_Tools::All,
00726                                    model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr
00727                                    model()->color( Style_Model::FieldDark ),  // Style_Model::fld_dark_clr
00728                                    aBrdTopCol, aBrdBotCol, false, false, false, false);
00729         }
00730         // Draw title
00731         if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
00732           QColor textColor = groupBox->textColor;
00733           if (textColor.isValid())
00734             p->setPen(textColor);
00735           int alignment = int(groupBox->textAlignment);
00736           if (!styleHint(QStyle::SH_UnderlineShortcut, opt, w))
00737             alignment |= Qt::TextHideMnemonic;
00738           QColor aColor = opt->palette.color( QPalette::Window );
00739           Style_Tools::arrowRect( p, textRect, opt->palette.color( QPalette::Dark ),
00740                                  aColor.dark(BUT_PERCENT_COL), aColor );
00741           drawItemText(p, textRect,  Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
00742                        pal, groupBox->state & State_Enabled, groupBox->text,
00743                        textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
00744           if (groupBox->state & State_HasFocus) {
00745             QStyleOptionFocusRect fropt;
00746             fropt.QStyleOption::operator=(*groupBox);
00747             fropt.rect = textRect;
00748             drawPrimitive(PE_FrameFocusRect, &fropt, p, w);
00749           }
00750         }
00751         // Draw checkbox
00752         if (groupBox->subControls & SC_GroupBoxCheckBox) {
00753             QStyleOptionButton box;
00754           box.QStyleOption::operator=(*groupBox);
00755           box.rect = checkBoxRect;
00756           drawPrimitive(PE_IndicatorCheckBox, &box, p, w);
00757         }
00758         break;
00759       }
00760     case CC_Dial: {
00761       QWindowsStyle::drawComplexControl( cc, opt, p, w );
00762       break;
00763     }
00764     default:
00765       QWindowsStyle::drawComplexControl( cc, opt, p, w );
00766   }
00767 }
00768 
00776 void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt,
00777                                QPainter* p, const QWidget* w ) const
00778 {
00779   if ( checkDebugLevel(5) ) {
00780     QWindowsStyle::drawControl( ce, opt, p, w );
00781     return;
00782   }
00783 
00784   switch ( ce ) {
00785     case CE_PushButton:
00786       if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
00787         drawControl(CE_PushButtonBevel, btn, p, w);
00788         QStyleOptionButton subopt = *btn;
00789         subopt.rect = subElementRect(SE_PushButtonContents, btn, w);
00790         drawControl(CE_PushButtonLabel, &subopt, p, w);
00791         if (btn->state & State_HasFocus) {
00792           QRect aRect = subElementRect( SE_PushButtonFocusRect, btn, w );
00793           Style_Tools::drawFocus( p, aRect, model()->widgetRounding( Style_Model::ButtonRadius ),
00794                                   Style_Tools::All, model()->color( Style_Model::BorderBottom ) );
00795         }
00796         break;
00797       }
00798     case CE_PushButtonBevel:
00799       if ( const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt) ) {
00800         double aRad = model()->widgetRounding( Style_Model::ButtonRadius );
00801         bool aStateOn = opt->state & ( State_Sunken | State_On );
00802         bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
00803         bool isHighWdg     = model()->widgetEffect() == Style_Model::HighlightEffect;
00804         bool enabled = opt->state & State_Enabled;
00805         bool hover = hasHover() && enabled && ( opt->state & State_MouseOver );
00806 
00807         QColor aBtnCol = opt->palette.color( QPalette::Button );
00808         QColor top = aBtnCol.light( BUT_PERCENT_COL ),
00809                bottom = aBtnCol.dark( BUT_PERCENT_COL );
00810         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
00811         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
00812         QRect r = opt->rect;
00813         bool antialized = model()->antialiasing();
00814         if ( isAutoRaising && hover && !aStateOn )
00815           Style_Tools::shadowRect( p, r, aRad, -1, SHADOW, Style_Tools::All, bottom, top,
00816                                    aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
00817         else if ( isHighWdg && hover && !aStateOn )
00818           drawHoverRect( p, r, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true );
00819         else
00820           Style_Tools::shadowRect( p, r, aRad, -1, SHADOW, Style_Tools::All, top, bottom,
00821                                    aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
00822        if (btn->features & QStyleOptionButton::HasMenu) {
00823          int mbi = pixelMetric(PM_MenuButtonIndicator, btn, w);
00824          QStyleOptionButton newBtn = *btn;
00825          newBtn.rect = QRect(r.right() - mbi-2, r.height()/2 - mbi/2, mbi, mbi);
00826          drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, w);
00827        }
00828         break;
00829       }
00830       case CE_DockWidgetTitle:
00831         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
00832           bool floating = false;
00833           int menuOffset = 0; //used to center text when floated
00834           QColor inactiveCaptionTextColor = opt->palette.color( QPalette::HighlightedText );
00835           const QDockWidget *dockWidget = qobject_cast<const QDockWidget *>(w);
00836           //Titlebar gradient
00837           if (dockWidget) {
00838             if ( dockWidget->isFloating() && dwOpt->movable) {
00839               floating = true;
00840               QColor top = opt->palette.color( QPalette::Highlight ).light();
00841               QColor bottom = opt->palette.color( QPalette::Highlight );
00842               menuOffset = 2;
00843               QBrush fillBrush(bottom);
00844               if (top != bottom) {
00845                 QPoint p1(dwOpt->rect.x(), dwOpt->rect.y());
00846                 QPoint p2(dwOpt->rect.x(), dwOpt->rect.bottom() );
00847                 QLinearGradient lg(p1, p2);
00848                 lg.setColorAt(0, top);
00849                 lg.setColorAt(1, bottom);
00850                 fillBrush = lg;
00851               }
00852               p->fillRect(dwOpt->rect.adjusted(0, 0, 0, -3), fillBrush);
00853             }
00854             else {
00855               QRect r = dwOpt->rect.adjusted(0, 0, -1, -1); 
00856               QColor bottom = opt->palette.color( QPalette::Window ),
00857                      top =    bottom.dark( BUT_PERCENT_COL );
00858               QRect aRect = dwOpt->rect;
00859               QLinearGradient gr( aRect.x(), aRect.y(), aRect.x(), aRect.y()+aRect.height() );
00860               gr.setColorAt( 0.0, top );
00861               gr.setColorAt( 0.4, bottom );
00862               gr.setColorAt( 0.6, bottom );
00863               gr.setColorAt( 1.0, top );
00864               p->fillRect( r, gr );
00865 
00866               QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );     // Style_Model::border_tab_top_clr
00867               QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom );  // Style_Model::border_tab_bot_clr
00868               p->setPen( aBrdTopCol );
00869               p->drawLine( r.x(), r.bottom(), r.x(), r.y() );
00870               p->drawLine( r.x(), r.y(), r.right(), r.y() );
00871               p->setPen( aBrdBotCol );
00872               p->drawLine( r.x(), r.bottom(), r.right(), r.bottom() );
00873               p->drawLine( r.right(), r.bottom(), r.right(), r.y() );
00874             }
00875           }
00876           p->setPen(dwOpt->palette.color(QPalette::Light));
00877 
00878           QString aTitle = dwOpt->title;
00879           if (!aTitle.isEmpty()) {
00880             int aMargin  = pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, w);
00881             const int indent = p->fontMetrics().descent();
00882             QRect r = dwOpt->rect.adjusted(indent + 1, - menuOffset, -indent - 1, -1);
00883             QPixmap aPxm = standardPixmap( SP_DockWidgetCloseButton, opt, w);
00884             int aWidth = r.width() - aPxm.width()-2/*button margins*/;
00885             aPxm = standardPixmap( SP_TitleBarNormalButton, opt, w);
00886             aWidth = aWidth - aPxm.width()-2/*button margins*/;
00887             r = QRect( r.x(), r.y(), aWidth-aMargin-2/*buttons separator*/-2/*margin from text*/, r.height() );
00888 
00889             QFont oldFont = p->font();
00890             QFont font = oldFont;
00891             if (floating) {
00892               font.setBold(true);
00893               p->setFont(font);
00894             }
00895             aTitle = titleText( aTitle, r.width(), r.height(), font );
00896 
00897             QPalette palette = dwOpt->palette;
00898             palette.setColor(QPalette::Window, inactiveCaptionTextColor);
00899             bool active = dwOpt->state & State_Active;
00900             //const int indent = p->fontMetrics().descent();
00901             drawItemText(p, r, Qt::AlignLeft | Qt::AlignVCenter, palette,
00902                          dwOpt->state & State_Enabled, aTitle,
00903                          floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
00904             p->setFont(oldFont);
00905           }
00906           break;
00907         }
00908     case CE_Splitter: {
00909       QWindowsStyle::drawControl( ce, opt, p, w );
00910       QRect r = opt->rect;
00911       bool horiz = r.width() > r.height();
00912       int aLen = model()->splitHandleLength();
00913       if ( horiz )
00914         r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
00915       else
00916         r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
00917       drawHandle( p, r, horiz, true );
00918       break;
00919     }
00920     case CE_TabBarTabShape:
00921       if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
00922         if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedEast ||
00923             tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::RoundedWest) {
00924           p->save();
00925           QRect tabRect = opt->rect;
00926           // line under selected tab bar object
00927           bool isSelected = opt->state & State_Selected;
00928           bool isLast = tab->position == QStyleOptionTab::End ||
00929                         tab->position == QStyleOptionTab::OnlyOneTab;
00930           QColor aColor = opt->palette.color( QPalette::Window ),
00931                  aDarkColor = aColor.dark( BUT_PERCENT_ON );
00932           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );     // Style_Model::border_tab_top_clr
00933           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom );  // Style_Model::border_tab_bot_clr
00934 
00935           bool isHover = hasHover() && (opt->state & State_Enabled) &&
00936                                        (opt->state & State_MouseOver);
00937           if ( isHover && !isSelected && model()->widgetEffect() == Style_Model::HighlightEffect ) {
00938             aColor     = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr
00939             aDarkColor = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr
00940           }
00941           Style_Tools::tabRect( p, tabRect, (int)tab->shape,
00942                                 model()->widgetRounding( Style_Model::FrameRadius ),
00943                                 DELTA_H_TAB, aColor, aDarkColor,
00944                                 aBrdTopCol, aBrdBotCol, isSelected, isLast, isHover );
00945           p->restore();
00946         } else
00947            QCommonStyle::drawControl(ce, opt, p, w);
00948         break;
00949       }
00950     case CE_TabBarTabLabel:
00951       if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
00952         if ( tab->position == QStyleOptionTab::End ||
00953              tab->position == QStyleOptionTab::OnlyOneTab ) {
00954           QRect oldRect = opt->rect;
00955           int aDelta = 0;
00956           if ( tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth ) {
00957             aDelta = (int)(opt->rect.height()*DELTA_H_TAB/2);
00958             oldRect = QRect( oldRect.topLeft(), QPoint( oldRect.right()-aDelta, oldRect.bottom() ) );
00959           }
00960           else {
00961             aDelta = (int)(opt->rect.width()*DELTA_H_TAB/2);
00962             oldRect = QRect( oldRect.topLeft(), QPoint( oldRect.right(), oldRect.bottom()-aDelta ) );
00963           }
00964           QStyleOptionTab* copyTab = (QStyleOptionTab*)tab;
00965           copyTab->rect = oldRect;
00966           QWindowsStyle::drawControl( ce, copyTab, p, w );
00967         }
00968         else
00969           QWindowsStyle::drawControl( ce, opt, p, w );
00970         break;
00971       }
00972     case CE_MenuBarItem:
00973       if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
00974         if ( w )
00975           drawBackground( p, w->rect(), opt->palette.color( QPalette::Window ), true, true, true );
00976         bool active = mbi->state & State_Selected;
00977         bool hasFocus = mbi->state & State_HasFocus;
00978         bool down = mbi->state & State_Sunken;
00979         QStyleOptionMenuItem newMbi = *mbi;
00980         if (active || hasFocus) {
00981           QBrush b( opt->palette.color( QPalette::Window ) );
00982           if (active && down)
00983             p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
00984           if ( active && hasFocus) {
00985             bool aStateOn = opt->state & (State_Sunken | State_On);
00986             QColor aBtnCol = opt->palette.color( QPalette::Window ),
00987                    top =    aBtnCol.light( BUT_PERCENT_ON ),
00988                    bottom = aBtnCol.dark( BUT_PERCENT_ON );
00989             QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
00990             QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
00991             bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
00992             if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) &&
00993                  (opt->state & State_Selected) )
00994               drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true);
00995             else {
00996               Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top, bottom,
00997                                    aBrdTopCol, aBrdBotCol,
00998                                    model()->antialiasing(), true, aStateOn );
00999             }
01000           }
01001           if (active && down) {
01002             newMbi.rect.translate(pixelMetric(PM_ButtonShiftHorizontal, mbi, w),
01003                                   pixelMetric(PM_ButtonShiftVertical, mbi, w));
01004             p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
01005           }
01006         }
01007         QCommonStyle::drawControl(ce, &newMbi, p, w);
01008         break;
01009       }
01010     case CE_MenuBarEmptyArea:
01011       drawBackground( p, opt->rect, opt->palette.color( QPalette::Window ), true, true, true );
01012       break;
01013     case CE_ProgressBarGroove: {
01014       QColor aBgColor = opt->palette.color( QPalette::Window ),
01015         top =    aBgColor.light( BUT_PERCENT_ON ),
01016         bottom = aBgColor.dark( BUT_PERCENT_ON );
01017       QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
01018       QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
01019       Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::EditRadius ), -1,
01020                                SHADOW, Style_Tools::All, top, bottom, aBrdTopCol, aBrdBotCol,
01021                                model()->antialiasing(), true );
01022       break;
01023       }
01024     case CE_ProgressBarLabel:
01025       if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
01026         // implementation from qplastiquestyle
01027         // The busy indicator doesn't draw a label
01028         if (bar->minimum == 0 && bar->maximum == 0)
01029           return;
01030         p->save();
01031         QRect rect = bar->rect;
01032         QRect leftRect;
01033         p->setPen(bar->palette.text().color());
01034 
01035         bool vertical = false;
01036         bool inverted = false;
01037         bool bottomToTop = false;
01038         // Get extra style options if version 2
01039         if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
01040           vertical = (bar2->orientation == Qt::Vertical);
01041           inverted = bar2->invertedAppearance;
01042           bottomToTop = bar2->bottomToTop;
01043         }
01044         if (vertical) {
01045           rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
01046           QMatrix m;
01047           if (bottomToTop) {
01048             m.translate(0.0, rect.width());
01049             m.rotate(-90);
01050           } else {
01051             m.translate(rect.height(), 0.0);
01052             m.rotate(90);
01053           }
01054           p->setMatrix(m);
01055         }
01056         int progressIndicatorPos = int(((bar->progress - bar->minimum) / double(bar->maximum - bar->minimum)) * rect.width());
01057         bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted)
01058                     || ((bar->direction == Qt::LeftToRight) && inverted))) || (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop)));
01059         if (flip) {
01060           int indicatorPos = rect.width() - progressIndicatorPos;
01061           if (indicatorPos >= 0 && indicatorPos <= rect.width()) {
01062             p->setPen(bar->palette.base().color());
01063             leftRect = QRect(rect.left(), rect.top(), indicatorPos, rect.height());
01064           } else if (indicatorPos > rect.width()) {
01065             p->setPen(bar->palette.text().color());
01066           } else {
01067             p->setPen(bar->palette.base().color());
01068           }
01069         } else {
01070           if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) {
01071             leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
01072           } else if (progressIndicatorPos > rect.width()) {
01073             p->setPen(bar->palette.base().color());
01074           } else {
01075             p->setPen(bar->palette.text().color());
01076           }
01077         }
01078 
01079         p->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
01080         if (!leftRect.isNull()) {
01081           p->setPen(flip ? bar->palette.text().color() : bar->palette.base().color());
01082           p->setClipRect(leftRect, Qt::IntersectClip);
01083           p->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
01084         }
01085         p->restore();
01086       }
01087       break;
01088     case CE_ProgressBarContents:
01089       if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
01090         QRect rect = pb->rect;
01091         bool vertical = false;
01092         bool inverted = false;
01093         // Get extra style options if version 2
01094         const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);
01095         if (pb2) {
01096           vertical = (pb2->orientation == Qt::Vertical);
01097           inverted = pb2->invertedAppearance;
01098         }
01099         QMatrix m;
01100         if (vertical) {
01101           rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
01102           m.translate(rect.height(), 0.0);
01103           m.rotate(90);
01104         }
01105         QPalette pal2 = pb->palette;
01106         // Correct the highlight color if it is the same as the background
01107         if (pal2.highlight() == pal2.background())
01108             pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
01109                                                                  QPalette::Highlight));
01110         bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
01111         if (inverted)
01112           reverse = !reverse;
01113         int fw = 2;
01114         int width = rect.width() - 2 * fw;
01115         if (pb->minimum == 0 && pb->maximum == 0) {
01116           // draw busy indicator
01117           int x = (pb->progress - pb->minimum) % (width * 2);
01118           if (x > width)
01119             x = 2 * width - x;
01120           x = reverse ? rect.right() - x : x + rect.x();
01121           p->setPen(QPen(pal2.highlight().color(), 4));
01122           p->drawLine(x, rect.y() + 1, x, rect.height() - fw);
01123         } else {
01124           const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, w);
01125           int u;
01126           if (unit_width > 1)
01127             u = (rect.width() + unit_width / 3) / unit_width;
01128           else
01129             u = width / unit_width;
01130 
01131           int p_v = pb->progress - pb->minimum;
01132           int t_s = pb->maximum - pb->minimum ? pb->maximum - pb->minimum : 1;
01133 
01134           if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
01135             // scale down to something usable.
01136             p_v /= u;
01137             t_s /= u;
01138           }
01139 
01140           // nu < tnu, if last chunk is only a partial chunk
01141           int tnu, nu;
01142           tnu = nu = p_v * u / t_s;
01143 
01144           if (nu * unit_width > width)
01145             --nu;
01146 
01147           // Draw nu units out of a possible u of unit_width
01148           // width, each a rectangle bordered by background
01149           // color, all in a sunken panel with a percentage text
01150           // display at the end.
01151           int x = 0;
01152           int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : fw)
01153                            : rect.x() + fw;
01154           QStyleOptionProgressBarV2 pbBits = *pb;
01155           pbBits.rect = rect;
01156           pbBits.palette = pal2;
01157           int myY = pbBits.rect.y();
01158           int myHeight = pbBits.rect.height();
01159           pbBits.state = State_None;
01160           QRect aRect;
01161           QColor aColor = model()->color( Style_Model::ProgressBar );    // Style_Model::prbar_clr
01162           QColor top    = aColor.light( BUT_PERCENT_COL );
01163           QColor bottom = aColor.dark( BUT_PERCENT_COL );
01164           int aType;
01165           for (int i = 0; i <= nu; ++i) {
01166             aType = Style_Tools::None;
01167             if ( i < nu ) { // not last element
01168               aRect = QRect(x0 + x, myY, unit_width, myHeight);
01169               if ( i == 0 ) {
01170                 if ( reverse )
01171                   aRect.setRight( aRect.right()-fw );
01172                 if ( vertical )
01173                   aType = reverse ? Style_Tools::BottomLeft | Style_Tools::BottomRight
01174                                   : Style_Tools::TopLeft | Style_Tools::TopRight;
01175                 else
01176                   aType = reverse ? Style_Tools::Right : Style_Tools::Left;
01177               }
01178             }
01179             else { // last element if it's necessary
01180               if ( nu >= tnu )
01181                 break;
01182               int pixels_left = width - (nu * unit_width);
01183               int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
01184               aRect = QRect(offset, myY, pixels_left, myHeight);
01185               if ( vertical )
01186                 aType = reverse ? Style_Tools::TopLeft | Style_Tools::TopRight
01187                                 : Style_Tools::BottomLeft | Style_Tools::BottomRight;
01188               else
01189                 aType = reverse ? Style_Tools::Left : Style_Tools::Right;
01190             }
01191             // display
01192             aRect = m.mapRect(aRect);
01193             if ( vertical )
01194               aRect = QRect(aRect.x(), aRect.y()+fw, aRect.width(), aRect.height());
01195 
01196             if ( !vertical )
01197               aRect = QRect(aRect.x()+1, aRect.y()+2, aRect.width()-1,
01198                             aRect.height()-4);
01199             else
01200               aRect = QRect(aRect.x()+1, aRect.y()-1, aRect.width()-5, aRect.height()-1);
01201             QColor aTopClr = aColor, aBotClr = aColor;
01202             if ( unit_width > 1 ) {
01203               aTopClr = aColor.light();
01204               aBotClr = aColor.dark();
01205             }
01206             Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::EditRadius ), -1, 0,
01207                                      aType, top, bottom, aTopClr, aBotClr, false, true );
01208             x += reverse ? -unit_width : unit_width;
01209           }
01210         }
01211       }
01212       break;
01213     case CE_MenuItem:
01214       if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
01215         const int windowsItemFrame    =  2; // definitions from qwindowstyle.cpp file
01216         const int windowsItemHMargin  =  3;
01217         const int windowsItemVMargin  =  2;
01218         const int windowsRightBorder  = 15;
01219         const int windowsArrowHMargin =  6;
01220         int x, y, width, h;
01221         menuitem->rect.getRect(&x, &y, &width, &h);
01222         int tab = menuitem->tabWidth;
01223         bool dis = !(menuitem->state & State_Enabled);
01224         bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
01225                        ? menuitem->checked : false;
01226         bool act = menuitem->state & State_Selected;
01227 
01228         // windows always has a check column, regardless whether we have an icon or not
01229         int checkcol = qMax(menuitem->maxIconWidth, 20);
01230 
01231         QColor aBgColor = opt->palette.color( QPalette::Window );
01232         double aMargin = LINE_GR_MARGIN;
01233         QLinearGradient gr(x,y,menuitem->rect.right(),y);
01234         gr.setColorAt( 0.0, aBgColor );
01235         gr.setColorAt( aMargin/width, model()->color( Style_Model::FieldLight ) ); // Style_Model::fld_light_clr
01236         gr.setColorAt( 1.0, model()->color( Style_Model::FieldLight ) );
01237         QBrush fill;
01238         if ( act )
01239           fill = menuitem->palette.brush( QPalette::Highlight );
01240         else
01241           fill = QBrush( gr );
01242         p->fillRect(menuitem->rect, fill);
01243         if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
01244           int yoff = y-1 + h / 2;
01245           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
01246           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
01247           p->setPen( aBrdBotCol );
01248           p->drawLine(x + 2, yoff, x + width - 4, yoff);
01249           p->setPen( aBrdTopCol );
01250           p->drawLine(x + 2, yoff + 1, x + width - 4, yoff + 1);
01251           return;
01252         }
01253         QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(),
01254                                       menuitem->rect.y(), checkcol, menuitem->rect.height()));
01255         if (checked) {
01256           if (act && !dis)
01257             qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, new QBrush(aBgColor));
01258           else {
01259             QColor aCol = aBgColor;
01260             aCol.setAlpha( 80 );
01261             QBrush fill(aCol);
01262             qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
01263           }
01264         } else if (!act)
01265           p->fillRect(vCheckRect, QBrush( gr ) );
01266         // On Windows Style, if we have a checkable item and an icon we
01267         // draw the icon recessed to indicate an item is checked. If we
01268         // have no icon, we draw a checkmark instead.
01269         if (!menuitem->icon.isNull()) {
01270           QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
01271           if (act && !dis)
01272             mode = QIcon::Active;
01273           QPixmap pixmap;
01274           if (checked)
01275             pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
01276           else
01277             pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
01278           int pixw = pixmap.width();
01279           int pixh = pixmap.height();
01280           if (act && !dis && !checked)
01281             qDrawShadePanel(p, vCheckRect,  menuitem->palette, false, 1,
01282                             new QBrush(aBgColor));
01283           QRect pmr(0, 0, pixw, pixh);
01284           pmr.moveCenter(vCheckRect.center());
01285           p->setPen(menuitem->palette.text().color());
01286           p->drawPixmap(pmr.topLeft(), pixmap);
01287         } else if (checked) {
01288           QStyleOptionMenuItem newMi = *menuitem;
01289           newMi.state = State_None;
01290           if (!dis)
01291             newMi.state |= State_Enabled;
01292           if (act)
01293             newMi.state |= State_On;
01294           newMi.rect = visualRect(opt->direction, menuitem->rect,
01295           QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
01296                 checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
01297           drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
01298         }
01299         p->setPen(act ? menuitem->palette.highlightedText().color() :
01300                         menuitem->palette.buttonText().color());
01301         QColor discol;
01302         if (dis) {
01303           discol = menuitem->palette.text().color();
01304           p->setPen(discol);
01305         }
01306         int xm = windowsItemFrame + checkcol + windowsItemHMargin;
01307         int xpos = menuitem->rect.x() + xm;
01308         QRect textRect(xpos, y + windowsItemVMargin, width - xm - windowsRightBorder - tab + 1,
01309                        h - 2 * windowsItemVMargin);
01310         QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
01311         QString s = menuitem->text;
01312         if (!s.isEmpty()) {                     // draw text
01313           p->save();
01314           int t = s.indexOf(QLatin1Char('\t'));
01315           int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip |
01316                            Qt::TextSingleLine;
01317           if (!styleHint(SH_UnderlineShortcut, menuitem, w))
01318             text_flags |= Qt::TextHideMnemonic;
01319           text_flags |= Qt::AlignLeft;
01320           if (t >= 0) {
01321             QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, 
01322             QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
01323             if (dis && !act) {
01324                p->setPen(menuitem->palette.light().color());
01325                p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
01326                p->setPen(discol);
01327              }
01328              p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
01329              s = s.left(t);
01330           }
01331           QFont font = menuitem->font;
01332           if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
01333             font.setBold(true);
01334             p->setFont(font);
01335             if (dis && !act) {
01336               p->setPen(menuitem->palette.light().color());
01337               p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
01338               p->setPen(discol);
01339             }
01340             p->drawText(vTextRect, text_flags, s.left(t));
01341             p->restore();
01342           }
01343           if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
01344             int dim = (h - 2 * windowsItemFrame) / 2;
01345             PrimitiveElement arrow;
01346             arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft :
01347                      PE_IndicatorArrowRight;
01348             xpos = x + width - windowsArrowHMargin - windowsItemFrame - dim;
01349             QRect  vSubMenuRect = visualRect(opt->direction, menuitem->rect,
01350                                              QRect(xpos, y + h / 2 - dim / 2, dim, dim));
01351             QStyleOptionMenuItem newMI = *menuitem;
01352             newMI.rect = vSubMenuRect;
01353             newMI.state = dis ? State_None : State_Enabled;
01354             if (act)
01355               newMI.palette.setColor(QPalette::ButtonText,
01356                                      newMI.palette.highlightedText().color());
01357             drawPrimitive(arrow, &newMI, p, w);
01358           }
01359         }
01360       break;
01361       /*
01362     case CE_ToolBoxTab:
01363       QCommonStyle::drawControl( ce, opt, p, w );
01364       break;
01365       */
01366     case CE_HeaderSection: {
01367       bool aStateOn = opt->state & State_On;
01368       QColor aColor = model()->color( Style_Model::Header );    // Style_Model::header_clr
01369       QColor  top =    aColor.light( BUT_PERCENT_COL ),
01370              bottom =  aColor.dark( BUT_PERCENT_COL );
01371       QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
01372       QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
01373       Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol,
01374                        aBrdBotCol, model()->antialiasing(), true, aStateOn );
01375       break;
01376     }
01377     case CE_ComboBoxLabel:
01378       if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
01379         QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, w);
01380         p->save();
01381         p->setClipRect(editRect);
01382         if (!cb->currentIcon.isNull()) {
01383           QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
01384                                                        : QIcon::Disabled;
01385           QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
01386           QRect iconRect(editRect);
01387           iconRect.setWidth(cb->iconSize.width() + 4);
01388           QRect alignRect = editRect;
01389           if ( cb->editable ) {
01390             int aHalfRect = (int)Style_Tools::getMaxRect( iconRect, 
01391                                (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
01392             alignRect.setLeft( alignRect.left() + aHalfRect );
01393             alignRect.setRight( alignRect.right() - aHalfRect );
01394           }
01395           iconRect = alignedRect(QApplication::layoutDirection(),
01396                                  Qt::AlignLeft | Qt::AlignVCenter,
01397                                  iconRect.size(), alignRect);
01398  
01399           // Here's absent filling of pixmap on basic color for editable comboBox
01400           drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
01401 
01402           if (cb->direction == Qt::RightToLeft)
01403             editRect.translate(-4 - cb->iconSize.width(), 0);
01404           else
01405             editRect.translate(cb->iconSize.width() + 4, 0);
01406         }
01407         if (!cb->currentText.isEmpty() && !cb->editable) {
01408           drawItemText(p, editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, cb->palette,
01409                        cb->state & State_Enabled, cb->currentText);
01410         }
01411         p->restore();
01412       }
01413       break;
01414     case CE_ScrollBarSubLine:
01415     case CE_ScrollBarAddLine: {
01416         bool aStateOn = opt->state & ( State_Sunken | State_On );
01417         QColor aBtnCol = opt->palette.color( QPalette::Button );
01418         QColor top =    aBtnCol.light( BUT_PERCENT_COL ),
01419                bottom = aBtnCol.dark( BUT_PERCENT_COL );
01420         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
01421         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
01422         Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol,
01423                                  aBrdBotCol, false, true, aStateOn, true );
01424       PrimitiveElement arrow;
01425       if (opt->state & State_Horizontal) {
01426         if (ce == CE_ScrollBarAddLine)
01427           arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
01428         else
01429           arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
01430       } else {
01431         if (ce == CE_ScrollBarAddLine)
01432           arrow = PE_IndicatorArrowDown;
01433         else
01434           arrow = PE_IndicatorArrowUp;
01435       }
01436       drawPrimitive(arrow, opt, p, w);
01437       break;
01438     }
01439     case CE_ScrollBarSlider:
01440       if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
01441         p->save();
01442         p->setRenderHint( QPainter::Antialiasing, true );
01443         bool enabled = opt->state & State_Enabled;
01444         bool horiz = scrollbar->orientation == Qt::Horizontal;
01445         double aRad = model()->widgetRounding( Style_Model::ButtonRadius );
01446         if ( hasHover() && enabled && (opt->state & State_MouseOver) )
01447          drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, false);
01448         else {
01449         QColor aColor = model()->color( Style_Model::Slider );      // Style_Model::slider_clr
01450           if ( !enabled )
01451             aColor = opt->palette.button().color();
01452           QColor top =    aColor.light( BUT_PERCENT_ON ),
01453                  bottom = aColor.dark( BUT_PERCENT_ON );
01454           QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
01455           QRect r = opt->rect;
01456           QPainterPath path = Style_Tools::roundRect( r, aRad,
01457                                                       Style_Tools::All );
01458           QLinearGradient gr;
01459           if (horiz)
01460             gr = QLinearGradient(r.x(), r.y(), r.x(), r.bottom());
01461           else
01462             gr = QLinearGradient(r.x(), r.y(), r.right(), r.y());
01463           gr.setColorAt( 0.0, bottom );
01464           gr.setColorAt( 0.5, top );
01465           gr.setColorAt( 1.0, bottom );
01466 
01467           p->fillPath( path, gr );
01468           p->strokePath( path, aBrdTopCol );
01469       }
01470       p->setRenderHint( QPainter::Antialiasing, false );
01471       // draw handle
01472       QRect aRect = opt->rect;
01473       int aWidth = aRect.width(), aHeight = aRect.height();
01474       if ( aWidth > aHeight + aRad )
01475         aRect = QRect( aRect.x() + (int)((aWidth-aHeight)/2),
01476                        aRect.y(), aHeight, aHeight );
01477       else if ( aHeight > aWidth + aRad )
01478         aRect = QRect( aRect.x(), aRect.y() + (int)((aHeight-aWidth)/2),
01479                        aWidth, aWidth );
01480       else {
01481         int aRad2 = (int)(aRad/3);
01482         aRect = QRect( aRect.x()+aRad2, aRect.y()+aRad2, aRect.width()-2*aRad2, aRect.height()-2*aRad2  );
01483       }
01484       drawHandle( p, aRect, horiz, true );
01485 
01486       p->restore();
01487       break;
01488     }
01489   case CE_ToolBar: {
01490     QRect r = w->rect();
01491     bool horiz = opt->state & State_Horizontal;
01492     drawBackground( p, r, opt->palette.color( QPalette::Window ), true, true, horiz );
01493     p->setRenderHint( QPainter::Antialiasing, false );
01494     drawBorder( p, r, horiz );
01495     break;
01496   }
01497   default:
01498     QWindowsStyle::drawControl( ce, opt, p, w );
01499     break;
01500   }
01501 }
01502 
01510 void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt,
01511                                   QPainter* p, const QWidget* w ) const
01512 {
01513   if ( checkDebugLevel(6) ) {
01514     QWindowsStyle::drawPrimitive( pe, opt, p, w );
01515     return;
01516   }
01517 
01518   const QPalette& pal = opt->palette;
01519   bool doRestore = false;
01520   switch ( pe ) {
01521     case PE_FrameMenu:
01522       if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
01523         QColor aBtnCol = opt->palette.color( QPalette::Window ),
01524                top =    aBtnCol.light( BUT_PERCENT_ON ),
01525                bottom = aBtnCol.dark( BUT_PERCENT_ON );
01526         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
01527         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
01528         Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top,
01529                                  bottom, aBrdTopCol, aBrdBotCol, false, false, false, false );
01530         break;
01531       }
01532     case PE_PanelButtonTool : {
01533       if ( w && ( opt->state & State_Enabled ) && 
01534            ( ( qobject_cast<QToolBar*>( w->parentWidget() ) ) ||
01535              ( w->inherits("QDockWidgetTitleButton") ) ||
01536              ( w->inherits("QtxWorkstackAreaTitleButton") ) ) ) {
01537         bool aStateOn = opt->state & (State_Sunken | State_On);
01538         bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
01539         if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) &&
01540              (opt->state & State_MouseOver) )
01541           drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true);
01542         else {
01543           QColor aBtnCol = opt->palette.color( QPalette::Window );
01544           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
01545           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
01546           QColor top =    aBtnCol.light( BUT_PERCENT_COL ),
01547                  bottom = aBtnCol.dark( BUT_PERCENT_COL );
01548           Style_Tools::shadowRect( p, opt->rect, 0.0, 0, SHADOW, Style_Tools::All, top, bottom,
01549            aBrdTopCol, aBrdBotCol, model()->antialiasing(), true, aStateOn );
01550         }
01551         break;
01552       }
01553       else
01554         QWindowsStyle::drawPrimitive( pe, opt, p, w );
01555     }
01556     break;
01557     case PE_FrameFocusRect: {
01558       if (w && qobject_cast<QTabBar*>((QWidget*)w)) {
01559         QTabBar* tabBar = qobject_cast<QTabBar*>((QWidget*)w);
01560         QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
01561         QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
01562         bool isHover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
01563         Style_Tools::tabRect( p, opt->rect, (int)tabBar->shape(),
01564                               model()->widgetRounding( Style_Model::FrameRadius ), DELTA_H_TAB,
01565                               pal.color( QPalette::Window ),
01566                               model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr
01567                               aBrdTopCol, aBrdBotCol, false, false, isHover, true );
01568       }
01569       else {
01570         QWindowsStyle::drawPrimitive( pe, opt, p, w );
01571       }
01572       break;
01573     }
01574     case PE_IndicatorArrowRight:
01575     case PE_IndicatorArrowLeft:
01576     case PE_IndicatorArrowUp:
01577     case PE_IndicatorArrowDown:
01578     case PE_IndicatorSpinUp:
01579     case PE_IndicatorSpinDown:
01580     case PE_IndicatorSpinPlus:
01581     case PE_IndicatorSpinMinus: {
01582       QRect rect = opt->rect;
01583       QColor pen, brush;
01584       if ( opt->state & State_Enabled ) {
01585         pen = model()->color( Style_Model::Pointer );    // Style_Model::pointer_clr
01586         brush = opt->palette.color( QPalette::Button );
01587         if ( ( opt->state & State_Sunken ) && (opt->state & State_Enabled ) )
01588           rect.moveTo( rect.x()+1, rect.y()+1 );
01589       } else {
01590         pen = opt->palette.mid().color();
01591         brush = pen;
01592       }
01593       if ( pe == PE_IndicatorSpinPlus || pe == PE_IndicatorSpinMinus )
01594         Style_Tools::drawSign( pe, p, rect, pen, brush );
01595       else
01596         Style_Tools::drawArrow( pe, p, rect, pen, brush );
01597       break;
01598     }
01599     case PE_IndicatorCheckBox: {
01600       if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) )
01601         drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ),
01602                       model()->widgetRounding( Style_Model::EditRadius ),
01603                       Style_Tools::All, false);
01604       QBrush fill;
01605       if (opt->state & State_NoChange)
01606         fill = QBrush( opt->palette.color( QPalette::Base ), Qt::Dense4Pattern);
01607       else if (opt->state & ( State_Sunken | ~State_Enabled ) )
01608         fill = opt->palette.color( QPalette::Window );
01609       else if (opt->state & State_Enabled) {
01610         if (!(opt->state & State_Off) )
01611           fill = QBrush( model()->color( Style_Model::Checked ) ); // Style_Model::checked_clr
01612         else
01613           fill = QBrush( opt->palette.color( QPalette::Base ) );
01614       }
01615       else
01616         fill = opt->palette.color( QPalette::Window );
01617       p->save();
01618       doRestore = true;
01619       QColor color = fill.color();
01620       QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
01621       QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
01622       if ( model()->antialiasing() )
01623         p->setRenderHint( QPainter::Antialiasing, true );
01624 
01625      // make sure the indicator is square
01626       QRect ir = opt->rect;
01627       if (opt->rect.width() < opt->rect.height()) {
01628         ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
01629         ir.setHeight(opt->rect.width());
01630       } else if (opt->rect.height() < opt->rect.width()) {
01631         ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
01632         ir.setWidth(opt->rect.height());
01633       }
01634 
01635       Style_Tools::shadowCheck( p, ir, 2., Style_Tools::All,
01636                                 color, color.dark( BUT_PERCENT_ON ), aBrdTopCol, aBrdBotCol );
01637       if ( model()->antialiasing() )
01638         p->setRenderHint( QPainter::Antialiasing, false );
01639       if (opt->state & State_NoChange)
01640         p->setPen(opt->palette.dark().color());
01641       else
01642         p->setPen(opt->palette.text().color());
01643      } // Fall through!
01644     case PE_IndicatorViewItemCheck:
01645     case PE_Q3CheckListIndicator: {
01646       if (!doRestore) {
01647         p->save();
01648         doRestore = true;
01649       }
01650       const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
01651       p->setPen(itemViewOpt && itemViewOpt->showDecorationSelected
01652                 && opt->state & State_Selected ? opt->palette.highlightedText().color()
01653                 : opt->palette.text().color());
01654       if (opt->state & State_NoChange)
01655         p->setBrush( opt->palette.color( QPalette::Button ) );
01656       p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
01657       if (!(opt->state & State_Off)) {
01658         QLineF lines[11];
01659         int i, xx, yy;
01660         xx = opt->rect.x() + 4;
01661         yy = opt->rect.y() + 5;
01662         for (i = 0; i < 3; ++i) {
01663           lines[i] = QLineF(xx, yy, xx, yy + 2);
01664           ++xx;
01665           ++yy;
01666         }
01667         yy -= 2;
01668         for (i = 3; i < 11; ++i) {
01669           lines[i] = QLineF(xx, yy, xx, yy+2);
01670           ++xx;
01671           --yy;
01672         }
01673         QColor aColor = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
01674         if ( !(opt->state & State_Enabled ) )
01675           aColor = opt->palette.mid().color();
01676         if ( opt->state & State_Selected && itemViewOpt && itemViewOpt->showDecorationSelected )
01677           aColor = opt->palette.highlightedText().color();
01678 
01679         p->setPen( QPen( aColor ) );
01680         p->drawLines(lines, 11);
01681       }
01682 
01683       if (doRestore)
01684           p->restore();
01685       break;
01686     }
01687     case PE_IndicatorRadioButton: {
01688       if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) )
01689         drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ), 
01690                       model()->widgetRounding( Style_Model::ButtonRadius ),
01691                       Style_Tools::All, false);
01692 #define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
01693       static const QPoint pts_border[] = {              // border line
01694         QPoint(1, 9),  QPoint(1, 8),  QPoint(0, 7),  QPoint(0, 4),  QPoint(1, 3),  QPoint(1, 2),
01695         QPoint(2, 1),  QPoint(3, 1),  QPoint(4, 0),  QPoint(7, 0),  QPoint(8, 1),  QPoint(9, 1),
01696         QPoint(10, 2), QPoint(10, 3), QPoint(11, 4), QPoint(11, 7), QPoint(10, 8), QPoint(10, 9), 
01697         QPoint(9, 10), QPoint(8, 10), QPoint(7, 11), QPoint(4, 11), QPoint(3, 10), QPoint(2, 10)
01698       };
01699      // make sure the indicator is square
01700       QRect ir = opt->rect;
01701       if (opt->rect.width() < opt->rect.height()) {
01702         ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
01703         ir.setHeight(opt->rect.width());
01704       } else if (opt->rect.height() < opt->rect.width()) {
01705         ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
01706         ir.setWidth(opt->rect.height());
01707       }
01708       p->save();
01709       bool down = opt->state & State_Sunken;
01710       bool enabled = opt->state & State_Enabled;
01711       bool on = opt->state & State_On;
01712       QPolygon a;
01713       p->translate(ir.x(), ir.y());
01714 
01715       if ( down || !enabled ) {
01716         QColor fillColor = opt->palette.color( QPalette::Window );
01717         p->setPen( fillColor );
01718         p->setBrush( fillColor );
01719       }
01720       else {
01721         QColor fillColor =  opt->palette.color( QPalette::Base );
01722         if ( enabled && on )
01723           fillColor = model()->color( Style_Model::Checked ); // Style_Model::checked_clr
01724         QLinearGradient gr( 3, 3, 8, 8 );
01725         gr.setColorAt( 0.0, fillColor.dark( BUT_PERCENT_ON ) );
01726         gr.setColorAt( 1.0, fillColor );
01727         p->setPen( fillColor.dark( BUT_PERCENT_ON ) );
01728         p->setBrush( gr );
01729       }
01730       p->drawPolygon(pts_border, PTSARRLEN(pts_border));
01731       int aSize = PTSARRLEN(pts_border),
01732           aHalfSize = (int)aSize/2;
01733       if ( model()->antialiasing() )
01734         p->setRenderHint( QPainter::Antialiasing, true );
01735       p->setPen( model()->color( Style_Model::BorderTop) );     // Style_Model::border_top_clr
01736       p->drawPolyline(pts_border, aHalfSize);
01737       p->setPen( model()->color( Style_Model::BorderBottom ) ); // Style_Model::border_bot_clr
01738       QPolygon aPolygon;
01739       for ( int i = aHalfSize; i < aSize; i++ )
01740         aPolygon << pts_border[i];
01741       p->drawPolyline( aPolygon );
01742       if ( model()->antialiasing() )
01743         p->setRenderHint( QPainter::Antialiasing, false );
01744 
01745       if (on) {
01746         QColor aPointerCol = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
01747         if ( !enabled )
01748           aPointerCol = opt->palette.mid().color();
01749         p->setPen( Qt::NoPen );
01750         p->setBrush( aPointerCol );
01751         p->drawRect( 5, 4, 2, 4 );
01752         p->drawRect( 4, 5, 4, 2 );
01753       }
01754 
01755       p->translate(-ir.x(), -ir.y()); // restore translate
01756       p->restore();
01757       break;
01758     }
01759     case PE_FrameDockWidget:
01760       if ( qstyleoption_cast<const QStyleOptionFrame *>(opt))
01761         QCommonStyle::drawPrimitive( pe, opt, p, w );
01762       break;
01763     case PE_FrameLineEdit:
01764     case PE_PanelLineEdit: {
01765       if ( w ) {
01766         if ( qobject_cast<const QComboBox*>( w->parentWidget() ) ||
01767              qobject_cast<const QAbstractSpinBox*>( w->parentWidget() ) )
01768           break;
01769       }
01770       if ( pe == PE_FrameLineEdit ) {
01771         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
01772         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
01773         bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
01774         double aRad = model()->widgetRounding( Style_Model::EditRadius );
01775         if ( hover )
01776           drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true);
01777         else {
01778           Style_Tools::shadowRect( p, opt->rect, aRad, LINE_GR_MARGIN, SHADOW,
01779                                    Style_Tools::All, opt->palette.color( QPalette::Base ), // getColor( Style_Model::fld_light_clr ),
01780                                    model()->color( Style_Model::FieldDark ), aBrdTopCol, aBrdBotCol,
01781                                    model()->antialiasing(), false );
01782         }
01783       }
01784       else {
01785         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
01786           QRect rect = panel->rect.adjusted( panel->lineWidth,  panel->lineWidth,
01787                                              -panel->lineWidth, -panel->lineWidth);
01788           if ( w->inherits("QLineEdit") && panel->lineWidth > 0 ) {
01789             drawPrimitive( PE_FrameLineEdit, panel, p, w );
01790           }
01791           else {
01792             QColor c = panel->palette.color(QPalette::Base); c.setAlpha(255);
01793             p->fillRect( rect, c ); // panel->palette.brush(QPalette::Base)
01794           }
01795         }
01796       }
01797       break;
01798     }
01799     case PE_FrameTabWidget: {
01800       if (w && qobject_cast<QTabWidget*>((QWidget*)w)) {
01801         QTabWidget* tabW = qobject_cast<QTabWidget*>((QWidget*)w);
01802         int aRoundType = Style_Tools::BottomRight;
01803         QTabWidget::TabPosition aTabPos = tabW->tabPosition();
01804         if ( aTabPos != QTabWidget::North && aTabPos != QTabWidget::West )
01805           aRoundType = aRoundType | Style_Tools::TopLeft;
01806         if ( aTabPos != QTabWidget::South )
01807           aRoundType = aRoundType | Style_Tools::BottomLeft;
01808         if ( aTabPos != QTabWidget::East )
01809           aRoundType = aRoundType | Style_Tools::TopRight;
01810         QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
01811         QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
01812         Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::FrameRadius ),
01813                                  0., SHADOW, aRoundType,
01814                                  model()->color( Style_Model::FieldLight ),
01815                                  opt->palette.color( QPalette::Dark ),
01816                                  aBrdTopCol, aBrdBotCol, false, false, false, false );
01817         break;
01818       }
01819     }
01820     case PE_IndicatorToolBarHandle: {
01821       p->save();
01822       QRect r = opt->rect;
01823       bool horiz = opt->state & State_Horizontal;
01824       QLinearGradient gr( r.x(), r.y(), horiz ? r.x() : r.right(), horiz ? r.bottom() : r.y() );
01825       QColor aBgCol = opt->palette.color( QPalette::Window );
01826       gr.setColorAt( 0.0, aBgCol.light( BUT_PERCENT_ON ) );
01827       gr.setColorAt( 1.0, aBgCol );
01828       p->fillRect( r, gr );
01829       drawHandle( p, r, horiz, false );
01830       p->restore();
01831       break;
01832     }
01833     case PE_Widget: {
01834       QWindowsStyle::drawPrimitive( pe, opt, p, w );
01835       if ( !w )
01836         break;
01837       if( w->parent() && !qobject_cast<QMenuBar*>((QWidget*)w) )
01838          break;
01839       drawBackground( p, w->rect(), opt->palette.color( QPalette::Window ), false );
01840       break;
01841     }
01842     case PE_FrameTabBarBase:
01843       // for a tabbar that isn't part of a tab widget(dockWidgets for example).
01844       if (const QStyleOptionTabBarBase *tbb
01845           = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
01846         if (tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedEast &&
01847             tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedWest) {
01848           QWindowsStyle::drawPrimitive( pe, opt, p, w );
01849           break;
01850         }
01851         QRect aSelRect = tbb->selectedTabRect;
01852         // line under selected tab bar object
01853         bool isSelected = opt->state & State_Selected;
01854         QTabBar* tabBar = qobject_cast<QTabBar*>((QWidget*)w);
01855         bool isLast = false;
01856         if ( tabBar )
01857           isLast = tabBar->currentIndex() == tabBar->count() -1;
01858         QColor aColor = opt->palette.color( QPalette::Window );
01859         bool isHover = hasHover() && (opt->state & State_Enabled) &&
01860                                      (opt->state & State_MouseOver);
01861         QPainterPath aSelPath = Style_Tools::tabRect( p, aSelRect, (int)tbb->shape,
01862                                                       model()->widgetRounding( Style_Model::FrameRadius ),
01863                                                       DELTA_H_TAB, aColor, aColor,
01864                             aColor, aColor, isSelected, isLast, isHover, false, false );
01865         if ( !aSelPath.isEmpty() )
01866           aSelRect = aSelPath.controlPointRect().toRect();
01867         QStyleOptionTabBarBase* copyOpt = (QStyleOptionTabBarBase*)tbb;
01868         copyOpt->selectedTabRect = aSelRect;
01869         QCommonStyle::drawPrimitive( pe, copyOpt, p, w );
01870         break;
01871       }
01872     case PE_IndicatorBranch: {
01873         // This is _way_ too similar to the common style.
01874         static const int decoration_size = 9;
01875         int mid_h = opt->rect.x() + opt->rect.width() / 2;
01876         int mid_v = opt->rect.y() + opt->rect.height() / 2;
01877         int bef_h = mid_h;
01878         int bef_v = mid_v;
01879         int aft_h = mid_h;
01880         int aft_v = mid_v;
01881         if (opt->state & State_Children) {
01882             int delta = decoration_size / 2;
01883             bef_h -= delta;
01884             bef_v -= delta;
01885             aft_h += delta;
01886             aft_v += delta;
01887             p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
01888             if (!(opt->state & State_Open))
01889                 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
01890             QPen oldPen = p->pen();
01891             p->setPen(opt->palette.dark().color());
01892             p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
01893             p->setPen(oldPen);
01894         }
01895         QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
01896         if (opt->state & State_Item) {
01897             if (opt->direction == Qt::RightToLeft)
01898                 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
01899             else
01900                 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
01901         }
01902         if (opt->state & State_Sibling)
01903             p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
01904         if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
01905             p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
01906         break;
01907       }
01908     case PE_IndicatorDockWidgetResizeHandle: {
01909       QRect r = opt->rect;
01910       drawBorder( p, r, opt->state & State_Horizontal );
01911       bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
01912       if ( hover )
01913           drawHoverRect(p, r, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, false);
01914       bool horiz = r.width() > r.height();
01915       int aLen = model()->splitHandleLength();
01916       if ( horiz )
01917         r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
01918       else
01919         r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
01920       drawHandle( p, r, horiz, true );
01921       break;
01922     }
01923     case PE_Frame: {
01924       QWidget* aWdg = (QWidget*)w;
01925       if ( qobject_cast<QTextEdit*>(aWdg) || qobject_cast<QTreeView*>(aWdg) ||
01926            qobject_cast<QListView*>(aWdg) ) {
01927         QRect r = opt->rect;
01928         if ( qobject_cast<QTreeView*>(aWdg) ) {
01929           QTreeView* trView = qobject_cast<QTreeView*>(aWdg);
01930           QHeaderView* aHeader = trView->header();
01931           if ( aHeader && aHeader->isVisible() ) {
01932             int aHeight = aHeader->contentsRect().height();
01933             r = QRect( r.x(), r.y()+aHeight, r.width(), r.height()-aHeight );
01934           }
01935         }
01936         QPalette aPal = aWdg->palette();
01937         double aMarg = LINE_GR_MARGIN;
01938         QColor base = model()->color( Style_Model::Base ), // Style_Model::pal_base_clr
01939           light = base,
01940           light_alt = base.dark(110),//AlternateBase color
01941           dark  = model()->color( Style_Model::FieldDark ); // Style_Model::fld_dark_clr
01942         //light.setAlpha( 0 ); // VSR commented: IPAL19262
01943         QLinearGradient gr_h(r.x(), r.y(), r.right(), r.y());
01944         gr_h.setColorAt( 0.0, dark );
01945         gr_h.setColorAt( aMarg / r.width(), light );
01946         gr_h.setColorAt( 1.0, light );
01947         QLinearGradient gr_v(r.x(), r.y(), r.x(), r.bottom() );
01948         gr_v.setColorAt( 0.0, dark );
01949         gr_v.setColorAt( aMarg / r.height(), light );
01950         gr_v.setColorAt( 1.0, light );
01951         // draw frame
01952         p->fillRect( r, base );
01953         p->fillRect( r, gr_h );
01954         p->fillRect( r, gr_v );
01955         aPal.setBrush( QPalette::Base, QBrush( light ) );
01956 
01957         QLinearGradient gr_alt(r.x(), r.y(), r.right(), r.y());
01958         gr_alt.setColorAt( 0.0, dark );
01959         gr_alt.setColorAt( (aMarg)*2/3/r.width(), light_alt );
01960         gr_alt.setColorAt( 1.0, light_alt );
01961         aPal.setBrush( QPalette::AlternateBase, QBrush( gr_alt ) );
01962         aWdg->setPalette( aPal );
01963       }
01964       QWindowsStyle::drawPrimitive( pe, opt, p, w );
01965       break;
01966     }
01967     default:
01968       QWindowsStyle::drawPrimitive( pe, opt, p, w );
01969   }
01970 }
01971 
01979 int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt,
01980                                const QWidget* w ) const
01981 {
01982   if ( checkDebugLevel(7) ) {
01983     return QWindowsStyle::pixelMetric( metric, opt, w );
01984   }
01985 
01986   int aRes = QWindowsStyle::pixelMetric( metric, opt, w );
01987   switch( metric ) {
01988     case PM_SliderLength: {
01989       aRes += (int)((double)model()->sliderSize()/2);
01990       break;
01991     }
01992     case PM_DockWidgetFrameWidth:
01993       aRes = 1;
01994     break;
01995     case PM_DockWidgetSeparatorExtent:
01996       aRes = 8;
01997     break;
01998     case PM_DockWidgetTitleMargin:
01999       aRes = 2;
02000     break;
02001     case PM_SplitterWidth:
02002       aRes = 6;
02003     break;
02004     default:
02005     break;
02006   }
02007   return aRes;
02008 }
02009 
02019 QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt,
02020                                       const QSize& contentsSize, const QWidget* w ) const
02021 {
02022   if ( checkDebugLevel(8) ) {
02023     return QWindowsStyle::sizeFromContents( ct, opt,contentsSize, w );
02024   }
02025 
02026   QSize sz = QWindowsStyle::sizeFromContents( ct, opt, contentsSize, w );
02027   switch (ct) {
02028     case CT_TabBarTab:
02029       if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
02030         if ( tab->position == QStyleOptionTab::End ||
02031              tab->position == QStyleOptionTab::OnlyOneTab ) {
02032           if ( tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth ) {
02033             int aDelta = (int)(opt->rect.height()*DELTA_H_TAB/2);
02034             sz.setWidth( sz.width() + aDelta );
02035           }
02036           if ( tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::RoundedWest ) {
02037             int aDelta = (int)(opt->rect.width()*DELTA_H_TAB/2);
02038             sz.setHeight( sz.height() + aDelta );
02039           }
02040         }
02041         break;
02042       }
02043       break;
02044       case CT_Slider: {
02045         int aValue = model()->sliderSize();
02046         sz.setWidth( sz.width() + aValue );
02047         sz.setHeight( sz.height() + aValue );
02048         break;
02049       }
02050       case CT_ComboBox:
02051         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
02052           QRect res = QRect( 0, 0, sz.width(), sz.height() );
02053           int aHalfRect = (int)Style_Tools::getMaxRect( res, 
02054                              (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); // left value
02055           QRect old_arrow = QWindowsStyle::subControlRect( CC_ComboBox, cmb,
02056                                                            SC_ComboBoxArrow, w );
02057           int aDelta = res.height() - old_arrow.width(); // right value
02058           if ( cmb->editable )
02059             aDelta += aHalfRect; // for right of line edit internal
02060           sz.setWidth( res.width() + aDelta + aHalfRect );
02061         }
02062         break;
02063       default:
02064       break;
02065   }
02066   return sz;
02067 }
02068 
02076 QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption *opt,
02077                                      const QWidget *w) const
02078 {
02079   if ( checkDebugLevel(9) ) {
02080     return QWindowsStyle::standardPixmap( stPixmap, opt, w );
02081   }
02082 
02083   switch ( stPixmap )
02084   {
02085   case SP_DockWidgetCloseButton:
02086   case SP_TitleBarCloseButton:
02087     return QPixmap( cross_xpm );
02088   case SP_TitleBarMaxButton:
02089     return QPixmap( maximize_xpm );
02090   case SP_TitleBarNormalButton:
02091     return QPixmap( normal_xpm );
02092   case SP_TitleBarMinButton:
02093     return QPixmap( minimize_xpm );
02094   default:
02095     return QWindowsStyle::standardPixmap( stPixmap, opt, w );
02096   }
02097 }
02098 
02106 QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon, 
02107                                                 const QStyleOption* opt,
02108                                                 const QWidget* w ) const
02109 {
02110   if ( checkDebugLevel(10) ) {
02111     return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
02112   }
02113 
02114   switch ( standardIcon )
02115   {
02116   case SP_MessageBoxInformation:
02117     return QPixmap( ":/images/information.png" );
02118   case SP_MessageBoxWarning:
02119     return QPixmap( ":/images/warning.png" );
02120   case SP_MessageBoxCritical:
02121     return QPixmap( ":/images/critical.png" );
02122   case SP_MessageBoxQuestion:
02123     return QPixmap( ":/images/question.png" );
02124   default:
02125     break;
02126   }
02127   return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
02128 }
02129 
02139 int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWidget* w,
02140                             QStyleHintReturn* returnData ) const
02141 {
02142   if ( checkDebugLevel(11) ) {
02143     return QWindowsStyle::styleHint( hint, opt, w, returnData );
02144   }
02145 
02146   int aRes = QWindowsStyle::styleHint( hint, opt, w, returnData );
02147   switch( hint ) {
02148     case SH_Table_GridLineColor: {
02149       if ( opt )
02150         aRes = model()->color( Style_Model::GridLine ).rgb(); // Style_Model::tbl_grline_clr
02151       else
02152         return aRes;
02153       break;
02154     }
02155     default:
02156       break;
02157   }
02158   return aRes;
02159 }
02160 
02171 QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex* opt,
02172                                     SubControl sc, const QWidget* wid ) const
02173 {
02174   if ( checkDebugLevel(12) ) {
02175     return QWindowsStyle::subControlRect( cc, opt, sc, wid );
02176   }
02177 
02178   QRect res = QWindowsStyle::subControlRect( cc, opt, sc, wid );
02179   switch ( cc ) {
02180     case CC_SpinBox: {
02181       int x = res.x(), w = res.width(), h = res.height();
02182       if ( sc==SC_SpinBoxUp || sc==SC_SpinBoxDown ) {
02183         QRect frame_r = QWindowsStyle::subControlRect( cc, opt, SC_SpinBoxFrame, wid );
02184         h = frame_r.height();
02185         res.setX( x+w-h );
02186         res.setWidth( h );
02187       }
02188       else if ( sc==QStyle::SC_SpinBoxEditField ) {
02189         res.setWidth( w-h );
02190         res.setTopLeft( QPoint( res.x(), res.y()-SHADOW ) );
02191       }
02192       break;
02193     }
02194     case CC_ComboBox: {
02195       if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
02196         res = cb->rect;
02197         int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
02198         int x = res.x(), w = res.width(), h = res.height();
02199         switch( sc ) {
02200           case SC_ComboBoxEditField: {
02201             res.setWidth( w-h );
02202             int aX = res.x();
02203             if ( !cb->editable )
02204               aX += aHalfRect;
02205             res.setTopLeft( QPoint( aX, res.y()-SHADOW ) );
02206             break;
02207           }
02208           case SC_ComboBoxArrow: {
02209             res.setX( x+w-h );
02210             res.setWidth( h );
02211             break;
02212           }
02213         }
02214       }
02215       break;
02216     }
02217     case CC_ScrollBar:
02218       if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
02219         QRect slider_r = QWindowsStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid );
02220         int aRect = Style_Tools::getMaxRect( slider_r, (int)model()->widgetRounding( Style_Model::ButtonRadius ) );
02221         switch( sc ) {
02222           case SC_ScrollBarSubPage:            // between top/left button and slider
02223             if (scrollbar->orientation == Qt::Horizontal)
02224               res.setRight( res.right()+aRect+1 );
02225             else
02226               res.setBottom( res.bottom()+aRect+1 );
02227             break;
02228           case SC_ScrollBarAddPage:            // between bottom/right button and slider
02229             if (scrollbar->orientation == Qt::Horizontal)
02230               res.setLeft( res.left() - aRect - 1 );
02231             else
02232               res.setTop( res.top() - aRect - 1);
02233           break;
02234           default:
02235             break;
02236         }
02237         break;
02238       }
02239     case CC_Slider: {
02240       if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
02241         switch ( sc ) {
02242           case SC_SliderGroove: {
02243             if ( slider->orientation == Qt::Horizontal ) {
02244               res.setLeft( res.left()+DELTA_SLIDER );
02245               res.setRight( res.right()-DELTA_SLIDER );
02246             }
02247             else {
02248               res.setTop( res.top()+DELTA_SLIDER );
02249               res.setBottom( res.bottom()-DELTA_SLIDER );
02250             }
02251             break;
02252           }
02253         }
02254       }
02255     }
02256   }
02257   return res;
02258 }
02259 
02269 QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt,
02270                                    const QWidget* wid ) const
02271 {
02272   if ( checkDebugLevel(13) ) {
02273     return QWindowsStyle::subElementRect( se, opt, wid );
02274   }
02275 
02276   QRect res = QWindowsStyle::subElementRect( se, opt, wid );
02277   int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
02278   int w = res.width(), h = res.height();
02279   switch ( se ) {
02280     case SE_ComboBoxFocusRect: {
02281       QRect old_r = QWindowsStyle::subControlRect( CC_ComboBox,
02282                      qstyleoption_cast<const QStyleOptionComplex*>( opt ),
02283                      SC_ComboBoxArrow, wid );
02284       int old_w = old_r.width();
02285       res.setWidth( w-h+old_w-2 );
02286       break;
02287     }
02288     case SE_LineEditContents: {
02289       res.setTopLeft( QPoint( res.x()+aHalfRect, res.y()-SHADOW ) );
02290       res.setTopRight( QPoint( res.right()-aHalfRect, res.y() ) );
02291       break;
02292     }
02293     case SE_ProgressBarLabel:
02294     case SE_ProgressBarContents:
02295     case SE_ProgressBarGroove:
02296       return opt->rect;
02297   }
02298   if( qobject_cast<const QRadioButton*>(wid) ||
02299       qobject_cast<const QCheckBox*>(wid) ) {
02300       if( hasHover() )
02301         res = res.adjusted(0, 0, 2, 0);
02302   }
02303   return res;
02304 }
02305 
02309 void Style_Salome::updatePaletteColors()
02310 {
02311   QPalette pal = QApplication::palette();
02312   // colors
02313   for ( int i = (int)QPalette::Active; i <= (int)QPalette::Inactive; i++ ) {
02314     for ( int j = (int)Style_Model::WindowText; j < (int)Style_Model::NColorRoles; j++ ) {
02315       if ( j == QPalette::NoRole ) continue;
02316       pal.setColor( (QPalette::ColorGroup)i, (QPalette::ColorRole)j,
02317                     model()->color( (Style_Model::ColorRole)j, (QPalette::ColorGroup)i ) );
02318     }
02319   }
02320   QPixmapCache::clear();
02321   QApplication::setPalette( pal );
02322 }
02323 
02328 void Style_Salome::updateAllWidgets( QApplication* app )
02329 {
02330   if ( !app )
02331     return;
02332 
02333   QWidgetList all = app->allWidgets();
02334   QWidget* w;
02335   for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) {
02336     w = *it2;
02337     if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)
02338         && !w->testAttribute(Qt::WA_SetStyle)) {
02339       QEvent e(QEvent::StyleChange);
02340       QApplication::sendEvent(w, &e);
02341       polish( w );
02342       w->update();
02343     }
02344   }
02345 }
02346 
02351 bool Style_Salome::hasHover() const
02352 {
02353   return model()->widgetEffect() != Style_Model::NoEffect;
02354 }
02355 
02365 void Style_Salome::drawHoverRect( QPainter* p, const QRect& r, const QColor& bgCol, const double rad,
02366                                   const int type, const bool border ) const
02367 {
02368   if ( !hasHover() )
02369     return;
02370   bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
02371   bool isHighWdg     = model()->widgetEffect() == Style_Model::HighlightEffect;
02372   QColor aBorder = model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr
02373          aCol, aBrdCol;
02374   double aMargin = HIGH_WDG_MARGIN;
02375   if  ( isAutoRaising ) {
02376     aCol = bgCol;
02377     aBrdCol = aCol.dark(BUT_PERCENT_ON);
02378     if ( !border )
02379       aBorder = aCol;
02380     aMargin = 0;
02381   }
02382   else if ( isHighWdg ) {
02383     aCol    = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr
02384     aBrdCol = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr
02385     if ( !border )
02386       aBorder = aBrdCol;
02387   }
02388   Style_Tools::highlightRect( p, r, rad, type, aMargin, aCol, aBrdCol, aBorder );
02389 }
02390 
02398 void Style_Salome::drawHandle( QPainter* p, const QRect& r, bool horiz, bool isRect ) const
02399 {
02400   QPixmap hole( (const char**)hole_xpm );
02401   int i, j;
02402   double d_hor = model()->handleDelta( Qt::Horizontal );
02403   double d_ver = model()->handleDelta( Qt::Vertical );
02404   if ( !d_hor || !d_ver || !r.width() || !r.height() )
02405     return;
02406   int c_hor = (int)(r.width()/d_hor)-1;
02407   int c_ver = (int)(r.height()/d_ver)-1;
02408   if ( c_hor+1 <= 0 || c_ver+1 <= 0 )
02409     return;
02410   // correction for delta value
02411   d_hor = r.width()/(c_hor+1);
02412   d_ver = r.height()/(c_ver+1);
02413 
02414   double dd_hor = 0, dd_ver = 0;
02415   if ( horiz ) {
02416     for ( i = 0; i < c_hor; i++ ) {
02417       for ( j = 0; j < c_ver; j++ ) {
02418           p->drawPixmap( (int)( r.x() + dd_hor + ( i + 1 ) * d_hor  - 1 ),
02419                          (int)( r.y() + dd_ver + ( j + 1 ) * d_ver - 1 ), hole );
02420       }
02421       if ( !isRect ) {
02422         dd_ver += (int(d_ver)/2) + (int(d_ver)%2);
02423         c_ver = c_ver - 1;
02424       }
02425     }
02426   }
02427   else {
02428     for ( j = 0; j < c_ver; j++ ) {
02429       for ( i = 0; i < c_hor; i++ ) {
02430           p->drawPixmap( (int)( r.x() + dd_hor + ( i + 1 ) * d_hor  - 1 ),
02431                          (int)( r.y() + dd_ver + ( j + 1 ) * d_ver - 1 ), hole );
02432       }
02433       if ( !isRect ) {
02434         dd_hor += (int(d_hor)/2) + (int(d_hor)%2);
02435         c_hor = c_hor - 1;
02436       }
02437     }
02438   }
02439 }
02440 
02450 void Style_Salome::drawBackground( QPainter* p, const QRect& r, const QColor& bgCol,
02451                                    const bool fill, const bool grad, const bool horiz ) const
02452 {
02453   if ( fill ) {
02454     if ( !grad )
02455       p->fillRect( r, bgCol );
02456     else {
02457       QLinearGradient gr( r.x(), r.y(), horiz ? r.x() : r.right(), horiz ? r.bottom() : r.y() );
02458       gr.setColorAt( 0.0, bgCol.light( BUT_PERCENT_ON ) );
02459       gr.setColorAt( 1.0, bgCol );
02460       p->fillRect( r, gr );
02461     }
02462   }
02463 
02464   int x = r.x(), y = r.y(), left = r.left(), top = r.top();
02465   int w = r.width(), h = r.height();
02466 
02467   QVector<QLine> lines;
02468 
02469   switch ( model()->linesType() ) {
02470   case Style_Model::Horizontal:
02471     {
02472       const int d = 3;
02473       for ( int i = 0; i <= h; i += d )
02474         lines.append( QLine( x, y+i, w, r.y()+i ) );
02475     }
02476     break;
02477   case Style_Model::Inclined:
02478     {
02479       const int d = 5;
02480       w = w/d*d;
02481       h = h/d*d;
02482       for ( int i = 0; i <= w; i += d )
02483         lines.append( QLine( x+i, y, x, y+i ) );
02484       for ( int i = 0; i < h; i += d )
02485         lines.append( QLine( left+w-i, top+h, left+w, top+h-i ) );
02486     }
02487     break;
02488   default:
02489     break;
02490   }
02491 
02492   if ( !lines.isEmpty() ) {
02493     QColor c = model()->color( Style_Model::Lines );
02494     int anAlpha = (int)( 255*( 1 - model()->linesTransparency()/100 ) ); 
02495     c.setAlpha( anAlpha );
02496     p->setPen( c );
02497     p->setRenderHint( QPainter::Antialiasing );
02498     p->drawLines( lines );
02499   }
02500 }
02501 
02508 void Style_Salome::drawBorder( QPainter* p, const QRect& r, bool horiz ) const 
02509 {
02510   QPen oldPen = p->pen();
02511   QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
02512   QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
02513   p->setPen( aBrdTopCol );
02514   if (horiz) {
02515     p->drawLine(r.left(),  r.top(), r.right(), r.top());
02516     p->setPen(aBrdBotCol);
02517     p->drawLine(r.left(), r.bottom(), r.right(), r.bottom());
02518   }
02519   else {
02520     p->drawLine(r.left(), r.top(), r.left(), r.bottom());
02521     p->setPen(aBrdBotCol);
02522     p->drawLine(r.right(), r.top(), r.right(), r.bottom());
02523   }
02524   p->setPen(oldPen);
02525 }
02526 
02535 QString Style_Salome::titleText( const QString& txt, const int W, const int H, QFont& f ) const
02536 {
02537   QString res = txt.trimmed();
02538 
02539   QFontMetrics fm( f );
02540   while( fm.height() > H && f.pointSize()>1 )
02541   {
02542     f.setPointSize( f.pointSize()-1 );
02543     fm = QFontMetrics( f );
02544   }
02545 
02546   if ( fm.width( res ) > W )
02547   {
02548     QString end( "..." );
02549     while ( !res.isEmpty() && fm.width( res + end ) > W )
02550       res.remove( res.length() - 1, 1 );
02551 
02552     if ( !res.isEmpty() )
02553       res += end;
02554   }
02555 
02556   return res;
02557 }