Stellarium 0.12.3
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 class StelShortcut;
33 class StelShortcutGroup;
34 class StelShortcutMgr;
35 
36 class QStandardItemModel;
37 class QStandardItem;
38 
39 
43 class ShortcutsFilterModel : public QSortFilterProxyModel
44 {
45  Q_OBJECT
46 
47 public:
48  ShortcutsFilterModel(QObject* parent = 0);
49 
50 protected:
51  bool filterAcceptsRow(int source_row,
52  const QModelIndex &source_parent) const;
53 };
54 
55 
57 {
58  Q_OBJECT
59 
60 public:
62  ~ShortcutsDialog();
63 
66  void drawCollisions();
67 
68 public slots:
70  void resetCollisions();
71  void retranslate();
73  void initEditors();
75  bool prefixMatchKeySequence(const QKeySequence &ks1, const QKeySequence &ks2);
77  QList<QStandardItem*> findCollidingItems(QKeySequence ks);
78  void handleCollisions(ShortcutLineEdit* currentEdit);
80  void handleChanges();
82  void applyChanges() const;
84  void switchToEditors(const QModelIndex& index);
87  void updateShortcutsItem(StelShortcut* shortcut, QStandardItem* shortcutItem = NULL);
88  void restoreDefaultShortcuts();
89  void updateTreeData();
90 
91 protected:
93  virtual void createDialogContent();
94 
95 private:
97  static bool itemIsEditable(QStandardItem *item);
101  void updateText();
102 
105  void polish();
106 
107  QStandardItem* updateGroup(StelShortcutGroup* group);
108 
110  QStandardItem* findItemByData(QVariant value, int role, int column = 0);
111 
113  StelShortcutMgr* shortcutMgr;
114 
116  QList<QStandardItem*> collisionItems;
117 
118  Ui_shortcutsDialogForm *ui;
119  ShortcutsFilterModel* filterModel;
120  QStandardItemModel* mainModel;
122  void resetModel();
124  void setModelHeader();
125 };
126 
127 #endif // SHORTCUTSDIALOG_HPP