From: nds Date: Tue, 23 Dec 2008 09:33:02 +0000 (+0000) Subject: There is a multi action improvement to hide/show items in the corresponded menu. X-Git-Tag: V2_0_0~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b45f2c36f0638ba77c2a4f0509e9d548aa883371;p=modules%2Fgui.git There is a multi action improvement to hide/show items in the corresponded menu. --- diff --git a/src/Qtx/QtxMultiAction.cxx b/src/Qtx/QtxMultiAction.cxx index 88e2b764b..d824322ce 100644 --- a/src/Qtx/QtxMultiAction.cxx +++ b/src/Qtx/QtxMultiAction.cxx @@ -391,19 +391,15 @@ void QtxMultiAction::updateButton( QToolButton* btn ) return; pm->clear(); - for ( int i = 0; pm->layout() && i < pm->layout()->count(); i++ ) - delete pm->layout()->widget(); - delete pm->layout(); - - QVBoxLayout* vbox = new QVBoxLayout( pm ); - vbox->setMargin( 1 ); - vbox->setSpacing( 0 ); - Filter* filter = new Filter( vbox ); + Filter* filter = new Filter( pm ); QList actList = actions(); for ( QList::iterator itr = actList.begin(); itr != actList.end(); ++itr ) { + if ( !(*itr) || !(*itr)->isVisible() ) + continue; QToolButton* b = new QToolButton( pm ); + b->setEnabled( (*itr)->isEnabled() ); b->setDefaultAction( *itr ); b->setToolTip( (*itr)->toolTip() ); b->setStatusTip( (*itr)->statusTip() ); @@ -412,7 +408,10 @@ void QtxMultiAction::updateButton( QToolButton* btn ) b->setToolButtonStyle( btn->toolButtonStyle() ); b->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); b->installEventFilter( filter ); - vbox->addWidget( b ); + + QWidgetAction* anAction = new QWidgetAction( pm ); + anAction->setDefaultWidget( b ); + pm->addAction( anAction ); } } @@ -425,21 +424,29 @@ void QtxMultiAction::updateButton( QToolButton* btn ) */ void QtxMultiAction::onActionChanged() { - if ( myCurrent && myCurrent->isEnabled() ) - return; + if ( !myCurrent || !myCurrent->isEnabled() ) { + QList alist = actions(); + QList::ConstIterator it; + + QList aVisList; + for ( it = alist.begin(); it != alist.end(); ++it ) { + if ( (*it)->isVisible() ) + aVisList.append( (*it) ); + } - QList alist = actions(); - QAction* a = 0; - for ( QList::ConstIterator it = alist.begin(); it != alist.end() && !a; ++it ) { - if ( (*it)->isEnabled() ) - a = *it; - } + QAction* a = 0; + for ( it = aVisList.begin(); it != aVisList.end() && !a; ++it ) { + if ( (*it)->isEnabled() ) + a = *it; + } - if ( a ) - myCurrent = a; - else - myCurrent = alist.isEmpty() ? 0 : alist.first(); + if ( a ) + myCurrent = a; + else + myCurrent = alist.isEmpty() ? 0 : alist.first(); + + setEnabled( myCurrent && myCurrent->isEnabled() ); + } - setEnabled( myCurrent && myCurrent->isEnabled() ); updateAction(); }