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