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