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

KDEUI

  • 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
55class KShortcutsDialog::KShortcutsDialogPrivate
56{
57public:
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
119KShortcutsDialog::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
145KShortcutsDialog::~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
153void KShortcutsDialog::addCollection(KActionCollection *collection, const QString &title)
154{
155 d->m_keyChooser->addCollection(collection, title);
156 d->m_collections << collection;
157}
158
159
160QList<KActionCollection*> KShortcutsDialog::actionCollections() const
161{
162 return d->m_collections;
163}
164
165//FIXME should there be a setSaveSettings method?
166bool 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
181QSize KShortcutsDialog::sizeHint() const
182{
183 return QSize(600, 480);
184}
185
186int 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;
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:57
KActionCollection::parentGUIClient
const KXMLGUIClient * parentGUIClient() const
The parent KXMLGUIClient, or null if not available.
Definition: kactioncollection.cpp:181
KConfigBase::Persistent
Persistent
KConfigBase::Global
Global
KConfigGroup
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:129
KDialog::setButtonIcon
void setButtonIcon(ButtonCode id, const KIcon &icon)
Sets the icon of any button.
Definition: kdialog.cpp:742
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: kdialog.cpp:338
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
KDialog::resetClicked
void resetClicked()
The Reset button was pressed.
KDialog::Details
@ Details
Show Details button. (this button will show the detail widget set with setDetailsWidget)
Definition: kdialog.h:149
KDialog::Ok
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition: kdialog.h:141
KDialog::Reset
@ Reset
Show Reset button.
Definition: kdialog.h:148
KDialog::User1
@ User1
Show User defined button 1.
Definition: kdialog.h:150
KDialog::Cancel
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition: kdialog.h:144
KDialog::setButtonText
void setButtonText(ButtonCode id, const QString &text)
Sets the text of any button.
Definition: kdialog.cpp:719
KDialog::okClicked
void okClicked()
The OK button was pressed.
KDialog::setDetailsWidget
void setDetailsWidget(QWidget *detailsWidget)
Sets the widget that gets shown when "Details" is enabled.
Definition: kdialog.cpp:806
KDialog::cancelClicked
void cancelClicked()
The Cancel button was pressed.
KDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:469
KDialog::user1Clicked
void user1Clicked()
The User1 button was pressed.
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KMessageBox::Yes
@ Yes
Definition: kmessagebox.h:72
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
KShortcutsDialog
Dialog for configuration of KActionCollection and KGlobalAccel.
Definition: kshortcutsdialog.h:70
KShortcutsDialog::~KShortcutsDialog
virtual ~KShortcutsDialog()
Destructor.
Definition: kshortcutsdialog.cpp:145
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
KShortcutsDialog::actionCollections
QList< KActionCollection * > actionCollections() const
Definition: kshortcutsdialog.cpp:160
KShortcutsDialog::sizeHint
virtual QSize sizeHint() const
Definition: kshortcutsdialog.cpp:181
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
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
KShortcutsEditor
Widget for configuration of KAccel and KGlobalAccel.
Definition: kshortcutseditor.h:61
KShortcutsEditor::LetterShortcuts
LetterShortcuts
Definition: kshortcutseditor.h:79
KShortcutsEditor::AllActions
@ AllActions
All actions.
Definition: kshortcutseditor.h:75
KXMLGUIClient
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
Definition: kxmlguiclient.h:47
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
KXMLGUIClient::setXMLGUIBuildDocument
void setXMLGUIBuildDocument(const QDomDocument &doc)
Definition: kxmlguiclient.cpp:587
KXMLGUIFactory
KXMLGUIFactory, together with KXMLGUIClient objects, can be used to create a GUI of container widgets...
Definition: kxmlguifactory.h:66
KXMLGUIFactory::changeShortcutScheme
void changeShortcutScheme(const QString &scheme)
Definition: kxmlguifactory.cpp:397
QCursor
QList
QWidget
kDebug
#define kDebug
kactioncollection.h
kdebug.h
klocale.h
i18n
QString i18n(const char *text)
kmessagebox.h
kshortcutsdialog.h
kxmlguiclient.h
kxmlguifactory.h
KGlobal::config
KSharedConfigPtr config()
group
group
KStandardAction::save
KAction * save(const QObject *recvr, const char *slot, QObject *parent)
Save the current document.
Definition: kstandardaction.cpp:244
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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