Sayonara Player
Shortcut.h
1 /* Shortcut.h */
2 
3 /* Copyright (C) 2011-2016 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 
22 
23 #ifndef SHORTCUT_H
24 #define SHORTCUT_H
25 
26 #include <QString>
27 #include <QWidget>
28 #include <QStringList>
29 #include <QShortcut>
30 #include <QKeySequence>
31 #include "Helper/Settings/SayonaraClass.h"
32 
33 class ShortcutWidget;
42 class Shortcut : private SayonaraClass
43 {
44 
45 private:
46  QStringList _default_shortcuts;
47  QStringList _shortcuts;
48  QString _name;
49  QString _identifier;
50  QList<QShortcut*> _qt_shortcuts;
51  ShortcutWidget* _parent=nullptr;
52 
53 private:
54  Shortcut();
55 
62  QList<QShortcut*> init_qt_shortcut(QWidget* parent);
63 
64 
65 public:
72  Shortcut(ShortcutWidget* parent, const QString& identifier, const QString& name, const QString& default_shortcut);
73 
80  Shortcut(ShortcutWidget* parent, const QString& identifier, const QString& name, const QStringList& default_shortcuts);
81 
86  Shortcut(const Shortcut& other);
87 
92  static Shortcut getInvalid();
93 
98  void change_shortcut(const QStringList& shortcuts);
99 
104  QString get_name() const;
105 
110  QStringList get_default() const;
111 
117 
122  QStringList get_shortcuts() const;
123 
128  QString get_identifier() const;
129 
134  bool is_valid() const;
135 
136  template<typename T>
142  void create_qt_shortcut(QWidget* parent, T func){
143 
144  QList<QShortcut*> shortcuts = init_qt_shortcut(parent);
145  for(QShortcut* sc : shortcuts){
146  parent->connect(sc, &QShortcut::activated, func);
147  }
148  }
149 
156  void create_qt_shortcut(QWidget* parent, QObject* receiver, const char* slot);
157 };
158 
159 #endif // SHORTCUT_H
QList< QKeySequence > get_sequences() const
get a list key squences mapped to this shortcut
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
QString get_name() const
get the human-readable name of the shortcut
QString get_identifier() const
get the unique identifier
static Shortcut getInvalid()
get a raw and invalid shortcut. This function is used instead of the default constructor ...
bool is_valid() const
Check if the shortcut is valid or if it was retrieved via getInvalid()
A single shortcut managed by ShortcutHandler. This class holds information about the default shortcut...
Definition: Shortcut.h:42
void create_qt_shortcut(QWidget *parent, T func)
create a qt shortcut for a widget
Definition: Shortcut.h:142
QStringList get_default() const
get a human-readable list of mapped default shortcuts
void change_shortcut(const QStringList &shortcuts)
QStringList get_shortcuts() const
get a human-readable list of mapped shortcuts
Interface that should be implemented when using configurable shortcuts.
Definition: ShortcutWidget.h:33