Sayonara Player
Shortcut.h
1 /* Shortcut.h */
2 
3 /* Copyright (C) 2011-2017 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 <QShortcut>
25 
26 #include "Helper/Settings/SayonaraClass.h"
27 #include "Helper/Pimpl.h"
28 
29 class ShortcutWidget;
30 class QKeySequence;
31 class QWidget;
32 class QStringList;
41 class Shortcut : private SayonaraClass
42 {
43 private:
44  PIMPL(Shortcut)
45 
46  Shortcut();
47 
54  QList<QShortcut*> init_qt_shortcut(QWidget* parent);
55 
56 
57 public:
64  Shortcut(ShortcutWidget* parent, const QString& identifier, const QString& name, const QString& default_shortcut);
65 
72  Shortcut(ShortcutWidget* parent, const QString& identifier, const QString& name, const QStringList& default_shortcuts);
73 
78  Shortcut(const Shortcut& other);
79 
80  ~Shortcut();
81 
82  Shortcut& operator=(const Shortcut& other);
83 
88  static Shortcut getInvalid();
89 
94  void change_shortcut(const QStringList& shortcuts);
95 
100  QString get_name() const;
101 
106  QStringList get_default() const;
107 
113 
118  QStringList get_shortcuts() const;
119 
124  QString get_identifier() const;
125 
130  bool is_valid() const;
131 
132  template<typename T>
138  void create_qt_shortcut(QWidget* parent, T func){
139  QList<QShortcut*> shortcuts = init_qt_shortcut(parent);
140  for(QShortcut* sc : shortcuts){
141  parent->connect(sc, &QShortcut::activated, func);
142  }
143  }
144 
151  void create_qt_shortcut(QWidget* parent, QObject* receiver, const char* slot);
152 };
153 
154 #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:29
QString get_name() const
get the human-readable name of the shortcut
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:41
QString get_identifier() const
get the unique identifier
void create_qt_shortcut(QWidget *parent, T func)
create a qt shortcut for a widget
Definition: Shortcut.h:138
void change_shortcut(const QStringList &shortcuts)
QStringList get_shortcuts() const
get a human-readable list of mapped shortcuts
QStringList get_default() const
get a human-readable list of mapped default shortcuts
Interface that should be implemented when using configurable shortcuts.
Definition: ShortcutWidget.h:30
Definition: org_mpris_media_player2_adaptor.h:20