📄 q3action.cpp
字号:
for (QList<Q3Action*>::Iterator it(actions.begin()); it != actions.end(); ++it) { if (that->isEnabled() && !(*it)->d->forceDisabled) (*it)->setEnabled(true); else if (!that->isEnabled() && (*it)->isEnabled()) { (*it)->setEnabled(false); (*it)->d->forceDisabled = false; } if (that->isVisible() && !(*it)->d->forceInvisible) { (*it)->setVisible(true); } else if (!that->isVisible() && (*it)->isVisible()) { (*it)->setVisible(false); (*it)->d->forceInvisible = false; } } for (QList<QComboBox*>::Iterator cb(comboboxes.begin()); cb != comboboxes.end(); ++cb) { QComboBox *combobox = *cb; combobox->setEnabled(that->isEnabled()); combobox->setShown(that->isVisible());#ifndef QT_NO_TOOLTIP QToolTip::remove(combobox); if (that->toolTip().size()) QToolTip::add(combobox, that->toolTip());#endif#ifndef QT_NO_WHATSTHIS QWhatsThis::remove(combobox); if (that->whatsThis().size()) QWhatsThis::add(combobox, that->whatsThis());#endif } for (QList<QToolButton*>::Iterator mb(menubuttons.begin()); mb != menubuttons.end(); ++mb) { QToolButton *button = *mb; button->setEnabled(that->isEnabled()); button->setShown(that->isVisible()); if (!that->text().isNull()) button->setTextLabel(that->text()); if (!that->iconSet().isNull()) button->setIconSet(that->iconSet());#ifndef QT_NO_TOOLTIP QToolTip::remove(*mb); if (that->toolTip().size()) QToolTip::add(button, that->toolTip());#endif#ifndef QT_NO_WHATSTHIS QWhatsThis::remove(button); if (that->whatsThis().size()) QWhatsThis::add(button, that->whatsThis());#endif } if(QAction *act = Q3ActionGroupPrivate::Action4Item::action) { act->setVisible(that->isVisible()); act->setEnabled(that->isEnabled()); } for (QList<Q3ActionGroupPrivate::MenuItem*>::Iterator pu(menuitems.begin()); pu != menuitems.end(); ++pu) { QWidget* parent = (*pu)->popup->parentWidget(); if (::qobject_cast<Q3PopupMenu*>(parent)) { Q3PopupMenu* ppopup = (Q3PopupMenu*)parent; ppopup->setItemEnabled((*pu)->id, that->isEnabled()); ppopup->setItemVisible((*pu)->id, that->isVisible()); } else { (*pu)->popup->setEnabled(that->isEnabled()); } } for (QList<Q3PopupMenu*>::Iterator pm(popupmenus.begin()); pm != popupmenus.end(); ++pm) { Q3PopupMenu *popup = *pm; Q3PopupMenu *parent = ::qobject_cast<Q3PopupMenu*>(popup->parentWidget()); if (!parent) continue; int index; parent->findPopup(popup, &index); int id = parent->idAt(index); if (!that->iconSet().isNull()) parent->changeItem(id, that->iconSet(), that->menuText()); else parent->changeItem(id, that->menuText()); parent->setItemEnabled(id, that->isEnabled());#ifndef QT_NO_ACCEL parent->setAccel(that->accel(), id);#endif }}/*! \class Q3ActionGroup q3action.h \brief The Q3ActionGroup class groups actions together. \compat In some situations it is useful to group actions together. For example, if you have a left justify action, a right justify action and a center action, only one of these actions should be active at any one time, and one simple way of achieving this is to group the actions together in an action group. An action group can also be added to a menu or a toolbar as a single unit, with all the actions within the action group appearing as separate menu options and toolbar buttons. The actions in an action group emit their activated() (and for toggle actions, toggled()) signals as usual. The setExclusive() function is used to ensure that only one action is active at any one time: it should be used with actions which have their \c toggleAction set to true. Action group actions appear as individual menu options and toolbar buttons. For exclusive action groups use setUsesDropDown() to display the actions in a subwidget of any widget the action group is added to. For example, the actions would appear in a combobox in a toolbar or as a submenu in a menu. Actions can be added to an action group using add(), but normally they are added by creating the action with the action group as parent. Actions can have separators dividing them using addSeparator(). Action groups are added to widgets with addTo().*//*! Constructs an action group called \a name, with parent \a parent. The action group is exclusive by default. Call setExclusive(false) to make the action group non-exclusive.*/Q3ActionGroup::Q3ActionGroup(QObject* parent, const char* name) : Q3Action(parent, name){ d = new Q3ActionGroupPrivate; d->exclusive = true; d->dropdown = false; d->selected = 0; d->separatorAction = 0; connect(this, SIGNAL(selected(Q3Action*)), SLOT(internalToggle(Q3Action*)));}/*! Constructs an action group called \a name, with parent \a parent. If \a exclusive is true only one toggle action in the group will ever be active. \sa exclusive*/Q3ActionGroup::Q3ActionGroup(QObject* parent, const char* name, bool exclusive) : Q3Action(parent, name){ d = new Q3ActionGroupPrivate; d->exclusive = exclusive; d->dropdown = false; d->selected = 0; d->separatorAction = 0; connect(this, SIGNAL(selected(Q3Action*)), SLOT(internalToggle(Q3Action*)));}/*! Destroys the object and frees allocated resources.*/Q3ActionGroup::~Q3ActionGroup(){ QList<Q3ActionGroupPrivate::MenuItem*>::Iterator mit(d->menuitems.begin()); while (mit != d->menuitems.end()) { Q3ActionGroupPrivate::MenuItem *mi = *mit; ++mit; if (mi->popup) mi->popup->disconnect(SIGNAL(destroyed()), this, SLOT(objectDestroyed())); } QList<QComboBox*>::Iterator cbit(d->comboboxes.begin()); while (cbit != d->comboboxes.end()) { QComboBox *cb = *cbit; ++cbit; cb->disconnect(SIGNAL(destroyed()), this, SLOT(objectDestroyed())); } QList<QToolButton*>::Iterator mbit(d->menubuttons.begin()); while (mbit != d->menubuttons.end()) { QToolButton *mb = *mbit; ++mbit; mb->disconnect(SIGNAL(destroyed()), this, SLOT(objectDestroyed())); } QList<Q3PopupMenu*>::Iterator pmit(d->popupmenus.begin()); while (pmit != d->popupmenus.end()) { Q3PopupMenu *pm = *pmit; ++pmit; pm->disconnect(SIGNAL(destroyed()), this, SLOT(objectDestroyed())); } QList<Q3ActionGroupPrivate::Action4Item*>::Iterator itmi4(d->action4items.begin()); Q3ActionGroupPrivate::Action4Item* mi4; while (itmi4 != d->action4items.end()) { mi4 = *itmi4; ++itmi4; mi4->widget->removeAction(mi4->action); } delete Q3ActionPrivate::Action4Item::action; Q3ActionPrivate::Action4Item::action = 0; delete d->separatorAction; while (!d->menubuttons.isEmpty()) delete d->menubuttons.takeFirst(); while (!d->comboboxes.isEmpty()) delete d->comboboxes.takeFirst(); while (!d->menuitems.isEmpty()) delete d->menuitems.takeFirst(); while (!d->popupmenus.isEmpty()) delete d->popupmenus.takeFirst(); delete d;}/*! \property Q3ActionGroup::exclusive \brief whether the action group does exclusive toggling If exclusive is true only one toggle action in the action group can ever be active at any one time. If the user chooses another toggle action in the group the one they chose becomes active and the one that was active becomes inactive. \sa Q3Action::toggleAction*/void Q3ActionGroup::setExclusive(bool enable){ d->exclusive = enable;}bool Q3ActionGroup::isExclusive() const{ return d->exclusive;}/*! \property Q3ActionGroup::usesDropDown \brief whether the group's actions are displayed in a subwidget of the widgets the action group is added to Exclusive action groups added to a toolbar display their actions in a combobox with the action's \l Q3Action::text and \l Q3Action::iconSet properties shown. Non-exclusive groups are represented by a tool button showing their \l Q3Action::iconSet and text() property. In a popup menu the member actions are displayed in a submenu. Changing usesDropDown only affects \e subsequent calls to addTo(). This property's default is false.*/void Q3ActionGroup::setUsesDropDown(bool enable){ d->dropdown = enable;}bool Q3ActionGroup::usesDropDown() const{ return d->dropdown;}/*! Adds action \a action to this group. Normally an action is added to a group by creating it with the group as parent, so this function is not usually used. \sa addTo()*/void Q3ActionGroup::add(Q3Action* action){ if (d->actions.contains(action)) return; d->actions.append(action); if (action->whatsThis().isNull()) action->setWhatsThis(whatsThis()); if (action->toolTip().isNull()) action->setToolTip(toolTip()); if (!action->d->forceDisabled) action->d->enabled = isEnabled(); if (!action->d->forceInvisible) action->d->visible = isVisible(); connect(action, SIGNAL(destroyed()), this, SLOT(childDestroyed())); connect(action, SIGNAL(activated()), this, SIGNAL(activated())); connect(action, SIGNAL(toggled(bool)), this, SLOT(childToggled(bool))); connect(action, SIGNAL(activated()), this, SLOT(childActivated())); for (QList<QComboBox*>::Iterator cb(d->comboboxes.begin()); cb != d->comboboxes.end(); ++cb) action->addTo(*cb); for (QList<QToolButton*>::Iterator mb(d->menubuttons.begin()); mb != d->menubuttons.end(); ++mb) { QMenu* menu = (*mb)->popup(); if (!menu) continue; action->addTo(menu); } for (QList<Q3ActionGroupPrivate::Action4Item*>::Iterator ac(d->action4items.begin()); ac != d->action4items.end(); ++ac) action->addTo((*ac)->action->menu()); for (QList<Q3ActionGroupPrivate::MenuItem*>::Iterator mi(d->menuitems.begin()); mi != d->menuitems.end(); ++mi) { Q3PopupMenu* popup = (*mi)->popup; if (!popup) continue; action->addTo(popup); }}/*! Adds a separator to the group.*/void Q3ActionGroup::addSeparator(){ if (!d->separatorAction) d->separatorAction = new Q3Action(0, "qt_separator_action"); d->actions.append(d->separatorAction);}/*! Adds this action group to the widget \a w. If isExclusive() is false or usesDropDown() is false, the actions within the group are added to the widget individually. For example, if the widget is a menu, the actions will appear as individual menu options, and if the widget is a toolbar, the actions will appear as toolbar buttons. If both isExclusive() and usesDropDown() are true, the actions are presented either in a combobox (if \a w is a toolbar) or in a submenu (if \a w is a menu). All actions should be added to the action group \e before the action group is added to the widget. If actions are added to the action group \e after the action group has been added to the widget these later actions will \e not appear. \sa setExclusive() setUsesDropDown() removeFrom()*/bool Q3ActionGroup::addTo(QWidget *w){#ifndef QT_NO_TOOLBAR if (qobject_cast<Q3ToolBar*>(w)) { if (d->dropdown) { if (!d->exclusive) { QList<Q3Action*>::Iterator it(d->actions.begin()); if (!(*it)) return true; Q3Action *defAction = *it; QToolButton* btn = new QToolButton((Q3ToolBar*) w, "qt_actiongroup_btn"); addedTo(btn, w); connect(btn, SIGNAL(destroyed()), SLOT(objectDestroyed())); d->menubuttons.append(btn); if (!iconSet().isNull()) btn->setIconSet(iconSet()); else if (!defAction->iconSet().isNull()) btn->setIconSet(defAction->iconSet()); if (text().size()) btn->setTextLabel(text()); else if (defAction->text().size()) btn->setTextLabel(defAction->text());#ifndef QT_NO_TOOLTIP if (toolTip().size()) QToolTip::add(btn, toolTip()); else if (defAction->toolTip().size()) QToolTip::add(btn, defAction->toolTip());#endif#ifndef QT_NO_WHATSTHIS if (whatsThis().size()) QWhatsThis::add(btn, whatsThis()); else if (defAction->whatsThis().size()) QWhatsThis::add(btn, defAction->whatsThis());#endif connect(btn, SIGNAL(clicked()), defAction, SIGNAL(activated())); connect(btn, SIGNAL(toggled(bool)), defAction, SLOT(toolButtonToggled(bool))); connect(btn, SIGNAL(destroyed()), defAction, SLOT(objectDestroyed())); Q3PopupMenu *menu = new Q3PopupMenu(btn, "qt_actiongroup_menu"); btn->setPopupDelay(0); btn->setPopup(menu); btn->setPopupMode(QToolButton::MenuButtonPopup); while (it != d->actions.end()) { (*it)->addTo(menu); ++it; } d->update(this); return true; } else { QComboBox *box = new QComboBox(false, w, "qt_actiongroup_combo"); addedTo(box, w); connect(box, SIGNAL(destroyed()), SLOT(objectDestroyed())); d->comboboxes.append(box);#ifndef QT_NO_TOOLTIP if (toolTip().size()) QToolTip::add(box, toolTip());#endif#ifndef QT_NO_WHATSTHIS if (whatsThis().size()) QWhatsThis::add(box, whatsThis());#endif int onIndex = 0; bool foundOn = false; for (QList<Q3Action*>::Iterator it(d->actions.begin()); it != d->actions.end(); ++it) { Q3Action *action = *it; if (!foundOn) foundOn = action->isOn(); if (action->objectName() != QLatin1String("qt_separator_action") && !foundOn) onIndex++; action->addTo(box); } if (foundOn) box->setCurrentItem(onIndex); connect(box, SIGNAL(activated(int)), this, SLOT(internalComboBoxActivated(int))); connect(box, SIGNAL(highlighted(int)), this, SLOT(internalComboBoxHighlighted(int))); d->update(this); return true; } } } else#endif if (::qobject_cast<Q3PopupMenu*>(w)) { Q3PopupMenu *popup; if (d->dropdown) { Q3PopupMenu *menu = (Q3PopupMenu*)w; popup = new Q3PopupMenu(w, "qt_actiongroup_menu"); d->popupmenus.append(popup); connect(popup, SIGNAL(destroyed()), SLOT(objectDestroyed())); int id; if (!iconSet().isNull()) { if (menuText().isEmpty())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -