Changeset View
Changeset View
Standalone View
Standalone View
libs/widgetutils/xmlgui/KisShortcutsEditor.cpp
Show All 20 Lines | 1 | /* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <donohoe@kde.org> | |||
---|---|---|---|---|---|
21 | along with this library; see the file COPYING.LIB. If not, write to | 21 | along with this library; see the file COPYING.LIB. If not, write to | ||
22 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
23 | Boston, MA 02110-1301, USA. | 23 | Boston, MA 02110-1301, USA. | ||
24 | */ | 24 | */ | ||
25 | 25 | | |||
26 | #include "KisShortcutsEditor.h" | 26 | #include "KisShortcutsEditor.h" | ||
27 | #include "KisShortcutsEditor_p.h" | 27 | #include "KisShortcutsEditor_p.h" | ||
28 | #include "config-xmlgui.h" | 28 | #include "config-xmlgui.h" | ||
29 | #include "kis_action_registry.h" | ||||
29 | 30 | | |||
30 | // The following is needed for KisShortcutsEditorPrivate and QTreeWidgetHack | 31 | // The following is needed for KisShortcutsEditorPrivate and QTreeWidgetHack | ||
31 | // #include "KisShortcutsDialog_p.h" | 32 | // #include "KisShortcutsDialog_p.h" | ||
32 | 33 | | |||
33 | #include <QAction> | 34 | #include <QAction> | ||
34 | #include <QList> | 35 | #include <QList> | ||
35 | #include <QObject> | 36 | #include <QObject> | ||
36 | #include <QTimer> | 37 | #include <QTimer> | ||
37 | #include <QTextDocument> | 38 | #include <QTextDocument> | ||
38 | #include <QTextTable> | 39 | #include <QTextTable> | ||
39 | #include <QTextCursor> | 40 | #include <QTextCursor> | ||
40 | #include <QTextTableFormat> | 41 | #include <QTextTableFormat> | ||
41 | #include <QPrinter> | 42 | #include <QPrinter> | ||
42 | #include <QDebug> | 43 | #include <QDebug> | ||
43 | 44 | | |||
44 | #include <kconfig.h> | 45 | #include <kconfig.h> | ||
45 | #include <kconfiggroup.h> | 46 | #include <kconfiggroup.h> | ||
47 | #include <ksharedconfig.h> | ||||
46 | #include <kmessagebox.h> | 48 | #include <kmessagebox.h> | ||
47 | #include "kactioncollection.h" | 49 | #include "kactioncollection.h" | ||
48 | #include "kactioncategory.h" | 50 | #include "kactioncategory.h" | ||
49 | #include <ktreewidgetsearchline.h> | 51 | #include <ktreewidgetsearchline.h> | ||
50 | 52 | | |||
51 | //--------------------------------------------------------------------- | 53 | //--------------------------------------------------------------------- | ||
52 | // KisShortcutsEditor | 54 | // KisShortcutsEditor | ||
53 | //--------------------------------------------------------------------- | 55 | //--------------------------------------------------------------------- | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 104 | { | |||
107 | } | 109 | } | ||
108 | 110 | | |||
109 | // Pause updating. | 111 | // Pause updating. | ||
110 | setUpdatesEnabled(false); | 112 | setUpdatesEnabled(false); | ||
111 | 113 | | |||
112 | 114 | | |||
113 | /** | 115 | /** | ||
114 | * Forward this actioncollection to the delegate which will do conflict checking. | 116 | * Forward this actioncollection to the delegate which will do conflict checking. | ||
115 | * TODO this seems to _replace_ any existing collections in the delegate. So, is that cool? | 117 | * This _replaces_ existing collections in the delegate. | ||
116 | */ | 118 | */ | ||
117 | d->actionCollections.append(collection); | 119 | d->actionCollections.append(collection); | ||
118 | d->delegate->setCheckActionCollections(d->actionCollections); | 120 | d->delegate->setCheckActionCollections(d->actionCollections); | ||
119 | 121 | | |||
120 | 122 | | |||
121 | // Determine how we should label this collection in the widget. | 123 | // Determine how we should label this collection in the widget. | ||
122 | QString collectionTitle; | 124 | QString collectionTitle; | ||
123 | if (!title.isEmpty()) { | 125 | if (!title.isEmpty()) { | ||
Show All 13 Lines | |||||
137 | // Remember which actions we have seen. We will be adding categorized | 139 | // Remember which actions we have seen. We will be adding categorized | ||
138 | // actions first, so this will help us keep track of which actions haven't | 140 | // actions first, so this will help us keep track of which actions haven't | ||
139 | // been categorized yet, so we can add them as uncategorized at the end. | 141 | // been categorized yet, so we can add them as uncategorized at the end. | ||
140 | QSet<QAction *> actionsSeen; | 142 | QSet<QAction *> actionsSeen; | ||
141 | 143 | | |||
142 | // Add a subtree for each category? Perhaps easier to think that this | 144 | // Add a subtree for each category? Perhaps easier to think that this | ||
143 | // doesn't exist. Basically you add KActionCategory as a QObject child of | 145 | // doesn't exist. Basically you add KActionCategory as a QObject child of | ||
144 | // KActionCollection, and then tag objects as belonging to the category. | 146 | // KActionCollection, and then tag objects as belonging to the category. | ||
145 | QList<KActionCategory *> categories = collection->findChildren<KActionCategory *>(); | 147 | foreach (KActionCategory *category, collection->categories()) { | ||
146 | foreach (KActionCategory *category, categories) { | 148 | | ||
149 | // Don't display empty categories. | ||||
150 | if (category->actions().isEmpty()) { | ||||
151 | continue; | ||||
152 | } | ||||
153 | | ||||
147 | hierarchy[KisShortcutsEditorPrivate::Action] = | 154 | hierarchy[KisShortcutsEditorPrivate::Action] = | ||
148 | d->findOrMakeItem(hierarchy[KisShortcutsEditorPrivate::Program], category->text()); | 155 | d->findOrMakeItem(hierarchy[KisShortcutsEditorPrivate::Program], category->text()); | ||
149 | 156 | | |||
150 | // Add every item from each category. | 157 | // Add every item from the category. | ||
151 | foreach (QAction *action, category->actions()) { | 158 | foreach (QAction *action, category->actions()) { | ||
152 | actionsSeen.insert(action); | 159 | actionsSeen.insert(action); | ||
153 | d->addAction(action, hierarchy, KisShortcutsEditorPrivate::Action); | 160 | d->addAction(action, hierarchy, KisShortcutsEditorPrivate::Action); | ||
154 | } | 161 | } | ||
162 | | ||||
163 | // Fold in each KActionCategory by default. | ||||
164 | hierarchy[KisShortcutsEditorPrivate::Action]->setExpanded(false); | ||||
165 | | ||||
155 | } | 166 | } | ||
156 | 167 | | |||
157 | // Finally, tack on any uncategorized actions. | 168 | // Finally, tack on any uncategorized actions. | ||
158 | foreach (QAction *action, collection->actions()) { | 169 | foreach (QAction *action, collection->actions()) { | ||
159 | if (!actionsSeen.contains(action)) { | 170 | if (!actionsSeen.contains(action)) { | ||
160 | d->addAction(action, hierarchy, KisShortcutsEditorPrivate::Program); | 171 | d->addAction(action, hierarchy, KisShortcutsEditorPrivate::Program); | ||
161 | } | 172 | } | ||
162 | } | 173 | } | ||
Show All 26 Lines | 195 | { | |||
189 | 200 | | |||
190 | if (d->actionTypes) { | 201 | if (d->actionTypes) { | ||
191 | QString groupName(QStringLiteral("Shortcuts")); | 202 | QString groupName(QStringLiteral("Shortcuts")); | ||
192 | KConfigGroup group(config, groupName); | 203 | KConfigGroup group(config, groupName); | ||
193 | foreach (KActionCollection *collection, d->actionCollections) { | 204 | foreach (KActionCollection *collection, d->actionCollections) { | ||
194 | collection->writeSettings(&group, true); | 205 | collection->writeSettings(&group, true); | ||
195 | } | 206 | } | ||
196 | } | 207 | } | ||
208 | | ||||
209 | KisActionRegistry::instance()->notifySettingsUpdated(); | ||||
197 | } | 210 | } | ||
198 | 211 | | |||
199 | void KisShortcutsEditor::writeConfiguration(KConfigGroup *config) const | 212 | void KisShortcutsEditor::writeConfiguration(KConfigGroup *config) const | ||
200 | { | 213 | { | ||
214 | // This is a horrible mess with pointers... | ||||
215 | auto cg = KConfigGroup(KSharedConfig::openConfig("kritashortcutsrc"), "Shortcuts"); | ||||
216 | if (config == 0) { | ||||
217 | config = &cg; | ||||
218 | } | ||||
219 | | ||||
201 | foreach (KActionCollection *collection, d->actionCollections) { | 220 | foreach (KActionCollection *collection, d->actionCollections) { | ||
202 | collection->writeSettings(config); | 221 | collection->writeSettings(config, true); | ||
203 | } | 222 | } | ||
223 | | ||||
224 | KisActionRegistry::instance()->notifySettingsUpdated(); | ||||
204 | } | 225 | } | ||
205 | 226 | | |||
206 | //slot | 227 | //slot | ||
207 | void KisShortcutsEditor::resizeColumns() | 228 | void KisShortcutsEditor::resizeColumns() | ||
208 | { | 229 | { | ||
209 | for (int i = 0; i < d->ui.list->columnCount(); i++) { | 230 | for (int i = 0; i < d->ui.list->columnCount(); i++) { | ||
210 | d->ui.list->resizeColumnToContents(i); | 231 | d->ui.list->resizeColumnToContents(i); | ||
211 | } | 232 | } | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |