shortcut-factory.hh
Go to the documentation of this file.
1 // Copyright (c) 2015-2018, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef GEPETTO_GUI_SHORTCUT_FACTORY_HH_
18 # define GEPETTO_GUI_SHORTCUT_FACTORY_HH_
19 
20 #include <QAction>
21 #include <QKeyEvent>
22 #include <QMouseEvent>
23 #include <QPushButton>
24 
25 #include <map>
26 #include <utility>
27 
28 namespace gepetto {
29  namespace gui {
30  class ShortcutFactory : public QObject {
31  Q_OBJECT
32  public:
35 
36  public:
43  void addBinding(QString widgetName, QString actionName, QAction* action);
44 
45  public slots:
47  void open();
48 
49  private:
50  void writeShortcutsFile();
51  void readShortcutsFile();
52 
53  typedef std::pair<QString, QAction*> Binding;
54  typedef std::list<Binding> BindingList;
55  typedef std::map<QString, BindingList> MapBindings;
56 
57  class ShortcutButton : public QPushButton {
58  public:
59  ShortcutButton(QAction* action, QWidget* parent = 0);
60  ~ShortcutButton();
61 
62  protected:
63  virtual void mouseDoubleClickEvent(QMouseEvent* event);
64  virtual void keyPressEvent(QKeyEvent* event);
65 
66  bool hasFocus_;
67  QList<int> modifiers_;
68  QAction* action_;
69  };
70 
71  MapBindings widgetsBindings_;
72  std::map<QString, QKeySequence> saved_;
73  };
74  }
75 }
76 
77 #endif /* GEPETTO_GUI_SHORTCUT_FACTORY_HH_ */
void open()
Open the widget that allows to change the different shortcut.
Definition: action-search-bar.hh:27
Definition: shortcut-factory.hh:30
void addBinding(QString widgetName, QString actionName, QAction *action)