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