1 /***************************************************************************
2 * Copyright (C) 2005-09 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************
20 * Parts of this implementation are taken from KDE's kaction.cpp *
21 ***************************************************************************/
25 #include <QApplication>
27 Action::Action(QObject *parent)
31 : QWidgetAction(parent)
37 Action::Action(const QString &text, QObject *parent, const QObject *receiver, const char *slot, const QKeySequence &shortcut)
41 : QWidgetAction(parent)
46 setShortcut(shortcut);
48 connect(this, SIGNAL(triggered()), receiver, slot);
51 Action::Action(const QIcon &icon, const QString &text, QObject *parent, const QObject *receiver, const char *slot, const QKeySequence &shortcut)
55 : QWidgetAction(parent)
61 setShortcut(shortcut);
63 connect(this, SIGNAL(triggered()), receiver, slot);
67 void Action::init() { }
70 connect(this, SIGNAL(triggered(bool)), this, SLOT(slotTriggered()));
72 setProperty("isShortcutConfigurable", true);
75 void Action::slotTriggered() {
76 emit triggered(QApplication::mouseButtons(), QApplication::keyboardModifiers());
79 bool Action::isShortcutConfigurable() const {
80 return property("isShortcutConfigurable").toBool();
83 void Action::setShortcutConfigurable(bool b) {
84 setProperty("isShortcutConfigurable", b);
87 QKeySequence Action::shortcut(ShortcutTypes type) const {
89 if(type == DefaultShortcut)
90 return property("defaultShortcut").value<QKeySequence>();
92 if(shortcuts().count()) return shortcuts().value(0);
93 return QKeySequence();
96 void Action::setShortcut(const QShortcut &shortcut, ShortcutTypes type) {
97 setShortcut(shortcut.key(), type);
100 void Action::setShortcut(const QKeySequence &key, ShortcutTypes type) {
103 if(type & DefaultShortcut)
104 setProperty("defaultShortcut", key);
106 if(type & ActiveShortcut)
107 QAction::setShortcut(key);
110 #endif /* HAVE_KDE */