1 /***************************************************************************
2 *                                                                         *
3 *   This program is free software; you can redistribute it and/or modify  *
4 *   it under the terms of the GNU General Public License as published by  *
5 *   the Free Software Foundation; either version 3 of the License, or     *
6 *   (at your option) any later version.                                   *
7 *                                                                         *
8 ***************************************************************************/
9 
10 #pragma once
11 
12 #include <QWidget>
13 #include <QAbstractItemModel>
14 #include <QStyledItemDelegate>
15 #include <QStyleOptionViewItem>
16 #include <QHash>
17 
18 #include "ui_UISettingsShortcuts.h"
19 #include "ShortcutEdit.h"
20 
21 class ShortcutItem{
22 
23 public:
24     ShortcutItem(ShortcutItem* = NULL);
25     virtual ~ShortcutItem();
26 
27     void appendChild(ShortcutItem *child);
28 
29     ShortcutItem *child(int row);
30     int childCount() const;
31     int columnCount() const;
32     int row() const;
33     ShortcutItem *parent();
34     QList<ShortcutItem*> childItems;
35 
36     QString title;
37     QString shortcut;
38 private:
39     ShortcutItem *parentItem;
40 };
41 
42 class ShortcutsModel : public QAbstractItemModel {
43     Q_OBJECT
44 
45 public:
46     ShortcutsModel(QObject * parent = 0);
47     virtual ~ShortcutsModel();
48 
49     virtual int rowCount(const QModelIndex & index = QModelIndex()) const;
50     virtual int columnCount(const QModelIndex & index = QModelIndex()) const;
51     virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
52     virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
53     virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
54     virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
55     virtual QModelIndex parent(const QModelIndex & parent) const;
56     Qt::ItemFlags flags(const QModelIndex &index) const;
57 
repaint()58     void repaint() { emit layoutChanged(); }
59     void save();
60 
61 private:
62     ShortcutItem *rootItem;
63     QHash<ShortcutItem*, QString> items;
64 };
65 
66 class SettingsShortcuts : public QWidget, private Ui::UISettingsShortcuts
67 {
68     Q_OBJECT
69 public:
70     explicit SettingsShortcuts(QWidget *parent = 0);
71     virtual ~SettingsShortcuts();
72 
73 public Q_SLOTS:
74     void ok();
75 
76 private Q_SLOTS:
77     void slotIndexClicked(const QModelIndex&);
78 
79 private:
80     ShortcutsModel *model;
81 };
82