Q3Action Class Reference

#include <q3action.h>

Inheritance diagram for Q3Action:

Inheritance graph
[legend]
Collaboration diagram for Q3Action:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3Action class provides an abstract user interface action that can appear both in menus and tool bars.

In GUI applications many commands can be invoked via a menu option, a toolbar button and a keyboard accelerator. Since the same action must be performed regardless of how the action was invoked, and since the menu and toolbar should be kept in sync, it is useful to represent a command as an action. An action can be added to a menu and a toolbar and will automatically keep them in sync. For example, if the user presses a Bold toolbar button the Bold menu item will automatically be checked.

A Q3Action may contain an icon, a menu text, an accelerator, a status text, a "What's This?" text and a tool tip. Most of these can be set in the constructor. They can also be set independently with setIconSet(), setText(), setMenuText(), setToolTip(), setStatusTip(), setWhatsThis() and setAccel().

An action may be a toggle action e.g. a Bold toolbar button, or a command action, e.g. 'Open File' to invoke an open file dialog. Toggle actions emit the toggled() signal when their state changes. Both command and toggle actions emit the activated() signal when they are invoked. Use setToggleAction() to set an action's toggled status. To see if an action is a toggle action use isToggleAction(). A toggle action may be "on", isOn() returns true, or "off", isOn() returns false.

Actions are added to widgets (menus or toolbars) using addTo(), and removed using removeFrom(). Note that when using Q3ToolBar and Q3PopupMenu, their actions must be Q3Actions.

Once a Q3Action has been created it should be added to the relevant menu and toolbar and then connected to the slot which will perform the action.

We recommend that actions are created as children of the window that they are used in. In most cases actions will be children of the application's main window.

To prevent recursion, don't create an action as a child of a widget that the action is later added to.

Definition at line 45 of file q3action.h.

Public Slots

void activate ()
void toggle ()
virtual void setOn (bool)
virtual void setEnabled (bool)
void setDisabled (bool)
virtual void setVisible (bool)

Signals

void activated ()
void toggled (bool)

Public Member Functions

 Q3Action (QObject *parent, const char *name=0)
 Q3Action (const QString &menuText, QKeySequence accel, QObject *parent, const char *name=0)
 Q3Action (const QIcon &icon, const QString &menuText, QKeySequence accel, QObject *parent, const char *name=0)
 Q3Action (const QString &text, const QIcon &icon, const QString &menuText, QKeySequence accel, QObject *parent, const char *name=0, bool toggle=false)
 Q3Action (const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name=0, bool toggle=false)
 Q3Action (QObject *parent, const char *name, bool toggle)
 ~Q3Action ()
virtual void setIconSet (const QIcon &)
QIcon iconSet () const
virtual void setText (const QString &)
QString text () const
virtual void setMenuText (const QString &)
QString menuText () const
virtual void setToolTip (const QString &)
QString toolTip () const
virtual void setStatusTip (const QString &)
QString statusTip () const
virtual void setWhatsThis (const QString &)
QString whatsThis () const
virtual void setAccel (const QKeySequence &key)
QKeySequence accel () const
virtual void setToggleAction (bool)
bool isToggleAction () const
bool isOn () const
bool isEnabled () const
bool isVisible () const
virtual bool addTo (QWidget *)
virtual bool removeFrom (QWidget *)

Protected Member Functions

virtual void addedTo (QWidget *actionWidget, QWidget *container)
virtual void addedTo (int index, Q3PopupMenu *menu)

Private Slots

void internalActivation ()
void toolButtonToggled (bool)
void objectDestroyed ()
void menuStatusText (int id)
void showStatusText (const QString &)
void clearStatusText ()

Private Member Functions

void init ()

Private Attributes

Q3ActionPrivated

Friends

class Q3ActionPrivate
class Q3ActionGroup
class Q3ActionGroupPrivate


Constructor & Destructor Documentation

Q3Action::Q3Action ( QObject parent,
const char *  name = 0 
)

Constructs an action called name with parent parent.

If parent is a Q3ActionGroup, the new action inserts itself into parent.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

Warning:
To prevent recursion, don't create an action as a child of a widget that the action is later added to.

Definition at line 411 of file q3action.cpp.

References d, init(), and Q3ActionPrivate.

Referenced by Q3ActionGroup::addSeparator().

00412     : QObject(parent, name)
00413 {
00414     d = new Q3ActionPrivate(this);
00415     init();
00416 }

Here is the call graph for this function:

Q3Action::Q3Action ( const QString menuText,
QKeySequence  accel,
QObject parent,
const char *  name = 0 
)

This constructor results in an icon-less action with the the menu text menuText and keyboard accelerator accel. It is a child of parent and called name.

If parent is a Q3ActionGroup, the action automatically becomes a member of it.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The action uses a stripped version of menuText (e.g. "&Menu Option..." becomes "Menu Option") as descriptive text for toolbuttons. You can override this by setting a specific description with setText(). The same text and accel will be used for tool tips and status tips unless you provide text for these using setToolTip() and setStatusTip().

Call setToggleAction(true) to make the action a toggle action.

Warning:
To prevent recursion, don't create an action as a child of a widget that the action is later added to.

Definition at line 501 of file q3action.cpp.

References accel(), d, init(), menuText(), Q3ActionPrivate::menutext, Q3ActionPrivate, qt_stripMenuText(), setAccel(), and Q3ActionPrivate::text.

00503     : QObject(parent, name)
00504 {
00505     d = new Q3ActionPrivate(this);
00506     d->text = qt_stripMenuText(menuText);
00507     d->menutext = menuText;
00508     setAccel(accel);
00509     init();
00510 }

Here is the call graph for this function:

Q3Action::Q3Action ( const QIcon icon,
const QString menuText,
QKeySequence  accel,
QObject parent,
const char *  name = 0 
)

This constructor creates an action with the following properties: the icon or icon icon, the menu text menuText and keyboard accelerator accel. It is a child of parent and called name.

If parent is a Q3ActionGroup, the action automatically becomes a member of it.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The action uses a stripped version of menuText (e.g. "&Menu Option..." becomes "Menu Option") as descriptive text for toolbuttons. You can override this by setting a specific description with setText(). The same text and accel will be used for tool tips and status tips unless you provide text for these using setToolTip() and setStatusTip().

Call setToggleAction(true) to make the action a toggle action.

Warning:
To prevent recursion, don't create an action as a child of a widget that the action is later added to.

Definition at line 465 of file q3action.cpp.

References accel(), d, init(), QIcon::isNull(), menuText(), Q3ActionPrivate::menutext, Q3ActionPrivate, qt_stripMenuText(), setAccel(), setIconSet(), and Q3ActionPrivate::text.

00467     : QObject(parent, name)
00468 {
00469     d = new Q3ActionPrivate(this);
00470     if (!icon.isNull())
00471         setIconSet(icon);
00472     d->text = qt_stripMenuText(menuText);
00473     d->menutext = menuText;
00474     setAccel(accel);
00475     init();
00476 }

Here is the call graph for this function:

Q3Action::Q3Action ( const QString text,
const QIcon icon,
const QString menuText,
QKeySequence  accel,
QObject parent,
const char *  name = 0,
bool  toggle = false 
)

This constructor creates an action with the following properties: the description text, the icon or icon icon, the menu text menuText and keyboard accelerator accel. It is a child of parent and called name. If toggle is true the action will be a toggle action, otherwise it will be a command action.

If parent is a Q3ActionGroup, the action automatically becomes a member of it.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The text and accel will be used for tool tips and status tips unless you provide specific text for these using setToolTip() and setStatusTip().

Definition at line 529 of file q3action.cpp.

References accel(), d, init(), QIcon::isNull(), menuText(), Q3ActionPrivate::menutext, Q3ActionPrivate, setAccel(), setIconSet(), text(), Q3ActionPrivate::text, and Q3ActionPrivate::toggleaction.

00530     : QObject(parent, name)
00531 {
00532     d = new Q3ActionPrivate(this);
00533     d->toggleaction = toggle;
00534     if (!icon.isNull())
00535         setIconSet(icon);
00536 
00537     d->text = text;
00538     d->menutext = menuText;
00539     setAccel(accel);
00540     init();
00541 }

Here is the call graph for this function:

Q3Action::Q3Action ( const QString text,
const QString menuText,
QKeySequence  accel,
QObject parent,
const char *  name = 0,
bool  toggle = false 
)

This constructor results in an icon-less action with the description text, the menu text menuText and the keyboard accelerator accel. Its parent is parent and it is called name. If toggle is true the action will be a toggle action, otherwise it will be a command action.

The action automatically becomes a member of parent if parent is a Q3ActionGroup.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The text and accel will be used for tool tips and status tips unless you provide specific text for these using setToolTip() and setStatusTip().

Definition at line 560 of file q3action.cpp.

References accel(), d, init(), menuText(), Q3ActionPrivate::menutext, Q3ActionPrivate, setAccel(), text(), Q3ActionPrivate::text, and Q3ActionPrivate::toggleaction.

00561     : QObject(parent, name)
00562 {
00563     d = new Q3ActionPrivate(this);
00564     d->toggleaction = toggle;
00565     d->text = text;
00566     d->menutext = menuText;
00567     setAccel(accel);
00568     init();
00569 }

Here is the call graph for this function:

Q3Action::Q3Action ( QObject parent,
const char *  name,
bool  toggle 
)

Constructs an action called name with parent parent.

If toggle is true the action will be a toggle action, otherwise it will be a command action.

If parent is a Q3ActionGroup, the new action inserts itself into parent.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

Definition at line 430 of file q3action.cpp.

References d, init(), Q3ActionPrivate, and Q3ActionPrivate::toggleaction.

00431     : QObject(parent, name)
00432 {
00433     d = new Q3ActionPrivate(this);
00434     d->toggleaction = toggle;
00435     init();
00436 }

Here is the call graph for this function:

Q3Action::~Q3Action (  ) 

Destroys the object and frees allocated resources.

Definition at line 585 of file q3action.cpp.

References d.

00586 {
00587     delete d;
00588 }


Member Function Documentation

void Q3Action::setIconSet ( const QIcon  )  [virtual]

Definition at line 603 of file q3action.cpp.

References d, i, Q3ActionPrivate::icon, Q3ActionPrivate::Icons, QIcon::isNull(), and Q3ActionPrivate::update().

Referenced by Q3Action(), and Q3ActionGroup::setIconSet().

00604 {
00605     register QIcon *i = d->icon;
00606     if (!icon.isNull())
00607         d->icon = new QIcon(icon);
00608     else
00609         d->icon = 0;
00610     delete i;
00611     d->update(Q3ActionPrivate::Icons);
00612 }

Here is the call graph for this function:

QIcon Q3Action::iconSet (  )  const

Definition at line 614 of file q3action.cpp.

References d, and Q3ActionPrivate::icon.

Referenced by Q3ActionGroup::addTo(), and Q3ActionGroupPrivate::update().

00615 {
00616     if (d->icon)
00617         return *d->icon;
00618     return QIcon();
00619 }

void Q3Action::setText ( const QString  )  [virtual]

Definition at line 627 of file q3action.cpp.

References d, text(), Q3ActionPrivate::text, and Q3ActionPrivate::update().

Referenced by Q3ActionGroup::setText().

00628 {
00629     d->text = text;
00630     d->update();
00631 }

Here is the call graph for this function:

QString Q3Action::text (  )  const

Definition at line 633 of file q3action.cpp.

References d, and Q3ActionPrivate::text.

Referenced by Q3ActionGroup::addTo(), addTo(), Q3ActionGroup::childEvent(), menuStatusText(), Q3Action(), Q3ActionGroup::setMenuText(), setMenuText(), Q3ActionGroup::setText(), setText(), Q3ActionGroup::setToolTip(), Q3ActionGroup::setWhatsThis(), showStatusText(), and Q3ActionGroupPrivate::update().

00634 {
00635     return d->text;
00636 }

void Q3Action::setMenuText ( const QString  )  [virtual]

Definition at line 651 of file q3action.cpp.

References d, Q3ActionPrivate::menutext, text(), and Q3ActionPrivate::update().

Referenced by Q3ActionGroup::setMenuText().

00652 {
00653     if (d->menutext == text)
00654         return;
00655 
00656     d->menutext = text;
00657     d->update();
00658 }

Here is the call graph for this function:

QString Q3Action::menuText (  )  const

Definition at line 660 of file q3action.cpp.

References d, and Q3ActionPrivate::menuText().

Referenced by Q3ActionGroup::addTo(), Q3Action(), Q3ActionGroup::setMenuText(), Q3ActionPrivate::update(), and Q3ActionGroupPrivate::update().

00661 {
00662     return d->menuText();
00663 }

Here is the call graph for this function:

void Q3Action::setToolTip ( const QString  )  [virtual]

Definition at line 680 of file q3action.cpp.

References d, Q3ActionPrivate::tooltip, and Q3ActionPrivate::update().

Referenced by Q3ActionGroup::setToolTip().

00681 {
00682     if (d->tooltip == tip)
00683         return;
00684 
00685     d->tooltip = tip;
00686     d->update();
00687 }

Here is the call graph for this function:

QString Q3Action::toolTip (  )  const

Definition at line 689 of file q3action.cpp.

References d, and Q3ActionPrivate::toolTip().

Referenced by Q3ActionGroup::add(), Q3ActionGroup::addTo(), Q3ActionGroup::setToolTip(), and Q3ActionGroupPrivate::update().

00690 {
00691     return d->toolTip();
00692 }

Here is the call graph for this function:

void Q3Action::setStatusTip ( const QString  )  [virtual]

Definition at line 707 of file q3action.cpp.

References d, Q3ActionPrivate::statustip, and Q3ActionPrivate::update().

00708 {
00709     // Old comment: ### Please reimp for Q3ActionGroup!
00710     // For consistency reasons even action groups should show
00711     // status tips (as they already do with tool tips)
00712     // Please change Q3ActionGroup class doc appropriately after
00713     // reimplementation.
00714 
00715     if (d->statustip == tip)
00716         return;
00717 
00718     d->statustip = tip;
00719     d->update();
00720 }

Here is the call graph for this function:

QString Q3Action::statusTip (  )  const

Definition at line 722 of file q3action.cpp.

References d, and Q3ActionPrivate::statusTip().

Referenced by clearStatusText(), and menuStatusText().

00723 {
00724     return d->statusTip();
00725 }

Here is the call graph for this function:

void Q3Action::setWhatsThis ( const QString  )  [virtual]

Definition at line 738 of file q3action.cpp.

References d, Q3ActionPrivate::update(), Q3ActionPrivate::whatsthis, and whatsThis().

Referenced by Q3ActionGroup::setWhatsThis().

00739 {
00740     if (d->whatsthis == whatsThis)
00741         return;
00742     d->whatsthis = whatsThis;
00743     d->update();
00744 }

Here is the call graph for this function:

QString Q3Action::whatsThis (  )  const

Definition at line 746 of file q3action.cpp.

References d, and Q3ActionPrivate::whatsthis.

Referenced by Q3ActionGroup::add(), Q3ActionGroup::addTo(), setWhatsThis(), Q3ActionGroup::setWhatsThis(), and Q3ActionGroupPrivate::update().

00747 {
00748     return d->whatsthis;
00749 }

void Q3Action::setAccel ( const QKeySequence key  )  [virtual]

Definition at line 765 of file q3action.cpp.

References Q3ActionPrivate::accel, Q3ActionPrivate::accelid, Q3Accel::connectItem(), d, data, Q3Accel::insertItem(), internalActivation(), key, Q3ActionPrivate::key, QObject::objectName(), p, QObject::parent(), qWarning(), SLOT, and Q3ActionPrivate::update().

Referenced by Q3Action().

00766 {
00767     if (d->key == key)
00768         return;
00769 
00770     d->key = key;
00771     delete d->accel;
00772     d->accel = 0;
00773 
00774     if (!(int)key) {
00775         d->update();
00776         return;
00777     }
00778 
00779     QObject* p = parent();
00780     while (p && !p->isWidgetType()) {
00781         p = p->parent();
00782     }
00783     if (p) {
00784         d->accel = new Q3Accel((QWidget*)p, this, "qt_action_accel");
00785         d->accelid = d->accel->insertItem(d->key);
00786         d->accel->connectItem(d->accelid, this, SLOT(internalActivation()));
00787     } else
00788         qWarning("Q3Action::setAccel() (%s) requires widget in parent chain", objectName().toLocal8Bit().data());
00789     d->update();
00790 }

Here is the call graph for this function:

QKeySequence Q3Action::accel (  )  const

Definition at line 793 of file q3action.cpp.

References d, and Q3ActionPrivate::key.

Referenced by Q3Action(), and Q3ActionGroupPrivate::update().

00794 {
00795     return d->key;
00796 }

void Q3Action::setToggleAction ( bool   )  [virtual]

Definition at line 816 of file q3action.cpp.

References d, Q3ActionPrivate::on, Q3ActionPrivate::toggleaction, and Q3ActionPrivate::update().

Referenced by Q3ActionGroup::setToggleAction().

00817 {
00818     if (enable == (bool)d->toggleaction)
00819         return;
00820 
00821     if (!enable)
00822         d->on = false;
00823 
00824     d->toggleaction = enable;
00825     d->update();
00826 }

Here is the call graph for this function:

bool Q3Action::isToggleAction (  )  const

Definition at line 828 of file q3action.cpp.

References d, and Q3ActionPrivate::toggleaction.

Referenced by activate(), internalActivation(), setOn(), toggle(), and toolButtonToggled().

00829 {
00830     return d->toggleaction;
00831 }

bool Q3Action::isOn (  )  const

Definition at line 892 of file q3action.cpp.

References d, and Q3ActionPrivate::on.

Referenced by internalActivation(), and toggle().

00893 {
00894     return d->on;
00895 }

bool Q3Action::isEnabled (  )  const

Definition at line 920 of file q3action.cpp.

References d, and Q3ActionPrivate::enabled.

Referenced by Q3ActionGroup::add(), Q3ActionGroup::setEnabled(), and Q3ActionGroupPrivate::update().

00921 {
00922     return d->enabled;
00923 }

bool Q3Action::isVisible (  )  const

Definition at line 962 of file q3action.cpp.

References d, and Q3ActionPrivate::visible.

Referenced by Q3ActionGroup::add(), and Q3ActionGroupPrivate::update().

00963 {
00964     return d->visible;
00965 }

bool Q3Action::addTo ( QWidget w  )  [virtual]

Adds this action to widget w.

Currently actions may be added to Q3ToolBar and Q3PopupMenu widgets.

An action added to a tool bar is automatically displayed as a tool button; an action added to a pop up menu appears as a menu option.

addTo() returns true if the action was added successfully and false otherwise. (If w is not a Q3ToolBar or Q3PopupMenu the action will not be added and false will be returned.)

See also:
removeFrom()

Definition at line 999 of file q3action.cpp.

References Q3ActionPrivate::Action4Item::action, Q3ActionPrivate::action4items, activated(), QWidget::addAction(), addedTo(), QList< T >::append(), clearStatusText(), Q3ActionPrivate::ComboItem::combo, Q3ActionPrivate::comboitems, QObject::connect(), QComboBox::count(), d, QObject::destroyed(), Q3ActionPrivate::EverythingElse, QString::fromLatin1(), Q3ActionPrivate::icon, Q3ActionPrivate::ComboItem::id, Q3ActionPrivate::MenuItem::id, QComboBox::insertItem(), internalActivation(), Q3ActionPrivate::menuitems, menuStatusText(), objectDestroyed(), QObject::objectName(), QIcon::pixmap(), Q3ActionPrivate::MenuItem::popup, qWarning(), QObject::setObjectName(), QAction::setSeparator(), SIGNAL, SLOT, Q3ActionPrivate::State, text(), Q3ActionPrivate::toggleaction, toggled(), Q3ActionPrivate::toolbuttons, toolButtonToggled(), Q3ActionPrivate::update(), Q3ActionPrivate::Visibility, w, and Q3ActionPrivate::Action4Item::widget.

01000 {
01001 #ifndef QT_NO_TOOLBAR
01002     if (::qobject_cast<Q3ToolBar*>(w)) {
01003         if (objectName() == QLatin1String("qt_separator_action")) {
01004             ((Q3ToolBar*)w)->addSeparator();
01005         } else {
01006             QString bname = objectName() + QLatin1String("_action_button");
01007             QToolButton* btn = new QToolButton((Q3ToolBar*) w);
01008             btn->setObjectName(bname);
01009             addedTo(btn, w);
01010             btn->setToggleButton(d->toggleaction);
01011             d->toolbuttons.append(btn);
01012             if (d->icon)
01013                 btn->setIconSet(*d->icon);
01014             d->update(Q3ActionPrivate::State | Q3ActionPrivate::Visibility | Q3ActionPrivate::EverythingElse) ;
01015             connect(btn, SIGNAL(clicked()), this, SIGNAL(activated()));
01016             connect(btn, SIGNAL(toggled(bool)), this, SLOT(toolButtonToggled(bool)));
01017             connect(btn, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
01018         }
01019     } else
01020 #endif
01021     if (qobject_cast<Q3PopupMenu*>(w)) {
01022         Q3ActionPrivate::MenuItem* mi = new Q3ActionPrivate::MenuItem;
01023         mi->popup = (Q3PopupMenu*) w;
01024         QIcon* dicon = d->icon;
01025         if (objectName() == QLatin1String("qt_separator_action"))
01026             mi->id = ((Q3PopupMenu*)w)->insertSeparator();
01027         else if (dicon)
01028             mi->id = mi->popup->insertItem(*dicon, QString::fromLatin1(""));
01029         else
01030             mi->id = mi->popup->insertItem(QString::fromLatin1(""));
01031         addedTo(mi->popup->indexOf(mi->id), mi->popup);
01032         mi->popup->connectItem(mi->id, this, SLOT(internalActivation()));
01033         d->menuitems.append(mi);
01034         d->update(Q3ActionPrivate::State | Q3ActionPrivate::Visibility | Q3ActionPrivate::EverythingElse);
01035         connect(mi->popup, SIGNAL(highlighted(int)), this, SLOT(menuStatusText(int)));
01036         connect(mi->popup, SIGNAL(aboutToHide()), this, SLOT(clearStatusText()));
01037         connect(mi->popup, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
01038     // Makes only sense when called by Q3ActionGroup::addTo
01039     } else if (qobject_cast<QComboBox*>(w)) {
01040         Q3ActionPrivate::ComboItem *ci = new Q3ActionPrivate::ComboItem;
01041         ci->combo = (QComboBox*)w;
01042         connect(ci->combo, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
01043         ci->id = ci->combo->count();
01044         if (objectName() == QLatin1String("qt_separator_action")) {
01045             if (d->icon)
01046                 ci->combo->insertItem(d->icon->pixmap(), text());
01047             else
01048                 ci->combo->insertItem(text());
01049         } else {
01050             ci->id = -1;
01051         }
01052         d->comboitems.append(ci);
01053         d->update(Q3ActionPrivate::State | Q3ActionPrivate::EverythingElse);
01054     } else if(qobject_cast<QMenu*>(w)) {
01055         Q3ActionPrivate::Action4Item *act = new Q3ActionPrivate::Action4Item;
01056         if(!act->action) { //static
01057             act->action = new QAction(this);
01058             if (objectName() == QLatin1String("qt_separator_action"))
01059                 act->action->setSeparator(true);
01060         }
01061         act->widget = w;
01062         act->widget->addAction(act->action);
01063         d->action4items.append(act);
01064         d->update(Q3ActionPrivate::State | Q3ActionPrivate::EverythingElse);
01065     } else {
01066         qWarning("Q3Action::addTo(), unknown object");
01067         return false;
01068     }
01069     return true;
01070 }

Here is the call graph for this function:

bool Q3Action::removeFrom ( QWidget w  )  [virtual]

Removes the action from widget w.

Returns true if the action was removed successfully; otherwise returns false.

See also:
addTo()

Definition at line 1183 of file q3action.cpp.

References Q3ActionPrivate::action4items, QList< T >::begin(), clearStatusText(), Q3ActionPrivate::comboitems, d, QObject::destroyed(), QObject::disconnect(), QList< T >::end(), Q3ActionPrivate::menuitems, menuStatusText(), objectDestroyed(), qWarning(), QList< T >::removeAll(), SIGNAL, SLOT, Q3ActionPrivate::toolbuttons, and w.

Referenced by Q3ActionGroup::childEvent().

01184 {
01185 #ifndef QT_NO_TOOLBAR
01186     if (::qobject_cast<Q3ToolBar*>(w)) {
01187         QList<QToolButton*>::Iterator it(d->toolbuttons.begin());
01188         QToolButton* btn;
01189         while (it != d->toolbuttons.end()) {
01190             btn = *it;
01191             ++it;
01192             if (btn->parentWidget() == w) {
01193                 d->toolbuttons.removeAll(btn);
01194                 disconnect(btn, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
01195                 delete btn;
01196                 // no need to disconnect from statusbar
01197             }
01198         }
01199     } else
01200 #endif
01201     if (::qobject_cast<Q3PopupMenu*>(w)) {
01202         QList<Q3ActionPrivate::MenuItem*>::Iterator it(d->menuitems.begin());
01203         Q3ActionPrivate::MenuItem* mi;
01204         while (it != d->menuitems.end()) {
01205             mi = *it;
01206             ++it;
01207             if (mi->popup == w) {
01208                 disconnect(mi->popup, SIGNAL(highlighted(int)), this, SLOT(menuStatusText(int)));
01209                 disconnect(mi->popup, SIGNAL(aboutToHide()), this, SLOT(clearStatusText()));
01210                 disconnect(mi->popup, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
01211                 mi->popup->removeItem(mi->id);
01212                 d->menuitems.removeAll(mi);
01213                 delete mi;
01214             }
01215         }
01216     } else if (::qobject_cast<QComboBox*>(w)) {
01217         QList<Q3ActionPrivate::ComboItem*>::Iterator it(d->comboitems.begin());
01218         Q3ActionPrivate::ComboItem *ci;
01219         while (it != d->comboitems.end()) {
01220             ci = *it;
01221             ++it;
01222             if (ci->combo == w) {
01223                 disconnect(ci->combo, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
01224                 d->comboitems.removeAll(ci);
01225                 delete ci;
01226             }
01227         }
01228     } else if (::qobject_cast<QMenu*>(w)) {
01229         QList<Q3ActionPrivate::Action4Item*>::Iterator it(d->action4items.begin());
01230         Q3ActionPrivate::Action4Item *a4i;
01231         while (it != d->action4items.end()) {
01232             a4i = *it;
01233             ++it;
01234             if (a4i->widget == w) {
01235                 a4i->widget->removeAction(a4i->action);
01236                 d->action4items.removeAll(a4i);
01237                 delete a4i;
01238             }
01239         }
01240     } else {
01241         qWarning("Q3Action::removeFrom(), unknown object");
01242         return false;
01243     }
01244     return true;
01245 }

Here is the call graph for this function:

void Q3Action::addedTo ( QWidget actionWidget,
QWidget container 
) [protected, virtual]

This function is called from the addTo() function when it has created a widget (actionWidget) for the action in the container.

Definition at line 1078 of file q3action.cpp.

Referenced by addTo().

01079 {
01080     Q_UNUSED(actionWidget);
01081     Q_UNUSED(container);
01082 }

void Q3Action::addedTo ( int  index,
Q3PopupMenu menu 
) [protected, virtual]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function is called from the addTo() function when it has created a menu item at the index position index in the popup menu menu.

Definition at line 1092 of file q3action.cpp.

01093 {
01094     Q_UNUSED(index);
01095     Q_UNUSED(menu);
01096 }

void Q3Action::activate (  )  [slot]

Activates the action and executes all connected slots. This only works for actions that are not toggle actions.

See also:
toggle()

Definition at line 839 of file q3action.cpp.

References activated(), data, emit, isToggleAction(), QObject::objectName(), and qWarning().

00840 {
00841     if (isToggleAction()) {
00842 #if defined(QT_CHECK_STATE)
00843         qWarning("Q3Action::%s() (%s) Toggle actions "
00844                   "can not be activated", "activate", objectName().toLocal8Bit().data());
00845 #endif
00846         return;
00847     }
00848     emit activated();
00849 }

void Q3Action::toggle (  )  [slot]

Toggles the state of a toggle action.

See also:
on, activate(), toggled(), isToggleAction()

Definition at line 856 of file q3action.cpp.

References data, isOn(), isToggleAction(), QObject::objectName(), qWarning(), and setOn().

00857 {
00858     if (!isToggleAction()) {
00859         qWarning("Q3Action::%s() (%s) Only toggle actions "
00860                   "can be switched", "toggle", objectName().toLocal8Bit().data());
00861         return;
00862     }
00863     setOn(!isOn());
00864 }

void Q3Action::setOn ( bool   )  [virtual, slot]

Definition at line 877 of file q3action.cpp.

References d, data, emit, isToggleAction(), QObject::objectName(), Q3ActionPrivate::on, qWarning(), Q3ActionPrivate::State, toggled(), and Q3ActionPrivate::update().

Referenced by internalActivation(), Q3ActionGroup::setOn(), toggle(), and toolButtonToggled().

00878 {
00879     if (!isToggleAction()) {
00880         if (enable)
00881             qWarning("Q3Action::%s() (%s) Only toggle actions "
00882                       "can be switched", "setOn", objectName().toLocal8Bit().data());
00883         return;
00884     }
00885     if (enable == (bool)d->on)
00886         return;
00887     d->on = enable;
00888     d->update(Q3ActionPrivate::State);
00889     emit toggled(enable);
00890 }

void Q3Action::setEnabled ( bool   )  [virtual, slot]

Definition at line 909 of file q3action.cpp.

References d, Q3ActionPrivate::enabled, Q3ActionPrivate::forceDisabled, Q3ActionPrivate::State, and Q3ActionPrivate::update().

Referenced by setDisabled(), and Q3ActionGroup::setEnabled().

00910 {
00911     d->forceDisabled = !enable;
00912 
00913     if ((bool)d->enabled == enable)
00914         return;
00915 
00916     d->enabled = enable;
00917     d->update(Q3ActionPrivate::State);
00918 }

void Q3Action::setDisabled ( bool  disable  )  [slot]

Disables the action if disable is true; otherwise enables the action.

See the enabled documentation for more information.

Definition at line 931 of file q3action.cpp.

References setEnabled().

00932 {
00933     setEnabled(!disable);
00934 }

void Q3Action::setVisible ( bool   )  [virtual, slot]

Definition at line 947 of file q3action.cpp.

References d, Q3ActionPrivate::forceInvisible, Q3ActionPrivate::update(), Q3ActionPrivate::Visibility, and Q3ActionPrivate::visible.

Referenced by Q3ActionGroup::setVisible().

00948 {
00949     d->forceInvisible = !visible;
00950 
00951     if ((bool)d->visible == visible)
00952         return;
00953 
00954     d->visible = visible;
00955     d->update(Q3ActionPrivate::Visibility);
00956 }

void Q3Action::activated (  )  [signal]

This signal is emitted when an action is activated by the user, e.g. when the user clicks a menu option or a toolbar button or presses an action's accelerator key combination.

Connect to this signal for command actions. Connect to the toggled() signal for toggle actions.

Referenced by activate(), Q3ActionGroup::add(), Q3ActionGroup::addTo(), addTo(), Q3ActionGroup::childActivated(), internalActivation(), and Q3ActionGroup::internalComboBoxActivated().

void Q3Action::toggled ( bool  on  )  [signal]

This signal is emitted when a toggle action changes state; command actions and {Q3ActionGroup}s don't emit toggled().

The on argument denotes the new state: If on is true the toggle action is switched on, and if on is false the toggle action is switched off.

To trigger a user command depending on whether a toggle action has been switched on or off connect it to a slot that takes a bool to indicate the state.

See also:
activated() setToggleAction() setOn()

Referenced by Q3ActionGroup::add(), Q3ActionGroup::addTo(), addTo(), and setOn().

void Q3Action::internalActivation (  )  [private, slot]

Definition at line 969 of file q3action.cpp.

References activated(), emit, isOn(), isToggleAction(), and setOn().

Referenced by addTo(), and setAccel().

00970 {
00971     if (isToggleAction())
00972         setOn(!isOn());
00973     emit activated();
00974 }

void Q3Action::toolButtonToggled ( bool   )  [private, slot]

Definition at line 978 of file q3action.cpp.

References isToggleAction(), and setOn().

Referenced by Q3ActionGroup::addTo(), and addTo().

00979 {
00980     if (!isToggleAction())
00981         return;
00982     setOn(on);
00983 }

void Q3Action::objectDestroyed (  )  [private, slot]

Definition at line 1250 of file q3action.cpp.

References Q3ActionPrivate::ComboItem::combo, Q3ActionPrivate::comboitems, d, i, Q3ActionPrivate::menuitems, Q3ActionPrivate::MenuItem::popup, QList< T >::removeAll(), QObject::sender(), and Q3ActionPrivate::toolbuttons.

Referenced by addTo(), and removeFrom().

01251 {
01252     const QObject* obj = sender();
01253     Q3ActionPrivate::MenuItem* mi;
01254     for (int i = 0; i < d->menuitems.size();) {
01255         mi = d->menuitems.at(i);
01256         ++i;
01257         if (mi->popup == obj) {
01258             d->menuitems.removeAll(mi);
01259             delete mi;
01260         }
01261     }
01262     Q3ActionPrivate::ComboItem *ci;
01263     QList<Q3ActionPrivate::ComboItem*>::Iterator it2(d->comboitems.begin());
01264     while (it2 != d->comboitems.end()) {
01265         ci = *it2;
01266         ++it2;
01267         if (ci->combo == obj) {
01268             d->comboitems.removeAll(ci);
01269             delete ci;
01270         }
01271     }
01272     d->toolbuttons.removeAll((QToolButton *)obj);
01273 }

void Q3Action::menuStatusText ( int  id  )  [private, slot]

Sets the status message to the menu item's status text, or to the tooltip, if there is no status text.

Definition at line 1146 of file q3action.cpp.

References clearStatusText(), d, QString::isEmpty(), Q3ActionPrivate::menuitems, showStatusText(), statusTip(), and text().

Referenced by addTo(), and removeFrom().

01147 {
01148     static int lastId = 0;
01149     QString text;
01150     QList<Q3ActionPrivate::MenuItem*>::Iterator it(d->menuitems.begin());
01151     while (it != d->menuitems.end()) {
01152         if ((*it)->id == id) {
01153             text = statusTip();
01154             break;
01155         }
01156         ++it;
01157     }
01158 
01159     if (!text.isEmpty())
01160         showStatusText(text);
01161     else if (id != lastId)
01162         clearStatusText();
01163     lastId = id;
01164 }

void Q3Action::showStatusText ( const QString text  )  [private, slot]

Sets the status message to text

Definition at line 1101 of file q3action.cpp.

References QStatusBar::clearMessage(), QString::isEmpty(), l, QObject::parent(), s, QObject::sender(), QStatusBar::showMessage(), QString::size(), and text().

Referenced by clearStatusText(), and menuStatusText().

01102 {
01103 #ifndef QT_NO_STATUSBAR
01104     // find out whether we are clearing the status bar by the popup that actually set the text
01105     static Q3PopupMenu *lastmenu = 0;
01106     QObject *s = (QObject*)sender();
01107     if (s) {
01108         Q3PopupMenu *menu = qobject_cast<Q3PopupMenu*>(s);
01109         if (menu && text.size())
01110             lastmenu = menu;
01111         else if (menu && text.isEmpty()) {
01112             if (lastmenu && menu != lastmenu)
01113                 return;
01114             lastmenu = 0;
01115         }
01116     }
01117 
01118     QObject* par = parent();
01119     QObject* lpar = 0;
01120     QStatusBar *bar = 0;
01121     while (par && !bar) {
01122         lpar = par;
01123         bar = (QStatusBar*)par->child(0, "QStatusBar", false);
01124         par = par->parent();
01125     }
01126     if (!bar && lpar) {
01127         QObjectList l = lpar->queryList("QStatusBar");
01128         if (l.isEmpty())
01129             return;
01130         // #### hopefully the last one is the one of the mainwindow...
01131         bar = static_cast<QStatusBar*>(l.at(l.size()-1));
01132     }
01133     if (bar) {
01134         if (text.isEmpty())
01135             bar->clearMessage();
01136         else
01137             bar->showMessage(text);
01138     }
01139 #endif
01140 }

void Q3Action::clearStatusText (  )  [private, slot]

Clears the status text.

Definition at line 1169 of file q3action.cpp.

References isEmpty(), showStatusText(), and statusTip().

Referenced by addTo(), Q3ActionGroup::internalComboBoxHighlighted(), menuStatusText(), and removeFrom().

01170 {
01171     if (!statusTip().isEmpty())
01172         showStatusText(QString());
01173 }

void Q3Action::init (  )  [private]

Definition at line 575 of file q3action.cpp.

References QObject::parent().

Referenced by Q3Action().

00576 {
00577     if (qobject_cast<Q3ActionGroup*>(parent()))
00578         ((Q3ActionGroup*) parent())->add(this);                // insert into action group
00579 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Q3ActionPrivate [friend]

Definition at line 134 of file q3action.h.

Referenced by Q3Action().

friend class Q3ActionGroup [friend]

Definition at line 135 of file q3action.h.

friend class Q3ActionGroupPrivate [friend]

Definition at line 136 of file q3action.h.


Member Data Documentation

Q3ActionPrivate* Q3Action::d [private]

Definition at line 132 of file q3action.h.

Referenced by accel(), addTo(), iconSet(), isEnabled(), isOn(), isToggleAction(), isVisible(), menuStatusText(), menuText(), objectDestroyed(), Q3Action(), removeFrom(), setAccel(), setEnabled(), setIconSet(), setMenuText(), setOn(), setStatusTip(), setText(), setToggleAction(), setToolTip(), setVisible(), setWhatsThis(), statusTip(), text(), toolTip(), whatsThis(), and ~Q3Action().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 15:40:18 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1