}
-/*
- \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
myBar = new QtxWorkstackTabBar( top );
tl->addWidget( myBar, 1 );
-
- CloseButton* close = new CloseButton( top );
- close->setIcon( style()->standardIcon( QStyle::SP_TitleBarCloseButton ) );
- myClose = close;
- tl->addWidget( myClose );
+ myBar->setTabsClosable( true );
myStack = new QStackedWidget( this );
base->addWidget( myStack, 1 );
- connect( myClose, SIGNAL( clicked() ), this, SLOT( onClose() ) );
+ connect( myBar, SIGNAL( tabCloseRequested( int ) ), this, SLOT( onClose( int ) ) );
connect( myBar, SIGNAL( currentChanged( int ) ), this, SLOT( onCurrentChanged( int ) ) );
connect( myBar, SIGNAL( dragActiveTab() ), this, SLOT( onDragActiveTab() ) );
connect( myBar, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onContextMenuRequested( QPoint ) ) );
if ( e->type() == QEvent::FocusIn || e->type() == QEvent::MouseButtonPress )
{
bool ok = false;
- while ( !ok && wid && wid != myClose )
+ while ( !ok && wid )
{
ok = wid == this;
wid = wid->parentWidget();
/*!
\brief Called when user presses "Close" button.
*/
-void QtxWorkstackArea::onClose()
+void QtxWorkstackArea::onClose( int idx )
{
- QWidget* wid = activeWidget();
+ QWidget* wid = widget( myBar->tabId( idx ) );
if ( wid )
wid->close();
}