Sayonara Player
Loading...
Searching...
No Matches
Shortcut.h
1/* Shortcut.h */
2
3/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef SHORTCUT_H
22#define SHORTCUT_H
23
24#include "ShortcutIdentifier.h"
25#include "Utils/Pimpl.h"
26
27#include <QShortcut>
28
29#define ShortcutHandlerPrivate private
30
31class QKeySequence;
32class QWidget;
42{
43 private:
44 PIMPL(Shortcut)
45
46 Shortcut();
47
54 QList<QShortcut*> initQtShortcut(QWidget* parent, Qt::ShortcutContext context);
55
56 friend class ShortcutHandler;
57 ShortcutHandlerPrivate:
58 void setQtShortcuts(const QList<QShortcut*>& qshortcuts);
59 void removeQtShortcut(QShortcut* qshortcut);
60 QList<QShortcut*> qtShortcuts() const;
61
62 public:
69 Shortcut(ShortcutIdentifier identifier, const QString& defaultShortcut);
70
77 Shortcut(ShortcutIdentifier identifier, const QStringList& defaultShortcuts);
78
83 Shortcut(const Shortcut& other);
84
85 Shortcut& operator=(const Shortcut& other);
86
87 ~Shortcut();
88
94
99 void changeShortcut(const QStringList& shortcuts);
100
105 QString name() const;
106
111 QStringList defaultShortcut() const;
112
118 QKeySequence sequence() const;
119
124 const QStringList& shortcuts() const;
125
130 ShortcutIdentifier identifier() const;
131 QString databaseKey() const;
132
137 bool isValid() const;
138
139 template<typename T>
145 void connect(QWidget* parent, T func, Qt::ShortcutContext context = Qt::WindowShortcut)
146 {
147 QList<QShortcut*> shortcuts = initQtShortcut(parent, context);
148 for(QShortcut* sc: shortcuts)
149 {
150 QObject::connect(sc, &QShortcut::activated, parent, func);
151 }
152 }
153
160 void
161 connect(QWidget* parent, QObject* receiver, const char* slot, Qt::ShortcutContext context = Qt::WindowShortcut);
162};
163
164#endif // SHORTCUT_H
Definition EngineUtils.h:33
A singleton class for retrieving shortcuts.
Definition ShortcutHandler.h:41
A single shortcut managed by ShortcutHandler. This class holds information about the default shortcut...
Definition Shortcut.h:42
bool isValid() const
Check if the shortcut is valid or if it was retrieved via getInvalid()
void connect(QWidget *parent, T func, Qt::ShortcutContext context=Qt::WindowShortcut)
create a qt shortcut for a widget
Definition Shortcut.h:145
void changeShortcut(const QStringList &shortcuts)
QString name() const
get the human-readable name of the shortcut
void connect(QWidget *parent, QObject *receiver, const char *slot, Qt::ShortcutContext context=Qt::WindowShortcut)
create a qt shortcut for a widget
QStringList defaultShortcut() const
get a human-readable list of mapped default shortcuts
static Shortcut getInvalid()
get a raw and invalid shortcut. This function is used instead of the default constructor
Shortcut(const Shortcut &other)
Copy constructor.
ShortcutIdentifier identifier() const
get the unique identifier
const QStringList & shortcuts() const
get a human-readable list of mapped shortcuts
Shortcut(ShortcutIdentifier identifier, const QStringList &defaultShortcuts)
Shortcut.
Shortcut(ShortcutIdentifier identifier, const QString &defaultShortcut)
Shortcut.
QList< QKeySequence > sequences() const
get a list key squences mapped to this shortcut