📄 q3action.cpp
字号:
For accelerators and status tips to work, \a parent must either be a widget, or an action group whose parent is a widget.*/Q3Action::Q3Action(QObject* parent, const char* name, bool toggle) : QObject(parent, name){ d = new Q3ActionPrivate(this); d->toggleaction = toggle; init();}#ifndef QT_NO_ACCEL/*! This constructor creates an action with the following properties: the icon or icon \a icon, the menu text \a menuText and keyboard accelerator \a accel. It is a child of \a parent and called \a name. If \a parent is a Q3ActionGroup, the action automatically becomes a member of it. For accelerators and status tips to work, \a parent must either be a widget, or an action group whose parent is a widget. The action uses a stripped version of \a menuText (e.g. "\&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description with setText(). The same text and \a 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.*/Q3Action::Q3Action(const QIcon& icon, const QString& menuText, QKeySequence accel, QObject* parent, const char* name) : QObject(parent, name){ d = new Q3ActionPrivate(this); if (!icon.isNull()) setIconSet(icon); d->text = qt_stripMenuText(menuText); d->menutext = menuText; setAccel(accel); init();}/*! This constructor results in an icon-less action with the the menu text \a menuText and keyboard accelerator \a accel. It is a child of \a parent and called \a name. If \a parent is a Q3ActionGroup, the action automatically becomes a member of it. For accelerators and status tips to work, \a parent must either be a widget, or an action group whose parent is a widget. The action uses a stripped version of \a menuText (e.g. "\&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description with setText(). The same text and \a 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.*/Q3Action::Q3Action(const QString& menuText, QKeySequence accel, QObject* parent, const char* name) : QObject(parent, name){ d = new Q3ActionPrivate(this); d->text = qt_stripMenuText(menuText); d->menutext = menuText; setAccel(accel); init();}/*! This constructor creates an action with the following properties: the description \a text, the icon or icon \a icon, the menu text \a menuText and keyboard accelerator \a accel. It is a child of \a parent and called \a name. If \a toggle is true the action will be a toggle action, otherwise it will be a command action. If \a parent is a Q3ActionGroup, the action automatically becomes a member of it. For accelerators and status tips to work, \a parent must either be a widget, or an action group whose parent is a widget. The \a text and \a accel will be used for tool tips and status tips unless you provide specific text for these using setToolTip() and setStatusTip().*/Q3Action::Q3Action(const QString& text, const QIcon& icon, const QString& menuText, QKeySequence accel, QObject* parent, const char* name, bool toggle) : QObject(parent, name){ d = new Q3ActionPrivate(this); d->toggleaction = toggle; if (!icon.isNull()) setIconSet(icon); d->text = text; d->menutext = menuText; setAccel(accel); init();}/*! This constructor results in an icon-less action with the description \a text, the menu text \a menuText and the keyboard accelerator \a accel. Its parent is \a parent and it is called \a name. If \a toggle is true the action will be a toggle action, otherwise it will be a command action. The action automatically becomes a member of \a parent if \a parent is a Q3ActionGroup. For accelerators and status tips to work, \a parent must either be a widget, or an action group whose parent is a widget. The \a text and \a accel will be used for tool tips and status tips unless you provide specific text for these using setToolTip() and setStatusTip().*/Q3Action::Q3Action(const QString& text, const QString& menuText, QKeySequence accel, QObject* parent, const char* name, bool toggle) : QObject(parent, name){ d = new Q3ActionPrivate(this); d->toggleaction = toggle; d->text = text; d->menutext = menuText; setAccel(accel); init();}#endif/*! \internal*/void Q3Action::init(){ if (qobject_cast<Q3ActionGroup*>(parent())) ((Q3ActionGroup*) parent())->add(this); // insert into action group}/*! Destroys the object and frees allocated resources.*/Q3Action::~Q3Action(){ delete d;}/*! \property Q3Action::iconSet \brief the action's icon The icon is used as the tool button icon and in the menu to the left of the menu text. There is no default icon. If a null icon (QIcon::isNull() is passed into this function, the icon of the action is cleared. (See the action/toggleaction/toggleaction.cpp example.)*/void Q3Action::setIconSet(const QIcon& icon){ register QIcon *i = d->icon; if (!icon.isNull()) d->icon = new QIcon(icon); else d->icon = 0; delete i; d->update(Q3ActionPrivate::Icons);}QIcon Q3Action::iconSet() const{ if (d->icon) return *d->icon; return QIcon();}/*! \property Q3Action::text \brief the action's descriptive text \sa setMenuText() setToolTip() setStatusTip()*/void Q3Action::setText(const QString& text){ d->text = text; d->update();}QString Q3Action::text() const{ return d->text;}/*! \property Q3Action::menuText \brief the action's menu text If the action is added to a menu the menu option will consist of the icon (if there is one), the menu text and the accelerator (if there is one). If the menu text is not explicitly set in the constructor or by using setMenuText() the action's description text will be used as the menu text. There is no default menu text. \sa text*/void Q3Action::setMenuText(const QString& text){ if (d->menutext == text) return; d->menutext = text; d->update();}QString Q3Action::menuText() const{ return d->menuText();}/*! \property Q3Action::toolTip \brief the action's tool tip This text is used for the tool tip. If no status tip has been set the tool tip will be used for the status tip. If no tool tip is specified the action's text is used, and if that hasn't been specified the description text is used as the tool tip text. There is no default tool tip text. \sa setStatusTip() setAccel()*/void Q3Action::setToolTip(const QString& tip){ if (d->tooltip == tip) return; d->tooltip = tip; d->update();}QString Q3Action::toolTip() const{ return d->toolTip();}/*! \property Q3Action::statusTip \brief the action's status tip The statusTip is displayed on all status bars that this action's top-level parent widget provides. If no status tip is defined, the action uses the tool tip text. There is no default statusTip text. \sa setToolTip()*/void Q3Action::setStatusTip(const QString& tip){ // Old comment: ### Please reimp for Q3ActionGroup! // For consistency reasons even action groups should show // status tips (as they already do with tool tips) // Please change Q3ActionGroup class doc appropriately after // reimplementation. if (d->statustip == tip) return; d->statustip = tip; d->update();}QString Q3Action::statusTip() const{ return d->statusTip();}/*! \property Q3Action::whatsThis \brief the action's "What's This?" help text The whats this text is used to provide a brief description of the action. The text may contain rich text (HTML-like tags -- see QStyleSheet for the list of supported tags). There is no default "What's This?" text. \sa QWhatsThis*/void Q3Action::setWhatsThis(const QString& whatsThis){ if (d->whatsthis == whatsThis) return; d->whatsthis = whatsThis; d->update();}QString Q3Action::whatsThis() const{ return d->whatsthis;}#ifndef QT_NO_ACCEL/*! \property Q3Action::accel \brief the action's accelerator key The keycodes can be found in \l Qt::Key and \l Qt::Modifier. There is no default accelerator key.*///#### Please reimp for Q3ActionGroup!//#### For consistency reasons even Q3ActionGroups should respond to//#### their accelerators and e.g. open the relevant submenu.//#### Please change appropriate Q3ActionGroup class doc after//#### reimplementation.void Q3Action::setAccel(const QKeySequence& key){ if (d->key == key) return; d->key = key; delete d->accel; d->accel = 0; if (!(int)key) { d->update(); return; } QObject* p = parent(); while (p && !p->isWidgetType()) { p = p->parent(); } if (p) { d->accel = new Q3Accel((QWidget*)p, this, "qt_action_accel"); d->accelid = d->accel->insertItem(d->key); d->accel->connectItem(d->accelid, this, SLOT(internalActivation())); } else qWarning("Q3Action::setAccel() (%s) requires widget in parent chain", objectName().toLocal8Bit().data()); d->update();}QKeySequence Q3Action::accel() const{ return d->key;}#endif/*! \property Q3Action::toggleAction \brief whether the action is a toggle action A toggle action is one which has an on/off state. For example a Bold toolbar button is either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. This property's default is false. In some situations, the state of one toggle action should depend on the state of others. For example, "Left Align", "Center" and "Right Align" toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a Q3ActionGroup with the \l Q3ActionGroup::exclusive property set to true.*/void Q3Action::setToggleAction(bool enable){ if (enable == (bool)d->toggleaction) return; if (!enable) d->on = false; d->toggleaction = enable; d->update();}bool Q3Action::isToggleAction() const{ return d->toggleaction;}/*! Activates the action and executes all connected slots. This only works for actions that are not toggle actions. \sa toggle()*/void Q3Action::activate(){ if (isToggleAction()) {#if defined(QT_CHECK_STATE) qWarning("Q3Action::%s() (%s) Toggle actions " "can not be activated", "activate", objectName().toLocal8Bit().data());#endif return; } emit activated();}/*! Toggles the state of a toggle action. \sa on, activate(), toggled(), isToggleAction()*/void Q3Action::toggle(){ if (!isToggleAction()) { qWarning("Q3Action::%s() (%s) Only toggle actions " "can be switched", "toggle", objectName().toLocal8Bit().data()); return; } setOn(!isOn());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -