From 44e5797abe2c91173b7a02356223e5781302d310 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 9 Oct 2007 11:14:42 +0000 Subject: [PATCH] Correction from BR_QT4_dev --- src/Qtx/QtxWorkstack.cxx | 155 ++++++++++++++++++++++++++++++++++++++- src/Qtx/QtxWorkstack.h | 7 +- 2 files changed, 156 insertions(+), 6 deletions(-) diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 0d72eb2ec..0927f0745 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -31,10 +31,12 @@ #include #include #include -#include #include #include #include +#include +#include +#include #define DARK_COLOR_LIGHT 250 @@ -238,6 +240,122 @@ void QtxWorkstackDrag::startDrawRect() myAreaRect->hide(); } + +/* + \class CloseButton + \brief Workstack area close button. + \internal +*/ +class CloseButton : public QAbstractButton +{ +public: + CloseButton( QWidget* ); + + QSize sizeHint() const; + QSize minimumSizeHint() const; + + void enterEvent( QEvent* ); + void leaveEvent( QEvent* ); + void paintEvent( QPaintEvent* ); +}; + +/*! + \brief Constructor + \internal + \param parent parent widget +*/ +CloseButton::CloseButton( QWidget* parent ) +: QAbstractButton( parent ) +{ + setFocusPolicy( Qt::NoFocus ); +} + +/*! + \brief Get appropriate size for the button. + \internal + \return size value +*/ +QSize CloseButton::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 ); +} + +/*! + \brief Get minimum appropriate size for the button. + \internal + \return minimum size value +*/ +QSize CloseButton::minimumSizeHint() const +{ + return sizeHint(); +} + +/*! + \brief Process mouse enter event. + \internal + \param event mouse enter event +*/ +void CloseButton::enterEvent( QEvent *event ) +{ + if ( isEnabled() ) + update(); + QAbstractButton::enterEvent( event ); +} + +/*! + \brief Process mouse leave event. + \internal + \param event mouse leave event +*/ +void CloseButton::leaveEvent( QEvent *event ) +{ + if( isEnabled() ) + update(); + QAbstractButton::leaveEvent( event ); +} + +/*! + \brief Process paint event. + \internal + \param event paint event +*/ +void CloseButton::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 @@ -255,6 +373,7 @@ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent ) QVBoxLayout* base = new QVBoxLayout( this ); base->setMargin( frameWidth() ); + base->setSpacing( 0 ); QWidget* top = new QWidget( this ); base->addWidget( top ); @@ -265,10 +384,8 @@ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent ) myBar = new QtxWorkstackTabBar( top ); tl->addWidget( myBar, 1 ); - QPushButton* close = new QPushButton( top ); + CloseButton* close = new CloseButton( top ); close->setIcon( style()->standardIcon( QStyle::SP_TitleBarCloseButton ) ); - close->setAutoDefault( true ); - close->setFlat( true ); myClose = close; tl->addWidget( myClose ); @@ -1029,6 +1146,7 @@ QtxWorkstackChild::QtxWorkstackChild( QWidget* wid, QWidget* parent, Qt::WindowF myWidget->setParent( this, f ); myWidget->installEventFilter( this ); QVBoxLayout* base = new QVBoxLayout( this ); + base->setMargin( 0 ); base->addWidget( myWidget ); connect( myWidget, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); @@ -1774,6 +1892,35 @@ int QtxWorkstack::accel( const int id ) const return res; } +/*! + \brief Get icon for the specified action. + + If \a id is invalid, null icon is returned. + + \param id menu action ID + \return menu item icon +*/ +QIcon QtxWorkstack::icon( const int id ) const +{ + QIcon ico; + if ( myActionsMap.contains( id ) ) + ico = myActionsMap[id]->icon(); + return ico; +} + +/*! + \brief Set menu item icon for the specified action. + \param id menu action ID + \param ico new menu item icon +*/ +void QtxWorkstack::setIcon( const int id, const QIcon& icon ) +{ + if ( !myActionsMap.contains( id ) ) + return; + + myActionsMap[id]->setIcon( icon ); +} + /*! \brief Set actions to be visible in the context popup menu. diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index 17adf9428..d549965d3 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -32,9 +32,9 @@ class QAction; class QSplitter; -class QPushButton; class QStackedWidget; class QRubberBand; +class QAbstractButton; class QtxWorkstackArea; class QtxWorkstackDrag; @@ -79,6 +79,9 @@ public: int accel( const int ) const; void setAccel( const int, const int ); + QIcon icon( const int ) const; + void setIcon( const int, const QIcon& ); + void setMenuActions( const int ); int menuActions() const; @@ -256,7 +259,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 -- 2.39.2