From: nds Date: Mon, 6 Aug 2007 07:42:21 +0000 (+0000) Subject: Button "Close" was changed for new Salome Style. X-Git-Tag: qt4_porting_delivery_220807~51 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0fec3e1c050cf763b807fda986bb1119ec0c79b0;p=modules%2Fgui.git Button "Close" was changed for new Salome Style. --- diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index f40955897..aaec1636c 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -31,10 +31,11 @@ #include #include #include -#include #include #include #include +#include +#include #define DARK_COLOR_LIGHT 250 @@ -238,6 +239,67 @@ void QtxWorkstackDrag::startDrawRect() myAreaRect->hide(); } + +QtxWorkstackAreaTitleButton::QtxWorkstackAreaTitleButton(QWidget *widget) +: QAbstractButton(widget) +{ + setFocusPolicy(Qt::NoFocus); +} + +QSize QtxWorkstackAreaTitleButton::sizeHint() const +{ + ensurePolished(); + int dim = 0; + if( !icon().isNull() ) { + const QPixmap pm = icon().pixmap( style()->pixelMetric( QStyle::PM_SmallIconSize ), + QIcon::Normal ); + dim = qMax(pm.width(), pm.height()); + } + return QSize( dim + 4, dim + 4 ); +} +void QtxWorkstackAreaTitleButton::enterEvent( QEvent *event ) +{ + if ( isEnabled() ) + update(); + QAbstractButton::enterEvent( event ); +} + +void QtxWorkstackAreaTitleButton::leaveEvent( QEvent *event ) +{ + if( isEnabled() ) + update(); + QAbstractButton::leaveEvent( event ); +} + +void QtxWorkstackAreaTitleButton::paintEvent( QPaintEvent* ) +{ + QPainter p(this); + + QRect r = rect(); + QStyleOption opt; + opt.init(this); + opt.state |= QStyle::State_AutoRaise; + if (isEnabled() && underMouse() && !isChecked() && !isDown()) + opt.state |= QStyle::State_Raised; + if (isChecked()) + opt.state |= QStyle::State_On; + if (isDown()) + opt.state |= QStyle::State_Sunken; + style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, &p, this); + + int shiftHorizontal = opt.state & QStyle::State_Sunken ? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &opt, this) : 0; + int shiftVertical = opt.state & QStyle::State_Sunken ? style()->pixelMetric(QStyle::PM_ButtonShiftVertical, &opt, this) : 0; + + r.adjust(2, 2, -2, -2); + r.translate(shiftHorizontal, shiftVertical); + + QPixmap pm = icon().pixmap( style()->pixelMetric( QStyle::PM_SmallIconSize ), isEnabled() ? + underMouse() ? QIcon::Active : QIcon::Normal + : QIcon::Disabled, + isDown() ? QIcon::On : QIcon::Off); + style()->drawItemPixmap(&p, r, Qt::AlignCenter, pm); +} + /*! \class QtxWorkstackArea \internal @@ -266,10 +328,8 @@ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent ) myBar = new QtxWorkstackTabBar( top ); tl->addWidget( myBar, 1 ); - QPushButton* close = new QPushButton( top ); + QtxWorkstackAreaTitleButton* close = new QtxWorkstackAreaTitleButton( top ); close->setIcon( style()->standardIcon( QStyle::SP_TitleBarCloseButton ) ); - close->setAutoDefault( true ); - close->setFlat( true ); myClose = close; tl->addWidget( myClose ); diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index 17adf9428..d2ee2b10e 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -29,10 +29,10 @@ #include #include #include +#include class QAction; class QSplitter; -class QPushButton; class QStackedWidget; class QRubberBand; @@ -155,6 +155,25 @@ private: friend class QtxWorkstackDrag; }; +/* + Tool window title +*/ +class QtxWorkstackAreaTitleButton : public QAbstractButton +{ + Q_OBJECT + +public: + QtxWorkstackAreaTitleButton(QWidget *widget); + + QSize sizeHint() const; + inline QSize minimumSizeHint() const + { return sizeHint(); } + + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + void paintEvent(QPaintEvent *event); +}; + class QtxWorkstackArea : public QFrame { Q_OBJECT @@ -256,7 +275,7 @@ private: private: QtxWorkstackTabBar* myBar; //!< workarea tab bar header - QPushButton* myClose; //!< close button + QAbstractButton* myClose; //!< close button QStackedWidget* myStack; //!< widget stack QWidgetList myList; //!< child widgets list diff --git a/src/Style/Style_Model.cxx b/src/Style/Style_Model.cxx index 99e328377..f35decc63 100644 --- a/src/Style/Style_Model.cxx +++ b/src/Style/Style_Model.cxx @@ -179,7 +179,7 @@ void Style_Model::setDefaults( QApplication* app ) void Style_Model::initFromResource( QtxResourceMgr* theResMgr ) { ValuesMap::iterator anIt = myValues.begin(), anEnd = myValues.end(); - for ( ; anIt != anEnd; anIt++ ) + for ( ; anIt != anEnd; ++anIt ) setValueFrom( theResMgr, anIt.key() ); if ( getBoolValue( is_defined_style ) ) @@ -193,7 +193,7 @@ bool Style_Model::updateFromResource( QtxResourceMgr* theResMgr, QString theProp return retrieve; ValuesMap::iterator anIt = myValues.begin(), anEnd = myValues.end(); int anId = -1; - for ( ; anIt != anEnd && anId == -1; anIt++ ) + for ( ; anIt != anEnd && anId == -1; ++anIt ) if ( anIt.value().myName == thePropName ) anId = anIt.key(); if ( anId == -1 ) @@ -205,7 +205,7 @@ bool Style_Model::updateFromResource( QtxResourceMgr* theResMgr, QString theProp setPredefinedStyle( getIntValue( defined_style ) ); retrieve = true; // update for resources all datas - for ( anIt = myValues.begin(); anIt != anEnd; anIt++ ) { + for ( anIt = myValues.begin(); anIt != anEnd; ++anIt ) { if ( anIt.key() != anId ) getValueTo( theResMgr, anIt.key(), false ); } diff --git a/src/Style/Style_Salome.cxx b/src/Style/Style_Salome.cxx index ca9bb294d..e0d9db3c2 100644 --- a/src/Style/Style_Salome.cxx +++ b/src/Style/Style_Salome.cxx @@ -1269,8 +1269,9 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, } case PE_PanelButtonTool : { if ( w && ( opt->state & State_Enabled ) && - ( qobject_cast( w->parentWidget() ) ) || - ( w->inherits("QDockWidgetTitleButton") ) ) { + ( ( qobject_cast( w->parentWidget() ) ) || + ( w->inherits("QDockWidgetTitleButton") ) || + ( w->inherits("QtxWorkstackAreaTitleButton") ) ) ) { bool aStateOn = opt->state & (State_Sunken | State_On); bool aHighWdg = hasHover() && !getBoolValue( Style_Model::auto_raising_wdg ) && getBoolValue( Style_Model::highlight_wdg );