From 68a9ad510d859fce8d6a6c27364d69cece276c27 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 12 Jul 2007 11:52:09 +0000 Subject: [PATCH] *** empty log message *** --- src/Qtx/QtxActionSet.cxx | 4 ++++ src/Qtx/QtxMultiAction.cxx | 40 ++++++++++++++++++++++++++++++++++---- src/Qtx/QtxMultiAction.h | 3 ++- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/Qtx/QtxActionSet.cxx b/src/Qtx/QtxActionSet.cxx index 6f6ab940c..da8d7630d 100644 --- a/src/Qtx/QtxActionSet.cxx +++ b/src/Qtx/QtxActionSet.cxx @@ -217,6 +217,10 @@ void QtxActionSet::clear() */ void QtxActionSet::onChanged() { + QList lst = createdWidgets(); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + (*it)->setEnabled( isEnabled() ); + if ( !isVisible() || !isEmptyAction() ) return; diff --git a/src/Qtx/QtxMultiAction.cxx b/src/Qtx/QtxMultiAction.cxx index 89c442044..806e0f00b 100644 --- a/src/Qtx/QtxMultiAction.cxx +++ b/src/Qtx/QtxMultiAction.cxx @@ -168,7 +168,7 @@ QtxMultiAction::~QtxMultiAction() */ void QtxMultiAction::setActiveAction( QAction* a ) { - if ( a && actions().contains( a ) && a != myCurrent ) { + if ( a && actions().contains( a ) && a != myCurrent && a->isEnabled() ) { myCurrent = a; updateAction(); } @@ -294,8 +294,8 @@ QWidget* QtxMultiAction::createWidget( QWidget* parent ) */ void QtxMultiAction::actionAdded( QAction* a ) { - if ( !myCurrent ) - myCurrent = a; + connect( a, SIGNAL( changed() ), this, SLOT( onActionChanged() ) ); + onActionChanged(); } /*! @@ -304,10 +304,14 @@ void QtxMultiAction::actionAdded( QAction* a ) */ void QtxMultiAction::actionRemoved( QAction* a ) { + disconnect( a, SIGNAL( changed() ), this, SLOT( onActionChanged() ) ); + if ( myCurrent != a ) return; - myCurrent = actions().isEmpty() ? 0 : actions().first(); + myCurrent = 0; + + onActionChanged(); updateAction(); } @@ -354,3 +358,31 @@ void QtxMultiAction::updateButton( QToolButton* btn ) vbox->addWidget( b ); } } + +/*! + \brief Called when any child action is enabled/disabled. + + If the current action is disabled, the multi-action switches + to first found enabled. If all child actions are disabled, the + action itself is also disabled. +*/ +void QtxMultiAction::onActionChanged() +{ + if ( myCurrent && myCurrent->isEnabled() ) + return; + + QList alist = actions(); + QAction* a = 0; + for ( QList::ConstIterator it = alist.begin(); it != alist.end() && !a; ++it ) { + if ( (*it)->isEnabled() ) + a = *it; + } + + if ( a ) + myCurrent = a; + else + myCurrent = alist.isEmpty() ? 0 : alist.first(); + + setEnabled( myCurrent && myCurrent->isEnabled() ); + updateAction(); +} diff --git a/src/Qtx/QtxMultiAction.h b/src/Qtx/QtxMultiAction.h index fa2ea5867..07bb3e062 100644 --- a/src/Qtx/QtxMultiAction.h +++ b/src/Qtx/QtxMultiAction.h @@ -43,9 +43,10 @@ public: void setActiveAction( QAction* ); QAction* activeAction() const; -public slots: +private slots: void onClicked( bool ); void onTriggered( QAction* ); + void onActionChanged(); protected: virtual bool isEmptyAction() const; -- 2.39.2