• 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
kshortcutsdialog.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  Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
10  Copyright (C) 2009 Chani Armitage <chani@kde.org>
11 
12  This library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU Library General Public
14  License as published by the Free Software Foundation; either
15  version 2 of the License, or (at your option) any later version.
16 
17  This library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Library General Public License for more details.
21 
22  You should have received a copy of the GNU Library General Public License
23  along with this library; see the file COPYING.LIB. If not, write to
24  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  Boston, MA 02110-1301, USA.
26 */
27 
28 #include "kshortcutsdialog.h"
29 #include "kshortcutsdialog_p.h"
30 #include "kshortcutschemeshelper_p.h"
31 
32 #include "kdebug.h"
33 #include "klocale.h"
34 
35 #include <QApplication>
36 #include <QDomDocument>
37 
38 #include <kmessagebox.h>
39 #include <kxmlguiclient.h>
40 #include <kxmlguifactory.h>
41 #include <kactioncollection.h>
42 
43 /************************************************************************/
44 /* KShortcutsDialog */
45 /* */
46 /* Originally by Nicolas Hadacek <hadacek@via.ecp.fr> */
47 /* */
48 /* Substantially revised by Mark Donohoe <donohoe@kde.org> */
49 /* */
50 /* And by Espen Sand <espen@kde.org> 1999-10-19 */
51 /* (by using KDialog there is almost no code left ;) */
52 /* */
53 /************************************************************************/
54 
55 class KShortcutsDialog::KShortcutsDialogPrivate
56 {
57 public:
58 
59  KShortcutsDialogPrivate(KShortcutsDialog *q): q(q), m_keyChooser(0), m_schemeEditor(0)
60  {}
61 
62  QList<KActionCollection*> m_collections;
63 
64  void changeShortcutScheme(const QString &scheme)
65  {
66  if (m_keyChooser->isModified() && KMessageBox::questionYesNo(q,
67  i18n("The current shortcut scheme is modified. Save before switching to the new one?")) == KMessageBox::Yes) {
68  m_keyChooser->save();
69  } else {
70  m_keyChooser->undoChanges();
71  }
72 
73  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
74  m_keyChooser->clearCollections();
75 
76  foreach (KActionCollection *collection, m_collections) {
77  // passing an empty stream forces the clients to reread the XML
78  KXMLGUIClient *client = const_cast<KXMLGUIClient *>(collection->parentGUIClient());
79  if (client) {
80  client->setXMLGUIBuildDocument( QDomDocument() );
81  }
82  }
83 
84  //get xmlguifactory
85  if (!m_collections.isEmpty()) {
86  const KXMLGUIClient *client = m_collections.first()->parentGUIClient();
87  if (client) {
88  KXMLGUIFactory *factory = client->factory();
89  if (factory) {
90  factory->changeShortcutScheme(scheme);
91  }
92  }
93  }
94 
95  foreach (KActionCollection *collection, m_collections) {
96  m_keyChooser->addCollection(collection);
97  }
98 
99  QApplication::restoreOverrideCursor();
100  }
101 
102  void undoChanges()
103  {
104  m_keyChooser->undoChanges();
105  }
106 
107  void save()
108  {
109  m_keyChooser->save();
110  emit q->saved();
111  }
112 
113  KShortcutsDialog *q;
114  KShortcutsEditor* m_keyChooser; // ### move
115  KShortcutSchemesEditor* m_schemeEditor;
116 };
117 
118 
119 KShortcutsDialog::KShortcutsDialog( KShortcutsEditor::ActionTypes types, KShortcutsEditor::LetterShortcuts allowLetterShortcuts, QWidget *parent )
120 : KDialog( parent ), d(new KShortcutsDialogPrivate(this))
121 {
122  setCaption(i18n("Configure Shortcuts"));
123  setButtons(Details|Reset|Ok|Cancel|KDialog::User1);
124  setButtonText(KDialog::User1, i18n("Print"));
125  setButtonIcon(KDialog::User1, KIcon("document-print"));
126  setModal(true);
127  d->m_keyChooser = new KShortcutsEditor( this, types, allowLetterShortcuts );
128  setMainWidget( d->m_keyChooser );
129  setButtonText(Reset,i18n("Reset to Defaults"));
130 
131  d->m_schemeEditor = new KShortcutSchemesEditor(this);
132  connect( d->m_schemeEditor, SIGNAL(shortcutsSchemeChanged(QString)),
133  this, SLOT(changeShortcutScheme(QString)) );
134  setDetailsWidget(d->m_schemeEditor);
135 
136  connect( this, SIGNAL(resetClicked()), d->m_keyChooser, SLOT(allDefault()) );
137  connect( this, SIGNAL(user1Clicked()), d->m_keyChooser, SLOT(printShortcuts()) );
138  connect(this, SIGNAL(cancelClicked()), SLOT(undoChanges()));
139 
140  KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
141  resize( group.readEntry( "Dialog Size", sizeHint() ) );
142 }
143 
144 
145 KShortcutsDialog::~KShortcutsDialog()
146 {
147  KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
148  group.writeEntry( "Dialog Size", size(), KConfigGroup::Persistent|KConfigGroup::Global );
149  delete d;
150 }
151 
152 
153 void KShortcutsDialog::addCollection(KActionCollection *collection, const QString &title)
154 {
155  d->m_keyChooser->addCollection(collection, title);
156  d->m_collections << collection;
157 }
158 
159 
160 QList<KActionCollection*> KShortcutsDialog::actionCollections() const
161 {
162  return d->m_collections;
163 }
164 
165 //FIXME should there be a setSaveSettings method?
166 bool KShortcutsDialog::configure(bool saveSettings)
167 {
168  disconnect(this, SIGNAL(okClicked()), this, SLOT(save()));
169  if (saveSettings) {
170  connect(this, SIGNAL(okClicked()), this, SLOT(save()));
171  }
172  if (isModal()) {
173  int retcode = exec();
174  return retcode;
175  } else {
176  show();
177  return false;
178  }
179 }
180 
181 QSize KShortcutsDialog::sizeHint() const
182 {
183  return QSize(600, 480);
184 }
185 
186 int KShortcutsDialog::configure(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts,
187  QWidget *parent, bool saveSettings)
188 {
189  kDebug(125) << "KShortcutsDialog::configureKeys( KActionCollection*, " << saveSettings << " )";
190  KShortcutsDialog dlg(KShortcutsEditor::AllActions, allowLetterShortcuts, parent);
191  dlg.d->m_keyChooser->addCollection(collection);
192  return dlg.configure(saveSettings);
193 }
194 
195 #include "kshortcutsdialog.moc"
196 #include "kshortcutsdialog_p.moc"
197 
198 //kate: space-indent on; indent-width 4; replace-tabs on;tab-width 4;
i18n
QString i18n(const char *text)
QWidget
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:56
KShortcutsEditor::AllActions
All actions.
Definition: kshortcutseditor.h:75
QDialog::setModal
void setModal(bool modal)
KDialog::okClicked
void okClicked()
The OK button was pressed.
kdebug.h
KXMLGUIClient
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
Definition: kxmlguiclient.h:46
group
KDialog::Reset
Show Reset button.
Definition: kdialog.h:148
kactioncollection.h
KShortcutsEditor::LetterShortcuts
LetterShortcuts
Definition: kshortcutseditor.h:79
KDialog::Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected) ...
Definition: kdialog.h:144
kxmlguifactory.h
KShortcutsDialog::KShortcutsDialog
KShortcutsDialog(KShortcutsEditor::ActionTypes types=KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcuts allowLetterShortcuts=KShortcutsEditor::LetterShortcutsAllowed, QWidget *parent=0)
Constructs a KShortcutsDialog as a child of parent.
Definition: kshortcutsdialog.cpp:119
QDialog::exec
int exec()
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KXMLGUIClient::factory
KXMLGUIFactory * factory() const
Retrieves a pointer to the KXMLGUIFactory this client is associated with (will return 0 if the client...
Definition: kxmlguiclient.cpp:602
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:128
KShortcutsDialog::KShortcutsDialogPrivate
friend class KShortcutsDialogPrivate
Definition: kshortcutsdialog.h:138
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
KDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:469
KGlobal::config
KSharedConfigPtr config()
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: kdialog.cpp:338
kshortcutsdialog.h
QWidget::resize
void resize(int w, int h)
KDialog::cancelClicked
void cancelClicked()
The Cancel button was pressed.
QApplication::setOverrideCursor
void setOverrideCursor(const QCursor &cursor)
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
QApplication::restoreOverrideCursor
void restoreOverrideCursor()
KDialog::resetClicked
void resetClicked()
The Reset button was pressed.
KShortcutsEditor
Widget for configuration of KAccel and KGlobalAccel.
Definition: kshortcutseditor.h:60
QString
QList< KActionCollection * >
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
QWidget::isModal
bool isModal() const
KShortcutsDialog::actionCollections
QList< KActionCollection * > actionCollections() const
Definition: kshortcutsdialog.cpp:160
KDialog::setButtonIcon
void setButtonIcon(ButtonCode id, const KIcon &icon)
Sets the icon of any button.
Definition: kdialog.cpp:742
KShortcutsDialog::addCollection
void addCollection(KActionCollection *, const QString &title=QString())
Add all actions of the collection to the ones displayed and configured by the dialog.
Definition: kshortcutsdialog.cpp:153
KMessageBox::questionYesNo
static int questionYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Notify)
Display a simple "question" dialog.
Definition: kmessagebox.cpp:353
KDialog::Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted) ...
Definition: kdialog.h:141
QSize
KXMLGUIFactory
KXMLGUIFactory, together with KXMLGUIClient objects, can be used to create a GUI of container widgets...
Definition: kxmlguifactory.h:65
QDomDocument
KDialog::setDetailsWidget
void setDetailsWidget(QWidget *detailsWidget)
Sets the widget that gets shown when "Details" is enabled.
Definition: kdialog.cpp:806
KShortcutsDialog::sizeHint
virtual QSize sizeHint() const
Definition: kshortcutsdialog.cpp:181
KConfigGroup
kxmlguiclient.h
KShortcutsDialog::~KShortcutsDialog
virtual ~KShortcutsDialog()
Destructor.
Definition: kshortcutsdialog.cpp:145
KXMLGUIFactory::changeShortcutScheme
void changeShortcutScheme(const QString &scheme)
Definition: kxmlguifactory.cpp:397
KMessageBox::Yes
Definition: kmessagebox.h:72
QWidget::show
void show()
KDialog::setButtonText
void setButtonText(ButtonCode id, const QString &text)
Sets the text of any button.
Definition: kdialog.cpp:719
KActionCollection::parentGUIClient
const KXMLGUIClient * parentGUIClient() const
The parent KXMLGUIClient, or null if not available.
Definition: kactioncollection.cpp:181
KDialog::user1Clicked
void user1Clicked()
The User1 button was pressed.
KDialog::User1
Show User defined button 1.
Definition: kdialog.h:150
kmessagebox.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KStandardAction::save
KAction * save(const QObject *recvr, const char *slot, QObject *parent)
Save the current document.
Definition: kstandardaction.cpp:244
KDialog::Details
Show Details button. (this button will show the detail widget set with setDetailsWidget) ...
Definition: kdialog.h:149
QCursor
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KShortcutsDialog
Dialog for configuration of KActionCollection and KGlobalAccel.
Definition: kshortcutsdialog.h:69
KXMLGUIClient::setXMLGUIBuildDocument
void setXMLGUIBuildDocument(const QDomDocument &doc)
Definition: kxmlguiclient.cpp:587
KShortcutsDialog::configure
bool configure(bool saveSettings=true)
Run the dialog and call writeSettings() on the action collections that were added if bSaveSettings is...
Definition: kshortcutsdialog.cpp:166
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