Stellarium 0.15.2
ShortcutsDialog.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2012 Anton Samoylov
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef SHORTCUTSDIALOG_HPP
21 #define SHORTCUTSDIALOG_HPP
22 
23 #include <QKeySequence>
24 #include <QModelIndex>
25 #include <QSortFilterProxyModel>
26 
27 #include "StelDialog.hpp"
28 
29 
30 class Ui_shortcutsDialogForm;
31 class ShortcutLineEdit;
32 
33 class QStandardItemModel;
34 class QStandardItem;
35 
36 
40 class ShortcutsFilterModel : public QSortFilterProxyModel
41 {
42  Q_OBJECT
43 
44 public:
45  ShortcutsFilterModel(QObject* parent = 0);
46 
47 protected:
48  bool filterAcceptsRow(int source_row,
49  const QModelIndex &source_parent) const;
50 };
51 
52 
54 {
55  Q_OBJECT
56 
57 public:
58  ShortcutsDialog(QObject* parent);
59  ~ShortcutsDialog();
60 
63  void drawCollisions();
64 
65 public slots:
67  void resetCollisions();
68  void retranslate();
70  void initEditors();
72  bool prefixMatchKeySequence(const QKeySequence &ks1, const QKeySequence &ks2);
74  QList<QStandardItem*> findCollidingItems(QKeySequence ks);
75  void handleCollisions(ShortcutLineEdit* currentEdit);
77  void handleChanges();
79  void applyChanges();
81  void switchToEditors(const QModelIndex& index);
84  void updateShortcutsItem(class StelAction* action, QStandardItem* shortcutItem = NULL);
85  void restoreDefaultShortcuts();
86  void updateTreeData();
87 
88 protected:
90  virtual void createDialogContent();
91 
92 private:
94  static bool itemIsEditable(QStandardItem *item);
98  void updateText();
99 
102  void polish();
103 
104  QStandardItem* updateGroup(const QString& group);
105 
107  QStandardItem* findItemByData(QVariant value, int role, int column = 0);
108 
110  class StelActionMgr* actionMgr;
111 
113  QList<QStandardItem*> collisionItems;
114 
115  Ui_shortcutsDialogForm *ui;
116  ShortcutsFilterModel* filterModel;
117  QStandardItemModel* mainModel;
119  void resetModel();
121  void setModelHeader();
122 };
123 
124 #endif // SHORTCUTSDIALOG_HPP
Specialised GUI control for entering keyboard shortcut combinations.
Custom filter class for filtering tree sub-items.
Base class for all the GUI windows in Stellarium.
Definition: StelDialog.hpp:72
Wrapper around an argumentless QObject slot or a bool Q_PROPERTY with WRITE method, allowing the slot to be called/property to be toggled using this action object.
Manager for StelAction instances. Allows registration of new actions, and finding an existing one by ...