1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : Style_Salome.cxx
21 // Author : Natalia Ermolaeva, Open CASCADE S.A.S.
23 #include "Style_Salome.h"
24 #include "Style_Tools.h"
25 #include "Style_Model.h"
27 #include <QApplication>
30 #include <QPainterPath>
33 #include <QStyleOptionFrame>
34 #include <QStyleOptionComplex>
35 #include <QStyleOptionSpinBox>
36 #include <QStyleOptionButton>
37 #include <QStyleOptionTab>
38 #include <QStyleOptionToolButton>
39 #include <QStyleOptionFocusRect>
40 #include <QStyleOption>
44 #include <QToolButton>
48 #include <QDockWidget>
52 #include <QHeaderView>
53 #include <QRadioButton>
55 #include <QPushButton>
56 #include <QAbstractSpinBox>
60 #include <QMainWindow>
61 #include <QPixmapCache>
65 #define LINE_GR_MARGIN 10
66 #define HIGH_WDG_MARGIN 10
68 #define BUT_PERCENT_COL 125
69 #define BUT_PERCENT_ON 115
72 #define DELTA_SLIDER 3
74 static const char* const hole_xpm[] = {
84 static const char* const cross_xpm[] = {
104 static const char* const maximize_xpm[] = {
124 static const char* const normal_xpm[] = {
144 static const char* const minimize_xpm[] = {
164 ///////////////////////////////////////////////////////////
165 // FOR debug purposes only!!!
169 static bool checkDebugLevel( int level )
171 return DEBUG_LEVEL == level || DEBUG_LEVEL == -1;
174 ///////////////////////////////////////////////////////////
176 Style_Model* Style_Salome::myModel = 0;
180 \brief SALOME style class.
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.
185 The usual way to use SALOME style is as following:
187 Style_Salome::initialize( resourceMgr() ); // initialize SALOME style from resources
188 if ( needSalomeStyle ) Style_Salome::apply(); // set SALOME style to the application
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:
194 Style_PrefDlg dlg( desktop() );
202 Use Style_Salome::apply() static function to set SALOME style to the application.
204 Style_Salome::Style_Salome()
205 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
211 // initialize SALOME style resources
212 Q_INIT_RESOURCE( Style );
218 Style_Salome::~Style_Salome()
224 \brief Initialize SALOME style.
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.
230 If the parameter \a resMgr is not 0, the style is initialized from the
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.
236 \param resMgr resources manager
237 \param section resources file section name
238 \sa apply(), restore()
240 void Style_Salome::initialize( QtxResourceMgr* resMgr, const QString& section )
242 model()->fromResources( resMgr, section );
246 \brief Set SALOME style to the application
247 \sa initialize(), restore()
249 void Style_Salome::apply()
251 // application object is not created yet
252 if ( !QApplication::instance() )
255 // update model (from the resources manager if needed)
258 // check if SALOME style is already set to the application
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
265 update(); // update style
269 \brief Restore original style to the application
270 \sa initialize(), apply()
272 void Style_Salome::restore()
274 // application object is not created yet
275 if ( !QApplication::instance() )
277 // check if SALOME style is set to the application
281 QApplication::setDesktopSettingsAware(true);
283 // restore previous style
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
291 bool Style_Salome::isActive()
293 return QApplication::instance() != 0 && qobject_cast<Style_Salome*>( QApplication::style() ) != 0;
297 \brief Update style from resources.
299 void Style_Salome::update()
301 // application object is not created yet
302 if ( !QApplication::instance() )
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() ) );
310 \brief Get style model
313 Style_Model* Style_Salome::model()
316 myModel = new Style_Model();
321 \brief Initialize the appearance of the application.
323 Performs late initialization of the given application object.
325 \param app application object
327 void Style_Salome::polish ( QApplication* app )
329 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
330 QWindowsStyle::polish( app );
332 QCommonStyle::polish( app );
335 if ( checkDebugLevel(1) ) {
339 updatePaletteColors();
340 app->setFont( model()->applicationFont() );
341 updateAllWidgets( app );
345 \brief Initializes the appearance of the given widget.
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.
350 \param w widget object
352 void Style_Salome::polish ( QWidget* w )
354 if ( checkDebugLevel(2) ) {
355 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
356 QWindowsStyle::polish( w );
358 QCommonStyle::polish( w );
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 );
373 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
374 QWindowsStyle::polish( w );
376 QCommonStyle::polish( w );
381 \brief Uninitialize the given widget's appearance.
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.
388 \param w widget object
390 void Style_Salome::unpolish( QWidget* w )
392 if ( checkDebugLevel(3) ) {
393 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
394 QWindowsStyle::unpolish( w );
396 QCommonStyle::unpolish( w );
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 );
411 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
412 QWindowsStyle::unpolish( w );
414 QCommonStyle::unpolish( w );
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
425 void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComplex* opt,
426 QPainter* p, const QWidget* w ) const
428 if ( checkDebugLevel(4) ) {
429 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
430 QWindowsStyle::drawComplexControl( cc, opt, p, w );
432 QCommonStyle::drawComplexControl( cc, opt, p, w );
437 const QPalette& pal = w->palette();
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
450 drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
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 );
460 drawHoverRect(p, aBtnRect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
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;
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;
476 copy.state |= State_Enabled;
478 if ( spin->activeSubControls == SC_SpinBoxUp && ( spin->state & State_Sunken ) ) {
479 copy.state |= State_On;
480 copy.state |= State_Sunken;
482 copy.state |= State_Raised;
483 copy.state &= ~State_Sunken;
485 pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
486 : PE_IndicatorSpinUp);
487 copy.rect = aBtnRect;
488 drawPrimitive(pe, ©, p, w);
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;
500 copy.state |= State_Enabled;
502 if (spin->activeSubControls == SC_SpinBoxDown && (spin->state & State_Sunken)) {
503 copy.state |= State_On;
504 copy.state |= State_Sunken;
506 copy.state |= State_Raised;
507 copy.state &= ~State_Sunken;
509 pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
510 : PE_IndicatorSpinDown);
511 copy.rect = aBtnRect;
512 drawPrimitive(pe, ©, p, w);
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 );
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
529 drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
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 );
540 drawHoverRect(p, ar, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
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);
551 arrowOpt.palette = cmb->palette;
552 arrowOpt.state = flags;
553 drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
555 if (cmb->subControls & SC_ComboBoxEditField) {
556 bool hi = cmb->state & State_HasFocus && !cmb->editable;
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,
562 p->setPen(cmb->palette.highlightedText().color());
565 p->setPen(cmb->palette.text().color());
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);
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);
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);
588 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w);
591 if (slider->subControls & SC_SliderTickmarks) {
592 QStyleOptionSlider tmpSlider = *slider;
593 tmpSlider.subControls = SC_SliderTickmarks;
594 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w);
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);
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;
620 type = Style_Tools::SlUp;
621 slRect.setTop( slRect.top()-aYAdd );
624 type = Style_Tools::SlDown;
625 slRect.setBottom( slRect.bottom()+aYAdd );
629 type = Style_Tools::SlLeft;
630 slRect.setLeft( slRect.left()-aXAdd );
633 type = Style_Tools::SlRight;
634 slRect.setRight( slRect.right()+aXAdd );
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 );
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);
657 if (w && ( qobject_cast<QToolBar *>(w->parentWidget() ) ||
658 ( toolbutton->state & State_AutoRaise && !( toolbutton->state & State_MouseOver ) ) )
660 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
661 QWindowsStyle::drawComplexControl( cc, opt, p, w );
663 QCommonStyle::drawComplexControl( cc, opt, p, w );
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 );
690 Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, top, bottom,
691 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
693 if (toolbutton->subControls & SC_ToolButtonMenu) {
695 if ( aMinDelta > menuArea.height()/2 )
696 aMinDelta = menuArea.height()/2;
697 if ( aMinDelta > menuArea.width()/2 )
698 aMinDelta = menuArea.width()/2;
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 );
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;
718 State mflags = bflags;
719 if (toolbutton->activeSubControls & SC_ToolButton)
720 bflags |= State_Sunken;
721 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
722 mflags |= State_Sunken;
724 drawPrimitive(PE_IndicatorArrowDown, &tool, p, w);
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 );
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 );
746 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
747 QWindowsStyle::drawComplexControl( cc, opt, p, w );
749 QCommonStyle::drawComplexControl( cc, opt, p, w );
754 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const
755 QStyleOptionGroupBox *>(opt)) {
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);
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);
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);
800 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
801 QWindowsStyle::drawComplexControl( cc, opt, p, w );
803 QCommonStyle::drawComplexControl( cc, opt, p, w );
808 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
809 QWindowsStyle::drawComplexControl( cc, opt, p, w );
811 QCommonStyle::drawComplexControl( cc, opt, p, w );
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
823 void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt,
824 QPainter* p, const QWidget* w ) const
826 if ( checkDebugLevel(5) ) {
827 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
828 QWindowsStyle::drawControl( ce, opt, p, w );
830 QCommonStyle::drawControl( ce, opt, p, w );
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 ) );
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 );
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
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 );
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);
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);
889 if ( dockWidget->isFloating() && dwOpt->movable) {
891 QColor top = opt->palette.color( QPalette::Highlight ).light();
892 QColor bottom = opt->palette.color( QPalette::Highlight );
894 QBrush fillBrush(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);
903 p->fillRect(dwOpt->rect.adjusted(0, 0, 0, -3), fillBrush);
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 );
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() );
927 p->setPen(dwOpt->palette.color(QPalette::Light));
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() );
940 QFont oldFont = p->font();
941 QFont font = oldFont;
946 aTitle = titleText( aTitle, r.width(), r.height(), font );
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);
960 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
961 QWindowsStyle::drawControl( ce, opt, p, w );
963 QCommonStyle::drawControl( ce, opt, p, w );
966 bool horiz = r.width() > r.height();
967 int aLen = model()->splitHandleLength();
969 r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
971 r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
972 drawHandle( p, r, horiz, true );
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) {
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
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
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 );
1002 QCommonStyle::drawControl( ce, opt, p, w );
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;
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() ) );
1016 aDelta = (int)(opt->rect.width()*DELTA_H_TAB/2);
1017 oldRect = QRect( oldRect.topLeft(), QPoint( oldRect.right(), oldRect.bottom()-aDelta ) );
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 );
1024 QCommonStyle::drawControl( ce, copyTab, p, w );
1028 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1029 QWindowsStyle::drawControl( ce, opt, p, w );
1031 QCommonStyle::drawControl( ce, opt, p, w );
1035 case CE_MenuBarItem:
1036 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
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 ) );
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);
1059 Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top, bottom,
1060 aBrdTopCol, aBrdBotCol,
1061 model()->antialiasing(), true, aStateOn );
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));
1070 QCommonStyle::drawControl(ce, &newMbi, p, w);
1073 case CE_MenuBarEmptyArea:
1074 drawBackground( p, opt->rect, opt->palette.color( QPalette::Window ), true, true, true );
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 );
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)
1094 QRect rect = bar->rect;
1096 p->setPen(bar->palette.text().color());
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;
1108 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1111 m.translate(0.0, rect.width());
1114 m.translate(rect.height(), 0.0);
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)));
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());
1130 p->setPen(bar->palette.base().color());
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());
1138 p->setPen(bar->palette.text().color());
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));
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);
1159 vertical = (pb2->orientation == Qt::Vertical);
1160 inverted = pb2->invertedAppearance;
1164 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1165 m.translate(rect.height(), 0.0);
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);
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);
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);
1187 const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, w);
1190 u = (rect.width() + unit_width / 3) / unit_width;
1192 u = width / unit_width;
1194 int p_v = pb->progress - pb->minimum;
1195 int t_s = pb->maximum - pb->minimum ? pb->maximum - pb->minimum : 1;
1197 if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
1198 // scale down to something usable.
1203 // nu < tnu, if last chunk is only a partial chunk
1205 tnu = nu = p_v * u / t_s;
1207 if (nu * unit_width > width)
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.
1215 int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : fw)
1217 QStyleOptionProgressBarV2 pbBits = *pb;
1219 pbBits.palette = pal2;
1220 int myY = pbBits.rect.y();
1221 int myHeight = pbBits.rect.height();
1222 pbBits.state = State_None;
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 );
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);
1234 aRect.setRight( aRect.right()-fw );
1236 aType = reverse ? Style_Tools::BottomLeft | Style_Tools::BottomRight
1237 : Style_Tools::TopLeft | Style_Tools::TopRight;
1239 aType = reverse ? Style_Tools::Right : Style_Tools::Left;
1242 else { // last element if it's necessary
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);
1249 aType = reverse ? Style_Tools::TopLeft | Style_Tools::TopRight
1250 : Style_Tools::BottomLeft | Style_Tools::BottomRight;
1252 aType = reverse ? Style_Tools::Left : Style_Tools::Right;
1255 aRect = m.mapRect(aRect);
1257 aRect = QRect(aRect.x(), aRect.y()+fw, aRect.width(), aRect.height());
1260 aRect = QRect(aRect.x()+1, aRect.y()+2, aRect.width()-1,
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();
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;
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;
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;
1291 // windows always has a check column, regardless whether we have an icon or not
1292 int checkcol = qMax(menuitem->maxIconWidth, 20);
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 ) );
1302 fill = menuitem->palette.brush( QPalette::Highlight );
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);
1316 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(),
1317 menuitem->rect.y(), checkcol, menuitem->rect.height()));
1320 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, new QBrush(aBgColor));
1322 QColor aCol = aBgColor;
1323 aCol.setAlpha( 80 );
1325 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
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;
1335 mode = QIcon::Active;
1338 pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
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;
1354 newMi.state |= State_Enabled;
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);
1362 p->setPen(act ? menuitem->palette.highlightedText().color() :
1363 menuitem->palette.buttonText().color());
1366 discol = menuitem->palette.text().color();
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
1377 int t = s.indexOf(QLatin1Char('\t'));
1378 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip |
1380 if (!styleHint(SH_UnderlineShortcut, menuitem, w))
1381 text_flags |= Qt::TextHideMnemonic;
1382 text_flags |= Qt::AlignLeft;
1384 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1385 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1387 p->setPen(menuitem->palette.light().color());
1388 p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
1391 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
1394 QFont font = menuitem->font;
1395 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1399 p->setPen(menuitem->palette.light().color());
1400 p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
1403 p->drawText(vTextRect, text_flags, s.left(t));
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;
1418 newMI.palette.setColor(QPalette::ButtonText,
1419 newMI.palette.highlightedText().color());
1420 drawPrimitive(arrow, &newMI, p, w);
1426 QCommonStyle::drawControl( ce, opt, p, w );
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 );
1440 case CE_ComboBoxLabel:
1441 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1442 QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, w);
1444 p->setClipRect(editRect);
1445 if (!cb->currentIcon.isNull()) {
1446 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
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 );
1458 iconRect = alignedRect(QApplication::layoutDirection(),
1459 Qt::AlignLeft | Qt::AlignVCenter,
1460 iconRect.size(), alignRect);
1462 // Here's absent filling of pixmap on basic color for editable comboBox
1463 drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
1465 if (cb->direction == Qt::RightToLeft)
1466 editRect.translate(-4 - cb->iconSize.width(), 0);
1468 editRect.translate(cb->iconSize.width() + 4, 0);
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);
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;
1492 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1494 if (ce == CE_ScrollBarAddLine)
1495 arrow = PE_IndicatorArrowDown;
1497 arrow = PE_IndicatorArrowUp;
1499 drawPrimitive(arrow, opt, p, w);
1502 case CE_ScrollBarSlider:
1503 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
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);
1512 QColor aColor = model()->color( Style_Model::Slider ); // Style_Model::slider_clr
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,
1523 gr = QLinearGradient(r.x(), r.y(), r.x(), r.bottom());
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 );
1530 p->fillPath( path, gr );
1531 p->strokePath( path, aBrdTopCol );
1533 p->setRenderHint( QPainter::Antialiasing, false );
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),
1544 int aRad2 = (int)(aRad/3);
1545 aRect = QRect( aRect.x()+aRad2, aRect.y()+aRad2, aRect.width()-2*aRad2, aRect.height()-2*aRad2 );
1547 drawHandle( p, aRect, horiz, true );
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 );
1561 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1562 QWindowsStyle::drawControl( ce, opt, p, w );
1564 QCommonStyle::drawControl( ce, opt, p, w );
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
1575 \param w widget (optional)
1577 void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt,
1578 QPainter* p, const QWidget* w ) const
1580 if ( checkDebugLevel(6) ) {
1581 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1582 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1584 QCommonStyle::drawPrimitive( pe, opt, p, w );
1589 const QPalette& pal = opt->palette;
1590 bool doRestore = false;
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 );
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);
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 );
1625 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1626 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1628 QCommonStyle::drawPrimitive( pe, opt, p, w );
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 );
1645 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1646 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1648 QCommonStyle::drawPrimitive( pe, opt, p, w );
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;
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 );
1669 pen = opt->palette.mid().color();
1672 if ( pe == PE_IndicatorSpinPlus || pe == PE_IndicatorSpinMinus )
1673 Style_Tools::drawSign( pe, p, rect, pen, brush );
1675 Style_Tools::drawArrow( pe, p, rect, pen, brush );
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);
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
1692 fill = QBrush( opt->palette.color( QPalette::Base ) );
1695 fill = opt->palette.color( QPalette::Window );
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 );
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());
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());
1721 p->setPen(opt->palette.text().color());
1723 case PE_IndicatorViewItemCheck:
1724 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1725 case PE_Q3CheckListIndicator:
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)) {
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);
1750 for (i = 3; i < 11; ++i) {
1751 lines[i] = QLineF(xx, yy, xx, yy+2);
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();
1761 p->setPen( QPen( aColor ) );
1762 p->drawLines(lines, 11);
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)
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());
1791 bool down = opt->state & State_Sunken;
1792 bool enabled = opt->state & State_Enabled;
1793 bool on = opt->state & State_On;
1795 p->translate(ir.x(), ir.y());
1797 if ( down || !enabled ) {
1798 QColor fillColor = opt->palette.color( QPalette::Window );
1799 p->setPen( fillColor );
1800 p->setBrush( fillColor );
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 ) );
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
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 );
1828 QColor aPointerCol = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
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 );
1837 p->translate(-ir.x(), -ir.y()); // restore translate
1841 case PE_FrameDockWidget:
1842 if ( qstyleoption_cast<const QStyleOptionFrame *>(opt))
1843 QCommonStyle::drawPrimitive( pe, opt, p, w );
1845 case PE_FrameLineEdit:
1846 case PE_PanelLineEdit: {
1848 if ( qobject_cast<const QComboBox*>( w->parentWidget() ) ||
1849 qobject_cast<const QAbstractSpinBox*>( w->parentWidget() ) )
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 );
1858 drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true);
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 );
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 );
1874 QColor c = panel->palette.color(QPalette::Base); c.setAlpha(255);
1875 p->fillRect( rect, c ); // panel->palette.brush(QPalette::Base)
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 );
1902 case PE_IndicatorToolBarHandle: {
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 );
1916 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1917 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1919 QCommonStyle::drawPrimitive( pe, opt, p, w );
1923 if( w->parent() && !qobject_cast<QMenuBar*>((QWidget*)w) )
1925 drawBackground( p, w->rect(), opt->palette.color( QPalette::Window ), false );
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 );
1937 QCommonStyle::drawPrimitive( pe, opt, p, w );
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;
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 );
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;
1971 if (opt->state & State_Children) {
1972 int delta = decoration_size / 2;
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);
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);
1990 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
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);
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);
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();
2007 r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
2009 r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
2010 drawHandle( p, r, horiz, true );
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 );
2026 QPalette aPal = aWdg->palette();
2027 double aMarg = LINE_GR_MARGIN;
2028 QColor base = model()->color( Style_Model::Base ), // Style_Model::pal_base_clr
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 );
2042 p->fillRect( r, base );
2043 p->fillRect( r, gr_h );
2044 p->fillRect( r, gr_v );
2045 aPal.setBrush( QPalette::Base, QBrush( light ) );
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 );
2054 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2055 QWindowsStyle::drawPrimitive( pe, opt, p, w );
2057 QCommonStyle::drawPrimitive( pe, opt, p, w );
2062 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2063 QWindowsStyle::drawPrimitive( pe, opt, p, w );
2065 QCommonStyle::drawPrimitive( pe, opt, p, w );
2071 \brief Returns the value of the given pixel \a metric.
2072 \param metric metric type
2073 \param opt style option
2075 \return metric value
2077 int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt,
2078 const QWidget* w ) const
2080 if ( checkDebugLevel(7) ) {
2081 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2082 return QWindowsStyle::pixelMetric( metric, opt, w );
2084 return QCommonStyle::pixelMetric( metric, opt, w );
2087 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2088 int aRes = QWindowsStyle::pixelMetric( metric, opt, w );
2090 int aRes = QCommonStyle::pixelMetric( metric, opt, w );
2093 case PM_SliderLength: {
2094 aRes += (int)((double)model()->sliderSize()/2);
2097 case PM_DockWidgetFrameWidth:
2100 case PM_DockWidgetSeparatorExtent:
2103 case PM_DockWidgetTitleMargin:
2106 case PM_SplitterWidth:
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
2124 QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt,
2125 const QSize& contentsSize, const QWidget* w ) const
2127 if ( checkDebugLevel(8) ) {
2128 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2129 return QWindowsStyle::sizeFromContents( ct, opt,contentsSize, w );
2131 return QCommonStyle::sizeFromContents( ct, opt,contentsSize, w );
2134 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2135 QSize sz = QWindowsStyle::sizeFromContents( ct, opt, contentsSize, w );
2137 QSize sz = QCommonStyle::sizeFromContents( ct, opt, contentsSize, w );
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 );
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 );
2157 int aValue = model()->sliderSize();
2158 sz.setWidth( sz.width() + aValue );
2159 sz.setHeight( sz.height() + aValue );
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 );
2171 QRect old_arrow = QCommonStyle::subControlRect( CC_ComboBox, cmb,
2172 SC_ComboBoxArrow, w );
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 );
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
2193 QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption *opt,
2194 const QWidget *w) const
2196 if ( checkDebugLevel(9) ) {
2197 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2198 return QWindowsStyle::standardPixmap( stPixmap, opt, w );
2200 return QCommonStyle::standardPixmap( stPixmap, opt, w );
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 );
2216 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2217 return QWindowsStyle::standardPixmap( stPixmap, opt, w );
2219 return QCommonStyle::standardPixmap( stPixmap, opt, w );
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
2231 QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon,
2232 const QStyleOption* opt,
2233 const QWidget* w ) const
2235 if ( checkDebugLevel(10) ) {
2236 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2237 return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
2239 return QCommonStyle::standardIcon( standardIcon, opt, w );
2243 switch ( standardIcon )
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" );
2256 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2257 return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
2259 return QCommonStyle::standardIcon( standardIcon, opt, w );
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
2272 int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWidget* w,
2273 QStyleHintReturn* returnData ) const
2275 if ( checkDebugLevel(11) ) {
2276 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2277 return QWindowsStyle::styleHint( hint, opt, w, returnData );
2279 return QCommonStyle::styleHint( hint, opt, w, returnData );
2282 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2283 int aRes = QWindowsStyle::styleHint( hint, opt, w, returnData );
2285 int aRes = QCommonStyle::styleHint( hint, opt, w, returnData );
2288 case SH_Table_GridLineColor: {
2290 aRes = model()->color( Style_Model::GridLine ).rgb(); // Style_Model::tbl_grline_clr
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
2311 QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex* opt,
2312 SubControl sc, const QWidget* wid ) const
2314 if ( checkDebugLevel(12) ) {
2315 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2316 return QWindowsStyle::subControlRect( cc, opt, sc, wid );
2318 return QCommonStyle::subControlRect( cc, opt, sc, wid );
2321 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2322 QRect res = QWindowsStyle::subControlRect( cc, opt, sc, wid );
2324 QRect res = QCommonStyle::subControlRect( cc, opt, sc, wid );
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 );
2333 QRect frame_r = QCommonStyle::subControlRect( cc, opt, SC_SpinBoxFrame, wid );
2335 h = frame_r.height();
2339 else if ( sc==QStyle::SC_SpinBoxEditField ) {
2340 res.setWidth( w-h );
2341 res.setTopLeft( QPoint( res.x(), res.y()-SHADOW ) );
2346 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
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();
2351 case SC_ComboBoxEditField: {
2352 res.setWidth( w-h );
2354 if ( !cb->editable )
2356 res.setTopLeft( QPoint( aX, res.y()-SHADOW ) );
2359 case SC_ComboBoxArrow: {
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 );
2373 QRect slider_r = QCommonStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid );
2375 int aRect = Style_Tools::getMaxRect( slider_r, (int)model()->widgetRounding( Style_Model::ButtonRadius ) );
2377 case SC_ScrollBarSubPage: // between top/left button and slider
2378 if (scrollbar->orientation == Qt::Horizontal)
2379 res.setRight( res.right()+aRect+1 );
2381 res.setBottom( res.bottom()+aRect+1 );
2383 case SC_ScrollBarAddPage: // between bottom/right button and slider
2384 if (scrollbar->orientation == Qt::Horizontal)
2385 res.setLeft( res.left() - aRect - 1 );
2387 res.setTop( res.top() - aRect - 1);
2395 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2397 case SC_SliderGroove: {
2398 if ( slider->orientation == Qt::Horizontal ) {
2399 res.setLeft( res.left()+DELTA_SLIDER );
2400 res.setRight( res.right()-DELTA_SLIDER );
2403 res.setTop( res.top()+DELTA_SLIDER );
2404 res.setBottom( res.bottom()-DELTA_SLIDER );
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
2424 QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt,
2425 const QWidget* wid ) const
2427 if ( checkDebugLevel(13) ) {
2428 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2429 return QWindowsStyle::subElementRect( se, opt, wid );
2431 return QCommonStyle::subElementRect( se, opt, wid );
2434 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
2435 QRect res = QWindowsStyle::subElementRect( se, opt, wid );
2437 QRect res = QCommonStyle::subElementRect( se, opt, wid );
2439 int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
2440 int w = res.width(), h = res.height();
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 );
2448 QRect old_r = QCommonStyle::subControlRect( CC_ComboBox,
2449 qstyleoption_cast<const QStyleOptionComplex*>( opt ),
2450 SC_ComboBoxArrow, wid );
2452 int old_w = old_r.width();
2453 res.setWidth( w-h+old_w-2 );
2456 case SE_LineEditContents: {
2457 res.setTopLeft( QPoint( res.x()+aHalfRect, res.y()-SHADOW ) );
2458 res.setTopRight( QPoint( res.right()-aHalfRect, res.y() ) );
2461 case SE_ProgressBarLabel:
2462 case SE_ProgressBarContents:
2463 case SE_ProgressBarGroove:
2466 if( qobject_cast<const QRadioButton*>(wid) ||
2467 qobject_cast<const QCheckBox*>(wid) ) {
2469 res = res.adjusted(0, 0, 2, 0);
2475 \brief Update palette colors from style model
2477 void Style_Salome::updatePaletteColors()
2479 QPalette pal = QApplication::palette();
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 ) );
2488 QPixmapCache::clear();
2489 QApplication::setPalette( pal );
2493 \brief Update all widgets with the current style properties.
2494 \param app application object
2496 void Style_Salome::updateAllWidgets( QApplication* app )
2501 QWidgetList all = app->allWidgets();
2503 for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++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);
2516 \brief Check if any widget effect is currently used
2517 \return \c true if any widget effect is currently used
2519 bool Style_Salome::hasHover() const
2521 return model()->widgetEffect() != Style_Model::NoEffect;
2525 \brief Draw rectangle for the hovered widget
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
2533 void Style_Salome::drawHoverRect( QPainter* p, const QRect& r, const QColor& bgCol, const double rad,
2534 const int type, const bool border ) const
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
2542 double aMargin = HIGH_WDG_MARGIN;
2543 if ( isAutoRaising ) {
2545 aBrdCol = aCol.dark(BUT_PERCENT_ON);
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
2556 Style_Tools::highlightRect( p, r, rad, type, aMargin, aCol, aBrdCol, aBorder );
2560 \brief Draw widget handle
2563 \param horiz if \c true draw horizontal handle, otherwise draw vertical handle
2564 \param isRect if \c true surrounding rectangle is also drawn
2566 void Style_Salome::drawHandle( QPainter* p, const QRect& r, bool horiz, bool isRect ) const
2568 QPixmap hole( (const char**)hole_xpm );
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() )
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 )
2578 // correction for delta value
2579 d_hor = r.width()/(c_hor+1);
2580 d_ver = r.height()/(c_ver+1);
2582 double dd_hor = 0, dd_ver = 0;
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 );
2590 dd_ver += (int(d_ver)/2) + (int(d_ver)%2);
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 );
2602 dd_hor += (int(d_hor)/2) + (int(d_hor)%2);
2610 \brief Draw background.
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)
2618 void Style_Salome::drawBackground( QPainter* p, const QRect& r, const QColor& bgCol,
2619 const bool fill, const bool grad, const bool horiz ) const
2623 p->fillRect( r, bgCol );
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 );
2632 int x = r.x(), y = r.y(), left = r.left(), top = r.top();
2633 int w = r.width(), h = r.height();
2635 QVector<QLine> lines;
2637 switch ( model()->linesType() ) {
2638 case Style_Model::Horizontal:
2641 for ( int i = 0; i <= h; i += d )
2642 lines.append( QLine( x, y+i, w, r.y()+i ) );
2645 case Style_Model::Inclined:
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 ) );
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 );
2665 p->setRenderHint( QPainter::Antialiasing );
2666 p->drawLines( lines );
2674 \param horiz 'draw horizontal item' flag
2676 void Style_Salome::drawBorder( QPainter* p, const QRect& r, bool horiz ) const
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 );
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());
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());
2696 \brief Get corrected title text
2697 \param txt original text
2698 \param W possible width
2699 \param H possible height
2701 \return corrected title text
2703 QString Style_Salome::titleText( const QString& txt, const int W, const int H, QFont& f ) const
2705 QString res = txt.trimmed();
2707 QFontMetrics fm( f );
2708 while( fm.height() > H && f.pointSize()>1 )
2710 f.setPointSize( f.pointSize()-1 );
2711 fm = QFontMetrics( f );
2714 if ( fm.width( res ) > W )
2716 QString end( "..." );
2717 while ( !res.isEmpty() && fm.width( res + end ) > W )
2718 res.remove( res.length() - 1, 1 );
2720 if ( !res.isEmpty() )