/quassel-0.7.3/src/uisupport/action.cpp
C++ | 110 lines | 72 code | 17 blank | 21 comment | 9 complexity | 3765d74a8934f55079ffe1e1f9567d34 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
1/***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
22
23#include "action.h"
24
25#include <QApplication>
26
27Action::Action(QObject *parent)
28#ifdef HAVE_KDE
29: KAction(parent)
30#else
31: QWidgetAction(parent)
32#endif
33{
34 init();
35}
36
37Action::Action(const QString &text, QObject *parent, const QObject *receiver, const char *slot, const QKeySequence &shortcut)
38#ifdef HAVE_KDE
39: KAction(parent)
40#else
41: QWidgetAction(parent)
42#endif
43{
44 init();
45 setText(text);
46 setShortcut(shortcut);
47 if(receiver && slot)
48 connect(this, SIGNAL(triggered()), receiver, slot);
49}
50
51Action::Action(const QIcon &icon, const QString &text, QObject *parent, const QObject *receiver, const char *slot, const QKeySequence &shortcut)
52#ifdef HAVE_KDE
53: KAction(parent)
54#else
55: QWidgetAction(parent)
56#endif
57{
58 init();
59 setIcon(icon);
60 setText(text);
61 setShortcut(shortcut);
62 if(receiver && slot)
63 connect(this, SIGNAL(triggered()), receiver, slot);
64}
65
66#ifdef HAVE_KDE
67void Action::init() { }
68#else
69void Action::init() {
70 connect(this, SIGNAL(triggered(bool)), this, SLOT(slotTriggered()));
71
72 setProperty("isShortcutConfigurable", true);
73}
74
75void Action::slotTriggered() {
76 emit triggered(QApplication::mouseButtons(), QApplication::keyboardModifiers());
77}
78
79bool Action::isShortcutConfigurable() const {
80 return property("isShortcutConfigurable").toBool();
81}
82
83void Action::setShortcutConfigurable(bool b) {
84 setProperty("isShortcutConfigurable", b);
85}
86
87QKeySequence Action::shortcut(ShortcutTypes type) const {
88 Q_ASSERT(type);
89 if(type == DefaultShortcut)
90 return property("defaultShortcut").value<QKeySequence>();
91
92 if(shortcuts().count()) return shortcuts().value(0);
93 return QKeySequence();
94}
95
96void Action::setShortcut(const QShortcut &shortcut, ShortcutTypes type) {
97 setShortcut(shortcut.key(), type);
98}
99
100void Action::setShortcut(const QKeySequence &key, ShortcutTypes type) {
101 Q_ASSERT(type);
102
103 if(type & DefaultShortcut)
104 setProperty("defaultShortcut", key);
105
106 if(type & ActiveShortcut)
107 QAction::setShortcut(key);
108}
109
110#endif /* HAVE_KDE */