• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • dialogs
kshortcutseditor.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
2  Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org>
3  Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org>
4  Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
5  Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
6  Copyright (C) 2007 Roberto Raggi <roberto@kdevelop.org>
7  Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
8  Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
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 
26 #include "kshortcutseditor.h"
27 
28 // The following is needed for KShortcutsEditorPrivate and QTreeWidgetHack
29 #include "kshortcutsdialog_p.h"
30 
31 #include <QHeaderView>
32 #include <QList>
33 #include <QObject>
34 #include <QTimer>
35 #include <QTextDocument>
36 #include <QTextTable>
37 #include <QTextCursor>
38 #include <QTextTableFormat>
39 #include <QPrinter>
40 #include <QPrintDialog>
41 
42 #include "kaction.h"
43 #include "kactioncollection.h"
44 #include "kactioncategory.h"
45 #include "kdebug.h"
46 #include "kdeprintdialog.h"
47 #include "kglobalaccel.h"
48 #include "kmessagebox.h"
49 #include "kshortcut.h"
50 #include "kaboutdata.h"
51 
52 //---------------------------------------------------------------------
53 // KShortcutsEditor
54 //---------------------------------------------------------------------
55 
56 KShortcutsEditor::KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionType,
57  LetterShortcuts allowLetterShortcuts )
58 : QWidget( parent )
59 , d(new KShortcutsEditorPrivate(this))
60 {
61  d->initGUI(actionType, allowLetterShortcuts);
62  addCollection(collection);
63 }
64 
65 
66 KShortcutsEditor::KShortcutsEditor(QWidget *parent, ActionTypes actionType, LetterShortcuts allowLetterShortcuts)
67 : QWidget(parent)
68 , d(new KShortcutsEditorPrivate(this))
69 {
70  d->initGUI(actionType, allowLetterShortcuts);
71 }
72 
73 
74 KShortcutsEditor::~KShortcutsEditor()
75 {
76  delete d;
77 }
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, SLOT(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 
120  if (displayTitle.isEmpty()) {
121  // Use the programName (Translated).
122  if (const KAboutData *about = collection->componentData().aboutData()) {
123  displayTitle = about->programName();
124  }
125  // Yes it happens. Some apps don't set the programName.
126  if (displayTitle.isEmpty()) {
127  displayTitle = i18n("Unknown");
128  }
129  }
130 
131  QTreeWidgetItem *hier[3];
132  hier[KShortcutsEditorPrivate::Root] = d->ui.list->invisibleRootItem();
133  hier[KShortcutsEditorPrivate::Program] = d->findOrMakeItem( hier[KShortcutsEditorPrivate::Root], displayTitle);
134  hier[KShortcutsEditorPrivate::Action] = NULL;
135 
136  // Set to remember which actions we have seen.
137  QSet<QAction*> actionsSeen;
138 
139  // Add all categories in their own subtree below the collections root node
140  QList<KActionCategory*> categories = collection->findChildren<KActionCategory*>();
141  foreach (KActionCategory *category, categories) {
142  hier[KShortcutsEditorPrivate::Action] = d->findOrMakeItem(hier[KShortcutsEditorPrivate::Program], category->text());
143  foreach(QAction *action, category->actions()) {
144  // Set a marker that we have seen this action
145  actionsSeen.insert(action);
146  d->addAction(action, hier, KShortcutsEditorPrivate::Action);
147  }
148  }
149 
150  // The rest of the shortcuts is added as a direct shild of the action
151  // collections root node
152  foreach (QAction *action, collection->actions()) {
153  if (actionsSeen.contains(action)) {
154  continue;
155  }
156 
157  d->addAction(action, hier, KShortcutsEditorPrivate::Program);
158  }
159 
160  // sort the list
161  d->ui.list->sortItems(Name, Qt::AscendingOrder);
162 
163  // reenable updating
164  setUpdatesEnabled(true);
165 
166  QTimer::singleShot(0, this, SLOT(resizeColumns()));
167 }
168 
169 
170 void KShortcutsEditor::clearConfiguration()
171 {
172  d->clearConfiguration();
173 }
174 
175 
176 #ifndef KDE_NO_DEPRECATED
177 void KShortcutsEditor::importConfiguration( KConfig *config)
178 {
179  d->importConfiguration(config);
180 }
181 #endif
182 
183 
184 void KShortcutsEditor::importConfiguration( KConfigBase *config)
185 {
186  d->importConfiguration(config);
187 }
188 
189 
190 #ifndef KDE_NO_DEPRECATED
191 void KShortcutsEditor::exportConfiguration( KConfig *config) const
192 {
193  exportConfiguration(static_cast<KConfigBase*>(config));
194 }
195 #endif
196 
197 
198 void KShortcutsEditor::exportConfiguration( KConfigBase *config) const
199 {
200  Q_ASSERT(config);
201  if (!config) return;
202 
203  if (d->actionTypes & KShortcutsEditor::GlobalAction) {
204  QString groupName = "Global Shortcuts";
205  KConfigGroup group( config, groupName );
206  foreach (KActionCollection* collection, d->actionCollections) {
207  collection->exportGlobalShortcuts( &group, true );
208  }
209  }
210  if (d->actionTypes & ~KShortcutsEditor::GlobalAction) {
211  QString groupName = "Shortcuts";
212  KConfigGroup group( config, groupName );
213  foreach (KActionCollection* collection, d->actionCollections) {
214  collection->writeSettings( &group, true );
215  }
216  }
217 }
218 
219 
220 void KShortcutsEditor::writeConfiguration( KConfigGroup *config) const
221 {
222  foreach (KActionCollection* collection, d->actionCollections)
223  collection->writeSettings(config);
224 }
225 
226 
227 //slot
228 void KShortcutsEditor::resizeColumns()
229 {
230  for (int i = 0; i < d->ui.list->columnCount(); i++)
231  d->ui.list->resizeColumnToContents(i);
232 }
233 
234 
235 void KShortcutsEditor::commit()
236 {
237  for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
238  if (KShortcutsEditorItem* item = dynamic_cast<KShortcutsEditorItem*>(*it)) {
239  item->commit();
240  }
241  }
242 }
243 
244 
245 void KShortcutsEditor::save()
246 {
247  writeConfiguration();
248  // we have to call commit. If we wouldn't do that the changes would be
249  // undone on deletion! That would lead to weird problems. Changes to
250  // Global Shortcuts would vanish completely. Changes to local shortcuts
251  // would vanish for this session.
252  commit();
253 }
254 
255 
256 // KDE5 : rename to undo()
257 void KShortcutsEditor::undoChanges()
258 {
259  //This function used to crash sometimes when invoked by clicking on "cancel"
260  //with Qt 4.2.something. Apparently items were deleted too early by Qt.
261  //It seems to work with 4.3-ish Qt versions. Keep an eye on this.
262  for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
263  if (KShortcutsEditorItem* item = dynamic_cast<KShortcutsEditorItem*>(*it)) {
264  item->undo();
265  }
266  }
267 }
268 
269 
270 //We ask the user here if there are any conflicts, as opposed to undoChanges().
271 //They don't do the same thing anyway, this just not to confuse any readers.
272 //slot
273 void KShortcutsEditor::allDefault()
274 {
275  d->allDefault();
276 }
277 
278 
279 void KShortcutsEditor::printShortcuts() const
280 {
281  d->printShortcuts();
282 }
283 
284 
285 //---------------------------------------------------------------------
286 // KShortcutsEditorPrivate
287 //---------------------------------------------------------------------
288 
289 KShortcutsEditorPrivate::KShortcutsEditorPrivate( KShortcutsEditor *q )
290  : q(q),
291  delegate(0)
292  {}
293 
294 void KShortcutsEditorPrivate::initGUI( KShortcutsEditor::ActionTypes types, KShortcutsEditor::LetterShortcuts allowLetterShortcuts )
295 {
296  actionTypes = types;
297 
298  ui.setupUi(q);
299  q->layout()->setMargin(0);
300  ui.searchFilter->searchLine()->setTreeWidget(ui.list); // Plug into search line
301  ui.list->header()->setResizeMode(QHeaderView::ResizeToContents);
302  ui.list->header()->hideSection(GlobalAlternate); //not expected to be very useful
303  ui.list->header()->hideSection(ShapeGesture); //mouse gestures didn't make it in time...
304  ui.list->header()->hideSection(RockerGesture);
305  if (!(actionTypes & KShortcutsEditor::GlobalAction)) {
306  ui.list->header()->hideSection(GlobalPrimary);
307  } else if (!(actionTypes & ~KShortcutsEditor::GlobalAction)) {
308  ui.list->header()->hideSection(LocalPrimary);
309  ui.list->header()->hideSection(LocalAlternate);
310  }
311 
312  // Create the Delegate. It is responsible for the KKeySeqeunceWidgets that
313  // really change the shortcuts.
314  delegate = new KShortcutsEditorDelegate(
315  ui.list,
316  allowLetterShortcuts == KShortcutsEditor::LetterShortcutsAllowed);
317 
318  ui.list->setItemDelegate(delegate);
319  ui.list->setSelectionBehavior(QAbstractItemView::SelectItems);
320  ui.list->setSelectionMode(QAbstractItemView::SingleSelection);
321  //we have our own editing mechanism
322  ui.list->setEditTriggers(QAbstractItemView::NoEditTriggers);
323  ui.list->setAlternatingRowColors(true);
324 
325  //TODO listen to changes to global shortcuts
326  QObject::connect(delegate, SIGNAL(shortcutChanged(QVariant,QModelIndex)),
327  q, SLOT(capturedShortcut(QVariant,QModelIndex)));
328  //hide the editor widget chen its item becomes hidden
329  QObject::connect(ui.searchFilter->searchLine(), SIGNAL(hiddenChanged(QTreeWidgetItem*,bool)),
330  delegate, SLOT(hiddenBySearchLine(QTreeWidgetItem*,bool)));
331 
332  ui.searchFilter->setFocus();
333 }
334 
335 
336 bool KShortcutsEditorPrivate::addAction(QAction *action, QTreeWidgetItem *hier[], hierarchyLevel level)
337 {
338  // If the action name starts with unnamed- spit out a warning and ignore
339  // it. That name will change at will and will break loading and writing
340  QString actionName = action->objectName();
341  if (actionName.isEmpty() || actionName.startsWith(QLatin1String("unnamed-"))) {
342  kError() << "Skipping action without name " << action->text() << "," << actionName << "!";
343  return false;
344  }
345 
346  // This code doesn't allow editing of QAction. It can not distinguish
347  // between default and active shortcuts. This breaks many assumptions the
348  // editor makes.
349  KAction *kact;
350  if ((kact = qobject_cast<KAction *>(action)) && kact->isShortcutConfigurable()) {
351  new KShortcutsEditorItem((hier[level]), kact);
352  return true;
353  }
354 
355  return false;
356 }
357 
358 void KShortcutsEditorPrivate::allDefault()
359 {
360  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
361  if (!(*it)->parent() || (*it)->type() != ActionItem)
362  continue;
363 
364  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
365  KAction *act = item->m_action;
366 
367  if (act->shortcut() != act->shortcut(KAction::DefaultShortcut)) {
368  changeKeyShortcut(item, LocalPrimary, act->shortcut(KAction::DefaultShortcut).primary());
369  changeKeyShortcut(item, LocalAlternate, act->shortcut(KAction::DefaultShortcut).alternate());
370  }
371 
372  if (act->globalShortcut() != act->globalShortcut(KAction::DefaultShortcut)) {
373  changeKeyShortcut(item, GlobalPrimary, act->globalShortcut(KAction::DefaultShortcut).primary());
374  changeKeyShortcut(item, GlobalAlternate, act->globalShortcut(KAction::DefaultShortcut).alternate());
375  }
376 
377  if (act->shapeGesture() != act->shapeGesture(KAction::DefaultShortcut))
378  changeShapeGesture(item, act->shapeGesture(KAction::DefaultShortcut));
379 
380  if (act->rockerGesture() != act->rockerGesture(KAction::DefaultShortcut))
381  changeRockerGesture(item, act->rockerGesture(KAction::DefaultShortcut));
382  }
383 }
384 
385 //static
386 KShortcutsEditorItem *KShortcutsEditorPrivate::itemFromIndex(QTreeWidget *const w,
387  const QModelIndex &index)
388 {
389  QTreeWidgetItem *item = static_cast<QTreeWidgetHack *>(w)->itemFromIndex(index);
390  if (item && item->type() == ActionItem) {
391  return static_cast<KShortcutsEditorItem *>(item);
392  }
393  return 0;
394 }
395 
396 
397 QTreeWidgetItem *KShortcutsEditorPrivate::findOrMakeItem(QTreeWidgetItem *parent, const QString &name)
398 {
399  for (int i = 0; i < parent->childCount(); i++) {
400  QTreeWidgetItem *child = parent->child(i);
401  if (child->text(0) == name)
402  return child;
403  }
404  QTreeWidgetItem *ret = new QTreeWidgetItem(parent, NonActionItem);
405  ret->setText(0, name);
406  ui.list->expandItem(ret);
407  ret->setFlags(ret->flags() & ~Qt::ItemIsSelectable);
408  return ret;
409 }
410 
411 
412 //private slot
413 void KShortcutsEditorPrivate::capturedShortcut(const QVariant &newShortcut, const QModelIndex &index)
414 {
415  //dispatch to the right handler
416  if (!index.isValid())
417  return;
418  int column = index.column();
419  KShortcutsEditorItem *item = itemFromIndex(ui.list, index);
420  Q_ASSERT(item);
421 
422  if (column >= LocalPrimary && column <= GlobalAlternate)
423  changeKeyShortcut(item, column, newShortcut.value<QKeySequence>());
424  else if (column == ShapeGesture)
425  changeShapeGesture(item, newShortcut.value<KShapeGesture>());
426  else if (column == RockerGesture)
427  changeRockerGesture(item, newShortcut.value<KRockerGesture>());
428 }
429 
430 
431 void KShortcutsEditorPrivate::changeKeyShortcut(KShortcutsEditorItem *item, uint column, const QKeySequence &capture)
432 {
433  // The keySequence we get is cleared by KKeySequenceWidget. No conflicts.
434  if (capture == item->keySequence(column)) {
435  return;
436  }
437 
438  item->setKeySequence(column, capture);
439  q->keyChange();
440  //force view update
441  item->setText(column, capture.toString(QKeySequence::NativeText));
442 }
443 
444 
445 void KShortcutsEditorPrivate::changeShapeGesture(KShortcutsEditorItem *item, const KShapeGesture &capture)
446 {
447  if (capture == item->m_action->shapeGesture())
448  return;
449 
450  if (capture.isValid()) {
451  bool conflict = false;
452  KShortcutsEditorItem *otherItem;
453 
454  //search for conflicts
455  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
456  if (!(*it)->parent() || (*it == item))
457  continue;
458 
459  otherItem = static_cast<KShortcutsEditorItem *>(*it);
460 
461  //comparisons are possibly expensive
462  if (!otherItem->m_action->shapeGesture().isValid())
463  continue;
464 
465  if (capture == otherItem->m_action->shapeGesture()) {
466  conflict = true;
467  break;
468  }
469  }
470 
471  if (conflict && !stealShapeGesture(otherItem, capture))
472  return;
473  }
474 
475  item->setShapeGesture(capture);
476 }
477 
478 
479 void KShortcutsEditorPrivate::changeRockerGesture(KShortcutsEditorItem *item, const KRockerGesture &capture)
480 {
481  if (capture == item->m_action->rockerGesture())
482  return;
483 
484  if (capture.isValid()) {
485  bool conflict = false;
486  KShortcutsEditorItem *otherItem;
487 
488  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
489  if (!(*it)->parent() || (*it == item))
490  continue;
491 
492  otherItem = static_cast<KShortcutsEditorItem *>(*it);
493 
494  if (capture == otherItem->m_action->rockerGesture()) {
495  conflict = true;
496  break;
497  }
498  }
499 
500  if (conflict && !stealRockerGesture(otherItem, capture))
501  return;
502  }
503 
504  item->setRockerGesture(capture);
505 }
506 
507 
508 void KShortcutsEditorPrivate::clearConfiguration()
509 {
510  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
511  if (!(*it)->parent())
512  continue;
513 
514  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
515 
516  changeKeyShortcut(item, LocalPrimary, QKeySequence());
517  changeKeyShortcut(item, LocalAlternate, QKeySequence());
518 
519  changeKeyShortcut(item, GlobalPrimary, QKeySequence());
520  changeKeyShortcut(item, GlobalAlternate, QKeySequence());
521 
522  changeShapeGesture(item, KShapeGesture() );
523 
524  }
525 }
526 
527 
528 void KShortcutsEditorPrivate::importConfiguration(KConfigBase *config)
529 {
530  Q_ASSERT(config);
531  if (!config) return;
532 
533  KConfigGroup globalShortcutsGroup(config, QLatin1String("Global Shortcuts"));
534  if ((actionTypes & KShortcutsEditor::GlobalAction) && globalShortcutsGroup.exists()) {
535 
536  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
537 
538  if (!(*it)->parent())
539  continue;
540 
541  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
542 
543  QString actionName = item->data(Id).toString();
544  KShortcut sc(globalShortcutsGroup.readEntry(actionName, QString()));
545  changeKeyShortcut(item, GlobalPrimary, sc.primary());
546  }
547  }
548 
549  KConfigGroup localShortcutsGroup(config, QLatin1String("Shortcuts"));
550  if (actionTypes & ~KShortcutsEditor::GlobalAction) {
551 
552  for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
553 
554  if (!(*it)->parent())
555  continue;
556 
557  KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
558 
559  QString actionName = item->data(Name).toString();
560  KShortcut sc(localShortcutsGroup.readEntry(actionName, QString()));
561  changeKeyShortcut(item, LocalPrimary, sc.primary());
562  changeKeyShortcut(item, LocalAlternate, sc.alternate());
563  }
564  }
565 }
566 
567 
568 bool KShortcutsEditorPrivate::stealShapeGesture(KShortcutsEditorItem *item, const KShapeGesture &gst)
569 {
570  QString title = i18n("Key Conflict");
571  QString message = i18n("The '%1' shape gesture has already been allocated to the \"%2\" action.\n"
572  "Do you want to reassign it from that action to the current one?",
573  gst.shapeName(), item->m_action->text());
574 
575  if (KMessageBox::warningContinueCancel(q, message, title, KGuiItem(i18n("Reassign")))
576  != KMessageBox::Continue)
577  return false;
578 
579  item->setShapeGesture(KShapeGesture());
580  return true;
581 }
582 
583 
584 bool KShortcutsEditorPrivate::stealRockerGesture(KShortcutsEditorItem *item, const KRockerGesture &gst)
585 {
586  QString title = i18n("Key Conflict");
587  QString message = i18n("The '%1' rocker gesture has already been allocated to the \"%2\" action.\n"
588  "Do you want to reassign it from that action to the current one?",
589  gst.rockerName(), item->m_action->text());
590 
591  if (KMessageBox::warningContinueCancel(q, message, title, KGuiItem(i18n("Reassign")))
592  != KMessageBox::Continue)
593  return false;
594 
595  item->setRockerGesture(KRockerGesture());
596  return true;
597 }
598 
599 
600 /*TODO for the printShortcuts function
601 Nice to have features (which I'm not sure I can do before may due to
602 more important things):
603 
604 - adjust the general page borders, IMHO they're too wide
605 
606 - add a custom printer options page that allows to filter out all
607  actions that don't have a shortcut set to reduce this list. IMHO this
608  should be optional as people might want to simply print all and when
609  they find a new action that they assign a shortcut they can simply use
610  a pen to fill out the empty space
611 
612 - find a way to align the Main/Alternate/Global entries in the shortcuts
613  column without adding borders. I first did this without a nested table
614  but instead simply added 3 rows and merged the 3 cells in the Action
615  name and description column, but unfortunately I didn't find a way to
616  remove the borders between the 6 shortcut cells.
617 */
618 void KShortcutsEditorPrivate::printShortcuts() const
619 {
620 // One cant print on wince
621 #ifndef _WIN32_WCE
622  QTreeWidgetItem* root = ui.list->invisibleRootItem();
623  QTextDocument doc;
624  doc.setDefaultFont(KGlobalSettings::generalFont());
625  QTextCursor cursor(&doc);
626  cursor.beginEditBlock();
627  QTextCharFormat headerFormat;
628  headerFormat.setProperty(QTextFormat::FontSizeAdjustment, 3);
629  headerFormat.setFontWeight(QFont::Bold);
630  cursor.insertText(i18nc("header for an applications shortcut list","Shortcuts for %1",
631  KGlobal::mainComponent().aboutData()->programName()),
632  headerFormat);
633  QTextCharFormat componentFormat;
634  componentFormat.setProperty(QTextFormat::FontSizeAdjustment, 2);
635  componentFormat.setFontWeight(QFont::Bold);
636  QTextBlockFormat componentBlockFormat = cursor.blockFormat();
637  componentBlockFormat.setTopMargin(16);
638  componentBlockFormat.setBottomMargin(16);
639 
640  QTextTableFormat tableformat;
641  tableformat.setHeaderRowCount(1);
642  tableformat.setCellPadding(4.0);
643  tableformat.setCellSpacing(0);
644  tableformat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
645  tableformat.setBorder(0.5);
646 
647  QList<QPair<QString,ColumnDesignation> > shortcutTitleToColumn;
648  shortcutTitleToColumn << qMakePair(i18n("Main:"), LocalPrimary);
649  shortcutTitleToColumn << qMakePair(i18n("Alternate:"), LocalAlternate);
650  shortcutTitleToColumn << qMakePair(i18n("Global:"), GlobalPrimary);
651 
652  for (int i = 0; i < root->childCount(); i++) {
653  QTreeWidgetItem* item = root->child(i);
654  cursor.insertBlock(componentBlockFormat, componentFormat);
655  cursor.insertText(item->text(0));
656 
657  QTextTable* table = cursor.insertTable(1,3);
658  table->setFormat(tableformat);
659  int currow = 0;
660 
661  QTextTableCell cell = table->cellAt(currow,0);
662  QTextCharFormat format = cell.format();
663  format.setFontWeight(QFont::Bold);
664  cell.setFormat(format);
665  cell.firstCursorPosition().insertText(i18n("Action Name"));
666 
667  cell = table->cellAt(currow,1);
668  cell.setFormat(format);
669  cell.firstCursorPosition().insertText(i18n("Shortcuts"));
670 
671  cell = table->cellAt(currow,2);
672  cell.setFormat(format);
673  cell.firstCursorPosition().insertText(i18n("Description"));
674  currow++;
675 
676  for (QTreeWidgetItemIterator it(item); *it; ++it) {
677  if ((*it)->type() != ActionItem)
678  continue;
679 
680  KShortcutsEditorItem* editoritem = static_cast<KShortcutsEditorItem*>(*it);
681  table->insertRows(table->rows(),1);
682  QVariant data = editoritem->data(Name,Qt::DisplayRole);
683  table->cellAt(currow, 0).firstCursorPosition().insertText(data.toString());
684 
685  QTextTable* shortcutTable = 0 ;
686  for(int k = 0; k < shortcutTitleToColumn.count(); k++) {
687  data = editoritem->data(shortcutTitleToColumn.at(k).second,Qt::DisplayRole);
688  QString key = data.value<QKeySequence>().toString();
689 
690  if(!key.isEmpty()) {
691  if( !shortcutTable ) {
692  shortcutTable = table->cellAt(currow, 1).firstCursorPosition().insertTable(1,2);
693  QTextTableFormat shortcutTableFormat = tableformat;
694  shortcutTableFormat.setCellSpacing(0.0);
695  shortcutTableFormat.setHeaderRowCount(0);
696  shortcutTableFormat.setBorder(0.0);
697  shortcutTable->setFormat(shortcutTableFormat);
698  } else {
699  shortcutTable->insertRows(shortcutTable->rows(),1);
700  }
701  shortcutTable->cellAt(shortcutTable->rows()-1,0).firstCursorPosition().insertText(shortcutTitleToColumn.at(k).first);
702  shortcutTable->cellAt(shortcutTable->rows()-1,1).firstCursorPosition().insertText(key);
703  }
704  }
705 
706  KAction* action = editoritem->m_action;
707  cell = table->cellAt(currow, 2);
708  format = cell.format();
709  format.setProperty(QTextFormat::FontSizeAdjustment, -1);
710  cell.setFormat(format);
711  cell.firstCursorPosition().insertHtml(action->whatsThis());
712 
713  currow++;
714  }
715  cursor.movePosition(QTextCursor::End);
716  }
717  cursor.endEditBlock();
718 
719  QPrinter printer;
720  QPrintDialog *dlg = KdePrint::createPrintDialog(&printer, q);
721  if (dlg->exec() == QDialog::Accepted) {
722  doc.print(&printer);
723  }
724  delete dlg;
725 #endif
726 }
727 
728 #include "kshortcutseditor.moc"
KShortcutsEditor::writeConfiguration
void writeConfiguration(KConfigGroup *config=0) const
Write the current settings to the config object.
Definition: kshortcutseditor.cpp:220
QAction::text
text
message
void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
KShortcutsEditor::undoChanges
void undoChanges()
Undo all change made since the last commit().
Definition: kshortcutseditor.cpp:257
i18n
QString i18n(const char *text)
KActionCategory
Categorize actions for KShortcutsEditor.
Definition: kactioncategory.h:95
QModelIndex
QTextTable
QWidget
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:56
QTextTableCell::firstCursorPosition
QTextCursor firstCursorPosition() const
QWidget::setupUi
void setupUi(QWidget *widget)
KMessageBox::Continue
Definition: kmessagebox.h:74
QTextCursor
QTextTable::rows
int rows() const
kdebug.h
QTextFormat::setProperty
void setProperty(int propertyId, const QVariant &value)
KShapeGesture::isValid
bool isValid() const
Return true if this gesture is valid.
Definition: kgesture.cpp:158
KActionCollection::componentData
KComponentData componentData() const
The KComponentData with which this class is associated.
Definition: kactioncollection.cpp:176
QTextCursor::insertHtml
void insertHtml(const QString &html)
QTreeWidgetItem::child
QTreeWidgetItem * child(int index) const
QTextTableFormat
group
QPrinter
KRockerGesture
Definition: kgesture.h:152
KAction::shapeGesture
KShapeGesture shapeGesture(ShortcutTypes type=ActiveShortcut) const
Definition: kaction.cpp:323
kactioncollection.h
KShortcutsEditor::LetterShortcuts
LetterShortcuts
Definition: kshortcutseditor.h:79
KShortcutsEditor::exportConfiguration
void exportConfiguration(KConfig *config) const
Export the current setting to configuration config.
Definition: kshortcutseditor.cpp:191
QTextBlockFormat
QList::at
const T & at(int i) const
QTreeWidgetItemIterator
KActionCategory::text
QString text
Definition: kactioncategory.h:99
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
kshortcut.h
Defines platform-independent classes for keyboard shortcut handling.
KActionCollection::writeSettings
void writeSettings(KConfigGroup *config=0, bool writeDefaults=false, QAction *oneAction=0) const
Write the current configurable key associations to config.
Definition: kactioncollection.cpp:563
QVariant::value
T value() const
KShortcutsEditor::commit
void commit()
Commit the changes without saving.
Definition: kshortcutseditor.cpp:235
QTextTableFormat::setCellSpacing
void setCellSpacing(qreal spacing)
KAction::shortcut
KShortcut shortcut
Definition: kaction.h:220
QTextTableCell::setFormat
void setFormat(const QTextCharFormat &format)
KComponentData::aboutData
const KAboutData * aboutData() const
KAction::globalShortcut
KShortcut globalShortcut
Definition: kaction.h:222
QSet::insert
const_iterator insert(const T &value)
KAction::DefaultShortcut
The shortcut is a default shortcut - it becomes active when somebody decides to reset shortcuts to de...
Definition: kaction.h:238
KdePrint::createPrintDialog
QPrintDialog * createPrintDialog(QPrinter *printer, PageSelectPolicy pageSelectPolicy, const QList< QWidget * > &customTabs, QWidget *parent=0)
Definition: kdeprintdialog.cpp:39
QTextTableFormat::setHeaderRowCount
void setHeaderRowCount(int count)
i18nc
QString i18nc(const char *ctxt, const char *text)
KShortcutsEditor::printShortcuts
void printShortcuts() const
Opens a printing dialog to print all the shortcuts.
Definition: kshortcutseditor.cpp:279
KShortcut
Represents a keyboard shortcut.
Definition: kshortcut.h:57
QObject::findChildren
QList< T > findChildren(const QString &name) const
QTreeWidgetItem::setFlags
void setFlags(QFlags< Qt::ItemFlag > flags)
QTreeWidget
QModelIndex::isValid
bool isValid() const
kshortcutseditor.h
QList::count
int count(const T &value) const
KStandardShortcut::End
Definition: kstandardshortcut.h:69
KShortcutsEditor::clearCollections
void clearCollections()
Removes all action collections from the editor.
Definition: kshortcutseditor.cpp:94
QTextFrameFormat::setBorder
void setBorder(qreal width)
QPrintDialog
QWidget::setUpdatesEnabled
void setUpdatesEnabled(bool enable)
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:36
QTextCursor::insertText
void insertText(const QString &text)
QObject::objectName
objectName
QString::isEmpty
bool isEmpty() const
KActionCollection::actions
QList< QAction * > actions() const
Returns the list of KActions which belong to this action collection.
Definition: kactioncollection.cpp:186
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:73
KAboutData
QTextTable::setFormat
void setFormat(const QTextTableFormat &format)
KShortcutsEditor::save
void save()
Save the changes.
Definition: kshortcutseditor.cpp:245
QSet
KShortcutsEditor
Widget for configuration of KAccel and KGlobalAccel.
Definition: kshortcutseditor.h:60
QString
QList
KShortcutsEditor::isModified
bool isModified() const
Are the unsaved changes?
Definition: kshortcutseditor.cpp:80
KShortcutsEditor::importConfiguration
void importConfiguration(KConfig *config)
Import the settings from configuration config.
Definition: kshortcutseditor.cpp:177
KConfigBase
QAction::whatsThis
whatsThis
KShortcutsEditor::resizeColumns
void resizeColumns()
Resize columns to width required.
Definition: kshortcutseditor.cpp:228
kaction.h
QTextCharFormat
QTextDocument::setDefaultFont
void setDefaultFont(const QFont &font)
QTextBlockFormat::setBottomMargin
void setBottomMargin(qreal margin)
KShortcut::alternate
QKeySequence alternate() const
Returns the alternate key sequence of this shortcut.
Definition: kshortcut.cpp:139
KShortcutsEditor::allDefault
void allDefault()
Set all shortcuts to their default values (bindings).
Definition: kshortcutseditor.cpp:273
QSet::contains
bool contains(const T &value) const
QTextBlockFormat::setTopMargin
void setTopMargin(qreal margin)
QTextTableCell::format
QTextCharFormat format() const
KShortcutsEditor::LetterShortcutsAllowed
Letter shortcuts are allowed.
Definition: kshortcutseditor.h:86
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)
KConfigGroup
KRockerGesture::rockerName
QString rockerName() const
Return a user-friendly name of the button combination.
Definition: kgesture.cpp:532
KConfig
KAction::rockerGesture
KRockerGesture rockerGesture(ShortcutTypes type=ActiveShortcut) const
Definition: kaction.cpp:332
KActionCollection::exportGlobalShortcuts
void exportGlobalShortcuts(KConfigGroup *config, bool writeDefaults=false) const
Export the current configurable global key associations to config.
Definition: kactioncollection.cpp:444
kdeprintdialog.h
KGlobalSettings::generalFont
static QFont generalFont()
Returns the default general font.
Definition: kglobalsettings.cpp:446
QTreeWidgetItem::flags
Qt::ItemFlags flags() const
QPrintDialog::exec
virtual int exec()
QKeySequence::toString
QString toString(SequenceFormat format) const
QTest::toString
char * toString(const T &value)
QTreeWidgetItem
QLatin1String
QKeySequence
KShapeGesture
Definition: kgesture.h:37
QTextTable::cellAt
QTextTableCell cellAt(int row, int column) const
KActionCategory::actions
const QList< QAction * > actions() const
Returns the actions belonging to this category.
Definition: kactioncategory.cpp:57
QTextDocument
QTextTable::insertRows
void insertRows(int index, int rows)
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
KActionCollection::isEmpty
bool isEmpty() const
Returns whether the action collection is empty or not.
Definition: kactioncollection.cpp:152
QTreeWidgetItem::setText
void setText(int column, const QString &text)
QTextTableFormat::setCellPadding
void setCellPadding(qreal padding)
KGlobal::mainComponent
const KComponentData & mainComponent()
QModelIndex::column
int column() const
QTextTableCell
KAction::isShortcutConfigurable
bool isShortcutConfigurable() const
Returns true if this action's shortcut is configurable.
Definition: kaction.cpp:173
KRockerGesture::isValid
bool isValid() const
Return true if this gesture is valid.
Definition: kgesture.cpp:544
QTreeWidgetItem::type
int type() const
QTextDocument::print
void print(QPrinter *printer) const
kaboutdata.h
kglobalaccel.h
kactioncategory.h
KShortcut::primary
QKeySequence primary() const
Returns the primary key sequence of this shortcut.
Definition: kshortcut.cpp:134
QTextFrameFormat::setBorderStyle
void setBorderStyle(BorderStyle style)
kmessagebox.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QTreeWidgetItem::childCount
int childCount() const
KShortcutsEditor::clearConfiguration
void clearConfiguration()
Removes all configured shortcuts.
Definition: kshortcutseditor.cpp:170
QString::data
QChar * data()
QVariant::toString
QString toString() const
QTreeWidgetItem::text
QString text(int column) const
KMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
Display a "warning" dialog.
Definition: kmessagebox.cpp:644
KShortcutsEditor::~KShortcutsEditor
virtual ~KShortcutsEditor()
Destructor.
Definition: kshortcutseditor.cpp:74
KShortcutsEditor::KShortcutsEditor
KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionTypes=AllActions, LetterShortcuts allowLetterShortcuts=LetterShortcutsAllowed)
Constructor.
Definition: kshortcutseditor.cpp:56
KShapeGesture::shapeName
QString shapeName() const
Return the user-visible name for this gesture's shape, like "triangle" or "line". ...
Definition: kgesture.cpp:152
QTimer::singleShot
singleShot
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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