modernize: Use override instead of virtual
[quassel.git] / src / uisupport / action.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************
20  * Parts of this API have been shamelessly stolen from KDE's kaction.h     *
21  ***************************************************************************/
22
23 #pragma once
24
25 #include "uisupport-export.h"
26
27 #include <QShortcut>
28 #include <QWidgetAction>
29
30 /// A specialized QWidgetAction, enhanced by some KDE features
31 /** This declares/implements a subset of KAction's API (notably we've left out global shortcuts
32  *  for now), which should make it easy to plug in KDE support later on.
33  */
34 class UISUPPORT_EXPORT Action : public QWidgetAction
35 {
36     Q_OBJECT
37
38     Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
39     Q_PROPERTY(bool shortcutConfigurable READ isShortcutConfigurable WRITE setShortcutConfigurable)
40     Q_FLAGS(ShortcutType)
41
42 public :
43         enum ShortcutType {
44         ActiveShortcut = 0x01,
45         DefaultShortcut = 0x02
46     };
47     Q_DECLARE_FLAGS(ShortcutTypes, ShortcutType)
48
49     explicit Action(QObject *parent);
50     Action(const QString &text, QObject *parent, const QObject *receiver = nullptr, const char *slot = nullptr, const QKeySequence &shortcut = 0);
51     Action(const QIcon &icon, const QString &text, QObject *parent, const QObject *receiver = nullptr, const char *slot = nullptr, const QKeySequence &shortcut = 0);
52
53     QKeySequence shortcut(ShortcutTypes types = ActiveShortcut) const;
54     void setShortcut(const QShortcut &shortcut, ShortcutTypes type = ShortcutTypes(ActiveShortcut | DefaultShortcut));
55     void setShortcut(const QKeySequence &shortcut, ShortcutTypes type = ShortcutTypes(ActiveShortcut | DefaultShortcut));
56
57     bool isShortcutConfigurable() const;
58     void setShortcutConfigurable(bool configurable);
59
60 signals:
61     void triggered(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
62
63 private:
64     void init();
65
66 private slots:
67     void slotTriggered();
68 };
69
70
71 Q_DECLARE_OPERATORS_FOR_FLAGS(Action::ShortcutTypes)