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 "Utils/Pimpl.h"
27 
28 class ShortcutWidget;
29 class QKeySequence;
30 class QWidget;
31 class QStringList;
40 class Shortcut
41 {
42 private:
43  PIMPL(Shortcut)
44 
45  Shortcut();
46 
53  QList<QShortcut*> init_qt_shortcut(QWidget* parent);
54 
55 
56 public:
63  Shortcut(ShortcutWidget* parent, const QString& identifier, const QString& name, const QString& default_shortcut);
64 
71  Shortcut(ShortcutWidget* parent, const QString& identifier, const QString& name, const QStringList& default_shortcuts);
72 
77  Shortcut(const Shortcut& other);
78 
79  ~Shortcut();
80 
81  Shortcut& operator=(const Shortcut& other);
82 
87  static Shortcut getInvalid();
88 
93  void change_shortcut(const QStringList& shortcuts);
94 
99  QString get_name() const;
100 
105  QStringList get_default() const;
106 
112 
117  QStringList get_shortcuts() const;
118 
123  QString get_identifier() const;
124 
129  bool is_valid() const;
130 
131  template<typename T>
137  void create_qt_shortcut(QWidget* parent, T func){
138  QList<QShortcut*> shortcuts = init_qt_shortcut(parent);
139  for(QShortcut* sc : shortcuts){
140  parent->connect(sc, &QShortcut::activated, func);
141  }
142  }
143 
150  void create_qt_shortcut(QWidget* parent, QObject* receiver, const char* slot);
151 };
152 
153 #endif // SHORTCUT_H
QList< QKeySequence > get_sequences() const
get a list key squences mapped to this shortcut
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:40
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:137
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