]> SALOME platform Git repositories - modules/gui.git/blob - src/Style/Style_Salome.cxx
Salome HOME
eeb12969f2336fcc726ffe799dbec166a6beace3
[modules/gui.git] / src / Style / Style_Salome.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : Style_Salome.cxx
23 // Author : Natalia Ermolaeva, Open CASCADE S.A.S.
24 //
25 #include "Style_Salome.h"
26 #include "Style_Tools.h"
27 #include "Style_Model.h"
28
29 #include <QApplication>
30 #include <QPainter>
31 #include <QMap>
32 #include <QPainterPath>
33 #include <QWidget>
34 #include <QComboBox>
35 #include <QStyleOptionFrame>
36 #include <QStyleOptionComplex>
37 #include <QStyleOptionSpinBox>
38 #include <QStyleOptionButton>
39 #include <QStyleOptionTab>
40 #include <QStyleOptionToolButton>
41 #include <QStyleOptionFocusRect>
42 #include <QStyleOption>
43 #include <QSize>
44 #include <QToolBar>
45 #include <QMenuBar>
46 #include <QToolButton>
47 #include <QTabWidget>
48 #include <QTabBar>
49 #include <QToolTip>
50 #include <QDockWidget>
51 #include <QTextEdit>
52 #include <QTreeView>
53 #include <QListView>
54 #include <QHeaderView>
55 #include <QRadioButton>
56 #include <QCheckBox>
57 #include <QPushButton>
58 #include <QAbstractSpinBox>
59 #include <QLineEdit>
60 #include <QScrollBar>
61 #include <QSlider>
62 #include <QMainWindow>
63 #include <QPixmapCache>
64
65 #include <limits.h>
66
67 #define SHADOW          1
68 #define LINE_GR_MARGIN  10
69 #define HIGH_WDG_MARGIN 10
70
71 #define BUT_PERCENT_COL 125
72 #define BUT_PERCENT_ON  115
73
74 #define DELTA_H_TAB     1
75 #define DELTA_SLIDER    3
76
77 static const char* const hole_xpm[] = {
78 "3 3 3 1",
79 ". c None",
80 "a c #999999",
81 "b c #FFFFFF",
82 "aa.",
83 "aab",
84 ".bb"
85 };
86
87 static const char* const cross_xpm[] = {
88 "12 12 4 1",
89 ". c None",
90 "a c #000000",
91 "b c #FFFFFF",
92 "c c #666666",
93 "............",
94 "............",
95 "............",
96 ".aaaa..aaaa.",
97 "..abbaabba..",
98 "...abbbba...",
99 "....abba....",
100 "...abbbba...",
101 "..abbaabba..",
102 ".aaaa..aaaa.",
103 "............",
104 "............"
105 };
106
107 static const char* const maximize_xpm[] = {
108 "12 12 4 1",
109 ". c None",
110 "a c #000000",
111 "b c #FFFFFF",
112 "c c #666666",
113 "............",
114 ".aaaaaaaaaa.",
115 ".acccccccca.",
116 ".acccccccca.",
117 ".abbbbbbbba.",
118 ".abbbbbbbba.",
119 ".abbbbbbbba.",
120 ".abbbbbbbba.",
121 ".abbbbbbbba.",
122 ".abbbbbbbba.",
123 ".aaaaaaaaaa.",
124 "............"
125 };
126
127 static const char* const normal_xpm[] = {
128 "12 12 4 1",
129 ". c None",
130 "a c #000000",
131 "b c #FFFFFF",
132 "c c #666666",
133 "............",
134 "...aaaaaaaa.",
135 "...acccccca.",
136 "...abbbbbba.",
137 "...aaaaaaba.",
138 ".aaaaaaaaba.",
139 ".accccccaba.",
140 ".abbbbbbaaa.",
141 ".abbbbbba...",
142 ".abbbbbba...",
143 ".aaaaaaaa...",
144 "............"
145 };
146
147 static const char* const minimize_xpm[] = {
148 "12 12 4 1",
149 ". c None",
150 "a c #000000",
151 "b c #FFFFFF",
152 "c c #666666",
153 "............",
154 "............",
155 "............",
156 "............",
157 "............",
158 "............",
159 "............",
160 "............",
161 "aaaaaaaaaaaa",
162 "abbbbbbbbbba",
163 "aaaaaaaaaaaa",
164 "............"
165 };
166
167 ///////////////////////////////////////////////////////////
168 // FOR debug purposes only!!!
169 //
170 int DEBUG_LEVEL = 0;
171
172 static bool checkDebugLevel( int level )
173 {
174   return DEBUG_LEVEL == level || DEBUG_LEVEL == -1;
175 }
176 //
177 ///////////////////////////////////////////////////////////
178
179 Style_Model* Style_Salome::myModel = 0;
180
181 /*!
182   \class Style_Salome
183   \brief SALOME style class.
184
185   To set SALOME style to the application, use static function Style_Salome::apply().
186   Static function restore() can be used then to restore initial application style.
187
188   The usual way to use SALOME style is as following:
189   \code
190   Style_Salome::initialize( resourceMgr() );     // initialize SALOME style from resources
191   if ( needSalomeStyle ) Style_Salome::apply();  // set SALOME style to the application
192   \endcode
193
194   Style_PrefDlg class can be then used to change style properties, select one of the
195   predefined style themes or even create user themes:
196   \code
197   Style_PrefDlg dlg( desktop() );
198   dlg.exec();
199   \endcode
200 */
201
202 /*!
203   \brief Constructor
204
205   Use Style_Salome::apply() static function to set SALOME style to the application.
206 */
207 Style_Salome::Style_Salome()
208   : QWindowsStyle()
209 {
210   // initialize SALOME style resources
211   Q_INIT_RESOURCE( Style );
212 }
213
214 /*!
215   \brief Destructor
216 */
217 Style_Salome::~Style_Salome()
218 {
219 }
220
221
222 /*!
223   \brief Initialize SALOME style.
224
225   This method should be called at the very beginning of the application
226   which uses SALOME style.
227   The method initializes style properties from the current settings.
228
229   If the parameter \a resMgr is not 0, the style is initialized from the
230   resources manager.
231
232   The parameter \a section allows customizing of the resources file section
233   used to store style's properties. By default "Theme" section name is used.
234
235   \param resMgr resources manager
236   \param section resources file section name
237   \sa apply(), restore()
238 */
239 void Style_Salome::initialize( QtxResourceMgr* resMgr, const QString& section )
240 {
241   model()->fromResources( resMgr, section );
242 }
243
244 /*!
245   \brief Set SALOME style to the application
246   \sa initialize(), restore()
247 */
248 void Style_Salome::apply()
249 {
250   // application object is not created yet
251   if ( !QApplication::instance() )
252     return;
253
254   // update model (from the resources manager if needed)
255   model()->update();
256
257   // check if SALOME style is already set to the application
258   if ( !isActive() ) {
259     // set SALOME style
260     QApplication::style()->setParent( 0 );           // avoid deleting original application style
261     QApplication::setStyle( new Style_Salome() );    // set style
262   }
263   update();                                          // update style
264 }
265
266 /*!
267   \brief Restore original style to the application
268   \sa initialize(), apply()
269 */
270 void Style_Salome::restore()
271 {
272   // application object is not created yet
273   if ( !QApplication::instance() )
274     return;
275   // check if SALOME style is set to the application
276   if ( !isActive() )
277     return;
278   // restore previous style
279   model()->restore();
280 }
281
282 /*!
283   \brief Check if the SALOME style is currently set to application.
284   \return \c true if SALOME style is set to the applcation or \c false otherwise
285 */
286 bool Style_Salome::isActive()
287 {
288   return QApplication::instance() != 0 && qobject_cast<Style_Salome*>( QApplication::style() ) != 0;
289 }
290
291 /*!
292   \brief Update style from resources.
293 */
294 void Style_Salome::update()
295 {
296   // application object is not created yet
297   if ( !QApplication::instance() )
298     return;
299   // check if SALOME style is set to the application
300   if ( Style_Salome* style = qobject_cast<Style_Salome*>( QApplication::style() ) )
301     style->polish( qobject_cast<QApplication*>( QApplication::instance() ) );
302 }
303
304 /*!
305   \brief Get style model
306   \return style model
307 */
308 Style_Model* Style_Salome::model()
309 {
310   if ( !myModel )
311     myModel = new Style_Model();
312   return myModel;
313 }
314
315 /*!
316   \brief Initialize the appearance of the application.
317   
318   Performs late initialization of the given application object.
319
320   \param app application object
321 */
322 void Style_Salome::polish ( QApplication* app )
323 {
324   QWindowsStyle::polish( app );
325
326   if ( checkDebugLevel(1) ) {
327     return;
328   }
329
330   updatePaletteColors();
331   app->setFont( model()->applicationFont() );
332   updateAllWidgets( app );
333 }
334
335 /*!
336   \brief Initializes the appearance of the given widget.
337
338   This function is called for every widget at some point after
339   it has been fully created but just before it is shown for the very first time.
340
341   \param w widget object
342 */
343 void Style_Salome::polish ( QWidget* w )
344 {
345   if ( checkDebugLevel(2) ) {
346     QWindowsStyle::polish( w );
347     return;
348   }
349
350   if ( w && hasHover() ) {
351     if ( qobject_cast<QPushButton*>(w) || qobject_cast<QToolButton*>(w)      ||
352          qobject_cast<QCheckBox*>(w)   || qobject_cast<QRadioButton*>(w)     ||
353          qobject_cast<QComboBox*>(w)   || qobject_cast<QAbstractSpinBox*>(w) ||
354          qobject_cast<QLineEdit*>(w)   || qobject_cast<QScrollBar*>(w)       ||
355          qobject_cast<QTabBar*>(w)     || qobject_cast<QSlider*>(w)          ||
356          qobject_cast<QMenuBar*>(w)    || qobject_cast<QDockWidget*>(w) )
357       w->setAttribute( Qt::WA_Hover );
358   }
359
360   QWindowsStyle::polish( w );
361 }
362
363 /*!
364   \brief Uninitialize the given widget's appearance.
365
366   This function is the counterpart to polish().
367   It is called for every polished widget whenever the style
368   is dynamically changed; the former style has to unpolish
369   its settings before the new style can polish them again.
370
371   \param w widget object
372 */
373 void Style_Salome::unpolish( QWidget* w )
374 {
375   if ( checkDebugLevel(3) ) {
376     QWindowsStyle::unpolish( w );
377     return;
378   }
379
380   if ( w && hasHover() ) {
381     if ( qobject_cast<QPushButton*>(w) || qobject_cast<QToolButton*>(w)||
382          qobject_cast<QCheckBox*>(w) || qobject_cast<QRadioButton*>(w) ||
383          qobject_cast<QComboBox*>(w) || qobject_cast<QAbstractSpinBox*>(w) ||
384          qobject_cast<QLineEdit*>(w) || qobject_cast<QScrollBar*>(w) ||
385          qobject_cast<QTabBar*>(w) || qobject_cast<QSlider*>(w) ||
386          qobject_cast<QMenuBar*>(w) || qobject_cast<QDockWidget*>(w) )
387       w->setAttribute( Qt::WA_Hover, false );
388   }
389
390   QWindowsStyle::unpolish( w );
391 }
392
393 /*!
394   \brief Draws the given control using the provided painter \p with the style options specified by \a opt.
395   \param cc complex control type
396   \param opt style option
397   \param p painter
398   \param w widget
399 */
400 void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComplex* opt,
401                                        QPainter* p, const QWidget* w ) const
402 {
403   if ( checkDebugLevel(4) ) {
404     QWindowsStyle::drawComplexControl( cc, opt, p, w );
405     return;
406   }
407
408   const QPalette& pal = w->palette();
409   switch( cc ) {
410     case CC_SpinBox:
411       if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
412         bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
413         QRect optr = opt->rect, arUp =   subControlRect( cc, spin, SC_SpinBoxUp, w );
414         optr.setWidth( arUp.x()-optr.x()+1 );
415         double aRad = model()->widgetRounding( Style_Model::EditRadius );
416         bool antialized = model()->antialiasing();
417         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
418         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
419         if ( hover )
420           drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
421         else
422           Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left,
423                                    model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr,
424                                    model()->color( Style_Model::FieldDark ),  // Style_Model::fld_dark_clr,
425                                    aBrdTopCol, aBrdBotCol, antialized, false );
426         QRect aBtnRect = QRect( QPoint( arUp.x(), optr.y() ), QPoint( arUp.right(), optr.bottom() ) );
427         QColor aBtnCol = opt->palette.color( QPalette::Button );
428         bool aStateOn = opt->state & ( State_Sunken | State_On );
429         if ( hover )
430           drawHoverRect(p, aBtnRect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
431         else
432           Style_Tools::shadowRect( p, aBtnRect, aRad, 0.0, SHADOW, Style_Tools::Right,
433                                   aBtnCol.light( BUT_PERCENT_COL ), aBtnCol.dark( BUT_PERCENT_COL ),
434                                   aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
435         State flags = State_None;
436         QStyleOptionSpinBox copy;
437         PrimitiveElement pe;
438         if (spin->subControls & SC_SpinBoxUp) {
439           copy.subControls = SC_SpinBoxUp;
440           QPalette pal2 = spin->palette;
441           if (!(spin->stepEnabled & QAbstractSpinBox::StepUpEnabled) ||
442               !(spin->state & State_Enabled)) {
443             pal2.setCurrentColorGroup(QPalette::Disabled);
444             copy.state &= ~State_Enabled;
445           }
446           else
447             copy.state |= State_Enabled;
448           copy.palette = pal2;
449           if ( spin->activeSubControls == SC_SpinBoxUp && ( spin->state & State_Sunken ) ) {
450             copy.state |= State_On;
451             copy.state |= State_Sunken;
452           } else {
453             copy.state |= State_Raised;
454             copy.state &= ~State_Sunken;
455           }
456           pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
457                : PE_IndicatorSpinUp);
458           copy.rect = aBtnRect;
459           drawPrimitive(pe, &copy, p, w);
460         }
461         if (spin->subControls & SC_SpinBoxDown) {
462           copy.subControls = SC_SpinBoxDown;
463           copy.state = spin->state;
464           QPalette pal2 = spin->palette;
465           if (!(spin->stepEnabled & QAbstractSpinBox::StepDownEnabled) ||
466                !(spin->state & State_Enabled)) {
467             pal2.setCurrentColorGroup(QPalette::Disabled);
468             copy.state &= ~State_Enabled;
469           }
470           else
471             copy.state |= State_Enabled;
472           copy.palette = pal2;
473           if (spin->activeSubControls == SC_SpinBoxDown && (spin->state & State_Sunken)) {
474              copy.state |= State_On;
475              copy.state |= State_Sunken;
476           } else {
477             copy.state |= State_Raised;
478             copy.state &= ~State_Sunken;
479           }
480           pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
481                : PE_IndicatorSpinDown);
482           copy.rect = aBtnRect;
483           drawPrimitive(pe, &copy, p, w);
484         }
485         break;
486      }
487      case CC_ComboBox: {
488       if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
489         bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
490         QRect optr = opt->rect,
491               ar = subControlRect( cc, cmb, SC_ComboBoxArrow, w );
492         optr.setY( ar.y() );
493         optr.setHeight( ar.height() );
494         optr.setWidth( ar.x()-optr.x()+1 );
495         bool antialized = model()->antialiasing();
496         double aRad = model()->widgetRounding( Style_Model::EditRadius );
497         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
498         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
499         if ( hover )
500           drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
501         else
502           Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left,
503                                    model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr,
504                                    model()->color( Style_Model::FieldDark ),  // Style_Model::fld_dark_clr,
505                                    aBrdTopCol, aBrdBotCol, antialized, false );
506         if (cmb->subControls & SC_ComboBoxArrow) {
507           State flags = State_None;
508           QColor aBtnCol = opt->palette.color( QPalette::Button );
509           bool aStateOn = opt->state & ( State_Sunken | State_On );
510           if ( hover )
511             drawHoverRect(p, ar, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
512           else
513             Style_Tools::shadowRect( p, ar, aRad, 0.0, SHADOW, Style_Tools::Right,
514                                      aBtnCol.light( BUT_PERCENT_COL ), aBtnCol.dark( BUT_PERCENT_COL ),
515                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
516           if (opt->state & State_Enabled)
517             flags |= State_Enabled;
518           if (cmb->activeSubControls == SC_ComboBoxArrow)
519             flags |= State_Sunken;
520           QStyleOption arrowOpt(0);
521           arrowOpt.rect = ar;
522           arrowOpt.palette = cmb->palette;
523           arrowOpt.state = flags;
524           drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
525         }
526         if (cmb->subControls & SC_ComboBoxEditField) {
527           bool hi = cmb->state & State_HasFocus && !cmb->editable;
528           if( hi ) {
529             Style_Tools::shadowRect( p, optr, aRad, 0.0, SHADOW, Style_Tools::Left,
530                                      pal.color( QPalette::Highlight ),
531                                      pal.color( QPalette::Highlight ), aBrdTopCol, aBrdBotCol,
532                                      antialized, false );
533             p->setPen(cmb->palette.highlightedText().color());
534           }
535           else
536             p->setPen(cmb->palette.text().color());
537         }
538         break;
539       }
540     }
541     case CC_Slider: {
542         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
543             QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, w);
544             QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, w);
545
546             if( hasHover() && (slider->state & State_Enabled) &&
547                          (slider->state & State_MouseOver) ) {
548               QRect moderated = w->rect();
549                 drawHoverRect(p, moderated, opt->palette.color( QPalette::Window ),
550                               model()->widgetRounding( Style_Model::ButtonRadius ), Style_Tools::All, false);
551             }
552
553             if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
554               QStyleOptionSlider tmpSlider = *slider;
555               tmpSlider.subControls = SC_SliderGroove;
556               QWindowsStyle::drawComplexControl(cc, &tmpSlider, p, w);
557             }
558             if (slider->subControls & SC_SliderTickmarks) {
559               QStyleOptionSlider tmpSlider = *slider;
560               tmpSlider.subControls = SC_SliderTickmarks;
561               QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w);
562             }
563             if (slider->subControls & SC_SliderHandle) {
564               if (slider->state & State_HasFocus) {
565                 QStyleOptionFocusRect fropt;
566                 fropt.QStyleOption::operator=(*slider);
567                 fropt.rect = subElementRect(SE_SliderFocusRect, slider, w);
568                 drawPrimitive(PE_FrameFocusRect, &fropt, p, w);
569               }
570               int x = handle.x(), y = handle.y(), wi = handle.width(), he = handle.height();
571               bool horiz = slider->orientation == Qt::Horizontal;
572               bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
573               bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
574               QColor aBtnCol = model()->color( Style_Model::Slider );          // Style_Model::slider_clr
575               QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
576               QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
577               // rect was changed on +/-DELTA_SLIDER value for correct painting Antialised border of slider
578               int aDelta = DELTA_SLIDER-1;
579               QRect slRect = QRect(x+aDelta, y+aDelta, wi-aDelta, he-aDelta);
580               int aXAdd = (int)(slRect.width()/6), aYAdd = (int)(slRect.height()/6);
581               Style_Tools::SliderType type = Style_Tools::SlNone;
582               if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow))
583                 type = Style_Tools::SlNone;
584               else {
585                 if (horiz)
586                   if (tickAbove) {
587                     type = Style_Tools::SlUp;
588                     slRect.setTop( slRect.top()-aYAdd );
589                   }
590                   else {
591                     type = Style_Tools::SlDown;
592                     slRect.setBottom( slRect.bottom()+aYAdd );
593                   }
594                 else
595                   if (tickAbove) {
596                     type = Style_Tools::SlLeft;
597                     slRect.setLeft( slRect.left()-aXAdd );
598                   }
599                   else {
600                     type = Style_Tools::SlRight;
601                     slRect.setRight( slRect.right()+aXAdd );
602                  }
603               }
604               Style_Tools::drawSlider( p, slRect, model()->widgetRounding( Style_Model::SliderRadius ), type,
605                                        aBtnCol.light( BUT_PERCENT_COL ),
606                                        aBtnCol.dark( BUT_PERCENT_COL ), aBrdTopCol, aBrdBotCol );
607               QRect aHRect = handle;
608               int aXRect = (int)(aHRect.width()/5),
609                   aYRect = (int)(aHRect.height()/5);
610               aHRect = QRect( aHRect.x()+aXRect, aHRect.y()+aYRect,
611                               aHRect.width()-2*aXRect, aHRect.height()-2*aYRect );
612               drawHandle( p, aHRect, horiz );
613             }
614             break;
615         }
616     }
617     case CC_ToolButton: {
618       if (const QStyleOptionToolButton *toolbutton
619            = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
620         QRect button, menuArea;
621         button = subControlRect(cc, toolbutton, SC_ToolButton, w);
622         menuArea = subControlRect(cc, toolbutton, SC_ToolButtonMenu, w);
623
624         if (w && ( qobject_cast<QToolBar *>(w->parentWidget() ) || 
625                    toolbutton->state & State_AutoRaise && !( toolbutton->state & State_MouseOver ) )
626             ) {
627           QWindowsStyle::drawComplexControl( cc, opt, p, w );
628           return;
629         }
630         int aMinDelta = (int)model()->widgetRounding( Style_Model::ButtonRadius );
631         if ( !toolbutton->icon.isNull() )
632           aMinDelta = Style_Tools::getMinDelta( toolbutton->rect, toolbutton->iconSize, aMinDelta );
633         bool aStateOn = opt->state & ( State_Sunken | State_On );
634         QColor aBtnCol = opt->palette.color( QPalette::Button ),
635                top    = aBtnCol.light( BUT_PERCENT_COL ),
636                bottom = aBtnCol.dark( BUT_PERCENT_COL );
637         bool isMenuBtn = toolbutton->features == QStyleOptionToolButton::Menu;
638         bool antialized = model()->antialiasing();
639         bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
640         bool isHighWdg     = model()->widgetEffect() == Style_Model::HighlightEffect;
641         bool hover = hasHover() && (opt->state & State_Enabled) && ( opt->state & State_MouseOver );
642         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
643         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
644         QRect aRect = button;
645         int aType = isMenuBtn ? Style_Tools::Left : Style_Tools::All;
646         if ( toolbutton->subControls & SC_ToolButton ) {
647           if ( isAutoRaising && hover && !aStateOn )
648             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, bottom, top, aBrdTopCol,
649                                      aBrdBotCol, antialized, true, aStateOn );
650           else if ( isHighWdg && hover && !aStateOn )
651             drawHoverRect( p, aRect, opt->palette.color( QPalette::Window ), aMinDelta, aType, true );
652           else
653             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, top, bottom,
654                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
655         }
656         if (toolbutton->subControls & SC_ToolButtonMenu) {
657           p->save();
658           if ( aMinDelta > menuArea.height()/2 )
659             aMinDelta = menuArea.height()/2;
660           if ( aMinDelta > menuArea.width()/2 )
661             aMinDelta = menuArea.width()/2;
662           aRect = menuArea;
663           aType = isMenuBtn ? Style_Tools::Right : Style_Tools::All;
664           if ( isAutoRaising && hover && !aStateOn )
665             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, bottom, top,
666                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
667           else if ( isHighWdg && hover && !aStateOn )
668             drawHoverRect( p, aRect, opt->palette.color( QPalette::Window ), aMinDelta, aType, true );
669           else
670             Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, top, bottom,
671                                      aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
672           QStyleOption tool(0);
673           tool.palette = toolbutton->palette;
674           tool.rect = menuArea;
675           State bflags = toolbutton->state;
676           if (bflags & State_AutoRaise) {
677               if (!(bflags & State_MouseOver)) {
678                   bflags &= ~State_Raised;
679               }
680           }
681           State mflags = bflags;
682             if (toolbutton->activeSubControls & SC_ToolButton)
683                 bflags |= State_Sunken;
684             if (toolbutton->activeSubControls & SC_ToolButtonMenu)
685                 mflags |= State_Sunken;
686           tool.state = mflags;
687           drawPrimitive(PE_IndicatorArrowDown, &tool, p, w);
688           p->restore();
689         }
690
691         if (toolbutton->state & State_HasFocus) {
692           QStyleOptionFocusRect fr;
693           fr.QStyleOption::operator=(*toolbutton);
694           fr.rect.adjust(3, 3, -3, -3);
695           if (toolbutton->features & QStyleOptionToolButton::Menu)
696             fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, w), 0);
697           Style_Tools::drawFocus( p, fr.rect, aMinDelta-1,  isMenuBtn ? Style_Tools::Left :
698                                   Style_Tools::All, aBrdBotCol );
699         }
700         QStyleOptionToolButton label = *toolbutton;
701         int fw = pixelMetric( PM_DefaultFrameWidth, opt, w );
702         label.rect = button.adjusted( fw, fw, -fw, -fw );
703         drawControl( CE_ToolButtonLabel, &label, p, w );
704
705         break;
706       }
707     }
708     case CC_TitleBar: {
709       QWindowsStyle::drawComplexControl( cc, opt, p, w );
710       break;
711     }
712     case CC_GroupBox:
713       if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const 
714                                                  QStyleOptionGroupBox *>(opt)) {
715         // Draw frame
716         QRect textRect = subControlRect( cc, opt, SC_GroupBoxLabel, w );
717         QRect checkBoxRect = subControlRect( cc, opt, SC_GroupBoxCheckBox, w);
718         if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
719           QRect aRect = subControlRect( cc, opt, SC_GroupBoxFrame, w);
720           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
721           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
722           Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::FrameRadius ), 0.,
723                                    SHADOW, Style_Tools::All,
724                                    model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr
725                                    model()->color( Style_Model::FieldDark ),  // Style_Model::fld_dark_clr
726                                    aBrdTopCol, aBrdBotCol, false, false, false, false);
727         }
728         // Draw title
729         if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
730           QColor textColor = groupBox->textColor;
731           if (textColor.isValid())
732             p->setPen(textColor);
733           int alignment = int(groupBox->textAlignment);
734           if (!styleHint(QStyle::SH_UnderlineShortcut, opt, w))
735             alignment |= Qt::TextHideMnemonic;
736           QColor aColor = opt->palette.color( QPalette::Window );
737           Style_Tools::arrowRect( p, textRect, opt->palette.color( QPalette::Dark ),
738                                  aColor.dark(BUT_PERCENT_COL), aColor );
739           drawItemText(p, textRect,  Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
740                        pal, groupBox->state & State_Enabled, groupBox->text,
741                        textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
742           if (groupBox->state & State_HasFocus) {
743             QStyleOptionFocusRect fropt;
744             fropt.QStyleOption::operator=(*groupBox);
745             fropt.rect = textRect;
746             drawPrimitive(PE_FrameFocusRect, &fropt, p, w);
747           }
748         }
749         // Draw checkbox
750         if (groupBox->subControls & SC_GroupBoxCheckBox) {
751             QStyleOptionButton box;
752           box.QStyleOption::operator=(*groupBox);
753           box.rect = checkBoxRect;
754           drawPrimitive(PE_IndicatorCheckBox, &box, p, w);
755         }
756         break;
757       }
758     case CC_Dial: {
759       QWindowsStyle::drawComplexControl( cc, opt, p, w );
760       break;
761     }
762     default:
763       QWindowsStyle::drawComplexControl( cc, opt, p, w );
764   }
765 }
766
767 /*!
768   \brief Draws the given element with the provided painter \p with the style options specified by \a opt.
769   \param ce control element type
770   \param opt style option
771   \param p painter
772   \param w widget
773 */
774 void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt,
775                                QPainter* p, const QWidget* w ) const
776 {
777   if ( checkDebugLevel(5) ) {
778     QWindowsStyle::drawControl( ce, opt, p, w );
779     return;
780   }
781
782   switch ( ce ) {
783     case CE_PushButton:
784       if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
785         drawControl(CE_PushButtonBevel, btn, p, w);
786         QStyleOptionButton subopt = *btn;
787         subopt.rect = subElementRect(SE_PushButtonContents, btn, w);
788         drawControl(CE_PushButtonLabel, &subopt, p, w);
789         if (btn->state & State_HasFocus) {
790           QRect aRect = subElementRect( SE_PushButtonFocusRect, btn, w );
791           Style_Tools::drawFocus( p, aRect, model()->widgetRounding( Style_Model::ButtonRadius ),
792                                   Style_Tools::All, model()->color( Style_Model::BorderBottom ) );
793         }
794         break;
795       }
796     case CE_PushButtonBevel:
797       if ( qstyleoption_cast<const QStyleOptionButton *>(opt) ) {
798         double aRad = model()->widgetRounding( Style_Model::ButtonRadius );
799         bool aStateOn = opt->state & ( State_Sunken | State_On );
800         bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
801         bool isHighWdg     = model()->widgetEffect() == Style_Model::HighlightEffect;
802         bool enabled = opt->state & State_Enabled;
803         bool hover = hasHover() && enabled && ( opt->state & State_MouseOver );
804
805         QColor aBtnCol = opt->palette.color( QPalette::Button );
806         QColor top = aBtnCol.light( BUT_PERCENT_COL ),
807                bottom = aBtnCol.dark( BUT_PERCENT_COL );
808         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
809         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
810         QRect r = opt->rect;
811         bool antialized = model()->antialiasing();
812         if ( isAutoRaising && hover && !aStateOn )
813           Style_Tools::shadowRect( p, r, aRad, -1, SHADOW, Style_Tools::All, bottom, top,
814                                    aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
815         else if ( isHighWdg && hover && !aStateOn )
816           drawHoverRect( p, r, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true );
817         else
818           Style_Tools::shadowRect( p, r, aRad, -1, SHADOW, Style_Tools::All, top, bottom,
819                                    aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
820         break;
821       }
822       case CE_DockWidgetTitle:
823         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
824           bool floating = false;
825           int menuOffset = 0; //used to center text when floated
826           QColor inactiveCaptionTextColor = opt->palette.color( QPalette::HighlightedText );
827           const QDockWidget *dockWidget = qobject_cast<const QDockWidget *>(w);
828           //Titlebar gradient
829           if (dockWidget) {
830             if ( dockWidget->isFloating() && dwOpt->movable) {
831               floating = true;
832               QColor top = opt->palette.color( QPalette::Highlight ).light();
833               QColor bottom = opt->palette.color( QPalette::Highlight );
834               menuOffset = 2;
835               QBrush fillBrush(bottom);
836               if (top != bottom) {
837                 QPoint p1(dwOpt->rect.x(), dwOpt->rect.y());
838                 QPoint p2(dwOpt->rect.x(), dwOpt->rect.bottom() );
839                 QLinearGradient lg(p1, p2);
840                 lg.setColorAt(0, top);
841                 lg.setColorAt(1, bottom);
842                 fillBrush = lg;
843               }
844               p->fillRect(dwOpt->rect.adjusted(0, 0, 0, -3), fillBrush);
845             }
846             else {
847               QRect r = dwOpt->rect.adjusted(0, 0, -1, -1); 
848               QColor bottom = opt->palette.color( QPalette::Window ),
849                      top =    bottom.dark( BUT_PERCENT_COL );
850               QRect aRect = dwOpt->rect;
851               QLinearGradient gr( aRect.x(), aRect.y(), aRect.x(), aRect.y()+aRect.height() );
852               gr.setColorAt( 0.0, top );
853               gr.setColorAt( 0.4, bottom );
854               gr.setColorAt( 0.6, bottom );
855               gr.setColorAt( 1.0, top );
856               p->fillRect( r, gr );
857
858               QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );     // Style_Model::border_tab_top_clr
859               QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom );  // Style_Model::border_tab_bot_clr
860               p->setPen( aBrdTopCol );
861               p->drawLine( r.x(), r.bottom(), r.x(), r.y() );
862               p->drawLine( r.x(), r.y(), r.right(), r.y() );
863               p->setPen( aBrdBotCol );
864               p->drawLine( r.x(), r.bottom(), r.right(), r.bottom() );
865               p->drawLine( r.right(), r.bottom(), r.right(), r.y() );
866             }
867           }
868           p->setPen(dwOpt->palette.color(QPalette::Light));
869
870           QString aTitle = dwOpt->title;
871           if (!aTitle.isEmpty()) {
872             int aMargin  = pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, w);
873             const int indent = p->fontMetrics().descent();
874             QRect r = dwOpt->rect.adjusted(indent + 1, - menuOffset, -indent - 1, -1);
875             QPixmap aPxm = standardPixmap( SP_DockWidgetCloseButton, opt, w);
876             int aWidth = r.width() - aPxm.width()-2/*button margins*/;
877             aPxm = standardPixmap( SP_TitleBarNormalButton, opt, w);
878             aWidth = aWidth - aPxm.width()-2/*button margins*/;
879             r = QRect( r.x(), r.y(), aWidth-aMargin-2/*buttons separator*/-2/*margin from text*/, r.height() );
880
881             QFont oldFont = p->font();
882             QFont font = oldFont;
883             if (floating) {
884               font.setBold(true);
885               p->setFont(font);
886             }
887             aTitle = titleText( aTitle, r.width(), r.height(), font );
888
889             QPalette palette = dwOpt->palette;
890             palette.setColor(QPalette::Window, inactiveCaptionTextColor);
891             bool active = dwOpt->state & State_Active;
892             //const int indent = p->fontMetrics().descent();
893             drawItemText(p, r, Qt::AlignLeft | Qt::AlignVCenter, palette,
894                          dwOpt->state & State_Enabled, aTitle,
895                          floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
896             p->setFont(oldFont);
897           }
898           break;
899         }
900     case CE_Splitter: {
901       QWindowsStyle::drawControl( ce, opt, p, w );
902       QRect r = opt->rect;
903       bool horiz = r.width() > r.height();
904       int aLen = model()->splitHandleLength();
905       if ( horiz )
906         r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
907       else
908         r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
909       drawHandle( p, r, horiz, true );
910       break;
911     }
912     case CE_TabBarTabShape:
913       if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
914         if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedEast ||
915             tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::RoundedWest) {
916           p->save();
917           QRect tabRect = opt->rect;
918           // line under selected tab bar object
919           bool isSelected = opt->state & State_Selected;
920           bool isLast = tab->position == QStyleOptionTab::End ||
921                         tab->position == QStyleOptionTab::OnlyOneTab;
922           QColor aColor = opt->palette.color( QPalette::Window ),
923                  aDarkColor = aColor.dark( BUT_PERCENT_ON );
924           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );     // Style_Model::border_tab_top_clr
925           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom );  // Style_Model::border_tab_bot_clr
926
927           bool isHover = hasHover() && (opt->state & State_Enabled) &&
928                                        (opt->state & State_MouseOver);
929           if ( isHover && !isSelected && model()->widgetEffect() == Style_Model::HighlightEffect ) {
930             aColor     = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr
931             aDarkColor = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr
932           }
933           Style_Tools::tabRect( p, tabRect, (int)tab->shape,
934                                 model()->widgetRounding( Style_Model::FrameRadius ),
935                                 DELTA_H_TAB, aColor, aDarkColor,
936                                 aBrdTopCol, aBrdBotCol, isSelected, isLast, isHover );
937           p->restore();
938         } else
939            QCommonStyle::drawControl(ce, opt, p, w);
940         break;
941       }
942     case CE_TabBarTabLabel:
943       if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
944         if ( tab->position == QStyleOptionTab::End ||
945              tab->position == QStyleOptionTab::OnlyOneTab ) {
946           QRect oldRect = opt->rect;
947           int aDelta = 0;
948           if ( tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth ) {
949             aDelta = (int)(opt->rect.height()*DELTA_H_TAB/2);
950             oldRect = QRect( oldRect.topLeft(), QPoint( oldRect.right()-aDelta, oldRect.bottom() ) );
951           }
952           else {
953             aDelta = (int)(opt->rect.width()*DELTA_H_TAB/2);
954             oldRect = QRect( oldRect.topLeft(), QPoint( oldRect.right(), oldRect.bottom()-aDelta ) );
955           }
956           QStyleOptionTab* copyTab = (QStyleOptionTab*)tab;
957           copyTab->rect = oldRect;
958           QWindowsStyle::drawControl( ce, copyTab, p, w );
959         }
960         else
961           QWindowsStyle::drawControl( ce, opt, p, w );
962         break;
963       }
964     case CE_MenuBarItem:
965       if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
966         if ( w )
967           drawBackground( p, w->rect(), opt->palette.color( QPalette::Window ), true, true, true );
968         bool active = mbi->state & State_Selected;
969         bool hasFocus = mbi->state & State_HasFocus;
970         bool down = mbi->state & State_Sunken;
971         QStyleOptionMenuItem newMbi = *mbi;
972         if (active || hasFocus) {
973           QBrush b( opt->palette.color( QPalette::Window ) );
974           if (active && down)
975             p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
976           if ( active && hasFocus) {
977             bool aStateOn = opt->state & (State_Sunken | State_On);
978             QColor aBtnCol = opt->palette.color( QPalette::Window ),
979                    top =    aBtnCol.light( BUT_PERCENT_ON ),
980                    bottom = aBtnCol.dark( BUT_PERCENT_ON );
981             QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
982             QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
983             bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
984             if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) &&
985                  (opt->state & State_Selected) )
986               drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true);
987             else {
988               Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top, bottom,
989                                    aBrdTopCol, aBrdBotCol,
990                                    model()->antialiasing(), true, aStateOn );
991             }
992           }
993           if (active && down) {
994             newMbi.rect.translate(pixelMetric(PM_ButtonShiftHorizontal, mbi, w),
995                                   pixelMetric(PM_ButtonShiftVertical, mbi, w));
996             p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
997           }
998         }
999         QCommonStyle::drawControl(ce, &newMbi, p, w);
1000         break;
1001       }
1002     case CE_MenuBarEmptyArea:
1003       drawBackground( p, opt->rect, opt->palette.color( QPalette::Window ), true, true, true );
1004       break;
1005     case CE_ProgressBarGroove: {
1006       QColor aBgColor = opt->palette.color( QPalette::Window ),
1007         top =    aBgColor.light( BUT_PERCENT_ON ),
1008         bottom = aBgColor.dark( BUT_PERCENT_ON );
1009       QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
1010       QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1011       Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::EditRadius ), -1,
1012                                SHADOW, Style_Tools::All, top, bottom, aBrdTopCol, aBrdBotCol,
1013                                model()->antialiasing(), true );
1014       break;
1015       }
1016     case CE_ProgressBarLabel:
1017       if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1018         // implementation from qplastiquestyle
1019         // The busy indicator doesn't draw a label
1020         if (bar->minimum == 0 && bar->maximum == 0)
1021           return;
1022         p->save();
1023         QRect rect = bar->rect;
1024         QRect leftRect;
1025         p->setPen(bar->palette.text().color());
1026
1027         bool vertical = false;
1028         bool inverted = false;
1029         bool bottomToTop = false;
1030         // Get extra style options if version 2
1031         if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
1032           vertical = (bar2->orientation == Qt::Vertical);
1033           inverted = bar2->invertedAppearance;
1034           bottomToTop = bar2->bottomToTop;
1035         }
1036         if (vertical) {
1037           rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1038           QMatrix m;
1039           if (bottomToTop) {
1040             m.translate(0.0, rect.width());
1041             m.rotate(-90);
1042           } else {
1043             m.translate(rect.height(), 0.0);
1044             m.rotate(90);
1045           }
1046           p->setMatrix(m);
1047         }
1048         int progressIndicatorPos = int(((bar->progress - bar->minimum) / double(bar->maximum - bar->minimum)) * rect.width());
1049         bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted)
1050                     || ((bar->direction == Qt::LeftToRight) && inverted))) || (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop)));
1051         if (flip) {
1052           int indicatorPos = rect.width() - progressIndicatorPos;
1053           if (indicatorPos >= 0 && indicatorPos <= rect.width()) {
1054             p->setPen(bar->palette.base().color());
1055             leftRect = QRect(rect.left(), rect.top(), indicatorPos, rect.height());
1056           } else if (indicatorPos > rect.width()) {
1057             p->setPen(bar->palette.text().color());
1058           } else {
1059             p->setPen(bar->palette.base().color());
1060           }
1061         } else {
1062           if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) {
1063             leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
1064           } else if (progressIndicatorPos > rect.width()) {
1065             p->setPen(bar->palette.base().color());
1066           } else {
1067             p->setPen(bar->palette.text().color());
1068           }
1069         }
1070
1071         p->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
1072         if (!leftRect.isNull()) {
1073           p->setPen(flip ? bar->palette.text().color() : bar->palette.base().color());
1074           p->setClipRect(leftRect, Qt::IntersectClip);
1075           p->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
1076         }
1077         p->restore();
1078       }
1079       break;
1080     case CE_ProgressBarContents:
1081       if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1082         QRect rect = pb->rect;
1083         bool vertical = false;
1084         bool inverted = false;
1085         // Get extra style options if version 2
1086         const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);
1087         if (pb2) {
1088           vertical = (pb2->orientation == Qt::Vertical);
1089           inverted = pb2->invertedAppearance;
1090         }
1091         QMatrix m;
1092         if (vertical) {
1093           rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1094           m.translate(rect.height(), 0.0);
1095           m.rotate(90);
1096         }
1097         QPalette pal2 = pb->palette;
1098         // Correct the highlight color if it is the same as the background
1099         if (pal2.highlight() == pal2.background())
1100             pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1101                                                                  QPalette::Highlight));
1102         bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1103         if (inverted)
1104           reverse = !reverse;
1105         int fw = 2;
1106         int width = rect.width() - 2 * fw;
1107         if (pb->minimum == 0 && pb->maximum == 0) {
1108           // draw busy indicator
1109           int x = (pb->progress - pb->minimum) % (width * 2);
1110           if (x > width)
1111             x = 2 * width - x;
1112           x = reverse ? rect.right() - x : x + rect.x();
1113           p->setPen(QPen(pal2.highlight().color(), 4));
1114           p->drawLine(x, rect.y() + 1, x, rect.height() - fw);
1115         } else {
1116           const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, w);
1117           int u;
1118           if (unit_width > 1)
1119             u = (rect.width() + unit_width / 3) / unit_width;
1120           else
1121             u = width / unit_width;
1122
1123           int p_v = pb->progress - pb->minimum;
1124           int t_s = pb->maximum - pb->minimum ? pb->maximum - pb->minimum : 1;
1125
1126           if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
1127             // scale down to something usable.
1128             p_v /= u;
1129             t_s /= u;
1130           }
1131
1132           // nu < tnu, if last chunk is only a partial chunk
1133           int tnu, nu;
1134           tnu = nu = p_v * u / t_s;
1135
1136           if (nu * unit_width > width)
1137             --nu;
1138
1139           // Draw nu units out of a possible u of unit_width
1140           // width, each a rectangle bordered by background
1141           // color, all in a sunken panel with a percentage text
1142           // display at the end.
1143           int x = 0;
1144           int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : fw)
1145                            : rect.x() + fw;
1146           QStyleOptionProgressBarV2 pbBits = *pb;
1147           pbBits.rect = rect;
1148           pbBits.palette = pal2;
1149           int myY = pbBits.rect.y();
1150           int myHeight = pbBits.rect.height();
1151           pbBits.state = State_None;
1152           QRect aRect;
1153           QColor aColor = model()->color( Style_Model::ProgressBar );    // Style_Model::prbar_clr
1154           QColor top    = aColor.light( BUT_PERCENT_COL );
1155           QColor bottom = aColor.dark( BUT_PERCENT_COL );
1156           int aType;
1157           for (int i = 0; i <= nu; ++i) {
1158             aType = Style_Tools::None;
1159             if ( i < nu ) { // not last element
1160               aRect = QRect(x0 + x, myY, unit_width, myHeight);
1161               if ( i == 0 ) {
1162                 if ( reverse )
1163                   aRect.setRight( aRect.right()-fw );
1164                 if ( vertical )
1165                   aType = reverse ? Style_Tools::BottomLeft | Style_Tools::BottomRight
1166                                   : Style_Tools::TopLeft | Style_Tools::TopRight;
1167                 else
1168                   aType = reverse ? Style_Tools::Right : Style_Tools::Left;
1169               }
1170             }
1171             else { // last element if it's necessary
1172               if ( nu >= tnu )
1173                 break;
1174               int pixels_left = width - (nu * unit_width);
1175               int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
1176               aRect = QRect(offset, myY, pixels_left, myHeight);
1177               if ( vertical )
1178                 aType = reverse ? Style_Tools::TopLeft | Style_Tools::TopRight
1179                                 : Style_Tools::BottomLeft | Style_Tools::BottomRight;
1180               else
1181                 aType = reverse ? Style_Tools::Left : Style_Tools::Right;
1182             }
1183             // display
1184             aRect = m.mapRect(aRect);
1185             if ( vertical )
1186               aRect = QRect(aRect.x(), aRect.y()+fw, aRect.width(), aRect.height());
1187
1188             if ( !vertical )
1189               aRect = QRect(aRect.x()+1, aRect.y()+2, aRect.width()-1,
1190                             aRect.height()-4);
1191             else
1192               aRect = QRect(aRect.x()+1, aRect.y()-1, aRect.width()-5, aRect.height()-1);
1193             QColor aTopClr = aColor, aBotClr = aColor;
1194             if ( unit_width > 1 ) {
1195               aTopClr = aColor.light();
1196               aBotClr = aColor.dark();
1197             }
1198             Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::EditRadius ), -1, 0,
1199                                      aType, top, bottom, aTopClr, aBotClr, false, true );
1200             x += reverse ? -unit_width : unit_width;
1201           }
1202         }
1203       }
1204       break;
1205     case CE_MenuItem:
1206       if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1207         const int windowsItemFrame    =  2; // definitions from qwindowstyle.cpp file
1208         const int windowsItemHMargin  =  3;
1209         const int windowsItemVMargin  =  2;
1210         const int windowsRightBorder  = 15;
1211         const int windowsArrowHMargin =  6;
1212         int x, y, width, h;
1213         menuitem->rect.getRect(&x, &y, &width, &h);
1214         int tab = menuitem->tabWidth;
1215         bool dis = !(menuitem->state & State_Enabled);
1216         bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1217                        ? menuitem->checked : false;
1218         bool act = menuitem->state & State_Selected;
1219
1220         // windows always has a check column, regardless whether we have an icon or not
1221         int checkcol = qMax(menuitem->maxIconWidth, 20);
1222
1223         QColor aBgColor = opt->palette.color( QPalette::Window );
1224         double aMargin = LINE_GR_MARGIN;
1225         QLinearGradient gr(x,y,menuitem->rect.right(),y);
1226         gr.setColorAt( 0.0, aBgColor );
1227         gr.setColorAt( aMargin/width, model()->color( Style_Model::FieldLight ) ); // Style_Model::fld_light_clr
1228         gr.setColorAt( 1.0, model()->color( Style_Model::FieldLight ) );
1229         QBrush fill;
1230         if ( act )
1231           fill = menuitem->palette.brush( QPalette::Highlight );
1232         else
1233           fill = QBrush( gr );
1234         p->fillRect(menuitem->rect, fill);
1235         if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1236           int yoff = y-1 + h / 2;
1237           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
1238           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1239           p->setPen( aBrdBotCol );
1240           p->drawLine(x + 2, yoff, x + width - 4, yoff);
1241           p->setPen( aBrdTopCol );
1242           p->drawLine(x + 2, yoff + 1, x + width - 4, yoff + 1);
1243           return;
1244         }
1245         QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(),
1246                                       menuitem->rect.y(), checkcol, menuitem->rect.height()));
1247         if (checked) {
1248           if (act && !dis)
1249             qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, new QBrush(aBgColor));
1250           else {
1251             QColor aCol = aBgColor;
1252             aCol.setAlpha( 80 );
1253             QBrush fill(aCol);
1254             qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1255           }
1256         } else if (!act)
1257           p->fillRect(vCheckRect, QBrush( gr ) );
1258         // On Windows Style, if we have a checkable item and an icon we
1259         // draw the icon recessed to indicate an item is checked. If we
1260         // have no icon, we draw a checkmark instead.
1261         if (!menuitem->icon.isNull()) {
1262           QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1263           if (act && !dis)
1264             mode = QIcon::Active;
1265           QPixmap pixmap;
1266           if (checked)
1267             pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
1268           else
1269             pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
1270           int pixw = pixmap.width();
1271           int pixh = pixmap.height();
1272           if (act && !dis && !checked)
1273             qDrawShadePanel(p, vCheckRect,  menuitem->palette, false, 1,
1274                             new QBrush(aBgColor));
1275           QRect pmr(0, 0, pixw, pixh);
1276           pmr.moveCenter(vCheckRect.center());
1277           p->setPen(menuitem->palette.text().color());
1278           p->drawPixmap(pmr.topLeft(), pixmap);
1279         } else if (checked) {
1280           QStyleOptionMenuItem newMi = *menuitem;
1281           newMi.state = State_None;
1282           if (!dis)
1283             newMi.state |= State_Enabled;
1284           if (act)
1285             newMi.state |= State_On;
1286           newMi.rect = visualRect(opt->direction, menuitem->rect,
1287           QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
1288                 checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
1289           drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
1290         }
1291         p->setPen(act ? menuitem->palette.highlightedText().color() :
1292                         menuitem->palette.buttonText().color());
1293         QColor discol;
1294         if (dis) {
1295           discol = menuitem->palette.text().color();
1296           p->setPen(discol);
1297         }
1298         int xm = windowsItemFrame + checkcol + windowsItemHMargin;
1299         int xpos = menuitem->rect.x() + xm;
1300         QRect textRect(xpos, y + windowsItemVMargin, width - xm - windowsRightBorder - tab + 1,
1301                        h - 2 * windowsItemVMargin);
1302         QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1303         QString s = menuitem->text;
1304         if (!s.isEmpty()) {                     // draw text
1305           p->save();
1306           int t = s.indexOf(QLatin1Char('\t'));
1307           int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip |
1308                            Qt::TextSingleLine;
1309           if (!styleHint(SH_UnderlineShortcut, menuitem, w))
1310             text_flags |= Qt::TextHideMnemonic;
1311           text_flags |= Qt::AlignLeft;
1312           if (t >= 0) {
1313             QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, 
1314             QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1315             if (dis && !act) {
1316                p->setPen(menuitem->palette.light().color());
1317                p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
1318                p->setPen(discol);
1319              }
1320              p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
1321              s = s.left(t);
1322           }
1323           QFont font = menuitem->font;
1324           if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1325             font.setBold(true);
1326             p->setFont(font);
1327             if (dis && !act) {
1328               p->setPen(menuitem->palette.light().color());
1329               p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
1330               p->setPen(discol);
1331             }
1332             p->drawText(vTextRect, text_flags, s.left(t));
1333             p->restore();
1334           }
1335           if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1336             int dim = (h - 2 * windowsItemFrame) / 2;
1337             PrimitiveElement arrow;
1338             arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft :
1339                      PE_IndicatorArrowRight;
1340             xpos = x + width - windowsArrowHMargin - windowsItemFrame - dim;
1341             QRect  vSubMenuRect = visualRect(opt->direction, menuitem->rect,
1342                                              QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1343             QStyleOptionMenuItem newMI = *menuitem;
1344             newMI.rect = vSubMenuRect;
1345             newMI.state = dis ? State_None : State_Enabled;
1346             if (act)
1347               newMI.palette.setColor(QPalette::ButtonText,
1348                                      newMI.palette.highlightedText().color());
1349             drawPrimitive(arrow, &newMI, p, w);
1350           }
1351         }
1352       break;
1353       /*
1354     case CE_ToolBoxTab:
1355       QCommonStyle::drawControl( ce, opt, p, w );
1356       break;
1357       */
1358     case CE_HeaderSection: {
1359       bool aStateOn = opt->state & State_On;
1360       QColor aColor = model()->color( Style_Model::Header );    // Style_Model::header_clr
1361       QColor  top =    aColor.light( BUT_PERCENT_COL ),
1362              bottom =  aColor.dark( BUT_PERCENT_COL );
1363       QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
1364       QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1365       Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol,
1366                        aBrdBotCol, model()->antialiasing(), true, aStateOn );
1367       break;
1368     }
1369     case CE_ComboBoxLabel:
1370       if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1371         QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, w);
1372         p->save();
1373         p->setClipRect(editRect);
1374         if (!cb->currentIcon.isNull()) {
1375           QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
1376                                                        : QIcon::Disabled;
1377           QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
1378           QRect iconRect(editRect);
1379           iconRect.setWidth(cb->iconSize.width() + 4);
1380           QRect alignRect = editRect;
1381           if ( cb->editable ) {
1382             int aHalfRect = (int)Style_Tools::getMaxRect( iconRect, 
1383                                (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
1384             alignRect.setLeft( alignRect.left() + aHalfRect );
1385             alignRect.setRight( alignRect.right() - aHalfRect );
1386           }
1387           iconRect = alignedRect(QApplication::layoutDirection(),
1388                                  Qt::AlignLeft | Qt::AlignVCenter,
1389                                  iconRect.size(), alignRect);
1390  
1391           // Here's absent filling of pixmap on basic color for editable comboBox
1392           drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
1393
1394           if (cb->direction == Qt::RightToLeft)
1395             editRect.translate(-4 - cb->iconSize.width(), 0);
1396           else
1397             editRect.translate(cb->iconSize.width() + 4, 0);
1398         }
1399         if (!cb->currentText.isEmpty() && !cb->editable) {
1400           drawItemText(p, editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, cb->palette,
1401                        cb->state & State_Enabled, cb->currentText);
1402         }
1403         p->restore();
1404       }
1405       break;
1406     case CE_ScrollBarSubLine:
1407     case CE_ScrollBarAddLine: {
1408         bool aStateOn = opt->state & ( State_Sunken | State_On );
1409         QColor aBtnCol = opt->palette.color( QPalette::Button );
1410         QColor top =    aBtnCol.light( BUT_PERCENT_COL ),
1411                bottom = aBtnCol.dark( BUT_PERCENT_COL );
1412         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
1413         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1414         Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol,
1415                                  aBrdBotCol, false, true, aStateOn, true );
1416       PrimitiveElement arrow;
1417       if (opt->state & State_Horizontal) {
1418         if (ce == CE_ScrollBarAddLine)
1419           arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1420         else
1421           arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1422       } else {
1423         if (ce == CE_ScrollBarAddLine)
1424           arrow = PE_IndicatorArrowDown;
1425         else
1426           arrow = PE_IndicatorArrowUp;
1427       }
1428       drawPrimitive(arrow, opt, p, w);
1429       break;
1430     }
1431     case CE_ScrollBarSlider:
1432       if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1433         p->save();
1434         p->setRenderHint( QPainter::Antialiasing, true );
1435         bool enabled = opt->state & State_Enabled;
1436         bool horiz = scrollbar->orientation == Qt::Horizontal;
1437         double aRad = model()->widgetRounding( Style_Model::ButtonRadius );
1438         if ( hasHover() && enabled && (opt->state & State_MouseOver) )
1439          drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, false);
1440         else {
1441         QColor aColor = model()->color( Style_Model::Slider );      // Style_Model::slider_clr
1442           if ( !enabled )
1443             aColor = opt->palette.button().color();
1444           QColor top =    aColor.light( BUT_PERCENT_ON ),
1445                  bottom = aColor.dark( BUT_PERCENT_ON );
1446           QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
1447           QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1448           QRect r = opt->rect;
1449           QPainterPath path = Style_Tools::roundRect( r, aRad,
1450                                                       Style_Tools::All );
1451           QLinearGradient gr;
1452           if (horiz)
1453             gr = QLinearGradient(r.x(), r.y(), r.x(), r.bottom());
1454           else
1455             gr = QLinearGradient(r.x(), r.y(), r.right(), r.y());
1456           gr.setColorAt( 0.0, bottom );
1457           gr.setColorAt( 0.5, top );
1458           gr.setColorAt( 1.0, bottom );
1459
1460           p->fillPath( path, gr );
1461           p->strokePath( path, aBrdTopCol );
1462       }
1463       p->setRenderHint( QPainter::Antialiasing, false );
1464       // draw handle
1465       QRect aRect = opt->rect;
1466       int aWidth = aRect.width(), aHeight = aRect.height();
1467       if ( aWidth > aHeight + aRad )
1468         aRect = QRect( aRect.x() + (int)((aWidth-aHeight)/2),
1469                        aRect.y(), aHeight, aHeight );
1470       else if ( aHeight > aWidth + aRad )
1471         aRect = QRect( aRect.x(), aRect.y() + (int)((aHeight-aWidth)/2),
1472                        aWidth, aWidth );
1473       else {
1474         int aRad2 = (int)(aRad/3);
1475         aRect = QRect( aRect.x()+aRad2, aRect.y()+aRad2, aRect.width()-2*aRad2, aRect.height()-2*aRad2  );
1476       }
1477       drawHandle( p, aRect, horiz, true );
1478
1479       p->restore();
1480       break;
1481     }
1482   case CE_ToolBar: {
1483     QRect r = w->rect();
1484     bool horiz = opt->state & State_Horizontal;
1485     drawBackground( p, r, opt->palette.color( QPalette::Window ), true, true, horiz );
1486     p->setRenderHint( QPainter::Antialiasing, false );
1487     drawBorder( p, r, horiz );
1488     break;
1489   }
1490   default:
1491     QWindowsStyle::drawControl( ce, opt, p, w );
1492     break;
1493   }
1494 }
1495
1496 /*!
1497   \brief Draws the given primitive element with the provided painter \p using the style options specified by \a opt.
1498   \param pe primitive type
1499   \param opt style option
1500   \param p painter
1501   \param w widget (optional)
1502 */
1503 void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt,
1504                                   QPainter* p, const QWidget* w ) const
1505 {
1506   if ( checkDebugLevel(6) ) {
1507     QWindowsStyle::drawPrimitive( pe, opt, p, w );
1508     return;
1509   }
1510
1511   const QPalette& pal = opt->palette;
1512   bool doRestore = false;
1513   switch ( pe ) {
1514     case PE_FrameMenu:
1515       if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1516         QColor aBtnCol = opt->palette.color( QPalette::Window ),
1517                top =    aBtnCol.light( BUT_PERCENT_ON ),
1518                bottom = aBtnCol.dark( BUT_PERCENT_ON );
1519         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
1520         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1521         Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top,
1522                                  bottom, aBrdTopCol, aBrdBotCol, false, false, false, false );
1523         break;
1524       }
1525     case PE_PanelButtonTool : {
1526       if ( w && ( opt->state & State_Enabled ) && 
1527            ( ( qobject_cast<QToolBar*>( w->parentWidget() ) ) ||
1528              ( w->inherits("QDockWidgetTitleButton") ) ||
1529              ( w->inherits("QtxWorkstackAreaTitleButton") ) ) ) {
1530         bool aStateOn = opt->state & (State_Sunken | State_On);
1531         bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
1532         if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) &&
1533              (opt->state & State_MouseOver) )
1534           drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true);
1535         else {
1536           QColor aBtnCol = opt->palette.color( QPalette::Window );
1537           QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
1538           QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1539           QColor top =    aBtnCol.light( BUT_PERCENT_COL ),
1540                  bottom = aBtnCol.dark( BUT_PERCENT_COL );
1541           Style_Tools::shadowRect( p, opt->rect, 0.0, 0, SHADOW, Style_Tools::All, top, bottom,
1542            aBrdTopCol, aBrdBotCol, model()->antialiasing(), true, aStateOn );
1543         }
1544         break;
1545       }
1546       else
1547         QWindowsStyle::drawPrimitive( pe, opt, p, w );
1548     }
1549     break;
1550     case PE_FrameFocusRect: {
1551       if (w && qobject_cast<QTabBar*>((QWidget*)w)) {
1552         QTabBar* tabBar = qobject_cast<QTabBar*>((QWidget*)w);
1553         QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
1554         QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1555         bool isHover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
1556         Style_Tools::tabRect( p, opt->rect, (int)tabBar->shape(),
1557                               model()->widgetRounding( Style_Model::FrameRadius ), DELTA_H_TAB,
1558                               pal.color( QPalette::Window ),
1559                               model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr
1560                               aBrdTopCol, aBrdBotCol, false, false, isHover, true );
1561       }
1562       else {
1563         QWindowsStyle::drawPrimitive( pe, opt, p, w );
1564       }
1565       break;
1566     }
1567     case PE_IndicatorArrowRight:
1568     case PE_IndicatorArrowLeft:
1569     case PE_IndicatorArrowUp:
1570     case PE_IndicatorArrowDown:
1571     case PE_IndicatorSpinUp:
1572     case PE_IndicatorSpinDown:
1573     case PE_IndicatorSpinPlus:
1574     case PE_IndicatorSpinMinus: {
1575       QRect rect = opt->rect;
1576       QColor pen, brush;
1577       if ( opt->state & State_Enabled ) {
1578         pen = model()->color( Style_Model::Pointer );    // Style_Model::pointer_clr
1579         brush = opt->palette.color( QPalette::Button );
1580         if ( ( opt->state & State_Sunken ) && (opt->state & State_Enabled ) )
1581           rect.moveTo( rect.x()+1, rect.y()+1 );
1582       } else {
1583         pen = opt->palette.mid().color();
1584         brush = pen;
1585       }
1586       if ( pe == PE_IndicatorSpinPlus || pe == PE_IndicatorSpinMinus )
1587         Style_Tools::drawSign( pe, p, rect, pen, brush );
1588       else
1589         Style_Tools::drawArrow( pe, p, rect, pen, brush );
1590       break;
1591     }
1592     case PE_IndicatorCheckBox: {
1593       if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) )
1594         drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ),
1595                       model()->widgetRounding( Style_Model::EditRadius ),
1596                       Style_Tools::All, false);
1597       QBrush fill;
1598       if (opt->state & State_NoChange)
1599         fill = QBrush( opt->palette.color( QPalette::Base ), Qt::Dense4Pattern);
1600       else if (opt->state & ( State_Sunken | ~State_Enabled ) )
1601         fill = opt->palette.color( QPalette::Window );
1602       else if (opt->state & State_Enabled) {
1603         if (!(opt->state & State_Off) )
1604           fill = QBrush( model()->color( Style_Model::Checked ) ); // Style_Model::checked_clr
1605         else
1606           fill = QBrush( opt->palette.color( QPalette::Base ) );
1607       }
1608       else
1609         fill = opt->palette.color( QPalette::Window );
1610       p->save();
1611       doRestore = true;
1612       QColor color = fill.color();
1613       QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
1614       QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1615       if ( model()->antialiasing() )
1616         p->setRenderHint( QPainter::Antialiasing, true );
1617
1618      // make sure the indicator is square
1619       QRect ir = opt->rect;
1620       if (opt->rect.width() < opt->rect.height()) {
1621         ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
1622         ir.setHeight(opt->rect.width());
1623       } else if (opt->rect.height() < opt->rect.width()) {
1624         ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
1625         ir.setWidth(opt->rect.height());
1626       }
1627
1628       Style_Tools::shadowCheck( p, ir, 2., Style_Tools::All,
1629                                 color, color.dark( BUT_PERCENT_ON ), aBrdTopCol, aBrdBotCol );
1630       if ( model()->antialiasing() )
1631         p->setRenderHint( QPainter::Antialiasing, false );
1632       if (opt->state & State_NoChange)
1633         p->setPen(opt->palette.dark().color());
1634       else
1635         p->setPen(opt->palette.text().color());
1636      } // Fall through!
1637     case PE_IndicatorViewItemCheck:
1638     case PE_Q3CheckListIndicator: {
1639       if (!doRestore) {
1640         p->save();
1641         doRestore = true;
1642       }
1643       const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
1644       p->setPen(itemViewOpt && itemViewOpt->showDecorationSelected
1645                 && opt->state & State_Selected ? opt->palette.highlightedText().color()
1646                 : opt->palette.text().color());
1647       if (opt->state & State_NoChange)
1648         p->setBrush( opt->palette.color( QPalette::Button ) );
1649       p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
1650       if (!(opt->state & State_Off)) {
1651         QLineF lines[11];
1652         int i, xx, yy;
1653         xx = opt->rect.x() + 4;
1654         yy = opt->rect.y() + 5;
1655         for (i = 0; i < 3; ++i) {
1656           lines[i] = QLineF(xx, yy, xx, yy + 2);
1657           ++xx;
1658           ++yy;
1659         }
1660         yy -= 2;
1661         for (i = 3; i < 11; ++i) {
1662           lines[i] = QLineF(xx, yy, xx, yy+2);
1663           ++xx;
1664           --yy;
1665         }
1666         QColor aColor = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
1667         if ( !(opt->state & State_Enabled ) )
1668           aColor = opt->palette.mid().color();
1669         if ( opt->state & State_Selected && itemViewOpt && itemViewOpt->showDecorationSelected )
1670           aColor = opt->palette.highlightedText().color();
1671
1672         p->setPen( QPen( aColor ) );
1673         p->drawLines(lines, 11);
1674       }
1675
1676       if (doRestore)
1677           p->restore();
1678       break;
1679     }
1680     case PE_IndicatorRadioButton: {
1681       if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) )
1682         drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ), 
1683                       model()->widgetRounding( Style_Model::ButtonRadius ),
1684                       Style_Tools::All, false);
1685 #define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
1686       static const QPoint pts_border[] = {              // border line
1687         QPoint(1, 9),  QPoint(1, 8),  QPoint(0, 7),  QPoint(0, 4),  QPoint(1, 3),  QPoint(1, 2),
1688         QPoint(2, 1),  QPoint(3, 1),  QPoint(4, 0),  QPoint(7, 0),  QPoint(8, 1),  QPoint(9, 1),
1689         QPoint(10, 2), QPoint(10, 3), QPoint(11, 4), QPoint(11, 7), QPoint(10, 8), QPoint(10, 9), 
1690         QPoint(9, 10), QPoint(8, 10), QPoint(7, 11), QPoint(4, 11), QPoint(3, 10), QPoint(2, 10)
1691       };
1692      // make sure the indicator is square
1693       QRect ir = opt->rect;
1694       if (opt->rect.width() < opt->rect.height()) {
1695         ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
1696         ir.setHeight(opt->rect.width());
1697       } else if (opt->rect.height() < opt->rect.width()) {
1698         ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
1699         ir.setWidth(opt->rect.height());
1700       }
1701       p->save();
1702       bool down = opt->state & State_Sunken;
1703       bool enabled = opt->state & State_Enabled;
1704       bool on = opt->state & State_On;
1705       QPolygon a;
1706       p->translate(ir.x(), ir.y());
1707
1708       if ( down || !enabled ) {
1709         QColor fillColor = opt->palette.color( QPalette::Window );
1710         p->setPen( fillColor );
1711         p->setBrush( fillColor );
1712       }
1713       else {
1714         QColor fillColor =  opt->palette.color( QPalette::Base );
1715         if ( enabled && on )
1716           fillColor = model()->color( Style_Model::Checked ); // Style_Model::checked_clr
1717         QLinearGradient gr( 3, 3, 8, 8 );
1718         gr.setColorAt( 0.0, fillColor.dark( BUT_PERCENT_ON ) );
1719         gr.setColorAt( 1.0, fillColor );
1720         p->setPen( fillColor.dark( BUT_PERCENT_ON ) );
1721         p->setBrush( gr );
1722       }
1723       p->drawPolygon(pts_border, PTSARRLEN(pts_border));
1724       int aSize = PTSARRLEN(pts_border),
1725           aHalfSize = (int)aSize/2;
1726       if ( model()->antialiasing() )
1727         p->setRenderHint( QPainter::Antialiasing, true );
1728       p->setPen( model()->color( Style_Model::BorderTop) );     // Style_Model::border_top_clr
1729       p->drawPolyline(pts_border, aHalfSize);
1730       p->setPen( model()->color( Style_Model::BorderBottom ) ); // Style_Model::border_bot_clr
1731       QPolygon aPolygon;
1732       for ( int i = aHalfSize; i < aSize; i++ )
1733         aPolygon << pts_border[i];
1734       p->drawPolyline( aPolygon );
1735       if ( model()->antialiasing() )
1736         p->setRenderHint( QPainter::Antialiasing, false );
1737
1738       if (on) {
1739         QColor aPointerCol = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
1740         if ( !enabled )
1741           aPointerCol = opt->palette.mid().color();
1742         p->setPen( Qt::NoPen );
1743         p->setBrush( aPointerCol );
1744         p->drawRect( 5, 4, 2, 4 );
1745         p->drawRect( 4, 5, 4, 2 );
1746       }
1747
1748       p->translate(-ir.x(), -ir.y()); // restore translate
1749       p->restore();
1750       break;
1751     }
1752     case PE_FrameDockWidget:
1753       if ( qstyleoption_cast<const QStyleOptionFrame *>(opt))
1754         QCommonStyle::drawPrimitive( pe, opt, p, w );
1755       break;
1756     case PE_FrameLineEdit:
1757     case PE_PanelLineEdit: {
1758       if ( w ) {
1759         if ( qobject_cast<const QComboBox*>( w->parentWidget() ) ||
1760              qobject_cast<const QAbstractSpinBox*>( w->parentWidget() ) )
1761           break;
1762       }
1763       if ( pe == PE_FrameLineEdit ) {
1764         QColor aBrdTopCol = model()->color( Style_Model::BorderTop );    // Style_Model::border_top_clr
1765         QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1766         bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
1767         double aRad = model()->widgetRounding( Style_Model::EditRadius );
1768         if ( hover )
1769           drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true);
1770         else {
1771           Style_Tools::shadowRect( p, opt->rect, aRad, LINE_GR_MARGIN, SHADOW,
1772                                    Style_Tools::All, opt->palette.color( QPalette::Base ), // getColor( Style_Model::fld_light_clr ),
1773                                    model()->color( Style_Model::FieldDark ), aBrdTopCol, aBrdBotCol,
1774                                    model()->antialiasing(), false );
1775         }
1776       }
1777       else {
1778         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1779           QRect rect = panel->rect.adjusted( panel->lineWidth,  panel->lineWidth,
1780                                              -panel->lineWidth, -panel->lineWidth);
1781           if ( w->inherits("QLineEdit") && panel->lineWidth > 0 ) {
1782             drawPrimitive( PE_FrameLineEdit, panel, p, w );
1783           }
1784           else {
1785             QColor c = panel->palette.color(QPalette::Base); c.setAlpha(255);
1786             p->fillRect( rect, c ); // panel->palette.brush(QPalette::Base)
1787           }
1788         }
1789       }
1790       break;
1791     }
1792     case PE_FrameTabWidget: {
1793       if (w && qobject_cast<QTabWidget*>((QWidget*)w)) {
1794         QTabWidget* tabW = qobject_cast<QTabWidget*>((QWidget*)w);
1795         int aRoundType = Style_Tools::BottomRight;
1796         QTabWidget::TabPosition aTabPos = tabW->tabPosition();
1797         if ( aTabPos != QTabWidget::North && aTabPos != QTabWidget::West )
1798           aRoundType = aRoundType | Style_Tools::TopLeft;
1799         if ( aTabPos != QTabWidget::South )
1800           aRoundType = aRoundType | Style_Tools::BottomLeft;
1801         if ( aTabPos != QTabWidget::East )
1802           aRoundType = aRoundType | Style_Tools::TopRight;
1803         QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
1804         QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1805         Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::FrameRadius ),
1806                                  0., SHADOW, aRoundType,
1807                                  model()->color( Style_Model::FieldLight ),
1808                                  opt->palette.color( QPalette::Dark ),
1809                                  aBrdTopCol, aBrdBotCol, false, false, false, false );
1810         break;
1811       }
1812     }
1813     case PE_IndicatorToolBarHandle: {
1814       p->save();
1815       QRect r = opt->rect;
1816       bool horiz = opt->state & State_Horizontal;
1817       QLinearGradient gr( r.x(), r.y(), horiz ? r.x() : r.right(), horiz ? r.bottom() : r.y() );
1818       QColor aBgCol = opt->palette.color( QPalette::Window );
1819       gr.setColorAt( 0.0, aBgCol.light( BUT_PERCENT_ON ) );
1820       gr.setColorAt( 1.0, aBgCol );
1821       p->fillRect( r, gr );
1822       QRect aRect = QRect( r.x(), r.y(), r.width(), r.height() );
1823       drawHandle( p, r, horiz, false );
1824       p->restore();
1825       break;
1826     }
1827     case PE_Widget: {
1828       QWindowsStyle::drawPrimitive( pe, opt, p, w );
1829       if ( !w )
1830         break;
1831       if( w->parent() && !qobject_cast<QMenuBar*>((QWidget*)w) )
1832          break;
1833       drawBackground( p, w->rect(), opt->palette.color( QPalette::Window ), false );
1834       break;
1835     }
1836     case PE_FrameTabBarBase:
1837       // for a tabbar that isn't part of a tab widget(dockWidgets for example).
1838       if (const QStyleOptionTabBarBase *tbb
1839           = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
1840         if (tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedEast &&
1841             tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedWest) {
1842           QWindowsStyle::drawPrimitive( pe, opt, p, w );
1843           break;
1844         }
1845         QRect aSelRect = tbb->selectedTabRect;
1846         // line under selected tab bar object
1847         bool isSelected = opt->state & State_Selected;
1848         QTabBar* tabBar = qobject_cast<QTabBar*>((QWidget*)w);
1849         bool isLast = false;
1850         if ( tabBar )
1851           isLast = tabBar->currentIndex() == tabBar->count() -1;
1852         QColor aColor = opt->palette.color( QPalette::Window );
1853         QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
1854         QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1855         bool isHover = hasHover() && (opt->state & State_Enabled) &&
1856                                      (opt->state & State_MouseOver);
1857         QPainterPath aSelPath = Style_Tools::tabRect( p, aSelRect, (int)tbb->shape,
1858                                                       model()->widgetRounding( Style_Model::FrameRadius ),
1859                                                       DELTA_H_TAB, aColor, aColor,
1860                             aColor, aColor, isSelected, isLast, isHover, false, false );
1861         if ( !aSelPath.isEmpty() )
1862           aSelRect = aSelPath.controlPointRect().toRect();
1863         QStyleOptionTabBarBase* copyOpt = (QStyleOptionTabBarBase*)tbb;
1864         copyOpt->selectedTabRect = aSelRect;
1865         QCommonStyle::drawPrimitive( pe, copyOpt, p, w );
1866         break;
1867       }
1868     case PE_IndicatorBranch: {
1869         // This is _way_ too similar to the common style.
1870         static const int decoration_size = 9;
1871         int mid_h = opt->rect.x() + opt->rect.width() / 2;
1872         int mid_v = opt->rect.y() + opt->rect.height() / 2;
1873         int bef_h = mid_h;
1874         int bef_v = mid_v;
1875         int aft_h = mid_h;
1876         int aft_v = mid_v;
1877         if (opt->state & State_Children) {
1878             int delta = decoration_size / 2;
1879             bef_h -= delta;
1880             bef_v -= delta;
1881             aft_h += delta;
1882             aft_v += delta;
1883             p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
1884             if (!(opt->state & State_Open))
1885                 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
1886             QPen oldPen = p->pen();
1887             p->setPen(opt->palette.dark().color());
1888             p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
1889             p->setPen(oldPen);
1890         }
1891         QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
1892         if (opt->state & State_Item) {
1893             if (opt->direction == Qt::RightToLeft)
1894                 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
1895             else
1896                 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
1897         }
1898         if (opt->state & State_Sibling)
1899             p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
1900         if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
1901             p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
1902         break;
1903       }
1904     case PE_IndicatorDockWidgetResizeHandle: {
1905       QRect r = opt->rect;
1906       drawBorder( p, r, opt->state & State_Horizontal );
1907       bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
1908       if ( hover )
1909           drawHoverRect(p, r, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, false);
1910       bool horiz = r.width() > r.height();
1911       int aLen = model()->splitHandleLength();
1912       if ( horiz )
1913         r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
1914       else
1915         r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
1916       drawHandle( p, r, horiz, true );
1917       break;
1918     }
1919     case PE_Frame: {
1920       QWidget* aWdg = (QWidget*)w;
1921       if ( qobject_cast<QTextEdit*>(aWdg) || qobject_cast<QTreeView*>(aWdg) ||
1922            qobject_cast<QListView*>(aWdg) ) {
1923         QRect r = opt->rect;
1924         if ( qobject_cast<QTreeView*>(aWdg) ) {
1925           QTreeView* trView = qobject_cast<QTreeView*>(aWdg);
1926           QHeaderView* aHeader = trView->header();
1927           if ( aHeader && aHeader->isVisible() ) {
1928             int aHeight = aHeader->contentsRect().height();
1929             r = QRect( r.x(), r.y()+aHeight, r.width(), r.height()-aHeight );
1930           }
1931         }
1932         QPalette aPal = aWdg->palette();
1933         double aMarg = LINE_GR_MARGIN;
1934         QColor base = model()->color( Style_Model::Base ), // Style_Model::pal_base_clr
1935           light = base,
1936           light_alt = base.dark(110),//AlternateBase color
1937           dark  = model()->color( Style_Model::FieldDark ); // Style_Model::fld_dark_clr
1938         //light.setAlpha( 0 ); // VSR commented: IPAL19262
1939         QLinearGradient gr_h(r.x(), r.y(), r.right(), r.y());
1940         gr_h.setColorAt( 0.0, dark );
1941         gr_h.setColorAt( aMarg / r.width(), light );
1942         gr_h.setColorAt( 1.0, light );
1943         QLinearGradient gr_v(r.x(), r.y(), r.x(), r.bottom() );
1944         gr_v.setColorAt( 0.0, dark );
1945         gr_v.setColorAt( aMarg / r.height(), light );
1946         gr_v.setColorAt( 1.0, light );
1947         // draw frame
1948         p->fillRect( r, base );
1949         p->fillRect( r, gr_h );
1950         p->fillRect( r, gr_v );
1951         aPal.setBrush( QPalette::Base, QBrush( light ) );
1952
1953         QLinearGradient gr_alt(r.x(), r.y(), r.right(), r.y());
1954         gr_alt.setColorAt( 0.0, dark );
1955         gr_alt.setColorAt( (aMarg)*2/3/r.width(), light_alt );
1956         gr_alt.setColorAt( 1.0, light_alt );
1957         aPal.setBrush( QPalette::AlternateBase, QBrush( gr_alt ) );
1958         aWdg->setPalette( aPal );
1959       }
1960       QWindowsStyle::drawPrimitive( pe, opt, p, w );
1961       break;
1962     }
1963     default:
1964       QWindowsStyle::drawPrimitive( pe, opt, p, w );
1965   }
1966 }
1967
1968 /*!
1969   \brief Returns the value of the given pixel \a metric.
1970   \param metric metric type
1971   \param opt style option
1972   \param w widget
1973   \return metric value
1974 */
1975 int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt,
1976                                const QWidget* w ) const
1977 {
1978   if ( checkDebugLevel(7) ) {
1979     return QWindowsStyle::pixelMetric( metric, opt, w );
1980   }
1981
1982   int aRes = QWindowsStyle::pixelMetric( metric, opt, w );
1983   switch( metric ) {
1984     case PM_SliderLength: {
1985       aRes += (int)((double)model()->sliderSize()/2);
1986       break;
1987     }
1988     case PM_DockWidgetFrameWidth:
1989       aRes = 1;
1990     break;
1991     case PM_DockWidgetSeparatorExtent:
1992       aRes = 8;
1993     break;
1994     case PM_DockWidgetTitleMargin:
1995       aRes = 2;
1996     break;
1997     case PM_SplitterWidth:
1998       aRes = 6;
1999     break;
2000     default:
2001     break;
2002   }
2003   return aRes;
2004 }
2005
2006 /*!
2007   \brief Returns the size of the element described by the specified option \a opt 
2008   and type \a ct, based on the provided \a contentsSize.
2009   \param ct contents type
2010   \param opt style option
2011   \param contentsSize contents size
2012   \param w widget (optional)
2013   \return size of the element
2014 */
2015 QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt,
2016                                       const QSize& contentsSize, const QWidget* w ) const
2017 {
2018   if ( checkDebugLevel(8) ) {
2019     return QWindowsStyle::sizeFromContents( ct, opt,contentsSize, w );
2020   }
2021
2022   QSize sz = QWindowsStyle::sizeFromContents( ct, opt, contentsSize, w );
2023   switch (ct) {
2024     case CT_TabBarTab:
2025       if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
2026         if ( tab->position == QStyleOptionTab::End ||
2027              tab->position == QStyleOptionTab::OnlyOneTab ) {
2028           if ( tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth ) {
2029             int aDelta = (int)(opt->rect.height()*DELTA_H_TAB/2);
2030             sz.setWidth( sz.width() + aDelta );
2031           }
2032           if ( tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::RoundedWest ) {
2033             int aDelta = (int)(opt->rect.width()*DELTA_H_TAB/2);
2034             sz.setHeight( sz.height() + aDelta );
2035           }
2036         }
2037         break;
2038       }
2039       break;
2040       case CT_Slider: {
2041         int aValue = model()->sliderSize();
2042         sz.setWidth( sz.width() + aValue );
2043         sz.setHeight( sz.height() + aValue );
2044         break;
2045       }
2046       case CT_ComboBox:
2047         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2048           QRect res = QRect( 0, 0, sz.width(), sz.height() );
2049           int aHalfRect = (int)Style_Tools::getMaxRect( res, 
2050                              (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); // left value
2051           QRect old_arrow = QWindowsStyle::subControlRect( CC_ComboBox, cmb,
2052                                                            SC_ComboBoxArrow, w );
2053           int aDelta = res.height() - old_arrow.width(); // right value
2054           if ( cmb->editable )
2055             aDelta += aHalfRect; // for right of line edit internal
2056           sz.setWidth( res.width() + aDelta + aHalfRect );
2057         }
2058         break;
2059       default:
2060       break;
2061   }
2062   return sz;
2063 }
2064
2065 /*!
2066   \brief Returns a pixmap for the given \a standardPixmap.
2067   \param stPixmap standard pixmap type
2068   \param opt style option
2069   \param w widget (optional)
2070   \return standard pixmap
2071 */
2072 QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption *opt,
2073                                      const QWidget *w) const
2074 {
2075   if ( checkDebugLevel(9) ) {
2076     return QWindowsStyle::standardPixmap( stPixmap, opt, w );
2077   }
2078
2079   switch ( stPixmap )
2080   {
2081   case SP_DockWidgetCloseButton:
2082   case SP_TitleBarCloseButton:
2083     return QPixmap( cross_xpm );
2084   case SP_TitleBarMaxButton:
2085     return QPixmap( maximize_xpm );
2086   case SP_TitleBarNormalButton:
2087     return QPixmap( normal_xpm );
2088   case SP_TitleBarMinButton:
2089     return QPixmap( minimize_xpm );
2090   default:
2091     return QWindowsStyle::standardPixmap( stPixmap, opt, w );
2092   }
2093 }
2094
2095 /*!
2096   \brief Returns an icon for the given \a standardIcon.
2097   \param standardIcon standard icon type
2098   \param opt style option
2099   \param w widget (optional)
2100   \return standard icon
2101 */
2102 QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon, 
2103                                                 const QStyleOption* opt,
2104                                                 const QWidget* w ) const
2105 {
2106   if ( checkDebugLevel(10) ) {
2107     return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
2108   }
2109
2110   switch ( standardIcon )
2111   {
2112   case SP_MessageBoxInformation:
2113     return QPixmap( ":/images/information.png" );
2114   case SP_MessageBoxWarning:
2115     return QPixmap( ":/images/warning.png" );
2116   case SP_MessageBoxCritical:
2117     return QPixmap( ":/images/critical.png" );
2118   case SP_MessageBoxQuestion:
2119     return QPixmap( ":/images/question.png" );
2120   default:
2121     break;
2122   }
2123   return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
2124 }
2125
2126 /*!
2127   \brief Returns an integer representing the specified style \a hint for the
2128   given widget \a w described by the provided style option \a opt.
2129   \param hint hint type
2130   \param opt style option
2131   \param w widget (optional)
2132   \param returnData (currently not used)
2133   \return style hint value
2134 */
2135 int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWidget* w,
2136                             QStyleHintReturn* returnData ) const
2137 {
2138   if ( checkDebugLevel(11) ) {
2139     return QWindowsStyle::styleHint( hint, opt, w, returnData );
2140   }
2141
2142   int aRes = QWindowsStyle::styleHint( hint, opt, w, returnData );
2143   switch( hint ) {
2144     case SH_Table_GridLineColor: {
2145       if ( opt )
2146         aRes = model()->color( Style_Model::GridLine ).rgb(); // Style_Model::tbl_grline_clr
2147       else
2148         return aRes;
2149       break;
2150     }
2151     default:
2152       break;
2153   }
2154   return aRes;
2155 }
2156
2157 /*!
2158   \brief Get the rectangle containing the specified subcontrol \a sc of the given
2159   complex control \a cc (with the style specified by option \a opt). 
2160   The rectangle is defined in screen coordinates.
2161   \param cc complex control type
2162   \param opt style option
2163   \param sc subcontrol type
2164   \param wid widget (optional)
2165   \return subcontrol rectangle
2166 */
2167 QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex* opt,
2168                                     SubControl sc, const QWidget* wid ) const
2169 {
2170   if ( checkDebugLevel(12) ) {
2171     return QWindowsStyle::subControlRect( cc, opt, sc, wid );
2172   }
2173
2174   QRect res = QWindowsStyle::subControlRect( cc, opt, sc, wid );
2175   switch ( cc ) {
2176     case CC_SpinBox: {
2177       int x = res.x(), w = res.width(), h = res.height();
2178       if ( sc==SC_SpinBoxUp || sc==SC_SpinBoxDown ) {
2179         QRect frame_r = QWindowsStyle::subControlRect( cc, opt, SC_SpinBoxFrame, wid );
2180         h = frame_r.height();
2181         res.setX( x+w-h );
2182         res.setWidth( h );
2183       }
2184       else if ( sc==QStyle::SC_SpinBoxEditField ) {
2185         res.setWidth( w-h );
2186         res.setTopLeft( QPoint( res.x(), res.y()-SHADOW ) );
2187       }
2188       break;
2189     }
2190     case CC_ComboBox: {
2191       if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2192         res = cb->rect;
2193         int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
2194         int x = res.x(), w = res.width(), h = res.height();
2195         switch( sc ) {
2196           case SC_ComboBoxEditField: {
2197             res.setWidth( w-h );
2198             int aX = res.x();
2199             if ( !cb->editable )
2200               aX += aHalfRect;
2201             res.setTopLeft( QPoint( aX, res.y()-SHADOW ) );
2202             break;
2203           }
2204           case SC_ComboBoxArrow: {
2205             res.setX( x+w-h );
2206             res.setWidth( h );
2207             break;
2208           }
2209         }
2210       }
2211       break;
2212     }
2213     case CC_ScrollBar:
2214       if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2215         QRect slider_r = QWindowsStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid );
2216         int aRect = Style_Tools::getMaxRect( slider_r, (int)model()->widgetRounding( Style_Model::ButtonRadius ) );
2217         switch( sc ) {
2218           case SC_ScrollBarSubPage:            // between top/left button and slider
2219             if (scrollbar->orientation == Qt::Horizontal)
2220               res.setRight( res.right()+aRect+1 );
2221             else
2222               res.setBottom( res.bottom()+aRect+1 );
2223             break;
2224           case SC_ScrollBarAddPage:            // between bottom/right button and slider
2225             if (scrollbar->orientation == Qt::Horizontal)
2226               res.setLeft( res.left() - aRect - 1 );
2227             else
2228               res.setTop( res.top() - aRect - 1);
2229           break;
2230           default:
2231             break;
2232         }
2233         break;
2234       }
2235     case CC_Slider: {
2236       if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2237         switch ( sc ) {
2238           case SC_SliderGroove: {
2239             if ( slider->orientation == Qt::Horizontal ) {
2240               res.setLeft( res.left()+DELTA_SLIDER );
2241               res.setRight( res.right()-DELTA_SLIDER );
2242             }
2243             else {
2244               res.setTop( res.top()+DELTA_SLIDER );
2245               res.setBottom( res.bottom()-DELTA_SLIDER );
2246             }
2247             break;
2248           }
2249         }
2250       }
2251     }
2252   }
2253   return res;
2254 }
2255
2256 /*!
2257   \brief Returns the sub-area for the given element \a se as described 
2258   in the provided style option \a opt.
2259   The returned rectangle is defined in screen coordinates.
2260   \param se subelement type
2261   \param opt style option
2262   \param wid widget (optional)
2263   \return subelement rectangle
2264 */
2265 QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt,
2266                                    const QWidget* wid ) const
2267 {
2268   if ( checkDebugLevel(13) ) {
2269     return QWindowsStyle::subElementRect( se, opt, wid );
2270   }
2271
2272   QRect res = QWindowsStyle::subElementRect( se, opt, wid );
2273   int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
2274   int w = res.width(), h = res.height();
2275   switch ( se ) {
2276     case SE_ComboBoxFocusRect: {
2277       QRect old_r = QWindowsStyle::subControlRect( CC_ComboBox,
2278                      qstyleoption_cast<const QStyleOptionComplex*>( opt ),
2279                      SC_ComboBoxArrow, wid );
2280       int old_w = old_r.width();
2281       res.setWidth( w-h+old_w-2 );
2282       break;
2283     }
2284     case SE_LineEditContents: {
2285       res.setTopLeft( QPoint( res.x()+aHalfRect, res.y()-SHADOW ) );
2286       res.setTopRight( QPoint( res.right()-aHalfRect, res.y() ) );
2287       break;
2288     }
2289     case SE_ProgressBarLabel:
2290     case SE_ProgressBarContents:
2291     case SE_ProgressBarGroove:
2292       return opt->rect;
2293   }
2294   if( qobject_cast<const QRadioButton*>(wid) ||
2295       qobject_cast<const QCheckBox*>(wid) ) {
2296       if( hasHover() )
2297         res = res.adjusted(0, 0, 2, 0);
2298   }
2299   return res;
2300 }
2301
2302 /*!
2303   \brief Update palette colors from style model
2304 */
2305 void Style_Salome::updatePaletteColors()
2306 {
2307   QPalette pal = QApplication::palette();
2308   // colors
2309   for ( int i = (int)QPalette::Active; i <= (int)QPalette::Inactive; i++ ) {
2310     for ( int j = (int)Style_Model::WindowText; j < (int)Style_Model::NColorRoles; j++ ) {
2311       if ( j == QPalette::NoRole ) continue;
2312       pal.setColor( (QPalette::ColorGroup)i, (QPalette::ColorRole)j,
2313                     model()->color( (Style_Model::ColorRole)j, (QPalette::ColorGroup)i ) );
2314     }
2315   }
2316   QPixmapCache::clear();
2317   QApplication::setPalette( pal );
2318 }
2319
2320 /*!
2321   \brief Update all widgets with the current style properties.
2322   \param app application object
2323 */
2324 void Style_Salome::updateAllWidgets( QApplication* app )
2325 {
2326   if ( !app )
2327     return;
2328
2329   QWidgetList all = app->allWidgets();
2330   QWidget* w;
2331   for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) {
2332     w = *it2;
2333     if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)
2334         && !w->testAttribute(Qt::WA_SetStyle)) {
2335       QEvent e(QEvent::StyleChange);
2336       QApplication::sendEvent(w, &e);
2337       polish( w );
2338       w->update();
2339     }
2340   }
2341 }
2342
2343 /*!
2344   \brief Check if any widget effect is currently used
2345   \return \c true if any widget effect is currently used
2346 */
2347 bool Style_Salome::hasHover() const
2348 {
2349   return model()->widgetEffect() != Style_Model::NoEffect;
2350 }
2351
2352 /*!
2353   \brief Draw rectangle for the hovered widget
2354   \param p painter
2355   \param r rectangle
2356   \param bgCol background color
2357   \param rad corners rounding radius
2358   \param type shadow type
2359   \param border if \c true border is colored with specific color
2360 */
2361 void Style_Salome::drawHoverRect( QPainter* p, const QRect& r, const QColor& bgCol, const double rad,
2362                                   const int type, const bool border ) const
2363 {
2364   if ( !hasHover() )
2365     return;
2366   bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
2367   bool isHighWdg     = model()->widgetEffect() == Style_Model::HighlightEffect;
2368   QColor aBorder = model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr
2369          aCol, aBrdCol;
2370   double aMargin = HIGH_WDG_MARGIN;
2371   if  ( isAutoRaising ) {
2372     aCol = bgCol;
2373     aBrdCol = aCol.dark(BUT_PERCENT_ON);
2374     if ( !border )
2375       aBorder = aCol;
2376     aMargin = 0;
2377   }
2378   else if ( isHighWdg ) {
2379     aCol    = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr
2380     aBrdCol = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr
2381     if ( !border )
2382       aBorder = aBrdCol;
2383   }
2384   Style_Tools::highlightRect( p, r, rad, type, aMargin, aCol, aBrdCol, aBorder );
2385 }
2386
2387 /*!
2388   \brief Draw widget handle
2389   \param p painter
2390   \param r rectangle
2391   \param horiz if \c true draw horizontal handle, otherwise draw vertical handle
2392   \param isRect if \c true surrounding rectangle is also drawn
2393 */
2394 void Style_Salome::drawHandle( QPainter* p, const QRect& r, bool horiz, bool isRect ) const
2395 {
2396   QPixmap hole( (const char**)hole_xpm );
2397   int i, j;
2398   double d_hor = model()->handleDelta( Qt::Horizontal );
2399   double d_ver = model()->handleDelta( Qt::Vertical );
2400   if ( !d_hor || !d_ver || !r.width() || !r.height() )
2401     return;
2402   int c_hor = (int)(r.width()/d_hor)-1;
2403   int c_ver = (int)(r.height()/d_ver)-1;
2404   if ( c_hor+1 <= 0 || c_ver+1 <= 0 )
2405     return;
2406   // correction for delta value
2407   d_hor = r.width()/(c_hor+1);
2408   d_ver = r.height()/(c_ver+1);
2409
2410   double dd_hor = 0, dd_ver = 0;
2411   if ( horiz ) {
2412     for ( i = 0; i < c_hor; i++ ) {
2413       for ( j = 0; j < c_ver; j++ ) {
2414           p->drawPixmap( (int)( r.x() + dd_hor + ( i + 1 ) * d_hor  - 1 ),
2415                          (int)( r.y() + dd_ver + ( j + 1 ) * d_ver - 1 ), hole );
2416       }
2417       if ( !isRect ) {
2418         dd_ver += (int(d_ver)/2) + (int(d_ver)%2);
2419         c_ver = c_ver - 1;
2420       }
2421     }
2422   }
2423   else {
2424     for ( j = 0; j < c_ver; j++ ) {
2425       for ( i = 0; i < c_hor; i++ ) {
2426           p->drawPixmap( (int)( r.x() + dd_hor + ( i + 1 ) * d_hor  - 1 ),
2427                          (int)( r.y() + dd_ver + ( j + 1 ) * d_ver - 1 ), hole );
2428       }
2429       if ( !isRect ) {
2430         dd_hor += (int(d_hor)/2) + (int(d_hor)%2);
2431         c_hor = c_hor - 1;
2432       }
2433     }
2434   }
2435 }
2436
2437 /*!
2438   \brief Draw background.
2439   \param p painter
2440   \param r rectangle
2441   \param bgCol background color
2442   \param fill 'fill rectangle' flag
2443   \param grad 'draw gradient' flag
2444   \param horix 'draw horizontal item' flag (usefull for gradient background)
2445 */
2446 void Style_Salome::drawBackground( QPainter* p, const QRect& r, const QColor& bgCol,
2447                                    const bool fill, const bool grad, const bool horiz ) const
2448 {
2449   if ( fill ) {
2450     if ( !grad )
2451       p->fillRect( r, bgCol );
2452     else {
2453       QLinearGradient gr( r.x(), r.y(), horiz ? r.x() : r.right(), horiz ? r.bottom() : r.y() );
2454       gr.setColorAt( 0.0, bgCol.light( BUT_PERCENT_ON ) );
2455       gr.setColorAt( 1.0, bgCol );
2456       p->fillRect( r, gr );
2457     }
2458   }
2459
2460   int x = r.x(), y = r.y(), left = r.left(), top = r.top();
2461   int w = r.width(), h = r.height();
2462
2463   QVector<QLine> lines;
2464
2465   switch ( model()->linesType() ) {
2466   case Style_Model::Horizontal:
2467     {
2468       const int d = 3;
2469       for ( int i = 0; i <= h; i += d )
2470         lines.append( QLine( x, y+i, w, r.y()+i ) );
2471     }
2472     break;
2473   case Style_Model::Inclined:
2474     {
2475       const int d = 5;
2476       w = w/d*d;
2477       h = h/d*d;
2478       for ( int i = 0; i <= w; i += d )
2479         lines.append( QLine( x+i, y, x, y+i ) );
2480       for ( int i = 0; i < h; i += d )
2481         lines.append( QLine( left+w-i, top+h, left+w, top+h-i ) );
2482     }
2483     break;
2484   default:
2485     break;
2486   }
2487
2488   if ( !lines.isEmpty() ) {
2489     QColor c = model()->color( Style_Model::Lines );
2490     int anAlpha = (int)( 255*( 1 - model()->linesTransparency()/100 ) ); 
2491     c.setAlpha( anAlpha );
2492     p->setPen( c );
2493     p->setRenderHint( QPainter::Antialiasing );
2494     p->drawLines( lines );
2495   }
2496 }
2497
2498 /*!
2499   \brief Draw border
2500   \param p painter
2501   \param r rectangle
2502   \param horiz 'draw horizontal item' flag
2503 */
2504 void Style_Salome::drawBorder( QPainter* p, const QRect& r, bool horiz ) const 
2505 {
2506   QPen oldPen = p->pen();
2507   QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop );    // Style_Model::border_tab_top_clr
2508   QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
2509   p->setPen( aBrdTopCol );
2510   if (horiz) {
2511     p->drawLine(r.left(),  r.top(), r.right(), r.top());
2512     p->setPen(aBrdBotCol);
2513     p->drawLine(r.left(), r.bottom(), r.right(), r.bottom());
2514   }
2515   else {
2516     p->drawLine(r.left(), r.top(), r.left(), r.bottom());
2517     p->setPen(aBrdBotCol);
2518     p->drawLine(r.right(), r.top(), r.right(), r.bottom());
2519   }
2520   p->setPen(oldPen);
2521 }
2522
2523 /*!
2524   \brief Get corrected title text
2525   \param txt original text
2526   \param W possible width
2527   \param H possible height
2528   \param f used font
2529   \return corrected title text
2530 */
2531 QString Style_Salome::titleText( const QString& txt, const int W, const int H, QFont& f ) const
2532 {
2533   QString res = txt.trimmed();
2534
2535   QFontMetrics fm( f );
2536   while( fm.height() > H && f.pointSize()>1 )
2537   {
2538     f.setPointSize( f.pointSize()-1 );
2539     fm = QFontMetrics( f );
2540   }
2541
2542   if ( fm.width( res ) > W )
2543   {
2544     QString end( "..." );
2545     while ( !res.isEmpty() && fm.width( res + end ) > W )
2546       res.remove( res.length() - 1, 1 );
2547
2548     if ( !res.isEmpty() )
2549       res += end;
2550   }
2551
2552   return res;
2553 }