Changeset View
Changeset View
Standalone View
Standalone View
src/settings/ProfileSettings.h
Show All 17 Lines | |||||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #ifndef PROFILESETTINGS_H | 20 | #ifndef PROFILESETTINGS_H | ||
21 | #define PROFILESETTINGS_H | 21 | #define PROFILESETTINGS_H | ||
22 | 22 | | |||
23 | // Qt | 23 | // Qt | ||
24 | #include <QStyledItemDelegate> | 24 | #include <QStyledItemDelegate> | ||
25 | #include <QSet> | 25 | #include <QSet> | ||
26 | #include <QKeySequenceEdit> | ||||
26 | 27 | | |||
27 | // KDE | 28 | // KDE | ||
28 | 29 | | |||
29 | // Konsole | 30 | // Konsole | ||
30 | #include "Profile.h" | 31 | #include "Profile.h" | ||
31 | #include "ui_ProfileSettings.h" | 32 | #include "ui_ProfileSettings.h" | ||
32 | 33 | | |||
33 | class QItemSelection; | 34 | class QItemSelection; | ||
34 | class QShowEvent; | 35 | class QShowEvent; | ||
35 | class QStandardItem; | 36 | class QStandardItem; | ||
36 | class QStandardItemModel; | 37 | class QStandardItemModel; | ||
37 | 38 | | |||
38 | namespace Konsole { | 39 | namespace Konsole { | ||
39 | /** | 40 | /** | ||
40 | * A dialog which lists the available types of profiles and allows | 41 | * A dialog which lists the available types of profiles and allows | ||
41 | * the user to add new profiles, and remove or edit existing | 42 | * the user to add new profiles, and remove or edit existing | ||
42 | * profile types. | 43 | * profile types. | ||
43 | */ | 44 | */ | ||
44 | class ProfileSettings : public QWidget, private Ui::ProfileSettings | 45 | class ProfileSettings : public QWidget, private Ui::ProfileSettings | ||
45 | { | 46 | { | ||
46 | Q_OBJECT | 47 | Q_OBJECT | ||
47 | 48 | | |||
48 | friend class FavoriteItemDelegate; | | |||
49 | friend class ShortcutItemDelegate; | 49 | friend class ShortcutItemDelegate; | ||
50 | 50 | | |||
51 | public: | 51 | public: | ||
52 | /** Constructs a new profile type with the specified parent. */ | 52 | /** Constructs a new profile type with the specified parent. */ | ||
53 | explicit ProfileSettings(QWidget *parent = nullptr); | 53 | explicit ProfileSettings(QWidget *parent = nullptr); | ||
54 | ~ProfileSettings() Q_DECL_OVERRIDE; | 54 | ~ProfileSettings() Q_DECL_OVERRIDE; | ||
55 | 55 | | |||
56 | /** | 56 | /** | ||
Show All 10 Lines | |||||
67 | protected: | 67 | protected: | ||
68 | 68 | | |||
69 | private Q_SLOTS: | 69 | private Q_SLOTS: | ||
70 | void slotAccepted(); | 70 | void slotAccepted(); | ||
71 | void deleteSelected(); | 71 | void deleteSelected(); | ||
72 | void setSelectedAsDefault(); | 72 | void setSelectedAsDefault(); | ||
73 | void createProfile(); | 73 | void createProfile(); | ||
74 | void editSelected(); | 74 | void editSelected(); | ||
75 | void moveUpSelected(); | | |||
76 | void moveDownSelected(); | | |||
77 | 75 | | |||
78 | void itemDataChanged(QStandardItem *item); | 76 | void itemDataChanged(QStandardItem *item); | ||
79 | 77 | | |||
80 | // enables or disables Edit/Delete/Set as Default buttons when the | 78 | // enables or disables Edit/Delete/Set as Default buttons when the | ||
81 | // selection changes | 79 | // selection changes | ||
82 | void tableSelectionChanged(const QItemSelection &); | 80 | void tableSelectionChanged(const QItemSelection &); | ||
83 | 81 | | |||
84 | void updateFavoriteStatus(const Profile::Ptr &profile, bool favorite); | 82 | void updateFavoriteStatus(const Profile::Ptr &profile, bool favorite); | ||
Show All 9 Lines | 91 | private: | |||
94 | Profile::Ptr currentProfile() const; | 92 | Profile::Ptr currentProfile() const; | ||
95 | QList<Profile::Ptr> selectedProfiles() const; | 93 | QList<Profile::Ptr> selectedProfiles() const; | ||
96 | bool isProfileDeletable(Profile::Ptr profile) const; | 94 | bool isProfileDeletable(Profile::Ptr profile) const; | ||
97 | 95 | | |||
98 | // updates the font of the items to match | 96 | // updates the font of the items to match | ||
99 | // their default / non-default profile status | 97 | // their default / non-default profile status | ||
100 | void updateDefaultItem(); | 98 | void updateDefaultItem(); | ||
101 | void updateItemsForProfile(const Profile::Ptr &profile,const QList<QStandardItem *> &items) const; | 99 | void updateItemsForProfile(const Profile::Ptr &profile,const QList<QStandardItem *> &items) const; | ||
100 | void updateShortcutField(QStandardItem *item, bool isFavorite) const; | ||||
102 | // updates the profile table to be in sync with the | 101 | // updates the profile table to be in sync with the | ||
103 | // session manager | 102 | // session manager | ||
104 | void populateTable(); | 103 | void populateTable(); | ||
105 | int rowForProfile(const Profile::Ptr &profile) const; | 104 | int rowForProfile(const Profile::Ptr &profile) const; | ||
106 | 105 | | |||
107 | QStandardItemModel *_sessionModel; | 106 | QStandardItemModel *_sessionModel; | ||
108 | 107 | | |||
109 | static const int ProfileNameColumn = 0; | 108 | enum Column { | ||
110 | static const int FavoriteStatusColumn = 1; | 109 | FavoriteStatusColumn = 0, | ||
111 | static const int ShortcutColumn = 2; | 110 | ProfileNameColumn = 1, | ||
112 | static const int ProfileKeyRole = Qt::UserRole + 1; | 111 | ShortcutColumn = 2, | ||
113 | static const int ShortcutRole = Qt::UserRole + 1; | 112 | ProfileColumn = 3, | ||
113 | }; | ||||
114 | | ||||
115 | enum Role { | ||||
116 | ProfilePtrRole = Qt::UserRole + 1, | ||||
117 | ShortcutRole, | ||||
118 | }; | ||||
114 | }; | 119 | }; | ||
115 | 120 | | |||
116 | class StyledBackgroundPainter | 121 | class StyledBackgroundPainter | ||
117 | { | 122 | { | ||
118 | public: | 123 | public: | ||
119 | static void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, | 124 | static void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, | ||
120 | const QModelIndex &index); | 125 | const QModelIndex &index); | ||
121 | }; | 126 | }; | ||
122 | 127 | | |||
123 | class FavoriteItemDelegate : public QStyledItemDelegate | 128 | class FilteredKeySequenceEdit: public QKeySequenceEdit | ||
124 | { | 129 | { | ||
125 | Q_OBJECT | 130 | Q_OBJECT | ||
126 | 131 | | |||
127 | public: | 132 | public: | ||
128 | explicit FavoriteItemDelegate(QObject *parent = nullptr); | 133 | explicit FilteredKeySequenceEdit(QWidget *parent = nullptr): QKeySequenceEdit(parent) {} | ||
129 | 134 | | |||
130 | bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, | 135 | protected: | ||
131 | const QModelIndex &index) Q_DECL_OVERRIDE; | 136 | void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; | ||
132 | void paint(QPainter *painter, const QStyleOptionViewItem &option, | | |||
133 | const QModelIndex &index) const Q_DECL_OVERRIDE; | | |||
134 | }; | 137 | }; | ||
135 | 138 | | |||
136 | class ShortcutItemDelegate : public QStyledItemDelegate | 139 | class ShortcutItemDelegate : public QStyledItemDelegate | ||
137 | { | 140 | { | ||
138 | Q_OBJECT | 141 | Q_OBJECT | ||
139 | 142 | | |||
140 | public: | 143 | public: | ||
141 | explicit ShortcutItemDelegate(QObject *parent = nullptr); | 144 | explicit ShortcutItemDelegate(QObject *parent = nullptr); | ||
142 | 145 | | |||
143 | void setModelData(QWidget *editor, QAbstractItemModel *model, | 146 | void setModelData(QWidget *editor, QAbstractItemModel *model, | ||
144 | const QModelIndex &index) const Q_DECL_OVERRIDE; | 147 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
145 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, | 148 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, | ||
146 | const QModelIndex &index) const Q_DECL_OVERRIDE; | 149 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
147 | void paint(QPainter *painter, const QStyleOptionViewItem &option, | 150 | void paint(QPainter *painter, const QStyleOptionViewItem &option, | ||
148 | const QModelIndex &index) const Q_DECL_OVERRIDE; | 151 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
152 | QSize sizeHint(const QStyleOptionViewItem &option, | ||||
153 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||||
154 | void destroyEditor(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE; | ||||
149 | 155 | | |||
150 | private Q_SLOTS: | 156 | private Q_SLOTS: | ||
151 | void editorModified(const QKeySequence &keys); | 157 | void editorModified(); | ||
152 | 158 | | |||
153 | private: | 159 | private: | ||
154 | mutable QSet<QWidget *> _modifiedEditors; | 160 | mutable QSet<QWidget *> _modifiedEditors; | ||
155 | mutable QSet<QModelIndex> _itemsBeingEdited; | 161 | mutable QSet<QModelIndex> _itemsBeingEdited; | ||
156 | }; | 162 | }; | ||
157 | } | 163 | } | ||
158 | #endif // MANAGEPROFILESDIALOG_H | 164 | #endif // MANAGEPROFILESDIALOG_H |