1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************
20 * Parts of this implementation are taken from KDE's kaction.cpp *
21 ***************************************************************************/
25 #include <QApplication>
27 Action::Action(QObject* parent)
28 : QWidgetAction(parent)
30 setProperty("isShortcutConfigurable", true);
31 connect(this, &QAction::triggered, this, &Action::slotTriggered);
34 Action::Action(const QString& text, QObject* parent, const QKeySequence& shortcut)
38 setShortcut(shortcut);
41 Action::Action(const QIcon& icon, const QString& text, QObject* parent, const QKeySequence& shortcut)
42 : Action(text, parent, shortcut)
47 void Action::slotTriggered()
49 emit triggered(QApplication::mouseButtons(), QApplication::keyboardModifiers());
52 bool Action::isShortcutConfigurable() const
54 return property("isShortcutConfigurable").toBool();
57 void Action::setShortcutConfigurable(bool b)
59 setProperty("isShortcutConfigurable", b);
62 QKeySequence Action::shortcut(ShortcutTypes type) const
65 if (type == DefaultShortcut) {
66 auto sequence = property("defaultShortcuts").value<QList<QKeySequence>>();
67 return sequence.isEmpty() ? QKeySequence() : sequence.first();
70 return shortcuts().isEmpty() ? QKeySequence() : shortcuts().first();
73 void Action::setShortcut(const QShortcut& shortcut, ShortcutTypes type)
75 setShortcut(shortcut.key(), type);
78 void Action::setShortcut(const QKeySequence& key, ShortcutTypes type)
82 if (type & DefaultShortcut) {
83 setProperty("defaultShortcuts", QVariant::fromValue(QList<QKeySequence>() << key));
85 if (type & ActiveShortcut)
86 QAction::setShortcut(key);