1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxAction.cxx
20 // Author: Sergey TELKOV
22 #include "QtxAction.h"
24 #include <qpopupmenu.h>
27 Name: QtxAction [public]
28 Desc: Constructs an action with given parent and name. If toggle is true the
29 action will be a toggle action, otherwise it will be a command action.
32 QtxAction::QtxAction( QObject* parent, const char* name, bool toggle )
33 : QAction( parent, name, toggle )
38 Name: QtxAction [public]
39 Desc: This constructor creates an action with the following properties: the
40 description text, the icon or iconset icon, the menu text and keyboard
41 accelerator. It is a child of given parent and named specified name.
42 If toggle is true the action will be a toggle action, otherwise it will
46 QtxAction::QtxAction( const QString& text, const QIconSet& icon,
47 const QString& menuText, int accel,
48 QObject* parent, const char* name, bool toggle )
49 : QAction( text, icon, menuText, accel, parent, name, toggle )
54 Name: QtxAction [public]
55 Desc: This constructor creates an action with the following properties: the
56 description text, the menu text and keyboard accelerator. It is a child
57 of given parent and named specified name. If toggle is true the action
58 will be a toggle action, otherwise it will be a command action.
61 QtxAction::QtxAction( const QString& text, const QString& menuText, int accel,
62 QObject* parent, const char* name, bool toggle )
63 : QAction( text, menuText, accel, parent, name, toggle )
68 Name: ~QtxAction [virtual public]
72 QtxAction::~QtxAction()
77 Name: addTo [virtual public]
78 Desc: Adds this action to widget. Returns true if the action was added
79 successfully and false otherwise.
82 bool QtxAction::addTo( QWidget* w )
84 return QAction::addTo( w );
88 Name: addTo [virtual public]
89 Desc: Adds this action to widget. If widget is QPopupMenu given index will
90 be used for menu item inserting. Returns true if the action was added
91 successfully and false otherwise.
94 bool QtxAction::addTo( QWidget* w, int index )
99 if ( w->inherits( "QPopupMenu" ) )
101 QPopupMenu* popup = (QPopupMenu*)w;
102 if ( index < (int)popup->count() - 1 )
104 int id = popup->idAt( popup->count() - 1 );
107 QMenuItem* item = popup->findItem( id );
108 if ( item && item->isSeparator() )
110 popup->removeItem( id );
111 popup->insertSeparator( index );
115 QPopupMenu* p = item ? item->popup() : 0;
116 int accel = popup->accel( id );
117 bool isOn = popup->isItemEnabled( id );
118 QString text = popup->text( id );
120 if ( popup->iconSet( id ) )
121 icon = *popup->iconSet( id );
122 popup->removeItem( id );
126 pos = popup->indexOf( popup->insertItem( text, p, id, index ) );
128 pos = popup->indexOf( popup->insertItem( text, id, index ) );
131 pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) );
133 pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) );
134 popup->setId( pos, id );
135 popup->setAccel( accel, id );
136 popup->setItemEnabled( id, isOn );
138 popup->connectItem( id, this, SLOT( internalActivation() ) );
148 Name: setPopup [virtual public]
149 Desc: Set or unset the sub popup menu for item with specified id in the given popup.
152 void QtxAction::setPopup( QPopupMenu* popup, const int id, QPopupMenu* subPopup ) const
158 const QMenuData* pmd = popup;
159 QMenuItem* item = popup->findItem( id, &md );
160 if ( !item || md != pmd )
163 QPopupMenu* oldPopup = item->popup();
164 if ( oldPopup == subPopup )
167 int accel = popup->accel( id );
168 bool isOn = popup->isItemEnabled( id );
169 QString text = popup->text( id );
171 if ( popup->iconSet( id ) )
172 icon = *popup->iconSet( id );
173 popup->removeItem( id );
177 pos = popup->indexOf( subPopup ? popup->insertItem( text, subPopup ) : popup->insertItem( text ) );
179 pos = popup->indexOf( subPopup ? popup->insertItem( icon, text, subPopup ) : popup->insertItem( icon, text ) );
181 popup->setId( pos, id );
182 popup->setAccel( accel, id );
183 popup->setItemEnabled( id, isOn );