From e09e6bea902f003229ba21ed601699e8ec9a0227 Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 15 Jun 2007 11:23:22 +0000 Subject: [PATCH] no message --- src/Qtx/QtxAction.cxx | 46 +++++++++++++++++++++++++++++++--------- src/Qtx/QtxAction.h | 8 +++++-- src/Qtx/QtxActionSet.cxx | 7 +++++- src/Qtx/QtxActionSet.h | 2 ++ src/Qtx/QtxComboBox.cxx | 4 +++- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/Qtx/QtxAction.cxx b/src/Qtx/QtxAction.cxx index 6e6692bb8..53f0f16e5 100755 --- a/src/Qtx/QtxAction.cxx +++ b/src/Qtx/QtxAction.cxx @@ -25,6 +25,20 @@ #include #include +class QtxAction::ActionNotify : public QEvent +{ +public: + ActionNotify( bool add, QWidget* wid ) : QEvent( QEvent::User ), myAdd( add ), myWidget( wid ) {}; + ~ActionNotify() {}; + + bool isAdded() const { return myAdd; } + QWidget* widget() const { return myWidget; } + +private: + bool myAdd; + QWidget* myWidget; +}; + /*! \class QtxAction \brief Generic action class. @@ -40,7 +54,7 @@ \param toggle if \c true the action is a toggle action */ QtxAction::QtxAction( QObject* parent, bool toggle ) -: QAction( parent ) +: QWidgetAction( parent ) { setCheckable( toggle ); @@ -60,10 +74,12 @@ QtxAction::QtxAction( QObject* parent, bool toggle ) \param name action name (in terms of QObject) \param toggle if \c true the action is a toggle action */ -QtxAction::QtxAction( const QString& text, const QIcon& icon, const QString& menuText, - int accel, QObject* parent, bool toggle ) -: QAction( icon, menuText, parent ) +QtxAction::QtxAction( const QString& text, const QIcon& icon, + const QString& menuText, int accel, QObject* parent, bool toggle ) +: QWidgetAction( parent ) { + setIcon( icon ); + setText( menuText ); setToolTip( text ); setShortcut( accel ); setCheckable( toggle ); @@ -85,8 +101,9 @@ QtxAction::QtxAction( const QString& text, const QIcon& icon, const QString& men */ QtxAction::QtxAction( const QString& text, const QString& menuText, int accel, QObject* parent, bool toggle ) -: QAction( menuText, parent ) +: QWidgetAction( parent ) { + setText( menuText ); setToolTip( text ); setShortcut( accel ); setCheckable( toggle ); @@ -117,11 +134,11 @@ bool QtxAction::eventFilter( QObject* o, QEvent* e ) if ( o && o->isWidgetType() ) { if ( e->type() == QEvent::ActionAdded && ((QActionEvent*)e)->action() == this ) - addedTo( (QWidget*)o ); + QApplication::postEvent( this, new ActionNotify( true, (QWidget*)o ) ); if ( e->type() == QEvent::ActionRemoved && ((QActionEvent*)e)->action() == this ) - removedFrom( (QWidget*)o ); + QApplication::postEvent( this, new ActionNotify( false, (QWidget*)o ) ); } - return QAction::eventFilter( o, e ); + return QWidgetAction::eventFilter( o, e ); } /*! @@ -185,7 +202,7 @@ bool QtxAction::removeFrom( QWidget* w ) \param w widget (menu or toolbar) */ -void QtxAction::addedTo( QWidget* /*w*/ ) +void QtxAction::addedTo( QWidget* ) { } @@ -197,6 +214,15 @@ void QtxAction::addedTo( QWidget* /*w*/ ) \param w widget (menu or toolbar) */ -void QtxAction::removedFrom( QWidget* /*w*/ ) +void QtxAction::removedFrom( QWidget* ) +{ +} + +void QtxAction::customEvent( QEvent* e ) { + ActionNotify* ae = (ActionNotify*)e; + if ( ae->isAdded() ) + addedTo( ae->widget() ); + else + removedFrom( ae->widget() ); } diff --git a/src/Qtx/QtxAction.h b/src/Qtx/QtxAction.h index e599c1f4c..265a1a4bb 100755 --- a/src/Qtx/QtxAction.h +++ b/src/Qtx/QtxAction.h @@ -24,7 +24,7 @@ #include "Qtx.h" -#include +#include class QIcon; @@ -32,10 +32,12 @@ class QIcon; #pragma warning ( disable:4251 ) #endif -class QTX_EXPORT QtxAction : public QAction +class QTX_EXPORT QtxAction : public QWidgetAction { Q_OBJECT + class ActionNotify; + public: QtxAction( QObject* = 0, bool = false ); QtxAction( const QString&, const QString&, int, QObject*, bool = false ); @@ -51,6 +53,8 @@ public: protected: virtual void addedTo( QWidget* ); virtual void removedFrom( QWidget* ); + + virtual void customEvent( QEvent* ); }; #ifdef WIN32 diff --git a/src/Qtx/QtxActionSet.cxx b/src/Qtx/QtxActionSet.cxx index fb4378853..7cfa6a63a 100644 --- a/src/Qtx/QtxActionSet.cxx +++ b/src/Qtx/QtxActionSet.cxx @@ -214,7 +214,7 @@ void QtxActionSet::clear() */ void QtxActionSet::onChanged() { - if ( !isVisible() ) + if ( !isVisible() || !isEmptyAction() ) return; bool block = signalsBlocked(); @@ -352,6 +352,11 @@ void QtxActionSet::update( QWidget* w ) } } +bool QtxActionSet::isEmptyAction() const +{ + return true; +} + /*! \fn void QtxActionSet::triggered( int id ); \brief Emitted when some child action is activated by the user. diff --git a/src/Qtx/QtxActionSet.h b/src/Qtx/QtxActionSet.h index 703f8081f..4de899787 100644 --- a/src/Qtx/QtxActionSet.h +++ b/src/Qtx/QtxActionSet.h @@ -68,6 +68,8 @@ protected: int actionId( QAction* ) const; void setActionId( QAction*, const int ); + virtual bool isEmptyAction() const; + private: void update(); void update( QWidget* ); diff --git a/src/Qtx/QtxComboBox.cxx b/src/Qtx/QtxComboBox.cxx index 8ffc1c073..360cd98e8 100755 --- a/src/Qtx/QtxComboBox.cxx +++ b/src/Qtx/QtxComboBox.cxx @@ -145,9 +145,11 @@ void QtxComboBox::paintEvent( QPaintEvent* e ) \brief Called when any item is activated by the user. \param idx activated item index (not used) */ -void QtxComboBox::onActivated( int /*idx*/ ) +void QtxComboBox::onActivated( int idx ) { resetClear(); + + emit activatedId( id( idx ) ); } /*! -- 2.39.2