• Skip to content
  • Skip to link menu
Brand

API Documentation

  1. KDE API Reference
  2. The KDE Frameworks
  3. KXmlGui
  • KDE Home
  • Contact Us

Quick Links

Skip menu "KXmlGui"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules
  • Dependencies
  • Related Pages

Class Picker

About

User configurable main windows

Maintainer
David Faure
Supported platforms
FreeBSD, Linux, MacOSX, Windows
Community
IRC: #kde-devel on Freenode
Mailing list: kde-frameworks-devel
Use with CMake
find_package(KF5XmlGui)
target_link_libraries(yourapp KF5::XmlGui)
Use with QMake
QT += KXmlGui 
Clone
git clone git://anongit.kde.org/kxmlgui.git
Browse source
KXmlGui on cgit.kde.org

KXmlGui

  • frameworks
  • frameworks
  • kxmlgui
  • src
kshortcutseditor.cpp
1 /* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <[email protected]>
2  Copyright (C) 1997 Nicolas Hadacek <[email protected]>
3  Copyright (C) 1998 Matthias Ettrich <[email protected]>
4  Copyright (C) 2001 Ellis Whitehead <[email protected]>
5  Copyright (C) 2006 Hamish Rodda <[email protected]>
6  Copyright (C) 2007 Roberto Raggi <[email protected]>
7  Copyright (C) 2007 Andreas Hartmetz <[email protected]>
8  Copyright (C) 2008 Michael Jansen <[email protected]>
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Library General Public
12  License as published by the Free Software Foundation; either
13  version 2 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
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,
23  Boston, MA 02110-1301, USA.
24 */
25 #include "config-xmlgui.h"
26 
27 #include "kshortcutseditor.h"
28 
29 // The following is needed for KShortcutsEditorPrivate and QTreeWidgetHack
30 #include "kshortcutsdialog_p.h"
31 
32 #include <QAction>
33 #include <QHeaderView>
34 #include <QList>
35 #include <QObject>
36 #include <QTimer>
37 #include <QTextDocument>
38 #include <QTextTable>
39 #include <QTextCursor>
40 #include <QTextTableFormat>
41 #include <QPrinter>
42 #include <QPrintDialog>
43 #include <QDebug>
44 
45 #include <kconfig.h>
46 #include <kconfiggroup.h>
47 #if HAVE_GLOBALACCEL
48 # include <kglobalaccel.h>
49 #endif
50 #include <kmessagebox.h>
51 #include "kactioncollection.h"
52 #include "kactioncategory.h"
53 #include <ktreewidgetsearchline.h>
54 
55 //---------------------------------------------------------------------
56 // KShortcutsEditor
57 //---------------------------------------------------------------------
58 
59 KShortcutsEditor::KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionType,
60  LetterShortcuts allowLetterShortcuts)
61  : QWidget(parent)
62  , d(new KShortcutsEditorPrivate(this))
63 {
64  d->initGUI(actionType, allowLetterShortcuts);
65  addCollection(collection);
66 }
67 
68 KShortcutsEditor::KShortcutsEditor(QWidget *parent, ActionTypes actionType, LetterShortcuts allowLetterShortcuts)
69  : QWidget(parent)
70  , d(new KShortcutsEditorPrivate(this))
71 {
72  d->initGUI(actionType, allowLetterShortcuts);
73 }
74 
75 KShortcutsEditor::~KShortcutsEditor()
76 {
77  delete d;
78 }
79 
80 bool KShortcutsEditor::isModified() const
81 {
82  // Iterate over all items
83  QTreeWidgetItemIterator it(d->ui.list, QTreeWidgetItemIterator::NoChildren);
84 
85  for (; (*it); ++it) {
86  KShortcutsEditorItem *item = dynamic_cast<KShortcutsEditorItem *>(*it);
87  if (item && item->isModified()) {
88  return true;
89  }
90  }
91  return false;
92 }
93 
94 void KShortcutsEditor::clearCollections()
95 {
96  d->delegate->contractAll();
97  d->ui.list->clear();
98  d->actionCollections.clear();
99  QTimer::singleShot(0, this, &KShortcutsEditor::resizeColumns);
100 }
101 
102 void KShortcutsEditor::addCollection(KActionCollection *collection, const QString &title)
103 {
104  // KXmlGui add action collections unconditionally. If some plugin doesn't
105  // provide actions we don't want to create empty subgroups.
106  if (collection->isEmpty()) {
107  return;
108  }
109 
110  // We add a bunch of items. Prevent the treewidget from permanently
111  // updating.
112  setUpdatesEnabled(false);
113 
114  d->actionCollections.append(collection);
115  // Forward our actionCollections to the delegate which does the conflict
116  // checking.
117  d->delegate->setCheckActionCollections(d->actionCollections);
118  QString displayTitle = title;
119  if (displayTitle.isEmpty()) {
120  // Use the programName (Translated).
121  displayTitle = collection->componentDisplayName();
122  }
123 
124  QTreeWidgetItem *hier[3];
125  hier[KShortcutsEditorPrivate::Root] = d->ui.list->invisibleRootItem();
126  hier[KShortcutsEditorPrivate::Program] = d->findOrMakeItem(hier[KShortcutsEditorPrivate::Root], displayTitle);
127  hier[KShortcutsEditorPrivate::Action] = nullptr;
128 
129  // Set to remember which actions we have seen.
130  QSet<QAction *> actionsSeen;
131 
132  // Add all categories in their own subtree below the collections root node
133  const QList<KActionCategory *> categories = collection->findChildren<KActionCategory *>();
134  for (KActionCategory *category : categories) {
135  hier[KShortcutsEditorPrivate::Action] = d->findOrMakeItem(hier[KShortcutsEditorPrivate::Program], category->text());
136  const auto categoryActions = category->actions();
137  for (QAction *action : categoryActions) {
138  // Set a marker that we have seen this action
139  actionsSeen.insert(action);
140  d->addAction(action, hier, KShortcutsEditorPrivate::Action);
141  }
142  }
143 
144  // The rest of the shortcuts is added as a direct shild of the action
145  // collections root node
146  const auto collectionActions = collection->actions();
147  for (QAction *action : collectionActions) {
148  if (actionsSeen.contains(action)) {
149  continue;
150  }
151 
152  d->addAction(action, hier, KShortcutsEditorPrivate::Program);
153  }
154 
155  // sort the list
156  d->ui.list->sortItems(Name, Qt::AscendingOrder);
157 
158  // reenable updating
159  setUpdatesEnabled(true);
160 
161  QTimer::singleShot(0, this, &KShortcutsEditor::resizeColumns);
162 }
163 
164 void KShortcutsEditor::clearConfiguration()
165 {
166  d->clearConfiguration();
167 }
168 
169 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
170 void KShortcutsEditor::importConfiguration(KConfig *config)
171 {
172  d->importConfiguration(config);
173 }
174 #endif
175 
176 void KShortcutsEditor::importConfiguration(KConfigBase *config)
177 {
178  d->importConfiguration(config);
179 }
180 
181 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
182 void KShortcutsEditor::exportConfiguration(KConfig *config) const
183 {
184  exportConfiguration(static_cast<KConfigBase *>(config));
185 }
186 #endif
187 
188 void KShortcutsEditor::exportConfiguration(KConfigBase *config) const
189 {
190  Q_ASSERT(config);
191  if (!config) {
192  return;
193  }
194 
195  if (d->actionTypes & KShortcutsEditor::GlobalAction) {
196  QString groupName(QStringLiteral("Global Shortcuts"));
197  KConfigGroup group(config, groupName);
198  for (KActionCollection *collection : qAsConst(d->actionCollections)) {
199  collection->exportGlobalShortcuts(&group, true);
200  }
201  }
202  if (d->actionTypes & ~KShortcutsEditor::GlobalAction) {
203  QString groupName(QStringLiteral("Shortcuts"));
204  KConfigGroup group(config, groupName);
205  for (KActionCollection *collection : qAsConst(d->actionCollections)) {
206  collection->writeSettings(&group, true);
207  }
208  }
209 }
210 
211 void KShortcutsEditor::writeConfiguration(KConfigGroup *config) const
212 {
213  for (KActionCollection *collection : qAsConst(d->actionCollections)) {
214  collection->writeSettings(config);
215  }
216 }
217 
218 //slot
219 void KShortcutsEditor::resizeColumns()
220 {
221  for (int i = 0; i < d->ui.list->columnCount(); i++) {
222  d->ui.list->resizeColumnToContents(i);
223  }
224 }
225 
226 void KShortcutsEditor::commit()
227 {
228  for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
229  if (KShortcutsEditorItem *item = dynamic_cast<KShortcutsEditorItem *>(*it)) {
230  item->commit();
231  }
232  }
233 }
234 
235 void KShortcutsEditor::save()
236 {
237  writeConfiguration();
238  // we have to call commit. If we wouldn't do that the changes would be
239  // undone on deletion! That would lead to weird problems. Changes to
240  // Global Shortcuts would vanish completely. Changes to local shortcuts
241  // would vanish for this session.
242  commit();
243 }
244 
245 // KDE5 : rename to undo()
246 void KShortcutsEditor::undoChanges()
247 {
248  //This function used to crash sometimes when invoked by clicking on "cancel"
249  //with Qt 4.2.something. Apparently items were deleted too early by Qt.
250  //It seems to work with 4.3-ish Qt versions. Keep an eye on this.
251  for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
252  if (KShortcutsEditorItem *item = dynamic_cast<KShortcutsEditorItem *>(*it)) {
253  item->undo();
254  }
255  }
256 }
257 
258 //We ask the user here if there are any conflicts, as opposed to undoChanges().
259 //They don't do the same thing anyway, this just not to confuse any readers.
260 //slot
261 void KShortcutsEditor::allDefault()
262 {
263  d->allDefault();
264 }
265 
266 void KShortcutsEditor::printShortcuts() const
267 {
268  d->printShortcuts();
269 }
270 
271 KShortcutsEditor::ActionTypes KShortcutsEditor::actionTypes() const
272 {
273  return d->actionTypes;
274 }
275 
276 void KShortcutsEditor::setActionTypes(ActionTypes actionTypes)
277 {
278  d->setActionTypes(actionTypes);
279 }
280 
281 //---------------------------------------------------------------------
282 // KShortcutsEditorPrivate
283 //---------------------------------------------------------------------
284 
285 KShortcutsEditorPrivate::KShortcutsEditorPrivate(KShortcutsEditor *q)
286  : q(q),
287  delegate(nullptr)
288 {}
289 
290 void KShortcutsEditorPrivate::initGUI(KShortcutsEditor::ActionTypes types, KShortcutsEditor::LetterShortcuts allowLetterShortcuts)
291 {
292  actionTypes = types;
293 
294  ui.setupUi(q);
295  q->layout()->setContentsMargins(0, 0, 0, 0);
296  ui.searchFilter->searchLine()->setTreeWidget(ui.list); // Plug into search line
297  ui.list->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
298  ui.list->header()->hideSection(ShapeGesture); //mouse gestures didn't make it in time...
299  ui.list->header()->hideSection(RockerGesture);
300 #if HAVE_GLOBALACCEL
301  bool hideGlobals = !(actionTypes & KShortcutsEditor::GlobalAction);
302 #else
303  bool hideGlobals = true;
304 #endif
305 
306  if (hideGlobals) {
307  ui.list->header()->hideSection(GlobalPrimary);
308  ui.list->header()->hideSection(GlobalAlternate);
309  } else if (!(actionTypes & ~KShortcutsEditor::GlobalAction)) {
310  ui.list->header()->hideSection(LocalPrimary);
311  ui.list->header()->hideSection(LocalAlternate);
312  }
313 
314  // Create the Delegate. It is responsible for the KKeySeqeunceWidgets that
315  // really change the shortcuts.
316  delegate = new KShortcutsEditorDelegate(
317  ui.list,
318  allowLetterShortcuts == KShortcutsEditor::LetterShortcutsAllowed);
319 
320  ui.list->setItemDelegate(delegate);
321  ui.list->setSelectionBehavior(QAbstractItemView::SelectItems);
322  ui.list->setSelectionMode(QAbstractItemView::SingleSelection);
323  //we have our own editing mechanism
324  ui.list->setEditTriggers(QAbstractItemView::NoEditTriggers);
325  ui.list->setAlternatingRowColors(true);
326 
327  //TODO listen to changes to global shortcuts
328  QObject::connect(delegate, SIGNAL(shortcutChanged(QVariant,QModelIndex)),
329  q, SLOT(capturedShortcut(QVariant,QModelIndex)));
330  //hide the editor widget chen its item becomes hidden
331  QObject::connect(ui.searchFilter->searchLine(), &KTreeWidgetSearchLine::hiddenChanged,
332  delegate, &KShortcutsEditorDelegate::hiddenBySearchLine);
333 
334  ui.searchFilter->setFocus();
335 }
336 
337 void KShortcutsEditorPrivate::setActionTypes(KShortcutsEditor::ActionTypes types)
338 {
339  if (actionTypes == types) {
340  return;
341  }
342  actionTypes = types;
343 
344  // show/hide the sections based on new selection
345  QHeaderView *header = ui.list->header();
346  if (actionTypes & KShortcutsEditor::GlobalAction) {
347  header->showSection(GlobalPrimary);
348  header->showSection(GlobalAlternate);
349  } else {
350  header->hideSection(GlobalPrimary);
351  header->hideSection(GlobalAlternate);
352  }
353  if (actionTypes & ~KShortcutsEditor::GlobalAction) {
354  header->showSection(LocalPrimary);
355  header->showSection(LocalAlternate);
356  } else {
357  header->hideSection(LocalPrimary);
358  header->hideSection(LocalAlternate);
359  }
360 }
361 
362 bool KShortcutsEditorPrivate::addAction(QAction *action, QTreeWidgetItem *hier[], hierarchyLevel level)
363 {
364  // If the action name starts with unnamed- spit out a warning and ignore
365  // it. That name will change at will and will break loading and writing
366  QString actionName = action->objectName();
367  if (actionName.isEmpty() || actionName.startsWith(QLatin1String("unnamed-"))) {
368  qCritical() << "Skipping action without name " << action->text() << "," << actionName << "!";
369  return false;
370  }
371 
372  // This code doesn't allow editing of QAction. It can not distinguish
373  // between default and active shortcuts. This breaks many assumptions the
374  // editor makes.
375  const QVariant value = action->property("isShortcutConfigurable");
376  if (!value.isValid() || value.toBool()) {
377  new KShortcutsEditorItem((hier[level]), action);
378  return true;
379  }
380 
381  return false;
382 }
383 
384 void KShortcutsEditorPrivate::allDefault()
385 {
386  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
387  if (!(*it)->parent() || (*it)->type() != ActionItem) {
388  continue;
389  }
390 
391  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
392  QAction *act = item->m_action;
393 
394  QList<QKeySequence> defaultShortcuts = act->property("defaultShortcuts").value<QList<QKeySequence> >();
395  if (act->shortcuts() != defaultShortcuts) {
396  QKeySequence primary = defaultShortcuts.isEmpty() ? QKeySequence() : defaultShortcuts.at(0);
397  QKeySequence alternate = defaultShortcuts.size() <= 1 ? QKeySequence() : defaultShortcuts.at(1);
398  changeKeyShortcut(item, LocalPrimary, primary);
399  changeKeyShortcut(item, LocalAlternate, alternate);
400  }
401 
402 #if HAVE_GLOBALACCEL
403  if (KGlobalAccel::self()->shortcut(act) != KGlobalAccel::self()->defaultShortcut(act)) {
404  QList<QKeySequence> defaultShortcut = KGlobalAccel::self()->defaultShortcut(act);
405  changeKeyShortcut(item, GlobalPrimary, primarySequence(defaultShortcut));
406  changeKeyShortcut(item, GlobalAlternate, alternateSequence(defaultShortcut));
407  }
408 #endif
409  }
410 }
411 
412 //static
413 KShortcutsEditorItem *KShortcutsEditorPrivate::itemFromIndex(QTreeWidget *const w,
414  const QModelIndex &index)
415 {
416  QTreeWidgetItem *item = static_cast<QTreeWidgetHack *>(w)->itemFromIndex(index);
417  if (item && item->type() == ActionItem) {
418  return static_cast<KShortcutsEditorItem *>(item);
419  }
420  return nullptr;
421 }
422 
423 QTreeWidgetItem *KShortcutsEditorPrivate::findOrMakeItem(QTreeWidgetItem *parent, const QString &name)
424 {
425  for (int i = 0; i < parent->childCount(); i++) {
426  QTreeWidgetItem *child = parent->child(i);
427  if (child->text(0) == name) {
428  return child;
429  }
430  }
431  QTreeWidgetItem *ret = new QTreeWidgetItem(parent, NonActionItem);
432  ret->setText(0, name);
433  ui.list->expandItem(ret);
434  ret->setFlags(ret->flags() & ~Qt::ItemIsSelectable);
435  return ret;
436 }
437 
438 //private slot
439 void KShortcutsEditorPrivate::capturedShortcut(const QVariant &newShortcut, const QModelIndex &index)
440 {
441  //dispatch to the right handler
442  if (!index.isValid()) {
443  return;
444  }
445  int column = index.column();
446  KShortcutsEditorItem *item = itemFromIndex(ui.list, index);
447  Q_ASSERT(item);
448 
449  if (column >= LocalPrimary && column <= GlobalAlternate) {
450  changeKeyShortcut(item, column, newShortcut.value<QKeySequence>());
451  }
452 }
453 
454 void KShortcutsEditorPrivate::changeKeyShortcut(KShortcutsEditorItem *item, uint column, const QKeySequence &capture)
455 {
456  // The keySequence we get is cleared by KKeySequenceWidget. No conflicts.
457  if (capture == item->keySequence(column)) {
458  return;
459  }
460 
461  item->setKeySequence(column, capture);
462  emit q->keyChange();
463  //force view update
464  item->setText(column, capture.toString(QKeySequence::NativeText));
465 }
466 
467 void KShortcutsEditorPrivate::clearConfiguration()
468 {
469  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
470  if (!(*it)->parent()) {
471  continue;
472  }
473 
474  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
475 
476  changeKeyShortcut(item, LocalPrimary, QKeySequence());
477  changeKeyShortcut(item, LocalAlternate, QKeySequence());
478 
479  changeKeyShortcut(item, GlobalPrimary, QKeySequence());
480  changeKeyShortcut(item, GlobalAlternate, QKeySequence());
481  }
482 }
483 
484 void KShortcutsEditorPrivate::importConfiguration(KConfigBase *config)
485 {
486  Q_ASSERT(config);
487  if (!config) {
488  return;
489  }
490 
491  KConfigGroup globalShortcutsGroup(config, QStringLiteral("Global Shortcuts"));
492  if ((actionTypes & KShortcutsEditor::GlobalAction) && globalShortcutsGroup.exists()) {
493 
494  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
495 
496  if (!(*it)->parent()) {
497  continue;
498  }
499 
500  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
501  const QString actionId = item->data(Id).toString();
502  if (!globalShortcutsGroup.hasKey(actionId))
503  continue;
504 
505  QList<QKeySequence> sc = QKeySequence::listFromString(globalShortcutsGroup.readEntry(actionId, QString()));
506  changeKeyShortcut(item, GlobalPrimary, primarySequence(sc));
507  changeKeyShortcut(item, GlobalAlternate, alternateSequence(sc));
508  }
509  }
510 
511  if (actionTypes & ~KShortcutsEditor::GlobalAction) {
512  const KConfigGroup localShortcutsGroup(config, QStringLiteral("Shortcuts"));
513  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
514 
515  if (!(*it)->parent()) {
516  continue;
517  }
518  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
519  const QString actionId = item->data(Id).toString();
520  if (!localShortcutsGroup.hasKey(actionId))
521  continue;
522 
523  QList<QKeySequence> sc = QKeySequence::listFromString(localShortcutsGroup.readEntry(actionId, QString()));
524  changeKeyShortcut(item, LocalPrimary, primarySequence(sc));
525  changeKeyShortcut(item, LocalAlternate, alternateSequence(sc));
526  }
527  }
528 }
529 
530 /*TODO for the printShortcuts function
531 Nice to have features (which I'm not sure I can do before may due to
532 more important things):
533 
534 - adjust the general page borders, IMHO they're too wide
535 
536 - add a custom printer options page that allows to filter out all
537  actions that don't have a shortcut set to reduce this list. IMHO this
538  should be optional as people might want to simply print all and when
539  they find a new action that they assign a shortcut they can simply use
540  a pen to fill out the empty space
541 
542 - find a way to align the Main/Alternate/Global entries in the shortcuts
543  column without adding borders. I first did this without a nested table
544  but instead simply added 3 rows and merged the 3 cells in the Action
545  name and description column, but unfortunately I didn't find a way to
546  remove the borders between the 6 shortcut cells.
547 */
548 void KShortcutsEditorPrivate::printShortcuts() const
549 {
550 // One cant print on wince
551 #ifndef _WIN32_WCE
552  QTreeWidgetItem *root = ui.list->invisibleRootItem();
553  QTextDocument doc;
554 
555  doc.setDefaultFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
556 
557  QTextCursor cursor(&doc);
558  cursor.beginEditBlock();
559  QTextCharFormat headerFormat;
560  headerFormat.setProperty(QTextFormat::FontSizeAdjustment, 3);
561  headerFormat.setFontWeight(QFont::Bold);
562  cursor.insertText(i18nc("header for an applications shortcut list", "Shortcuts for %1",
563  QGuiApplication::applicationDisplayName()),
564  headerFormat);
565  QTextCharFormat componentFormat;
566  componentFormat.setProperty(QTextFormat::FontSizeAdjustment, 2);
567  componentFormat.setFontWeight(QFont::Bold);
568  QTextBlockFormat componentBlockFormat = cursor.blockFormat();
569  componentBlockFormat.setTopMargin(16);
570  componentBlockFormat.setBottomMargin(16);
571 
572  QTextTableFormat tableformat;
573  tableformat.setHeaderRowCount(1);
574  tableformat.setCellPadding(4.0);
575  tableformat.setCellSpacing(0);
576  tableformat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
577  tableformat.setBorder(0.5);
578 
579  const QPair<QString, ColumnDesignation> shortcutTitleToColumnMap[] = {
580  qMakePair(i18n("Main:"), LocalPrimary),
581  qMakePair(i18n("Alternate:"), LocalAlternate),
582  qMakePair(i18n("Global:"), GlobalPrimary),
583  qMakePair(i18n("Global alternate:"), GlobalAlternate),
584  };
585 
586  for (int i = 0; i < root->childCount(); i++) {
587  QTreeWidgetItem *item = root->child(i);
588  cursor.insertBlock(componentBlockFormat, componentFormat);
589  cursor.insertText(item->text(0));
590 
591  QTextTable *table = cursor.insertTable(1, 3);
592  table->setFormat(tableformat);
593  int currow = 0;
594 
595  QTextTableCell cell = table->cellAt(currow, 0);
596  QTextCharFormat format = cell.format();
597  format.setFontWeight(QFont::Bold);
598  cell.setFormat(format);
599  cell.firstCursorPosition().insertText(i18n("Action Name"));
600 
601  cell = table->cellAt(currow, 1);
602  cell.setFormat(format);
603  cell.firstCursorPosition().insertText(i18n("Shortcuts"));
604 
605  cell = table->cellAt(currow, 2);
606  cell.setFormat(format);
607  cell.firstCursorPosition().insertText(i18n("Description"));
608  currow++;
609 
610  for (QTreeWidgetItemIterator it(item); *it; ++it) {
611  if ((*it)->type() != ActionItem) {
612  continue;
613  }
614 
615  KShortcutsEditorItem *editoritem = static_cast<KShortcutsEditorItem *>(*it);
616  table->insertRows(table->rows(), 1);
617  QVariant data = editoritem->data(Name, Qt::DisplayRole);
618  table->cellAt(currow, 0).firstCursorPosition().insertText(data.toString());
619 
620  QTextTable *shortcutTable = nullptr;
621  for (const auto &shortcutTitleToColumn : shortcutTitleToColumnMap) {
622  data = editoritem->data(shortcutTitleToColumn.second, Qt::DisplayRole);
623  QString key = data.value<QKeySequence>().toString();
624 
625  if (!key.isEmpty()) {
626  if (!shortcutTable) {
627  shortcutTable = table->cellAt(currow, 1).firstCursorPosition().insertTable(1, 2);
628  QTextTableFormat shortcutTableFormat = tableformat;
629  shortcutTableFormat.setCellSpacing(0.0);
630  shortcutTableFormat.setHeaderRowCount(0);
631  shortcutTableFormat.setBorder(0.0);
632  shortcutTable->setFormat(shortcutTableFormat);
633  } else {
634  shortcutTable->insertRows(shortcutTable->rows(), 1);
635  }
636  shortcutTable->cellAt(shortcutTable->rows() - 1, 0).firstCursorPosition().insertText(shortcutTitleToColumn.first);
637  shortcutTable->cellAt(shortcutTable->rows() - 1, 1).firstCursorPosition().insertText(key);
638  }
639  }
640 
641  QAction *action = editoritem->m_action;
642  cell = table->cellAt(currow, 2);
643  format = cell.format();
644  format.setProperty(QTextFormat::FontSizeAdjustment, -1);
645  cell.setFormat(format);
646  cell.firstCursorPosition().insertHtml(action->whatsThis());
647 
648  currow++;
649  }
650  cursor.movePosition(QTextCursor::End);
651  }
652  cursor.endEditBlock();
653 
654  QPrinter printer;
655  QPrintDialog *dlg = new QPrintDialog(&printer, q);
656  if (dlg->exec() == QDialog::Accepted) {
657  doc.print(&printer);
658  }
659  delete dlg;
660 #endif
661 }
662 
663 #include "moc_kshortcutseditor.cpp"
QWidget::layout
QLayout * layout() const
QAction::text
text
KShortcutsEditor::undoChanges
void undoChanges()
Undo all change made since the last commit().
Definition: kshortcutseditor.cpp:246
KActionCategory
Categorize actions for KShortcutsEditor.
Definition: kactioncategory.h:96
QModelIndex
KShortcutsEditor::importConfiguration
void importConfiguration(KConfigBase *config)
Import the settings from configuration config.
Definition: kshortcutseditor.cpp:176
QTextTable
QWidget
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:58
QTextTableCell::firstCursorPosition
QTextCursor firstCursorPosition() const
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
QTextCursor
QTextTable::rows
int rows() const
QWidget::cursor
QCursor cursor() const
QTextFormat::setProperty
void setProperty(int propertyId, const QVariant &value)
QKeySequence::listFromString
QList< QKeySequence > listFromString(const QString &str, SequenceFormat format)
QTextCursor::insertHtml
void insertHtml(const QString &html)
QTreeWidgetItem::child
QTreeWidgetItem * child(int index) const
QTextTableFormat
QPrinter
QHeaderView::showSection
void showSection(int logicalIndex)
KShortcutsEditor::LetterShortcuts
LetterShortcuts
Definition: kshortcutseditor.h:81
QTextBlockFormat
QList::at
const T & at(int i) const
QTreeWidgetItemIterator
QAction::shortcuts
QList< QKeySequence > shortcuts() const
QVariant::value
T value() const
KShortcutsEditor::commit
void commit()
Commit the changes without saving.
Definition: kshortcutseditor.cpp:226
QTextTableFormat::setCellSpacing
void setCellSpacing(qreal spacing)
QTextTableCell::setFormat
void setFormat(const QTextCharFormat &format)
KShortcutsEditor::actionTypes
ActionTypes actionTypes() const
QSet::insert
iterator insert(const T &value)
QTextTableFormat::setHeaderRowCount
void setHeaderRowCount(int count)
QTextCursor::movePosition
bool movePosition(MoveOperation operation, MoveMode mode, int n)
QList::size
int size() const
KShortcutsEditor::printShortcuts
void printShortcuts() const
Opens a printing dialog to print all the shortcuts.
Definition: kshortcutseditor.cpp:266
KTreeWidgetSearchLine::hiddenChanged
void hiddenChanged(QTreeWidgetItem *, bool)
QObject::findChildren
QList< T > findChildren(const QString &name, QFlags< Qt::FindChildOption > options) const
QTreeWidgetItem::setFlags
void setFlags(Qt::ItemFlags flags)
QTreeWidget
QModelIndex::isValid
bool isValid() const
QTextCursor::insertBlock
void insertBlock()
Qt
KShortcutsEditor::clearCollections
void clearCollections()
Removes all action collections from the editor.
Definition: kshortcutseditor.cpp:94
QObject::property
QVariant property(const char *name) const
QTextFrameFormat::setBorder
void setBorder(qreal width)
QPrintDialog
i18nc
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KConfigGroup::exists
bool exists() const
QWidget::setUpdatesEnabled
void setUpdatesEnabled(bool enable)
QTextCursor::endEditBlock
void endEditBlock()
QTextCursor::insertText
void insertText(const QString &text)
QList::isEmpty
bool isEmpty() const
QObject::objectName
objectName
QString::isEmpty
bool isEmpty() const
KActionCollection::actions
QList< QAction * > actions() const
Returns the list of QActions which belong to this action collection.
Definition: kactioncollection.cpp:219
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KShortcutsEditor::GlobalAction
Actions which are triggered by any keypress in the windowing system.
Definition: kshortcutseditor.h:75
QTextTable::setFormat
void setFormat(const QTextTableFormat &format)
KShortcutsEditor::save
void save()
Save the changes.
Definition: kshortcutseditor.cpp:235
QSet
KShortcutsEditor
Widget for configuration of KAccel and KGlobalAccel.
Definition: kshortcutseditor.h:61
KShortcutsEditor::keyChange
void keyChange()
Emitted when an action&#39;s shortcut has been changed.
QString
QList
KShortcutsEditor::isModified
bool isModified() const
Are the unsaved changes?
Definition: kshortcutseditor.cpp:80
KConfigBase
QAction::whatsThis
whatsThis
QPair
KShortcutsEditor::resizeColumns
void resizeColumns()
Resize columns to width required.
Definition: kshortcutseditor.cpp:219
QTextCharFormat
QTextDocument::setDefaultFont
void setDefaultFont(const QFont &font)
QTextBlockFormat::setBottomMargin
void setBottomMargin(qreal margin)
QHeaderView::hideSection
void hideSection(int logicalIndex)
QTextCursor::beginEditBlock
void beginEditBlock()
KShortcutsEditor::allDefault
void allDefault()
Set all shortcuts to their default values (bindings).
Definition: kshortcutseditor.cpp:261
QSet::contains
bool contains(const T &value) const
KConfigGroup::hasKey
bool hasKey(const QString &key) const
QTextBlockFormat::setTopMargin
void setTopMargin(qreal margin)
QTextTableCell::format
QTextCharFormat format() const
KShortcutsEditor::LetterShortcutsAllowed
Letter shortcuts are allowed.
Definition: kshortcutseditor.h:88
QTextCharFormat::setFontWeight
void setFontWeight(int weight)
KShortcutsEditor::addCollection
void addCollection(KActionCollection *, const QString &title=QString())
Insert an action collection, i.e.
Definition: kshortcutseditor.cpp:102
QTextCursor::insertTable
QTextTable * insertTable(int rows, int columns, const QTextTableFormat &format)
i18n
QString i18n(const char *text, const TYPE &arg...)
KConfigGroup
KActionCollection::componentDisplayName
QString componentDisplayName() const
The display name for the associated component.
Definition: kactioncollection.cpp:203
KGlobalAccel::self
static KGlobalAccel * self()
QFontDatabase::systemFont
QFont systemFont(SystemFont type)
KConfig
KShortcutsEditor::writeConfiguration
void writeConfiguration(KConfigGroup *config=nullptr) const
Write the current settings to the config object.
Definition: kshortcutseditor.cpp:211
QTreeWidgetItem::flags
Qt::ItemFlags flags() const
QPrintDialog::exec
virtual int exec()
QKeySequence::toString
QString toString(SequenceFormat format) const
QTreeWidgetItem
QLatin1String
QKeySequence
QTextTable::cellAt
QTextTableCell cellAt(int row, int column) const
QTextDocument
QTextTable::insertRows
void insertRows(int index, int rows)
QAction
KActionCollection::isEmpty
bool isEmpty() const
Returns whether the action collection is empty or not.
Definition: kactioncollection.cpp:169
QTreeWidgetItem::setText
void setText(int column, const QString &text)
QTextTableFormat::setCellPadding
void setCellPadding(qreal padding)
QModelIndex::column
int column() const
QVariant::toBool
bool toBool() const
QTextTableCell
QVariant::isValid
bool isValid() const
QTreeWidgetItem::type
int type() const
QHeaderView
QTextDocument::print
void print(QPagedPaintDevice *printer) const
KGlobalAccel::defaultShortcut
QList< QKeySequence > defaultShortcut(const QAction *action) const
QTextFrameFormat::setBorderStyle
void setBorderStyle(BorderStyle style)
QObject::connect
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KShortcutsEditor::setActionTypes
void setActionTypes(ActionTypes actionTypes)
Sets the types of actions to display in this widget.
Definition: kshortcutseditor.cpp:276
QObject::parent
QObject * parent() const
QTreeWidgetItem::childCount
int childCount() const
KShortcutsEditor::clearConfiguration
void clearConfiguration()
Removes all configured shortcuts.
Definition: kshortcutseditor.cpp:164
QString::data
QChar * data()
QVariant::toString
QString toString() const
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
QTreeWidgetItem::text
QString text(int column) const
QGuiApplication::applicationDisplayName
QString applicationDisplayName()
KShortcutsEditor::~KShortcutsEditor
virtual ~KShortcutsEditor()
Destructor.
Definition: kshortcutseditor.cpp:75
KShortcutsEditor::exportConfiguration
void exportConfiguration(KConfigBase *config) const
Export the current setting to configuration config.
Definition: kshortcutseditor.cpp:188
QTextCursor::blockFormat
QTextBlockFormat blockFormat() const
KShortcutsEditor::KShortcutsEditor
KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionTypes=AllActions, LetterShortcuts allowLetterShortcuts=LetterShortcutsAllowed)
Constructor.
Definition: kshortcutseditor.cpp:59
QTimer::singleShot
singleShot
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Fri Dec 13 2019 02:12:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal