#include <QActionEvent>
#include <QApplication>
+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.
\param toggle if \c true the action is a toggle action
*/
QtxAction::QtxAction( QObject* parent, bool toggle )
-: QAction( parent )
+: QWidgetAction( parent )
{
setCheckable( 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 );
*/
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 );
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 );
}
/*!
\param w widget (menu or toolbar)
*/
-void QtxAction::addedTo( QWidget* /*w*/ )
+void QtxAction::addedTo( QWidget* )
{
}
\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() );
}
#include "Qtx.h"
-#include <QAction>
+#include <QWidgetAction>
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 );
protected:
virtual void addedTo( QWidget* );
virtual void removedFrom( QWidget* );
+
+ virtual void customEvent( QEvent* );
};
#ifdef WIN32