51 #include <private/qshortcutmap_p.h> 52 #include <private/qapplication_p.h> 53 #include <private/qmenu_p.h> 55 #define QAPP_CHECK(functionName) \ 57 qWarning("QAction: Initialize QApplication before calling '" functionName "'."); \ 70 while (i < s.
size()) {
83 visible(1), forceInvisible(0), checkable(0), checked(0), separator(0), fontSet(false),
84 forceEnabledInSoftkeys(false), menuActionSoftkeys(false),
85 iconVisibleInMenu(-1),
86 menuRole(
QAction::TextHeuristicRole), softKeyRole(
QAction::NoSoftKey),
87 priority(
QAction::NormalPriority)
90 static int qt_static_action_id = -1;
91 param =
id = --qt_static_action_id;
94 #ifndef QT_NO_SHORTCUT 107 #ifdef QT_NO_STATUSTIP 128 #ifndef QT_NO_GRAPHICSVIEW 139 #ifndef QT_NO_SHORTCUT 195 #endif // QT_NO_SHORTCUT 334 d->group->addAction(
this);
358 d->group->addAction(
this);
381 d->group->addAction(
this);
393 d->group->addAction(
this);
422 #ifndef QT_NO_GRAPHICSVIEW 435 return d->graphicsWidgets;
439 #ifndef QT_NO_SHORTCUT 455 if (
d->shortcut == shortcut)
459 d->redoGrab(
qApp->d_func()->shortcutMap);
460 d->sendDataChanged();
484 if (
d->shortcut == primary &&
d->alternateShortcuts == listCopy)
489 d->shortcut = primary;
490 d->alternateShortcuts = listCopy;
491 d->redoGrab(
qApp->d_func()->shortcutMap);
492 d->redoGrabAlternate(
qApp->d_func()->shortcutMap);
493 d->sendDataChanged();
541 if (!
d->shortcut.isEmpty())
542 shortcuts <<
d->shortcut;
543 if (!
d->alternateShortcuts.isEmpty())
544 shortcuts <<
d->alternateShortcuts;
561 if (
d->shortcutContext == context)
564 d->shortcutContext = context;
565 d->redoGrab(
qApp->d_func()->shortcutMap);
566 d->redoGrabAlternate(
qApp->d_func()->shortcutMap);
567 d->sendDataChanged();
573 return d->shortcutContext;
592 if (
d->autorepeat == on)
596 d->redoGrab(
qApp->d_func()->shortcutMap);
597 d->redoGrabAlternate(
qApp->d_func()->shortcutMap);
598 d->sendDataChanged();
604 return d->autorepeat;
606 #endif // QT_NO_SHORTCUT 631 d->sendDataChanged();
652 d->group->addAction(
this);
669 d->group->addAction(
this);
687 d->group->addAction(
this);
697 for (
int i =
d->widgets.size()-1; i >= 0; --i) {
701 #ifndef QT_NO_GRAPHICSVIEW 702 for (
int i =
d->graphicsWidgets.size()-1; i >= 0; --i) {
708 d->group->removeAction(
this);
709 #ifndef QT_NO_SHORTCUT 710 if (
d->shortcutId &&
qApp) {
711 qApp->d_func()->shortcutMap.removeShortcut(
d->shortcutId,
this);
712 for(
int i = 0; i <
d->alternateShortcutIds.count(); ++i) {
713 const int id =
d->alternateShortcutIds.at(i);
714 qApp->d_func()->shortcutMap.removeShortcut(
id,
this);
731 if(group ==
d->group)
735 d->group->removeAction(
this);
776 d->sendDataChanged();
806 d->menu->d_func()->setOverrideMenuAction(0);
809 menu->d_func()->setOverrideMenuAction(
this);
810 d->sendDataChanged();
826 if (
d->separator == b)
830 d->sendDataChanged();
867 d->sendDataChanged();
910 if (
d->iconText == text)
914 d->sendDataChanged();
920 if (
d->iconText.isEmpty())
942 if (
d->tooltip == tooltip)
945 d->tooltip = tooltip;
946 d->sendDataChanged();
952 if (
d->tooltip.isEmpty()) {
953 if (!
d->text.isEmpty())
977 if (
d->statustip == statustip)
980 d->statustip = statustip;
981 d->sendDataChanged();
1006 if (
d->whatsthis == whatsthis)
1009 d->whatsthis = whatsthis;
1010 d->sendDataChanged();
1016 return d->whatsthis;
1059 if (
d->priority == priority)
1063 d->sendDataChanged();
1097 if (
d->checkable == b)
1102 d->sendDataChanged();
1108 return d->checkable;
1141 if (!
d->checkable ||
d->checked == b)
1146 d->sendDataChanged();
1195 if (b ==
d->enabled && b !=
d->forceDisabled)
1197 d->forceDisabled = !b;
1198 if (b && (!
d->visible || (
d->group && !
d->group->isEnabled())))
1202 #ifndef QT_NO_SHORTCUT 1203 d->setShortcutEnabled(b,
qApp->d_func()->shortcutMap);
1205 d->sendDataChanged();
1233 if (b ==
d->visible && b !=
d->forceInvisible)
1236 d->forceInvisible = !b;
1238 d->enabled = b && !
d->forceDisabled && (!
d->group ||
d->group->isEnabled()) ;
1239 #ifndef QT_NO_SHORTCUT 1240 d->setShortcutEnabled(
d->enabled,
qApp->d_func()->shortcutMap);
1242 d->sendDataChanged();
1258 #ifndef QT_NO_SHORTCUT 1261 Q_ASSERT_X(se->
key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->
key()),
1263 "Received shortcut event from incorrect shortcut");
1301 d->sendDataChanged();
1317 return d_func()->showStatusText(widget,
statusTip());
1334 if (
d->checked && (
d->group &&
d->group->isExclusive()
1335 &&
d->group->checkedAction() ==
this)) {
1347 emit activated(
d->param);
1350 }
else if(event ==
Hover) {
1572 if (
d->menuRole == menuRole)
1576 d->sendDataChanged();
1602 if (
d->softKeyRole == softKeyRole)
1606 d->sendDataChanged();
1612 return d->softKeyRole;
1639 if (
d->iconVisibleInMenu == -1 || visible !=
bool(
d->iconVisibleInMenu)) {
1640 int oldValue =
d->iconVisibleInMenu;
1646 d->sendDataChanged();
1654 if (
d->iconVisibleInMenu == -1) {
1657 return d->iconVisibleInMenu;
1662 #include "moc_qaction.cpp" 1664 #endif // QT_NO_ACTION void setShortcutContext(Qt::ShortcutContext context)
The QVariant class acts like a union for the most common Qt data types.
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
bool event(QEvent *)
Reimplemented Function
void setShortcut(const QKeySequence &shortcut)
#define QT_END_NAMESPACE
This macro expands to.
int setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key=QKeySequence())
Changes the enable state of a shortcut to enable.
void setStatusTip(const QString &statusTip)
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
const QChar at(int i) const
Returns the character at the given index position in the string.
bool showStatusText(QWidget *widget=0)
Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent w...
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
void setSeparator(bool b)
If b is true then this action will be considered a separator.
void setFont(const QFont &font)
ActionEvent
This enum type is used when calling QAction::activate()
void setIconVisibleInMenu(bool visible)
QString & replace(int i, int len, QChar after)
QList< QWidget * > widgets
#define QAPP_CHECK(functionName)
void setMenu(QMenu *menu)
Sets the menu contained by this action to the specified menu.
QAction(QObject *parent)
Constructs an action with parent.
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
void setToolTip(const QString &tip)
Priority
This enum defines priorities for actions in user interface.
QList< int > alternateShortcutIds
void hovered()
This signal is emitted when an action is highlighted by the user; for example, when the user pauses w...
void setWhatsThis(const QString &what)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void toggle()
This is a convenience function for the checked property.
int count(const T &t) const
Returns the number of occurrences of value in the list.
StandardKey
This enum represent standard key bindings.
The QActionEvent class provides an event that is generated when a QAction is added, removed, or changed.
static QList< QKeySequence > keyBindings(StandardKey key)
Returns a list of key bindings for the given key.
Qt::ShortcutContext shortcutContext
void setMenuRole(MenuRole menuRole)
The QString class provides a Unicode character string.
void redoGrabAlternate(QShortcutMap &map)
T * qobject_cast(QObject *object)
static QString qt_strippedText(QString s)
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
The QActionGroup class groups actions together.
void setData(const QVariant &var)
Sets the action's internal data to the given userData.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void setObjectName(const QString &name)
QList< QWidget * > associatedWidgets() const
Returns a list of widgets this action has been added to.
QWidget * parentWidget() const
Returns the parent widget.
void append(const T &t)
Inserts value at the end of the list.
QKeySequence shortcut() const
bool isIconVisibleInMenu() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
void toggled(bool)
This signal is emitted whenever a checkable action changes its isChecked() status.
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
T takeFirst()
Removes the first item in the list and returns it.
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setSoftKeyRole(SoftKeyRole softKeyRole)
QList< QGraphicsWidget * > associatedGraphicsWidgets() const
Returns a list of widgets this action has been added to.
QString whatsThis() const
Priority priority() const
QAction * addAction(QAction *a)
Adds the action to this group, and returns it.
const T & at(int i) const
Returns the item at index position i in the list.
QList< QGraphicsWidget * > graphicsWidgets
void setIconText(const QString &text)
void setShortcutEnabled(bool enable, QShortcutMap &map)
void setPriority(Priority priority)
Q_CORE_EXPORT void qWarning(const char *,...)
void setText(const QString &text)
QList< QKeySequence > shortcuts() const
Returns the list of shortcuts, with the primary shortcut as the first element of the list...
SoftKeyRole softKeyRole() const
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool visible
whether the action can be seen (e.g.
SoftKeyRole
This enum describes how an action should be placed in the softkey bar.
void clear()
Removes all items from the list.
~QAction()
Destroys the object and frees allocated resources.
bool isEmpty() const
Returns true if the key sequence is empty; otherwise returns false.
void setShortcuts(const QList< QKeySequence > &shortcuts)
Sets shortcuts as the list of shortcuts that trigger the action.
const QKeySequence & key()
int setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key=QKeySequence())
Changes the auto repeat state of a shortcut to enable.
QList< QKeySequence > alternateShortcuts
#define Q_ASSERT_X(cond, where, what)
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
QMenu * menu() const
Returns the menu contained by this action.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
void redoGrab(QShortcutMap &map)
MenuRole menuRole() const
The QFont class specifies a font used for drawing text.
static QCoreApplication * instance()
Returns a pointer to the application's QCoreApplication (or QApplication) instance.
The QStatusTipEvent class provides an event that is used to show messages in a status bar...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
QObject * parent() const
Returns a pointer to the parent object.
QVariant data() const
Returns the user data as set in QAction::setData.
int size() const
Returns the number of items in the list.
int removeShortcut(int id, QObject *owner, const QKeySequence &key=QKeySequence())
Removes a shortcut from the global map.
if(void) toggleToolbarShown
void setActionGroup(QActionGroup *group)
Sets this action group to group.
void setIcon(const QIcon &icon)
Qt::ShortcutContext shortcutContext() const
MenuRole
This enum describes how an action should be moved into the application menu on Mac OS X...
int addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context)
Adds a shortcut to the global map.
QActionGroup * actionGroup() const
Returns the action group for this action.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
bool showStatusText(QWidget *w, const QString &str)
QString statusTip() const
const QChar * constData() const
Returns a pointer to the data stored in the QString.
The QAction class provides an abstract user interface action that can be inserted into widgets...
The QIcon class provides scalable icons in different modes and states.