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