2 // Author: Sergey TELKOV
6 #include <qpopupmenu.h>
9 Name: QtxAction [public]
10 Desc: Constructs an action with given parent and name. If toggle is true the
11 action will be a toggle action, otherwise it will be a command action.
14 QtxAction::QtxAction( QObject* parent, const char* name, bool toggle )
15 : QAction( parent, name, toggle )
20 Name: QtxAction [public]
21 Desc: This constructor creates an action with the following properties: the
22 description text, the icon or iconset icon, the menu text and keyboard
23 accelerator. It is a child of given parent and named specified name.
24 If toggle is true the action will be a toggle action, otherwise it will
28 QtxAction::QtxAction( const QString& text, const QIconSet& icon,
29 const QString& menuText, int accel,
30 QObject* parent, const char* name, bool toggle )
31 : QAction( text, icon, menuText, accel, parent, name, toggle )
36 Name: QtxAction [public]
37 Desc: This constructor creates an action with the following properties: the
38 description text, the menu text and keyboard accelerator. It is a child
39 of given parent and named specified name. If toggle is true the action
40 will be a toggle action, otherwise it will be a command action.
43 QtxAction::QtxAction( const QString& text, const QString& menuText, int accel,
44 QObject* parent, const char* name, bool toggle )
45 : QAction( text, menuText, accel, parent, name, toggle )
50 Name: ~QtxAction [virtual public]
54 QtxAction::~QtxAction()
59 Name: addTo [virtual public]
60 Desc: Adds this action to widget. Returns true if the action was added
61 successfully and false otherwise.
64 bool QtxAction::addTo( QWidget* w )
66 return QAction::addTo( w );
70 Name: addTo [virtual public]
71 Desc: Adds this action to widget. If widget is QPopupMenu given index will
72 be used for menu item inserting. Returns true if the action was added
73 successfully and false otherwise.
76 bool QtxAction::addTo( QWidget* w, int index )
81 if ( w->inherits( "QPopupMenu" ) )
83 QPopupMenu* popup = (QPopupMenu*)w;
84 if ( index < (int)popup->count() - 1 )
86 int id = popup->idAt( popup->count() - 1 );
89 QMenuItem* item = popup->findItem( id );
90 if ( item && item->isSeparator() )
92 popup->removeItem( id );
93 popup->insertSeparator( index );
97 QPopupMenu* p = item ? item->popup() : 0;
98 int accel = popup->accel( id );
99 bool isOn = popup->isItemEnabled( id );
100 QString text = popup->text( id );
102 if ( popup->iconSet( id ) )
103 icon = *popup->iconSet( id );
104 popup->removeItem( id );
108 pos = popup->indexOf( popup->insertItem( text, p, id, index ) );
110 pos = popup->indexOf( popup->insertItem( text, id, index ) );
113 pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) );
115 pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) );
116 popup->setId( pos, id );
117 popup->setAccel( accel, id );
118 popup->setItemEnabled( id, isOn );
120 popup->connectItem( id, this, SLOT( internalActivation() ) );
130 Name: setPopup [virtual public]
131 Desc: Set or unset the sub popup menu for item with specified id in the given popup.
134 void QtxAction::setPopup( QPopupMenu* popup, const int id, QPopupMenu* subPopup ) const
140 const QMenuData* pmd = popup;
141 QMenuItem* item = popup->findItem( id, &md );
142 if ( !item || md != pmd )
145 QPopupMenu* oldPopup = item->popup();
146 if ( oldPopup == subPopup )
149 int accel = popup->accel( id );
150 bool isOn = popup->isItemEnabled( id );
151 QString text = popup->text( id );
153 if ( popup->iconSet( id ) )
154 icon = *popup->iconSet( id );
155 popup->removeItem( id );
159 pos = popup->indexOf( subPopup ? popup->insertItem( text, subPopup ) : popup->insertItem( text ) );
161 pos = popup->indexOf( subPopup ? popup->insertItem( icon, text, subPopup ) : popup->insertItem( icon, text ) );
163 popup->setId( pos, id );
164 popup->setAccel( accel, id );
165 popup->setItemEnabled( id, isOn );