1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : Style_Salome.cxx
23 // Author : Natalia Ermolaeva, Open CASCADE S.A.S.
25 #include "Style_Salome.h"
26 #include "Style_Tools.h"
27 #include "Style_Model.h"
29 #include <QApplication>
32 #include <QPainterPath>
35 #include <QStyleOptionFrame>
36 #include <QStyleOptionComplex>
37 #include <QStyleOptionSpinBox>
38 #include <QStyleOptionButton>
39 #include <QStyleOptionTab>
40 #include <QStyleOptionToolButton>
41 #include <QStyleOptionFocusRect>
42 #include <QStyleOption>
46 #include <QToolButton>
50 #include <QDockWidget>
54 #include <QHeaderView>
55 #include <QRadioButton>
57 #include <QPushButton>
58 #include <QAbstractSpinBox>
62 #include <QMainWindow>
63 #include <QPixmapCache>
68 #define LINE_GR_MARGIN 10
69 #define HIGH_WDG_MARGIN 10
71 #define BUT_PERCENT_COL 125
72 #define BUT_PERCENT_ON 115
75 #define DELTA_SLIDER 3
77 static const char* const hole_xpm[] = {
87 static const char* const cross_xpm[] = {
107 static const char* const maximize_xpm[] = {
127 static const char* const normal_xpm[] = {
147 static const char* const minimize_xpm[] = {
167 ///////////////////////////////////////////////////////////
168 // FOR debug purposes only!!!
172 static bool checkDebugLevel( int level )
174 return DEBUG_LEVEL == level || DEBUG_LEVEL == -1;
177 ///////////////////////////////////////////////////////////
179 Style_Model* Style_Salome::myModel = 0;
183 \brief SALOME style class.
185 To set SALOME style to the application, use static function Style_Salome::apply().
186 Static function restore() can be used then to restore initial application style.
188 The usual way to use SALOME style is as following:
190 Style_Salome::initialize( resourceMgr() ); // initialize SALOME style from resources
191 if ( needSalomeStyle ) Style_Salome::apply(); // set SALOME style to the application
194 Style_PrefDlg class can be then used to change style properties, select one of the
195 predefined style themes or even create user themes:
197 Style_PrefDlg dlg( desktop() );
205 Use Style_Salome::apply() static function to set SALOME style to the application.
207 Style_Salome::Style_Salome()
210 // initialize SALOME style resources
211 Q_INIT_RESOURCE( Style );
217 Style_Salome::~Style_Salome()
223 \brief Initialize SALOME style.
225 This method should be called at the very beginning of the application
226 which uses SALOME style.
227 The method initializes style properties from the current settings.
229 If the parameter \a resMgr is not 0, the style is initialized from the
232 The parameter \a section allows customizing of the resources file section
233 used to store style's properties. By default "Theme" section name is used.
235 \param resMgr resources manager
236 \param section resources file section name
237 \sa apply(), restore()
239 void Style_Salome::initialize( QtxResourceMgr* resMgr, const QString& section )
241 model()->fromResources( resMgr, section );
245 \brief Set SALOME style to the application
246 \sa initialize(), restore()
248 void Style_Salome::apply()
250 // application object is not created yet
251 if ( !QApplication::instance() )
254 // update model (from the resources manager if needed)
257 // check if SALOME style is already set to the application
260 QApplication::style()->setParent( 0 ); // avoid deleting original application style
261 QApplication::setStyle( new Style_Salome() ); // set style
263 update(); // update style
267 \brief Restore original style to the application
268 \sa initialize(), apply()
270 void Style_Salome::restore()
272 // application object is not created yet
273 if ( !QApplication::instance() )
275 // check if SALOME style is set to the application
278 // restore previous style
283 \brief Check if the SALOME style is currently set to application.
284 \return \c true if SALOME style is set to the applcation or \c false otherwise
286 bool Style_Salome::isActive()
288 return QApplication::instance() != 0 && qobject_cast<Style_Salome*>( QApplication::style() ) != 0;
292 \brief Update style from resources.
294 void Style_Salome::update()
296 // application object is not created yet
297 if ( !QApplication::instance() )
299 // check if SALOME style is set to the application
300 if ( Style_Salome* style = qobject_cast<Style_Salome*>( QApplication::style() ) )
301 style->polish( qobject_cast<QApplication*>( QApplication::instance() ) );
305 \brief Get style model
308 Style_Model* Style_Salome::model()
311 myModel = new Style_Model();
316 \brief Initialize the appearance of the application.
318 Performs late initialization of the given application object.
320 \param app application object
322 void Style_Salome::polish ( QApplication* app )
324 QWindowsStyle::polish( app );
326 if ( checkDebugLevel(1) ) {
330 updatePaletteColors();
331 app->setFont( model()->applicationFont() );
332 updateAllWidgets( app );
336 \brief Initializes the appearance of the given widget.
338 This function is called for every widget at some point after
339 it has been fully created but just before it is shown for the very first time.
341 \param w widget object
343 void Style_Salome::polish ( QWidget* w )
345 if ( checkDebugLevel(2) ) {
346 QWindowsStyle::polish( w );
350 if ( w && hasHover() ) {
351 if ( qobject_cast<QPushButton*>(w) || qobject_cast<QToolButton*>(w) ||
352 qobject_cast<QCheckBox*>(w) || qobject_cast<QRadioButton*>(w) ||
353 qobject_cast<QComboBox*>(w) || qobject_cast<QAbstractSpinBox*>(w) ||
354 qobject_cast<QLineEdit*>(w) || qobject_cast<QScrollBar*>(w) ||
355 qobject_cast<QTabBar*>(w) || qobject_cast<QSlider*>(w) ||
356 qobject_cast<QMenuBar*>(w) || qobject_cast<QDockWidget*>(w) )
357 w->setAttribute( Qt::WA_Hover );
360 QWindowsStyle::polish( w );
364 \brief Uninitialize the given widget's appearance.
366 This function is the counterpart to polish().
367 It is called for every polished widget whenever the style
368 is dynamically changed; the former style has to unpolish
369 its settings before the new style can polish them again.
371 \param w widget object
373 void Style_Salome::unpolish( QWidget* w )
375 if ( checkDebugLevel(3) ) {
376 QWindowsStyle::unpolish( w );
380 if ( w && hasHover() ) {
381 if ( qobject_cast<QPushButton*>(w) || qobject_cast<QToolButton*>(w)||
382 qobject_cast<QCheckBox*>(w) || qobject_cast<QRadioButton*>(w) ||
383 qobject_cast<QComboBox*>(w) || qobject_cast<QAbstractSpinBox*>(w) ||
384 qobject_cast<QLineEdit*>(w) || qobject_cast<QScrollBar*>(w) ||
385 qobject_cast<QTabBar*>(w) || qobject_cast<QSlider*>(w) ||
386 qobject_cast<QMenuBar*>(w) || qobject_cast<QDockWidget*>(w) )
387 w->setAttribute( Qt::WA_Hover, false );
390 QWindowsStyle::unpolish( w );
394 \brief Draws the given control using the provided painter \p with the style options specified by \a opt.
395 \param cc complex control type
396 \param opt style option
400 void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComplex* opt,
401 QPainter* p, const QWidget* w ) const
403 if ( checkDebugLevel(4) ) {
404 QWindowsStyle::drawComplexControl( cc, opt, p, w );
408 const QPalette& pal = w->palette();
411 if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
412 bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
413 QRect optr = opt->rect, arUp = subControlRect( cc, spin, SC_SpinBoxUp, w );
414 optr.setWidth( arUp.x()-optr.x()+1 );
415 double aRad = model()->widgetRounding( Style_Model::EditRadius );
416 bool antialized = model()->antialiasing();
417 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
418 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
420 drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
422 Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left,
423 model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr,
424 model()->color( Style_Model::FieldDark ), // Style_Model::fld_dark_clr,
425 aBrdTopCol, aBrdBotCol, antialized, false );
426 QRect aBtnRect = QRect( QPoint( arUp.x(), optr.y() ), QPoint( arUp.right(), optr.bottom() ) );
427 QColor aBtnCol = opt->palette.color( QPalette::Button );
428 bool aStateOn = opt->state & ( State_Sunken | State_On );
430 drawHoverRect(p, aBtnRect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
432 Style_Tools::shadowRect( p, aBtnRect, aRad, 0.0, SHADOW, Style_Tools::Right,
433 aBtnCol.light( BUT_PERCENT_COL ), aBtnCol.dark( BUT_PERCENT_COL ),
434 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
435 State flags = State_None;
436 QStyleOptionSpinBox copy;
438 if (spin->subControls & SC_SpinBoxUp) {
439 copy.subControls = SC_SpinBoxUp;
440 QPalette pal2 = spin->palette;
441 if (!(spin->stepEnabled & QAbstractSpinBox::StepUpEnabled) ||
442 !(spin->state & State_Enabled)) {
443 pal2.setCurrentColorGroup(QPalette::Disabled);
444 copy.state &= ~State_Enabled;
447 copy.state |= State_Enabled;
449 if ( spin->activeSubControls == SC_SpinBoxUp && ( spin->state & State_Sunken ) ) {
450 copy.state |= State_On;
451 copy.state |= State_Sunken;
453 copy.state |= State_Raised;
454 copy.state &= ~State_Sunken;
456 pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
457 : PE_IndicatorSpinUp);
458 copy.rect = aBtnRect;
459 drawPrimitive(pe, ©, p, w);
461 if (spin->subControls & SC_SpinBoxDown) {
462 copy.subControls = SC_SpinBoxDown;
463 copy.state = spin->state;
464 QPalette pal2 = spin->palette;
465 if (!(spin->stepEnabled & QAbstractSpinBox::StepDownEnabled) ||
466 !(spin->state & State_Enabled)) {
467 pal2.setCurrentColorGroup(QPalette::Disabled);
468 copy.state &= ~State_Enabled;
471 copy.state |= State_Enabled;
473 if (spin->activeSubControls == SC_SpinBoxDown && (spin->state & State_Sunken)) {
474 copy.state |= State_On;
475 copy.state |= State_Sunken;
477 copy.state |= State_Raised;
478 copy.state &= ~State_Sunken;
480 pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
481 : PE_IndicatorSpinDown);
482 copy.rect = aBtnRect;
483 drawPrimitive(pe, ©, p, w);
488 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
489 bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
490 QRect optr = opt->rect,
491 ar = subControlRect( cc, cmb, SC_ComboBoxArrow, w );
493 optr.setHeight( ar.height() );
494 optr.setWidth( ar.x()-optr.x()+1 );
495 bool antialized = model()->antialiasing();
496 double aRad = model()->widgetRounding( Style_Model::EditRadius );
497 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
498 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
500 drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true);
502 Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left,
503 model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr,
504 model()->color( Style_Model::FieldDark ), // Style_Model::fld_dark_clr,
505 aBrdTopCol, aBrdBotCol, antialized, false );
506 if (cmb->subControls & SC_ComboBoxArrow) {
507 State flags = State_None;
508 QColor aBtnCol = opt->palette.color( QPalette::Button );
509 bool aStateOn = opt->state & ( State_Sunken | State_On );
511 drawHoverRect(p, ar, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Right, true);
513 Style_Tools::shadowRect( p, ar, aRad, 0.0, SHADOW, Style_Tools::Right,
514 aBtnCol.light( BUT_PERCENT_COL ), aBtnCol.dark( BUT_PERCENT_COL ),
515 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
516 if (opt->state & State_Enabled)
517 flags |= State_Enabled;
518 if (cmb->activeSubControls == SC_ComboBoxArrow)
519 flags |= State_Sunken;
520 QStyleOption arrowOpt(0);
522 arrowOpt.palette = cmb->palette;
523 arrowOpt.state = flags;
524 drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
526 if (cmb->subControls & SC_ComboBoxEditField) {
527 bool hi = cmb->state & State_HasFocus && !cmb->editable;
529 Style_Tools::shadowRect( p, optr, aRad, 0.0, SHADOW, Style_Tools::Left,
530 pal.color( QPalette::Highlight ),
531 pal.color( QPalette::Highlight ), aBrdTopCol, aBrdBotCol,
533 p->setPen(cmb->palette.highlightedText().color());
536 p->setPen(cmb->palette.text().color());
542 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
543 QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, w);
544 QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, w);
546 if( hasHover() && (slider->state & State_Enabled) &&
547 (slider->state & State_MouseOver) ) {
548 QRect moderated = w->rect();
549 drawHoverRect(p, moderated, opt->palette.color( QPalette::Window ),
550 model()->widgetRounding( Style_Model::ButtonRadius ), Style_Tools::All, false);
553 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
554 QStyleOptionSlider tmpSlider = *slider;
555 tmpSlider.subControls = SC_SliderGroove;
556 QWindowsStyle::drawComplexControl(cc, &tmpSlider, p, w);
558 if (slider->subControls & SC_SliderTickmarks) {
559 QStyleOptionSlider tmpSlider = *slider;
560 tmpSlider.subControls = SC_SliderTickmarks;
561 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w);
563 if (slider->subControls & SC_SliderHandle) {
564 if (slider->state & State_HasFocus) {
565 QStyleOptionFocusRect fropt;
566 fropt.QStyleOption::operator=(*slider);
567 fropt.rect = subElementRect(SE_SliderFocusRect, slider, w);
568 drawPrimitive(PE_FrameFocusRect, &fropt, p, w);
570 int x = handle.x(), y = handle.y(), wi = handle.width(), he = handle.height();
571 bool horiz = slider->orientation == Qt::Horizontal;
572 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
573 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
574 QColor aBtnCol = model()->color( Style_Model::Slider ); // Style_Model::slider_clr
575 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
576 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
577 // rect was changed on +/-DELTA_SLIDER value for correct painting Antialised border of slider
578 int aDelta = DELTA_SLIDER-1;
579 QRect slRect = QRect(x+aDelta, y+aDelta, wi-aDelta, he-aDelta);
580 int aXAdd = (int)(slRect.width()/6), aYAdd = (int)(slRect.height()/6);
581 Style_Tools::SliderType type = Style_Tools::SlNone;
582 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow))
583 type = Style_Tools::SlNone;
587 type = Style_Tools::SlUp;
588 slRect.setTop( slRect.top()-aYAdd );
591 type = Style_Tools::SlDown;
592 slRect.setBottom( slRect.bottom()+aYAdd );
596 type = Style_Tools::SlLeft;
597 slRect.setLeft( slRect.left()-aXAdd );
600 type = Style_Tools::SlRight;
601 slRect.setRight( slRect.right()+aXAdd );
604 Style_Tools::drawSlider( p, slRect, model()->widgetRounding( Style_Model::SliderRadius ), type,
605 aBtnCol.light( BUT_PERCENT_COL ),
606 aBtnCol.dark( BUT_PERCENT_COL ), aBrdTopCol, aBrdBotCol );
607 QRect aHRect = handle;
608 int aXRect = (int)(aHRect.width()/5),
609 aYRect = (int)(aHRect.height()/5);
610 aHRect = QRect( aHRect.x()+aXRect, aHRect.y()+aYRect,
611 aHRect.width()-2*aXRect, aHRect.height()-2*aYRect );
612 drawHandle( p, aHRect, horiz );
617 case CC_ToolButton: {
618 if (const QStyleOptionToolButton *toolbutton
619 = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
620 QRect button, menuArea;
621 button = subControlRect(cc, toolbutton, SC_ToolButton, w);
622 menuArea = subControlRect(cc, toolbutton, SC_ToolButtonMenu, w);
624 if (w && ( qobject_cast<QToolBar *>(w->parentWidget() ) ||
625 toolbutton->state & State_AutoRaise && !( toolbutton->state & State_MouseOver ) )
627 QWindowsStyle::drawComplexControl( cc, opt, p, w );
630 int aMinDelta = (int)model()->widgetRounding( Style_Model::ButtonRadius );
631 if ( !toolbutton->icon.isNull() )
632 aMinDelta = Style_Tools::getMinDelta( toolbutton->rect, toolbutton->iconSize, aMinDelta );
633 bool aStateOn = opt->state & ( State_Sunken | State_On );
634 QColor aBtnCol = opt->palette.color( QPalette::Button ),
635 top = aBtnCol.light( BUT_PERCENT_COL ),
636 bottom = aBtnCol.dark( BUT_PERCENT_COL );
637 bool isMenuBtn = toolbutton->features == QStyleOptionToolButton::Menu;
638 bool antialized = model()->antialiasing();
639 bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
640 bool isHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
641 bool hover = hasHover() && (opt->state & State_Enabled) && ( opt->state & State_MouseOver );
642 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
643 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
644 QRect aRect = button;
645 int aType = isMenuBtn ? Style_Tools::Left : Style_Tools::All;
646 if ( toolbutton->subControls & SC_ToolButton ) {
647 if ( isAutoRaising && hover && !aStateOn )
648 Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, bottom, top, aBrdTopCol,
649 aBrdBotCol, antialized, true, aStateOn );
650 else if ( isHighWdg && hover && !aStateOn )
651 drawHoverRect( p, aRect, opt->palette.color( QPalette::Window ), aMinDelta, aType, true );
653 Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, top, bottom,
654 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
656 if (toolbutton->subControls & SC_ToolButtonMenu) {
658 if ( aMinDelta > menuArea.height()/2 )
659 aMinDelta = menuArea.height()/2;
660 if ( aMinDelta > menuArea.width()/2 )
661 aMinDelta = menuArea.width()/2;
663 aType = isMenuBtn ? Style_Tools::Right : Style_Tools::All;
664 if ( isAutoRaising && hover && !aStateOn )
665 Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, bottom, top,
666 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
667 else if ( isHighWdg && hover && !aStateOn )
668 drawHoverRect( p, aRect, opt->palette.color( QPalette::Window ), aMinDelta, aType, true );
670 Style_Tools::shadowRect( p, aRect, aMinDelta, -1, SHADOW, aType, top, bottom,
671 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
672 QStyleOption tool(0);
673 tool.palette = toolbutton->palette;
674 tool.rect = menuArea;
675 State bflags = toolbutton->state;
676 if (bflags & State_AutoRaise) {
677 if (!(bflags & State_MouseOver)) {
678 bflags &= ~State_Raised;
681 State mflags = bflags;
682 if (toolbutton->activeSubControls & SC_ToolButton)
683 bflags |= State_Sunken;
684 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
685 mflags |= State_Sunken;
687 drawPrimitive(PE_IndicatorArrowDown, &tool, p, w);
691 if (toolbutton->state & State_HasFocus) {
692 QStyleOptionFocusRect fr;
693 fr.QStyleOption::operator=(*toolbutton);
694 fr.rect.adjust(3, 3, -3, -3);
695 if (toolbutton->features & QStyleOptionToolButton::Menu)
696 fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, w), 0);
697 Style_Tools::drawFocus( p, fr.rect, aMinDelta-1, isMenuBtn ? Style_Tools::Left :
698 Style_Tools::All, aBrdBotCol );
700 QStyleOptionToolButton label = *toolbutton;
701 int fw = pixelMetric( PM_DefaultFrameWidth, opt, w );
702 label.rect = button.adjusted( fw, fw, -fw, -fw );
703 drawControl( CE_ToolButtonLabel, &label, p, w );
709 QWindowsStyle::drawComplexControl( cc, opt, p, w );
713 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const
714 QStyleOptionGroupBox *>(opt)) {
716 QRect textRect = subControlRect( cc, opt, SC_GroupBoxLabel, w );
717 QRect checkBoxRect = subControlRect( cc, opt, SC_GroupBoxCheckBox, w);
718 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
719 QRect aRect = subControlRect( cc, opt, SC_GroupBoxFrame, w);
720 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
721 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
722 Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::FrameRadius ), 0.,
723 SHADOW, Style_Tools::All,
724 model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr
725 model()->color( Style_Model::FieldDark ), // Style_Model::fld_dark_clr
726 aBrdTopCol, aBrdBotCol, false, false, false, false);
729 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
730 QColor textColor = groupBox->textColor;
731 if (textColor.isValid())
732 p->setPen(textColor);
733 int alignment = int(groupBox->textAlignment);
734 if (!styleHint(QStyle::SH_UnderlineShortcut, opt, w))
735 alignment |= Qt::TextHideMnemonic;
736 QColor aColor = opt->palette.color( QPalette::Window );
737 Style_Tools::arrowRect( p, textRect, opt->palette.color( QPalette::Dark ),
738 aColor.dark(BUT_PERCENT_COL), aColor );
739 drawItemText(p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
740 pal, groupBox->state & State_Enabled, groupBox->text,
741 textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
742 if (groupBox->state & State_HasFocus) {
743 QStyleOptionFocusRect fropt;
744 fropt.QStyleOption::operator=(*groupBox);
745 fropt.rect = textRect;
746 drawPrimitive(PE_FrameFocusRect, &fropt, p, w);
750 if (groupBox->subControls & SC_GroupBoxCheckBox) {
751 QStyleOptionButton box;
752 box.QStyleOption::operator=(*groupBox);
753 box.rect = checkBoxRect;
754 drawPrimitive(PE_IndicatorCheckBox, &box, p, w);
759 QWindowsStyle::drawComplexControl( cc, opt, p, w );
763 QWindowsStyle::drawComplexControl( cc, opt, p, w );
768 \brief Draws the given element with the provided painter \p with the style options specified by \a opt.
769 \param ce control element type
770 \param opt style option
774 void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt,
775 QPainter* p, const QWidget* w ) const
777 if ( checkDebugLevel(5) ) {
778 QWindowsStyle::drawControl( ce, opt, p, w );
784 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
785 drawControl(CE_PushButtonBevel, btn, p, w);
786 QStyleOptionButton subopt = *btn;
787 subopt.rect = subElementRect(SE_PushButtonContents, btn, w);
788 drawControl(CE_PushButtonLabel, &subopt, p, w);
789 if (btn->state & State_HasFocus) {
790 QRect aRect = subElementRect( SE_PushButtonFocusRect, btn, w );
791 Style_Tools::drawFocus( p, aRect, model()->widgetRounding( Style_Model::ButtonRadius ),
792 Style_Tools::All, model()->color( Style_Model::BorderBottom ) );
796 case CE_PushButtonBevel:
797 if ( qstyleoption_cast<const QStyleOptionButton *>(opt) ) {
798 double aRad = model()->widgetRounding( Style_Model::ButtonRadius );
799 bool aStateOn = opt->state & ( State_Sunken | State_On );
800 bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
801 bool isHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
802 bool enabled = opt->state & State_Enabled;
803 bool hover = hasHover() && enabled && ( opt->state & State_MouseOver );
805 QColor aBtnCol = opt->palette.color( QPalette::Button );
806 QColor top = aBtnCol.light( BUT_PERCENT_COL ),
807 bottom = aBtnCol.dark( BUT_PERCENT_COL );
808 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
809 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
811 bool antialized = model()->antialiasing();
812 if ( isAutoRaising && hover && !aStateOn )
813 Style_Tools::shadowRect( p, r, aRad, -1, SHADOW, Style_Tools::All, bottom, top,
814 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
815 else if ( isHighWdg && hover && !aStateOn )
816 drawHoverRect( p, r, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true );
818 Style_Tools::shadowRect( p, r, aRad, -1, SHADOW, Style_Tools::All, top, bottom,
819 aBrdTopCol, aBrdBotCol, antialized, true, aStateOn );
822 case CE_DockWidgetTitle:
823 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
824 bool floating = false;
825 int menuOffset = 0; //used to center text when floated
826 QColor inactiveCaptionTextColor = opt->palette.color( QPalette::HighlightedText );
827 const QDockWidget *dockWidget = qobject_cast<const QDockWidget *>(w);
830 if ( dockWidget->isFloating() && dwOpt->movable) {
832 QColor top = opt->palette.color( QPalette::Highlight ).light();
833 QColor bottom = opt->palette.color( QPalette::Highlight );
835 QBrush fillBrush(bottom);
837 QPoint p1(dwOpt->rect.x(), dwOpt->rect.y());
838 QPoint p2(dwOpt->rect.x(), dwOpt->rect.bottom() );
839 QLinearGradient lg(p1, p2);
840 lg.setColorAt(0, top);
841 lg.setColorAt(1, bottom);
844 p->fillRect(dwOpt->rect.adjusted(0, 0, 0, -3), fillBrush);
847 QRect r = dwOpt->rect.adjusted(0, 0, -1, -1);
848 QColor bottom = opt->palette.color( QPalette::Window ),
849 top = bottom.dark( BUT_PERCENT_COL );
850 QRect aRect = dwOpt->rect;
851 QLinearGradient gr( aRect.x(), aRect.y(), aRect.x(), aRect.y()+aRect.height() );
852 gr.setColorAt( 0.0, top );
853 gr.setColorAt( 0.4, bottom );
854 gr.setColorAt( 0.6, bottom );
855 gr.setColorAt( 1.0, top );
856 p->fillRect( r, gr );
858 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
859 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
860 p->setPen( aBrdTopCol );
861 p->drawLine( r.x(), r.bottom(), r.x(), r.y() );
862 p->drawLine( r.x(), r.y(), r.right(), r.y() );
863 p->setPen( aBrdBotCol );
864 p->drawLine( r.x(), r.bottom(), r.right(), r.bottom() );
865 p->drawLine( r.right(), r.bottom(), r.right(), r.y() );
868 p->setPen(dwOpt->palette.color(QPalette::Light));
870 QString aTitle = dwOpt->title;
871 if (!aTitle.isEmpty()) {
872 int aMargin = pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, w);
873 const int indent = p->fontMetrics().descent();
874 QRect r = dwOpt->rect.adjusted(indent + 1, - menuOffset, -indent - 1, -1);
875 QPixmap aPxm = standardPixmap( SP_DockWidgetCloseButton, opt, w);
876 int aWidth = r.width() - aPxm.width()-2/*button margins*/;
877 aPxm = standardPixmap( SP_TitleBarNormalButton, opt, w);
878 aWidth = aWidth - aPxm.width()-2/*button margins*/;
879 r = QRect( r.x(), r.y(), aWidth-aMargin-2/*buttons separator*/-2/*margin from text*/, r.height() );
881 QFont oldFont = p->font();
882 QFont font = oldFont;
887 aTitle = titleText( aTitle, r.width(), r.height(), font );
889 QPalette palette = dwOpt->palette;
890 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
891 bool active = dwOpt->state & State_Active;
892 //const int indent = p->fontMetrics().descent();
893 drawItemText(p, r, Qt::AlignLeft | Qt::AlignVCenter, palette,
894 dwOpt->state & State_Enabled, aTitle,
895 floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
901 QWindowsStyle::drawControl( ce, opt, p, w );
903 bool horiz = r.width() > r.height();
904 int aLen = model()->splitHandleLength();
906 r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
908 r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
909 drawHandle( p, r, horiz, true );
912 case CE_TabBarTabShape:
913 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
914 if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedEast ||
915 tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::RoundedWest) {
917 QRect tabRect = opt->rect;
918 // line under selected tab bar object
919 bool isSelected = opt->state & State_Selected;
920 bool isLast = tab->position == QStyleOptionTab::End ||
921 tab->position == QStyleOptionTab::OnlyOneTab;
922 QColor aColor = opt->palette.color( QPalette::Window ),
923 aDarkColor = aColor.dark( BUT_PERCENT_ON );
924 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
925 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
927 bool isHover = hasHover() && (opt->state & State_Enabled) &&
928 (opt->state & State_MouseOver);
929 if ( isHover && !isSelected && model()->widgetEffect() == Style_Model::HighlightEffect ) {
930 aColor = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr
931 aDarkColor = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr
933 Style_Tools::tabRect( p, tabRect, (int)tab->shape,
934 model()->widgetRounding( Style_Model::FrameRadius ),
935 DELTA_H_TAB, aColor, aDarkColor,
936 aBrdTopCol, aBrdBotCol, isSelected, isLast, isHover );
939 QCommonStyle::drawControl(ce, opt, p, w);
942 case CE_TabBarTabLabel:
943 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
944 if ( tab->position == QStyleOptionTab::End ||
945 tab->position == QStyleOptionTab::OnlyOneTab ) {
946 QRect oldRect = opt->rect;
948 if ( tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth ) {
949 aDelta = (int)(opt->rect.height()*DELTA_H_TAB/2);
950 oldRect = QRect( oldRect.topLeft(), QPoint( oldRect.right()-aDelta, oldRect.bottom() ) );
953 aDelta = (int)(opt->rect.width()*DELTA_H_TAB/2);
954 oldRect = QRect( oldRect.topLeft(), QPoint( oldRect.right(), oldRect.bottom()-aDelta ) );
956 QStyleOptionTab* copyTab = (QStyleOptionTab*)tab;
957 copyTab->rect = oldRect;
958 QWindowsStyle::drawControl( ce, copyTab, p, w );
961 QWindowsStyle::drawControl( ce, opt, p, w );
965 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
967 drawBackground( p, w->rect(), opt->palette.color( QPalette::Window ), true, true, true );
968 bool active = mbi->state & State_Selected;
969 bool hasFocus = mbi->state & State_HasFocus;
970 bool down = mbi->state & State_Sunken;
971 QStyleOptionMenuItem newMbi = *mbi;
972 if (active || hasFocus) {
973 QBrush b( opt->palette.color( QPalette::Window ) );
975 p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
976 if ( active && hasFocus) {
977 bool aStateOn = opt->state & (State_Sunken | State_On);
978 QColor aBtnCol = opt->palette.color( QPalette::Window ),
979 top = aBtnCol.light( BUT_PERCENT_ON ),
980 bottom = aBtnCol.dark( BUT_PERCENT_ON );
981 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
982 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
983 bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
984 if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) &&
985 (opt->state & State_Selected) )
986 drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true);
988 Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top, bottom,
989 aBrdTopCol, aBrdBotCol,
990 model()->antialiasing(), true, aStateOn );
993 if (active && down) {
994 newMbi.rect.translate(pixelMetric(PM_ButtonShiftHorizontal, mbi, w),
995 pixelMetric(PM_ButtonShiftVertical, mbi, w));
996 p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
999 QCommonStyle::drawControl(ce, &newMbi, p, w);
1002 case CE_MenuBarEmptyArea:
1003 drawBackground( p, opt->rect, opt->palette.color( QPalette::Window ), true, true, true );
1005 case CE_ProgressBarGroove: {
1006 QColor aBgColor = opt->palette.color( QPalette::Window ),
1007 top = aBgColor.light( BUT_PERCENT_ON ),
1008 bottom = aBgColor.dark( BUT_PERCENT_ON );
1009 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
1010 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1011 Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::EditRadius ), -1,
1012 SHADOW, Style_Tools::All, top, bottom, aBrdTopCol, aBrdBotCol,
1013 model()->antialiasing(), true );
1016 case CE_ProgressBarLabel:
1017 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1018 // implementation from qplastiquestyle
1019 // The busy indicator doesn't draw a label
1020 if (bar->minimum == 0 && bar->maximum == 0)
1023 QRect rect = bar->rect;
1025 p->setPen(bar->palette.text().color());
1027 bool vertical = false;
1028 bool inverted = false;
1029 bool bottomToTop = false;
1030 // Get extra style options if version 2
1031 if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
1032 vertical = (bar2->orientation == Qt::Vertical);
1033 inverted = bar2->invertedAppearance;
1034 bottomToTop = bar2->bottomToTop;
1037 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1040 m.translate(0.0, rect.width());
1043 m.translate(rect.height(), 0.0);
1048 int progressIndicatorPos = int(((bar->progress - bar->minimum) / double(bar->maximum - bar->minimum)) * rect.width());
1049 bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted)
1050 || ((bar->direction == Qt::LeftToRight) && inverted))) || (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop)));
1052 int indicatorPos = rect.width() - progressIndicatorPos;
1053 if (indicatorPos >= 0 && indicatorPos <= rect.width()) {
1054 p->setPen(bar->palette.base().color());
1055 leftRect = QRect(rect.left(), rect.top(), indicatorPos, rect.height());
1056 } else if (indicatorPos > rect.width()) {
1057 p->setPen(bar->palette.text().color());
1059 p->setPen(bar->palette.base().color());
1062 if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) {
1063 leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
1064 } else if (progressIndicatorPos > rect.width()) {
1065 p->setPen(bar->palette.base().color());
1067 p->setPen(bar->palette.text().color());
1071 p->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
1072 if (!leftRect.isNull()) {
1073 p->setPen(flip ? bar->palette.text().color() : bar->palette.base().color());
1074 p->setClipRect(leftRect, Qt::IntersectClip);
1075 p->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
1080 case CE_ProgressBarContents:
1081 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1082 QRect rect = pb->rect;
1083 bool vertical = false;
1084 bool inverted = false;
1085 // Get extra style options if version 2
1086 const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);
1088 vertical = (pb2->orientation == Qt::Vertical);
1089 inverted = pb2->invertedAppearance;
1093 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
1094 m.translate(rect.height(), 0.0);
1097 QPalette pal2 = pb->palette;
1098 // Correct the highlight color if it is the same as the background
1099 if (pal2.highlight() == pal2.background())
1100 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1101 QPalette::Highlight));
1102 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1106 int width = rect.width() - 2 * fw;
1107 if (pb->minimum == 0 && pb->maximum == 0) {
1108 // draw busy indicator
1109 int x = (pb->progress - pb->minimum) % (width * 2);
1112 x = reverse ? rect.right() - x : x + rect.x();
1113 p->setPen(QPen(pal2.highlight().color(), 4));
1114 p->drawLine(x, rect.y() + 1, x, rect.height() - fw);
1116 const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, w);
1119 u = (rect.width() + unit_width / 3) / unit_width;
1121 u = width / unit_width;
1123 int p_v = pb->progress - pb->minimum;
1124 int t_s = pb->maximum - pb->minimum ? pb->maximum - pb->minimum : 1;
1126 if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
1127 // scale down to something usable.
1132 // nu < tnu, if last chunk is only a partial chunk
1134 tnu = nu = p_v * u / t_s;
1136 if (nu * unit_width > width)
1139 // Draw nu units out of a possible u of unit_width
1140 // width, each a rectangle bordered by background
1141 // color, all in a sunken panel with a percentage text
1142 // display at the end.
1144 int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : fw)
1146 QStyleOptionProgressBarV2 pbBits = *pb;
1148 pbBits.palette = pal2;
1149 int myY = pbBits.rect.y();
1150 int myHeight = pbBits.rect.height();
1151 pbBits.state = State_None;
1153 QColor aColor = model()->color( Style_Model::ProgressBar ); // Style_Model::prbar_clr
1154 QColor top = aColor.light( BUT_PERCENT_COL );
1155 QColor bottom = aColor.dark( BUT_PERCENT_COL );
1157 for (int i = 0; i <= nu; ++i) {
1158 aType = Style_Tools::None;
1159 if ( i < nu ) { // not last element
1160 aRect = QRect(x0 + x, myY, unit_width, myHeight);
1163 aRect.setRight( aRect.right()-fw );
1165 aType = reverse ? Style_Tools::BottomLeft | Style_Tools::BottomRight
1166 : Style_Tools::TopLeft | Style_Tools::TopRight;
1168 aType = reverse ? Style_Tools::Right : Style_Tools::Left;
1171 else { // last element if it's necessary
1174 int pixels_left = width - (nu * unit_width);
1175 int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
1176 aRect = QRect(offset, myY, pixels_left, myHeight);
1178 aType = reverse ? Style_Tools::TopLeft | Style_Tools::TopRight
1179 : Style_Tools::BottomLeft | Style_Tools::BottomRight;
1181 aType = reverse ? Style_Tools::Left : Style_Tools::Right;
1184 aRect = m.mapRect(aRect);
1186 aRect = QRect(aRect.x(), aRect.y()+fw, aRect.width(), aRect.height());
1189 aRect = QRect(aRect.x()+1, aRect.y()+2, aRect.width()-1,
1192 aRect = QRect(aRect.x()+1, aRect.y()-1, aRect.width()-5, aRect.height()-1);
1193 QColor aTopClr = aColor, aBotClr = aColor;
1194 if ( unit_width > 1 ) {
1195 aTopClr = aColor.light();
1196 aBotClr = aColor.dark();
1198 Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::EditRadius ), -1, 0,
1199 aType, top, bottom, aTopClr, aBotClr, false, true );
1200 x += reverse ? -unit_width : unit_width;
1206 if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1207 const int windowsItemFrame = 2; // definitions from qwindowstyle.cpp file
1208 const int windowsItemHMargin = 3;
1209 const int windowsItemVMargin = 2;
1210 const int windowsRightBorder = 15;
1211 const int windowsArrowHMargin = 6;
1213 menuitem->rect.getRect(&x, &y, &width, &h);
1214 int tab = menuitem->tabWidth;
1215 bool dis = !(menuitem->state & State_Enabled);
1216 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1217 ? menuitem->checked : false;
1218 bool act = menuitem->state & State_Selected;
1220 // windows always has a check column, regardless whether we have an icon or not
1221 int checkcol = qMax(menuitem->maxIconWidth, 20);
1223 QColor aBgColor = opt->palette.color( QPalette::Window );
1224 double aMargin = LINE_GR_MARGIN;
1225 QLinearGradient gr(x,y,menuitem->rect.right(),y);
1226 gr.setColorAt( 0.0, aBgColor );
1227 gr.setColorAt( aMargin/width, model()->color( Style_Model::FieldLight ) ); // Style_Model::fld_light_clr
1228 gr.setColorAt( 1.0, model()->color( Style_Model::FieldLight ) );
1231 fill = menuitem->palette.brush( QPalette::Highlight );
1233 fill = QBrush( gr );
1234 p->fillRect(menuitem->rect, fill);
1235 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1236 int yoff = y-1 + h / 2;
1237 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
1238 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1239 p->setPen( aBrdBotCol );
1240 p->drawLine(x + 2, yoff, x + width - 4, yoff);
1241 p->setPen( aBrdTopCol );
1242 p->drawLine(x + 2, yoff + 1, x + width - 4, yoff + 1);
1245 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(),
1246 menuitem->rect.y(), checkcol, menuitem->rect.height()));
1249 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, new QBrush(aBgColor));
1251 QColor aCol = aBgColor;
1252 aCol.setAlpha( 80 );
1254 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1257 p->fillRect(vCheckRect, QBrush( gr ) );
1258 // On Windows Style, if we have a checkable item and an icon we
1259 // draw the icon recessed to indicate an item is checked. If we
1260 // have no icon, we draw a checkmark instead.
1261 if (!menuitem->icon.isNull()) {
1262 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1264 mode = QIcon::Active;
1267 pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
1269 pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
1270 int pixw = pixmap.width();
1271 int pixh = pixmap.height();
1272 if (act && !dis && !checked)
1273 qDrawShadePanel(p, vCheckRect, menuitem->palette, false, 1,
1274 new QBrush(aBgColor));
1275 QRect pmr(0, 0, pixw, pixh);
1276 pmr.moveCenter(vCheckRect.center());
1277 p->setPen(menuitem->palette.text().color());
1278 p->drawPixmap(pmr.topLeft(), pixmap);
1279 } else if (checked) {
1280 QStyleOptionMenuItem newMi = *menuitem;
1281 newMi.state = State_None;
1283 newMi.state |= State_Enabled;
1285 newMi.state |= State_On;
1286 newMi.rect = visualRect(opt->direction, menuitem->rect,
1287 QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
1288 checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
1289 drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
1291 p->setPen(act ? menuitem->palette.highlightedText().color() :
1292 menuitem->palette.buttonText().color());
1295 discol = menuitem->palette.text().color();
1298 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
1299 int xpos = menuitem->rect.x() + xm;
1300 QRect textRect(xpos, y + windowsItemVMargin, width - xm - windowsRightBorder - tab + 1,
1301 h - 2 * windowsItemVMargin);
1302 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1303 QString s = menuitem->text;
1304 if (!s.isEmpty()) { // draw text
1306 int t = s.indexOf(QLatin1Char('\t'));
1307 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip |
1309 if (!styleHint(SH_UnderlineShortcut, menuitem, w))
1310 text_flags |= Qt::TextHideMnemonic;
1311 text_flags |= Qt::AlignLeft;
1313 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1314 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1316 p->setPen(menuitem->palette.light().color());
1317 p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
1320 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
1323 QFont font = menuitem->font;
1324 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1328 p->setPen(menuitem->palette.light().color());
1329 p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
1332 p->drawText(vTextRect, text_flags, s.left(t));
1335 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1336 int dim = (h - 2 * windowsItemFrame) / 2;
1337 PrimitiveElement arrow;
1338 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft :
1339 PE_IndicatorArrowRight;
1340 xpos = x + width - windowsArrowHMargin - windowsItemFrame - dim;
1341 QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect,
1342 QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1343 QStyleOptionMenuItem newMI = *menuitem;
1344 newMI.rect = vSubMenuRect;
1345 newMI.state = dis ? State_None : State_Enabled;
1347 newMI.palette.setColor(QPalette::ButtonText,
1348 newMI.palette.highlightedText().color());
1349 drawPrimitive(arrow, &newMI, p, w);
1355 QCommonStyle::drawControl( ce, opt, p, w );
1358 case CE_HeaderSection: {
1359 bool aStateOn = opt->state & State_On;
1360 QColor aColor = model()->color( Style_Model::Header ); // Style_Model::header_clr
1361 QColor top = aColor.light( BUT_PERCENT_COL ),
1362 bottom = aColor.dark( BUT_PERCENT_COL );
1363 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
1364 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1365 Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol,
1366 aBrdBotCol, model()->antialiasing(), true, aStateOn );
1369 case CE_ComboBoxLabel:
1370 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1371 QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, w);
1373 p->setClipRect(editRect);
1374 if (!cb->currentIcon.isNull()) {
1375 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
1377 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
1378 QRect iconRect(editRect);
1379 iconRect.setWidth(cb->iconSize.width() + 4);
1380 QRect alignRect = editRect;
1381 if ( cb->editable ) {
1382 int aHalfRect = (int)Style_Tools::getMaxRect( iconRect,
1383 (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
1384 alignRect.setLeft( alignRect.left() + aHalfRect );
1385 alignRect.setRight( alignRect.right() - aHalfRect );
1387 iconRect = alignedRect(QApplication::layoutDirection(),
1388 Qt::AlignLeft | Qt::AlignVCenter,
1389 iconRect.size(), alignRect);
1391 // Here's absent filling of pixmap on basic color for editable comboBox
1392 drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
1394 if (cb->direction == Qt::RightToLeft)
1395 editRect.translate(-4 - cb->iconSize.width(), 0);
1397 editRect.translate(cb->iconSize.width() + 4, 0);
1399 if (!cb->currentText.isEmpty() && !cb->editable) {
1400 drawItemText(p, editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, cb->palette,
1401 cb->state & State_Enabled, cb->currentText);
1406 case CE_ScrollBarSubLine:
1407 case CE_ScrollBarAddLine: {
1408 bool aStateOn = opt->state & ( State_Sunken | State_On );
1409 QColor aBtnCol = opt->palette.color( QPalette::Button );
1410 QColor top = aBtnCol.light( BUT_PERCENT_COL ),
1411 bottom = aBtnCol.dark( BUT_PERCENT_COL );
1412 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
1413 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1414 Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol,
1415 aBrdBotCol, false, true, aStateOn, true );
1416 PrimitiveElement arrow;
1417 if (opt->state & State_Horizontal) {
1418 if (ce == CE_ScrollBarAddLine)
1419 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1421 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1423 if (ce == CE_ScrollBarAddLine)
1424 arrow = PE_IndicatorArrowDown;
1426 arrow = PE_IndicatorArrowUp;
1428 drawPrimitive(arrow, opt, p, w);
1431 case CE_ScrollBarSlider:
1432 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1434 p->setRenderHint( QPainter::Antialiasing, true );
1435 bool enabled = opt->state & State_Enabled;
1436 bool horiz = scrollbar->orientation == Qt::Horizontal;
1437 double aRad = model()->widgetRounding( Style_Model::ButtonRadius );
1438 if ( hasHover() && enabled && (opt->state & State_MouseOver) )
1439 drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, false);
1441 QColor aColor = model()->color( Style_Model::Slider ); // Style_Model::slider_clr
1443 aColor = opt->palette.button().color();
1444 QColor top = aColor.light( BUT_PERCENT_ON ),
1445 bottom = aColor.dark( BUT_PERCENT_ON );
1446 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
1447 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1448 QRect r = opt->rect;
1449 QPainterPath path = Style_Tools::roundRect( r, aRad,
1453 gr = QLinearGradient(r.x(), r.y(), r.x(), r.bottom());
1455 gr = QLinearGradient(r.x(), r.y(), r.right(), r.y());
1456 gr.setColorAt( 0.0, bottom );
1457 gr.setColorAt( 0.5, top );
1458 gr.setColorAt( 1.0, bottom );
1460 p->fillPath( path, gr );
1461 p->strokePath( path, aBrdTopCol );
1463 p->setRenderHint( QPainter::Antialiasing, false );
1465 QRect aRect = opt->rect;
1466 int aWidth = aRect.width(), aHeight = aRect.height();
1467 if ( aWidth > aHeight + aRad )
1468 aRect = QRect( aRect.x() + (int)((aWidth-aHeight)/2),
1469 aRect.y(), aHeight, aHeight );
1470 else if ( aHeight > aWidth + aRad )
1471 aRect = QRect( aRect.x(), aRect.y() + (int)((aHeight-aWidth)/2),
1474 int aRad2 = (int)(aRad/3);
1475 aRect = QRect( aRect.x()+aRad2, aRect.y()+aRad2, aRect.width()-2*aRad2, aRect.height()-2*aRad2 );
1477 drawHandle( p, aRect, horiz, true );
1483 QRect r = w->rect();
1484 bool horiz = opt->state & State_Horizontal;
1485 drawBackground( p, r, opt->palette.color( QPalette::Window ), true, true, horiz );
1486 p->setRenderHint( QPainter::Antialiasing, false );
1487 drawBorder( p, r, horiz );
1491 QWindowsStyle::drawControl( ce, opt, p, w );
1497 \brief Draws the given primitive element with the provided painter \p using the style options specified by \a opt.
1498 \param pe primitive type
1499 \param opt style option
1501 \param w widget (optional)
1503 void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt,
1504 QPainter* p, const QWidget* w ) const
1506 if ( checkDebugLevel(6) ) {
1507 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1511 const QPalette& pal = opt->palette;
1512 bool doRestore = false;
1515 if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1516 QColor aBtnCol = opt->palette.color( QPalette::Window ),
1517 top = aBtnCol.light( BUT_PERCENT_ON ),
1518 bottom = aBtnCol.dark( BUT_PERCENT_ON );
1519 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
1520 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1521 Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top,
1522 bottom, aBrdTopCol, aBrdBotCol, false, false, false, false );
1525 case PE_PanelButtonTool : {
1526 if ( w && ( opt->state & State_Enabled ) &&
1527 ( ( qobject_cast<QToolBar*>( w->parentWidget() ) ) ||
1528 ( w->inherits("QDockWidgetTitleButton") ) ||
1529 ( w->inherits("QtxWorkstackAreaTitleButton") ) ) ) {
1530 bool aStateOn = opt->state & (State_Sunken | State_On);
1531 bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
1532 if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) &&
1533 (opt->state & State_MouseOver) )
1534 drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true);
1536 QColor aBtnCol = opt->palette.color( QPalette::Window );
1537 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
1538 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1539 QColor top = aBtnCol.light( BUT_PERCENT_COL ),
1540 bottom = aBtnCol.dark( BUT_PERCENT_COL );
1541 Style_Tools::shadowRect( p, opt->rect, 0.0, 0, SHADOW, Style_Tools::All, top, bottom,
1542 aBrdTopCol, aBrdBotCol, model()->antialiasing(), true, aStateOn );
1547 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1550 case PE_FrameFocusRect: {
1551 if (w && qobject_cast<QTabBar*>((QWidget*)w)) {
1552 QTabBar* tabBar = qobject_cast<QTabBar*>((QWidget*)w);
1553 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
1554 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1555 bool isHover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
1556 Style_Tools::tabRect( p, opt->rect, (int)tabBar->shape(),
1557 model()->widgetRounding( Style_Model::FrameRadius ), DELTA_H_TAB,
1558 pal.color( QPalette::Window ),
1559 model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr
1560 aBrdTopCol, aBrdBotCol, false, false, isHover, true );
1563 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1567 case PE_IndicatorArrowRight:
1568 case PE_IndicatorArrowLeft:
1569 case PE_IndicatorArrowUp:
1570 case PE_IndicatorArrowDown:
1571 case PE_IndicatorSpinUp:
1572 case PE_IndicatorSpinDown:
1573 case PE_IndicatorSpinPlus:
1574 case PE_IndicatorSpinMinus: {
1575 QRect rect = opt->rect;
1577 if ( opt->state & State_Enabled ) {
1578 pen = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
1579 brush = opt->palette.color( QPalette::Button );
1580 if ( ( opt->state & State_Sunken ) && (opt->state & State_Enabled ) )
1581 rect.moveTo( rect.x()+1, rect.y()+1 );
1583 pen = opt->palette.mid().color();
1586 if ( pe == PE_IndicatorSpinPlus || pe == PE_IndicatorSpinMinus )
1587 Style_Tools::drawSign( pe, p, rect, pen, brush );
1589 Style_Tools::drawArrow( pe, p, rect, pen, brush );
1592 case PE_IndicatorCheckBox: {
1593 if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) )
1594 drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ),
1595 model()->widgetRounding( Style_Model::EditRadius ),
1596 Style_Tools::All, false);
1598 if (opt->state & State_NoChange)
1599 fill = QBrush( opt->palette.color( QPalette::Base ), Qt::Dense4Pattern);
1600 else if (opt->state & ( State_Sunken | ~State_Enabled ) )
1601 fill = opt->palette.color( QPalette::Window );
1602 else if (opt->state & State_Enabled) {
1603 if (!(opt->state & State_Off) )
1604 fill = QBrush( model()->color( Style_Model::Checked ) ); // Style_Model::checked_clr
1606 fill = QBrush( opt->palette.color( QPalette::Base ) );
1609 fill = opt->palette.color( QPalette::Window );
1612 QColor color = fill.color();
1613 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
1614 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1615 if ( model()->antialiasing() )
1616 p->setRenderHint( QPainter::Antialiasing, true );
1618 // make sure the indicator is square
1619 QRect ir = opt->rect;
1620 if (opt->rect.width() < opt->rect.height()) {
1621 ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
1622 ir.setHeight(opt->rect.width());
1623 } else if (opt->rect.height() < opt->rect.width()) {
1624 ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
1625 ir.setWidth(opt->rect.height());
1628 Style_Tools::shadowCheck( p, ir, 2., Style_Tools::All,
1629 color, color.dark( BUT_PERCENT_ON ), aBrdTopCol, aBrdBotCol );
1630 if ( model()->antialiasing() )
1631 p->setRenderHint( QPainter::Antialiasing, false );
1632 if (opt->state & State_NoChange)
1633 p->setPen(opt->palette.dark().color());
1635 p->setPen(opt->palette.text().color());
1637 case PE_IndicatorViewItemCheck:
1638 case PE_Q3CheckListIndicator: {
1643 const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
1644 p->setPen(itemViewOpt && itemViewOpt->showDecorationSelected
1645 && opt->state & State_Selected ? opt->palette.highlightedText().color()
1646 : opt->palette.text().color());
1647 if (opt->state & State_NoChange)
1648 p->setBrush( opt->palette.color( QPalette::Button ) );
1649 p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
1650 if (!(opt->state & State_Off)) {
1653 xx = opt->rect.x() + 4;
1654 yy = opt->rect.y() + 5;
1655 for (i = 0; i < 3; ++i) {
1656 lines[i] = QLineF(xx, yy, xx, yy + 2);
1661 for (i = 3; i < 11; ++i) {
1662 lines[i] = QLineF(xx, yy, xx, yy+2);
1666 QColor aColor = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
1667 if ( !(opt->state & State_Enabled ) )
1668 aColor = opt->palette.mid().color();
1669 if ( opt->state & State_Selected && itemViewOpt && itemViewOpt->showDecorationSelected )
1670 aColor = opt->palette.highlightedText().color();
1672 p->setPen( QPen( aColor ) );
1673 p->drawLines(lines, 11);
1680 case PE_IndicatorRadioButton: {
1681 if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) )
1682 drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ),
1683 model()->widgetRounding( Style_Model::ButtonRadius ),
1684 Style_Tools::All, false);
1685 #define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
1686 static const QPoint pts_border[] = { // border line
1687 QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2),
1688 QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1),
1689 QPoint(10, 2), QPoint(10, 3), QPoint(11, 4), QPoint(11, 7), QPoint(10, 8), QPoint(10, 9),
1690 QPoint(9, 10), QPoint(8, 10), QPoint(7, 11), QPoint(4, 11), QPoint(3, 10), QPoint(2, 10)
1692 // make sure the indicator is square
1693 QRect ir = opt->rect;
1694 if (opt->rect.width() < opt->rect.height()) {
1695 ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
1696 ir.setHeight(opt->rect.width());
1697 } else if (opt->rect.height() < opt->rect.width()) {
1698 ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
1699 ir.setWidth(opt->rect.height());
1702 bool down = opt->state & State_Sunken;
1703 bool enabled = opt->state & State_Enabled;
1704 bool on = opt->state & State_On;
1706 p->translate(ir.x(), ir.y());
1708 if ( down || !enabled ) {
1709 QColor fillColor = opt->palette.color( QPalette::Window );
1710 p->setPen( fillColor );
1711 p->setBrush( fillColor );
1714 QColor fillColor = opt->palette.color( QPalette::Base );
1715 if ( enabled && on )
1716 fillColor = model()->color( Style_Model::Checked ); // Style_Model::checked_clr
1717 QLinearGradient gr( 3, 3, 8, 8 );
1718 gr.setColorAt( 0.0, fillColor.dark( BUT_PERCENT_ON ) );
1719 gr.setColorAt( 1.0, fillColor );
1720 p->setPen( fillColor.dark( BUT_PERCENT_ON ) );
1723 p->drawPolygon(pts_border, PTSARRLEN(pts_border));
1724 int aSize = PTSARRLEN(pts_border),
1725 aHalfSize = (int)aSize/2;
1726 if ( model()->antialiasing() )
1727 p->setRenderHint( QPainter::Antialiasing, true );
1728 p->setPen( model()->color( Style_Model::BorderTop) ); // Style_Model::border_top_clr
1729 p->drawPolyline(pts_border, aHalfSize);
1730 p->setPen( model()->color( Style_Model::BorderBottom ) ); // Style_Model::border_bot_clr
1732 for ( int i = aHalfSize; i < aSize; i++ )
1733 aPolygon << pts_border[i];
1734 p->drawPolyline( aPolygon );
1735 if ( model()->antialiasing() )
1736 p->setRenderHint( QPainter::Antialiasing, false );
1739 QColor aPointerCol = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr
1741 aPointerCol = opt->palette.mid().color();
1742 p->setPen( Qt::NoPen );
1743 p->setBrush( aPointerCol );
1744 p->drawRect( 5, 4, 2, 4 );
1745 p->drawRect( 4, 5, 4, 2 );
1748 p->translate(-ir.x(), -ir.y()); // restore translate
1752 case PE_FrameDockWidget:
1753 if ( qstyleoption_cast<const QStyleOptionFrame *>(opt))
1754 QCommonStyle::drawPrimitive( pe, opt, p, w );
1756 case PE_FrameLineEdit:
1757 case PE_PanelLineEdit: {
1759 if ( qobject_cast<const QComboBox*>( w->parentWidget() ) ||
1760 qobject_cast<const QAbstractSpinBox*>( w->parentWidget() ) )
1763 if ( pe == PE_FrameLineEdit ) {
1764 QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr
1765 QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr
1766 bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
1767 double aRad = model()->widgetRounding( Style_Model::EditRadius );
1769 drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true);
1771 Style_Tools::shadowRect( p, opt->rect, aRad, LINE_GR_MARGIN, SHADOW,
1772 Style_Tools::All, opt->palette.color( QPalette::Base ), // getColor( Style_Model::fld_light_clr ),
1773 model()->color( Style_Model::FieldDark ), aBrdTopCol, aBrdBotCol,
1774 model()->antialiasing(), false );
1778 if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1779 QRect rect = panel->rect.adjusted( panel->lineWidth, panel->lineWidth,
1780 -panel->lineWidth, -panel->lineWidth);
1781 if ( w->inherits("QLineEdit") && panel->lineWidth > 0 ) {
1782 drawPrimitive( PE_FrameLineEdit, panel, p, w );
1785 QColor c = panel->palette.color(QPalette::Base); c.setAlpha(255);
1786 p->fillRect( rect, c ); // panel->palette.brush(QPalette::Base)
1792 case PE_FrameTabWidget: {
1793 if (w && qobject_cast<QTabWidget*>((QWidget*)w)) {
1794 QTabWidget* tabW = qobject_cast<QTabWidget*>((QWidget*)w);
1795 int aRoundType = Style_Tools::BottomRight;
1796 QTabWidget::TabPosition aTabPos = tabW->tabPosition();
1797 if ( aTabPos != QTabWidget::North && aTabPos != QTabWidget::West )
1798 aRoundType = aRoundType | Style_Tools::TopLeft;
1799 if ( aTabPos != QTabWidget::South )
1800 aRoundType = aRoundType | Style_Tools::BottomLeft;
1801 if ( aTabPos != QTabWidget::East )
1802 aRoundType = aRoundType | Style_Tools::TopRight;
1803 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
1804 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1805 Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::FrameRadius ),
1806 0., SHADOW, aRoundType,
1807 model()->color( Style_Model::FieldLight ),
1808 opt->palette.color( QPalette::Dark ),
1809 aBrdTopCol, aBrdBotCol, false, false, false, false );
1813 case PE_IndicatorToolBarHandle: {
1815 QRect r = opt->rect;
1816 bool horiz = opt->state & State_Horizontal;
1817 QLinearGradient gr( r.x(), r.y(), horiz ? r.x() : r.right(), horiz ? r.bottom() : r.y() );
1818 QColor aBgCol = opt->palette.color( QPalette::Window );
1819 gr.setColorAt( 0.0, aBgCol.light( BUT_PERCENT_ON ) );
1820 gr.setColorAt( 1.0, aBgCol );
1821 p->fillRect( r, gr );
1822 QRect aRect = QRect( r.x(), r.y(), r.width(), r.height() );
1823 drawHandle( p, r, horiz, false );
1828 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1831 if( w->parent() && !qobject_cast<QMenuBar*>((QWidget*)w) )
1833 drawBackground( p, w->rect(), opt->palette.color( QPalette::Window ), false );
1836 case PE_FrameTabBarBase:
1837 // for a tabbar that isn't part of a tab widget(dockWidgets for example).
1838 if (const QStyleOptionTabBarBase *tbb
1839 = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
1840 if (tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedEast &&
1841 tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedWest) {
1842 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1845 QRect aSelRect = tbb->selectedTabRect;
1846 // line under selected tab bar object
1847 bool isSelected = opt->state & State_Selected;
1848 QTabBar* tabBar = qobject_cast<QTabBar*>((QWidget*)w);
1849 bool isLast = false;
1851 isLast = tabBar->currentIndex() == tabBar->count() -1;
1852 QColor aColor = opt->palette.color( QPalette::Window );
1853 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
1854 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
1855 bool isHover = hasHover() && (opt->state & State_Enabled) &&
1856 (opt->state & State_MouseOver);
1857 QPainterPath aSelPath = Style_Tools::tabRect( p, aSelRect, (int)tbb->shape,
1858 model()->widgetRounding( Style_Model::FrameRadius ),
1859 DELTA_H_TAB, aColor, aColor,
1860 aColor, aColor, isSelected, isLast, isHover, false, false );
1861 if ( !aSelPath.isEmpty() )
1862 aSelRect = aSelPath.controlPointRect().toRect();
1863 QStyleOptionTabBarBase* copyOpt = (QStyleOptionTabBarBase*)tbb;
1864 copyOpt->selectedTabRect = aSelRect;
1865 QCommonStyle::drawPrimitive( pe, copyOpt, p, w );
1868 case PE_IndicatorBranch: {
1869 // This is _way_ too similar to the common style.
1870 static const int decoration_size = 9;
1871 int mid_h = opt->rect.x() + opt->rect.width() / 2;
1872 int mid_v = opt->rect.y() + opt->rect.height() / 2;
1877 if (opt->state & State_Children) {
1878 int delta = decoration_size / 2;
1883 p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
1884 if (!(opt->state & State_Open))
1885 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
1886 QPen oldPen = p->pen();
1887 p->setPen(opt->palette.dark().color());
1888 p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
1891 QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
1892 if (opt->state & State_Item) {
1893 if (opt->direction == Qt::RightToLeft)
1894 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
1896 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
1898 if (opt->state & State_Sibling)
1899 p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
1900 if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
1901 p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
1904 case PE_IndicatorDockWidgetResizeHandle: {
1905 QRect r = opt->rect;
1906 drawBorder( p, r, opt->state & State_Horizontal );
1907 bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver);
1909 drawHoverRect(p, r, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, false);
1910 bool horiz = r.width() > r.height();
1911 int aLen = model()->splitHandleLength();
1913 r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height());
1915 r = QRect( r.x(), r.y() +(int)((r.height()-aLen)/2), r.width(), aLen);
1916 drawHandle( p, r, horiz, true );
1920 QWidget* aWdg = (QWidget*)w;
1921 if ( qobject_cast<QTextEdit*>(aWdg) || qobject_cast<QTreeView*>(aWdg) ||
1922 qobject_cast<QListView*>(aWdg) ) {
1923 QRect r = opt->rect;
1924 if ( qobject_cast<QTreeView*>(aWdg) ) {
1925 QTreeView* trView = qobject_cast<QTreeView*>(aWdg);
1926 QHeaderView* aHeader = trView->header();
1927 if ( aHeader && aHeader->isVisible() ) {
1928 int aHeight = aHeader->contentsRect().height();
1929 r = QRect( r.x(), r.y()+aHeight, r.width(), r.height()-aHeight );
1932 QPalette aPal = aWdg->palette();
1933 double aMarg = LINE_GR_MARGIN;
1934 QColor base = model()->color( Style_Model::Base ), // Style_Model::pal_base_clr
1936 light_alt = base.dark(110),//AlternateBase color
1937 dark = model()->color( Style_Model::FieldDark ); // Style_Model::fld_dark_clr
1938 //light.setAlpha( 0 ); // VSR commented: IPAL19262
1939 QLinearGradient gr_h(r.x(), r.y(), r.right(), r.y());
1940 gr_h.setColorAt( 0.0, dark );
1941 gr_h.setColorAt( aMarg / r.width(), light );
1942 gr_h.setColorAt( 1.0, light );
1943 QLinearGradient gr_v(r.x(), r.y(), r.x(), r.bottom() );
1944 gr_v.setColorAt( 0.0, dark );
1945 gr_v.setColorAt( aMarg / r.height(), light );
1946 gr_v.setColorAt( 1.0, light );
1948 p->fillRect( r, base );
1949 p->fillRect( r, gr_h );
1950 p->fillRect( r, gr_v );
1951 aPal.setBrush( QPalette::Base, QBrush( light ) );
1953 QLinearGradient gr_alt(r.x(), r.y(), r.right(), r.y());
1954 gr_alt.setColorAt( 0.0, dark );
1955 gr_alt.setColorAt( (aMarg)*2/3/r.width(), light_alt );
1956 gr_alt.setColorAt( 1.0, light_alt );
1957 aPal.setBrush( QPalette::AlternateBase, QBrush( gr_alt ) );
1958 aWdg->setPalette( aPal );
1960 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1964 QWindowsStyle::drawPrimitive( pe, opt, p, w );
1969 \brief Returns the value of the given pixel \a metric.
1970 \param metric metric type
1971 \param opt style option
1973 \return metric value
1975 int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt,
1976 const QWidget* w ) const
1978 if ( checkDebugLevel(7) ) {
1979 return QWindowsStyle::pixelMetric( metric, opt, w );
1982 int aRes = QWindowsStyle::pixelMetric( metric, opt, w );
1984 case PM_SliderLength: {
1985 aRes += (int)((double)model()->sliderSize()/2);
1988 case PM_DockWidgetFrameWidth:
1991 case PM_DockWidgetSeparatorExtent:
1994 case PM_DockWidgetTitleMargin:
1997 case PM_SplitterWidth:
2007 \brief Returns the size of the element described by the specified option \a opt
2008 and type \a ct, based on the provided \a contentsSize.
2009 \param ct contents type
2010 \param opt style option
2011 \param contentsSize contents size
2012 \param w widget (optional)
2013 \return size of the element
2015 QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt,
2016 const QSize& contentsSize, const QWidget* w ) const
2018 if ( checkDebugLevel(8) ) {
2019 return QWindowsStyle::sizeFromContents( ct, opt,contentsSize, w );
2022 QSize sz = QWindowsStyle::sizeFromContents( ct, opt, contentsSize, w );
2025 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
2026 if ( tab->position == QStyleOptionTab::End ||
2027 tab->position == QStyleOptionTab::OnlyOneTab ) {
2028 if ( tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth ) {
2029 int aDelta = (int)(opt->rect.height()*DELTA_H_TAB/2);
2030 sz.setWidth( sz.width() + aDelta );
2032 if ( tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::RoundedWest ) {
2033 int aDelta = (int)(opt->rect.width()*DELTA_H_TAB/2);
2034 sz.setHeight( sz.height() + aDelta );
2041 int aValue = model()->sliderSize();
2042 sz.setWidth( sz.width() + aValue );
2043 sz.setHeight( sz.height() + aValue );
2047 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2048 QRect res = QRect( 0, 0, sz.width(), sz.height() );
2049 int aHalfRect = (int)Style_Tools::getMaxRect( res,
2050 (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); // left value
2051 QRect old_arrow = QWindowsStyle::subControlRect( CC_ComboBox, cmb,
2052 SC_ComboBoxArrow, w );
2053 int aDelta = res.height() - old_arrow.width(); // right value
2054 if ( cmb->editable )
2055 aDelta += aHalfRect; // for right of line edit internal
2056 sz.setWidth( res.width() + aDelta + aHalfRect );
2066 \brief Returns a pixmap for the given \a standardPixmap.
2067 \param stPixmap standard pixmap type
2068 \param opt style option
2069 \param w widget (optional)
2070 \return standard pixmap
2072 QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption *opt,
2073 const QWidget *w) const
2075 if ( checkDebugLevel(9) ) {
2076 return QWindowsStyle::standardPixmap( stPixmap, opt, w );
2081 case SP_DockWidgetCloseButton:
2082 case SP_TitleBarCloseButton:
2083 return QPixmap( cross_xpm );
2084 case SP_TitleBarMaxButton:
2085 return QPixmap( maximize_xpm );
2086 case SP_TitleBarNormalButton:
2087 return QPixmap( normal_xpm );
2088 case SP_TitleBarMinButton:
2089 return QPixmap( minimize_xpm );
2091 return QWindowsStyle::standardPixmap( stPixmap, opt, w );
2096 \brief Returns an icon for the given \a standardIcon.
2097 \param standardIcon standard icon type
2098 \param opt style option
2099 \param w widget (optional)
2100 \return standard icon
2102 QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon,
2103 const QStyleOption* opt,
2104 const QWidget* w ) const
2106 if ( checkDebugLevel(10) ) {
2107 return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
2110 switch ( standardIcon )
2112 case SP_MessageBoxInformation:
2113 return QPixmap( ":/images/information.png" );
2114 case SP_MessageBoxWarning:
2115 return QPixmap( ":/images/warning.png" );
2116 case SP_MessageBoxCritical:
2117 return QPixmap( ":/images/critical.png" );
2118 case SP_MessageBoxQuestion:
2119 return QPixmap( ":/images/question.png" );
2123 return QWindowsStyle::standardIconImplementation( standardIcon, opt, w );
2127 \brief Returns an integer representing the specified style \a hint for the
2128 given widget \a w described by the provided style option \a opt.
2129 \param hint hint type
2130 \param opt style option
2131 \param w widget (optional)
2132 \param returnData (currently not used)
2133 \return style hint value
2135 int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWidget* w,
2136 QStyleHintReturn* returnData ) const
2138 if ( checkDebugLevel(11) ) {
2139 return QWindowsStyle::styleHint( hint, opt, w, returnData );
2142 int aRes = QWindowsStyle::styleHint( hint, opt, w, returnData );
2144 case SH_Table_GridLineColor: {
2146 aRes = model()->color( Style_Model::GridLine ).rgb(); // Style_Model::tbl_grline_clr
2158 \brief Get the rectangle containing the specified subcontrol \a sc of the given
2159 complex control \a cc (with the style specified by option \a opt).
2160 The rectangle is defined in screen coordinates.
2161 \param cc complex control type
2162 \param opt style option
2163 \param sc subcontrol type
2164 \param wid widget (optional)
2165 \return subcontrol rectangle
2167 QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex* opt,
2168 SubControl sc, const QWidget* wid ) const
2170 if ( checkDebugLevel(12) ) {
2171 return QWindowsStyle::subControlRect( cc, opt, sc, wid );
2174 QRect res = QWindowsStyle::subControlRect( cc, opt, sc, wid );
2177 int x = res.x(), w = res.width(), h = res.height();
2178 if ( sc==SC_SpinBoxUp || sc==SC_SpinBoxDown ) {
2179 QRect frame_r = QWindowsStyle::subControlRect( cc, opt, SC_SpinBoxFrame, wid );
2180 h = frame_r.height();
2184 else if ( sc==QStyle::SC_SpinBoxEditField ) {
2185 res.setWidth( w-h );
2186 res.setTopLeft( QPoint( res.x(), res.y()-SHADOW ) );
2191 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2193 int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
2194 int x = res.x(), w = res.width(), h = res.height();
2196 case SC_ComboBoxEditField: {
2197 res.setWidth( w-h );
2199 if ( !cb->editable )
2201 res.setTopLeft( QPoint( aX, res.y()-SHADOW ) );
2204 case SC_ComboBoxArrow: {
2214 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2215 QRect slider_r = QWindowsStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid );
2216 int aRect = Style_Tools::getMaxRect( slider_r, (int)model()->widgetRounding( Style_Model::ButtonRadius ) );
2218 case SC_ScrollBarSubPage: // between top/left button and slider
2219 if (scrollbar->orientation == Qt::Horizontal)
2220 res.setRight( res.right()+aRect+1 );
2222 res.setBottom( res.bottom()+aRect+1 );
2224 case SC_ScrollBarAddPage: // between bottom/right button and slider
2225 if (scrollbar->orientation == Qt::Horizontal)
2226 res.setLeft( res.left() - aRect - 1 );
2228 res.setTop( res.top() - aRect - 1);
2236 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2238 case SC_SliderGroove: {
2239 if ( slider->orientation == Qt::Horizontal ) {
2240 res.setLeft( res.left()+DELTA_SLIDER );
2241 res.setRight( res.right()-DELTA_SLIDER );
2244 res.setTop( res.top()+DELTA_SLIDER );
2245 res.setBottom( res.bottom()-DELTA_SLIDER );
2257 \brief Returns the sub-area for the given element \a se as described
2258 in the provided style option \a opt.
2259 The returned rectangle is defined in screen coordinates.
2260 \param se subelement type
2261 \param opt style option
2262 \param wid widget (optional)
2263 \return subelement rectangle
2265 QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt,
2266 const QWidget* wid ) const
2268 if ( checkDebugLevel(13) ) {
2269 return QWindowsStyle::subElementRect( se, opt, wid );
2272 QRect res = QWindowsStyle::subElementRect( se, opt, wid );
2273 int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 );
2274 int w = res.width(), h = res.height();
2276 case SE_ComboBoxFocusRect: {
2277 QRect old_r = QWindowsStyle::subControlRect( CC_ComboBox,
2278 qstyleoption_cast<const QStyleOptionComplex*>( opt ),
2279 SC_ComboBoxArrow, wid );
2280 int old_w = old_r.width();
2281 res.setWidth( w-h+old_w-2 );
2284 case SE_LineEditContents: {
2285 res.setTopLeft( QPoint( res.x()+aHalfRect, res.y()-SHADOW ) );
2286 res.setTopRight( QPoint( res.right()-aHalfRect, res.y() ) );
2289 case SE_ProgressBarLabel:
2290 case SE_ProgressBarContents:
2291 case SE_ProgressBarGroove:
2294 if( qobject_cast<const QRadioButton*>(wid) ||
2295 qobject_cast<const QCheckBox*>(wid) ) {
2297 res = res.adjusted(0, 0, 2, 0);
2303 \brief Update palette colors from style model
2305 void Style_Salome::updatePaletteColors()
2307 QPalette pal = QApplication::palette();
2309 for ( int i = (int)QPalette::Active; i <= (int)QPalette::Inactive; i++ ) {
2310 for ( int j = (int)Style_Model::WindowText; j < (int)Style_Model::NColorRoles; j++ ) {
2311 if ( j == QPalette::NoRole ) continue;
2312 pal.setColor( (QPalette::ColorGroup)i, (QPalette::ColorRole)j,
2313 model()->color( (Style_Model::ColorRole)j, (QPalette::ColorGroup)i ) );
2316 QPixmapCache::clear();
2317 QApplication::setPalette( pal );
2321 \brief Update all widgets with the current style properties.
2322 \param app application object
2324 void Style_Salome::updateAllWidgets( QApplication* app )
2329 QWidgetList all = app->allWidgets();
2331 for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) {
2333 if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)
2334 && !w->testAttribute(Qt::WA_SetStyle)) {
2335 QEvent e(QEvent::StyleChange);
2336 QApplication::sendEvent(w, &e);
2344 \brief Check if any widget effect is currently used
2345 \return \c true if any widget effect is currently used
2347 bool Style_Salome::hasHover() const
2349 return model()->widgetEffect() != Style_Model::NoEffect;
2353 \brief Draw rectangle for the hovered widget
2356 \param bgCol background color
2357 \param rad corners rounding radius
2358 \param type shadow type
2359 \param border if \c true border is colored with specific color
2361 void Style_Salome::drawHoverRect( QPainter* p, const QRect& r, const QColor& bgCol, const double rad,
2362 const int type, const bool border ) const
2366 bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect;
2367 bool isHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect;
2368 QColor aBorder = model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr
2370 double aMargin = HIGH_WDG_MARGIN;
2371 if ( isAutoRaising ) {
2373 aBrdCol = aCol.dark(BUT_PERCENT_ON);
2378 else if ( isHighWdg ) {
2379 aCol = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr
2380 aBrdCol = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr
2384 Style_Tools::highlightRect( p, r, rad, type, aMargin, aCol, aBrdCol, aBorder );
2388 \brief Draw widget handle
2391 \param horiz if \c true draw horizontal handle, otherwise draw vertical handle
2392 \param isRect if \c true surrounding rectangle is also drawn
2394 void Style_Salome::drawHandle( QPainter* p, const QRect& r, bool horiz, bool isRect ) const
2396 QPixmap hole( (const char**)hole_xpm );
2398 double d_hor = model()->handleDelta( Qt::Horizontal );
2399 double d_ver = model()->handleDelta( Qt::Vertical );
2400 if ( !d_hor || !d_ver || !r.width() || !r.height() )
2402 int c_hor = (int)(r.width()/d_hor)-1;
2403 int c_ver = (int)(r.height()/d_ver)-1;
2404 if ( c_hor+1 <= 0 || c_ver+1 <= 0 )
2406 // correction for delta value
2407 d_hor = r.width()/(c_hor+1);
2408 d_ver = r.height()/(c_ver+1);
2410 double dd_hor = 0, dd_ver = 0;
2412 for ( i = 0; i < c_hor; i++ ) {
2413 for ( j = 0; j < c_ver; j++ ) {
2414 p->drawPixmap( (int)( r.x() + dd_hor + ( i + 1 ) * d_hor - 1 ),
2415 (int)( r.y() + dd_ver + ( j + 1 ) * d_ver - 1 ), hole );
2418 dd_ver += (int(d_ver)/2) + (int(d_ver)%2);
2424 for ( j = 0; j < c_ver; j++ ) {
2425 for ( i = 0; i < c_hor; i++ ) {
2426 p->drawPixmap( (int)( r.x() + dd_hor + ( i + 1 ) * d_hor - 1 ),
2427 (int)( r.y() + dd_ver + ( j + 1 ) * d_ver - 1 ), hole );
2430 dd_hor += (int(d_hor)/2) + (int(d_hor)%2);
2438 \brief Draw background.
2441 \param bgCol background color
2442 \param fill 'fill rectangle' flag
2443 \param grad 'draw gradient' flag
2444 \param horix 'draw horizontal item' flag (usefull for gradient background)
2446 void Style_Salome::drawBackground( QPainter* p, const QRect& r, const QColor& bgCol,
2447 const bool fill, const bool grad, const bool horiz ) const
2451 p->fillRect( r, bgCol );
2453 QLinearGradient gr( r.x(), r.y(), horiz ? r.x() : r.right(), horiz ? r.bottom() : r.y() );
2454 gr.setColorAt( 0.0, bgCol.light( BUT_PERCENT_ON ) );
2455 gr.setColorAt( 1.0, bgCol );
2456 p->fillRect( r, gr );
2460 int x = r.x(), y = r.y(), left = r.left(), top = r.top();
2461 int w = r.width(), h = r.height();
2463 QVector<QLine> lines;
2465 switch ( model()->linesType() ) {
2466 case Style_Model::Horizontal:
2469 for ( int i = 0; i <= h; i += d )
2470 lines.append( QLine( x, y+i, w, r.y()+i ) );
2473 case Style_Model::Inclined:
2478 for ( int i = 0; i <= w; i += d )
2479 lines.append( QLine( x+i, y, x, y+i ) );
2480 for ( int i = 0; i < h; i += d )
2481 lines.append( QLine( left+w-i, top+h, left+w, top+h-i ) );
2488 if ( !lines.isEmpty() ) {
2489 QColor c = model()->color( Style_Model::Lines );
2490 int anAlpha = (int)( 255*( 1 - model()->linesTransparency()/100 ) );
2491 c.setAlpha( anAlpha );
2493 p->setRenderHint( QPainter::Antialiasing );
2494 p->drawLines( lines );
2502 \param horiz 'draw horizontal item' flag
2504 void Style_Salome::drawBorder( QPainter* p, const QRect& r, bool horiz ) const
2506 QPen oldPen = p->pen();
2507 QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr
2508 QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr
2509 p->setPen( aBrdTopCol );
2511 p->drawLine(r.left(), r.top(), r.right(), r.top());
2512 p->setPen(aBrdBotCol);
2513 p->drawLine(r.left(), r.bottom(), r.right(), r.bottom());
2516 p->drawLine(r.left(), r.top(), r.left(), r.bottom());
2517 p->setPen(aBrdBotCol);
2518 p->drawLine(r.right(), r.top(), r.right(), r.bottom());
2524 \brief Get corrected title text
2525 \param txt original text
2526 \param W possible width
2527 \param H possible height
2529 \return corrected title text
2531 QString Style_Salome::titleText( const QString& txt, const int W, const int H, QFont& f ) const
2533 QString res = txt.trimmed();
2535 QFontMetrics fm( f );
2536 while( fm.height() > H && f.pointSize()>1 )
2538 f.setPointSize( f.pointSize()-1 );
2539 fm = QFontMetrics( f );
2542 if ( fm.width( res ) > W )
2544 QString end( "..." );
2545 while ( !res.isEmpty() && fm.width( res + end ) > W )
2546 res.remove( res.length() - 1, 1 );
2548 if ( !res.isEmpty() )