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