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

KDEUI

kshortcutsdialog.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
00002     Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org>
00003     Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org>
00004     Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
00005     Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
00006     Copyright (C) 2007 Roberto Raggi <roberto@kdevelop.org>
00007     Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
00008     Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
00009     Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
00010     Copyright (C) 2009 Chani Armitage <chani@kde.org>
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Library General Public
00014     License as published by the Free Software Foundation; either
00015     version 2 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Library General Public License for more details.
00021 
00022     You should have received a copy of the GNU Library General Public License
00023     along with this library; see the file COPYING.LIB.  If not, write to
00024     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00025     Boston, MA 02110-1301, USA.
00026 */
00027 
00028 #include "kshortcutsdialog.h"
00029 #include "kshortcutsdialog_p.h"
00030 #include "kshortcutschemeshelper_p.h"
00031 
00032 #include "kdebug.h"
00033 #include "klocale.h"
00034 
00035 #include <QApplication>
00036 #include <QDomDocument>
00037 
00038 #include <kmessagebox.h>
00039 #include <kxmlguiclient.h>
00040 #include <kxmlguifactory.h>
00041 #include <kactioncollection.h>
00042 
00043 /************************************************************************/
00044 /* KShortcutsDialog                                                     */
00045 /*                                                                      */
00046 /* Originally by Nicolas Hadacek <hadacek@via.ecp.fr>                   */
00047 /*                                                                      */
00048 /* Substantially revised by Mark Donohoe <donohoe@kde.org>              */
00049 /*                                                                      */
00050 /* And by Espen Sand <espen@kde.org> 1999-10-19                         */
00051 /* (by using KDialog there is almost no code left ;)                    */
00052 /*                                                                      */
00053 /************************************************************************/
00054 
00055 class KShortcutsDialog::KShortcutsDialogPrivate
00056 {
00057 public:
00058 
00059     KShortcutsDialogPrivate(KShortcutsDialog *q): q(q), m_keyChooser(0), m_schemeEditor(0)
00060         {}
00061 
00062     QList<KActionCollection*> m_collections;
00063 
00064     void changeShortcutScheme(const QString &scheme)
00065     {
00066         if (m_keyChooser->isModified() && KMessageBox::questionYesNo(q,
00067                 i18n("The current shortcut scheme is modified. Save before switching to the new one?")) == KMessageBox::Yes) {
00068             m_keyChooser->save();
00069         } else {
00070             m_keyChooser->undoChanges();
00071         }
00072 
00073         QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00074         m_keyChooser->clearCollections();
00075 
00076         foreach (KActionCollection *collection, m_collections) {
00077             // passing an empty stream forces the clients to reread the XML
00078             KXMLGUIClient *client = const_cast<KXMLGUIClient *>(collection->parentGUIClient());
00079             if (client) {
00080                 client->setXMLGUIBuildDocument( QDomDocument() );
00081             }
00082         }
00083 
00084         //get xmlguifactory
00085         if (!m_collections.isEmpty()) {
00086             const KXMLGUIClient *client = m_collections.first()->parentGUIClient();
00087             if (client) {
00088                 KXMLGUIFactory *factory = client->factory();
00089                 if (factory) {
00090                     factory->changeShortcutScheme(scheme);
00091                 }
00092             }
00093         }
00094 
00095         foreach (KActionCollection *collection, m_collections) {
00096             m_keyChooser->addCollection(collection);
00097         }
00098 
00099         QApplication::restoreOverrideCursor();
00100      }
00101 
00102     void undoChanges()
00103     {
00104         m_keyChooser->undoChanges();
00105     }
00106 
00107     void save()
00108     {
00109         m_keyChooser->save();
00110         emit q->saved();
00111     }
00112 
00113     KShortcutsDialog *q;
00114     KShortcutsEditor* m_keyChooser; // ### move
00115     KShortcutSchemesEditor* m_schemeEditor;
00116 };
00117 
00118 
00119 KShortcutsDialog::KShortcutsDialog( KShortcutsEditor::ActionTypes types, KShortcutsEditor::LetterShortcuts allowLetterShortcuts, QWidget *parent )
00120 : KDialog( parent ), d(new KShortcutsDialogPrivate(this))
00121 {
00122     setCaption(i18n("Configure Shortcuts"));
00123     setButtons(Details|Reset|Ok|Cancel|KDialog::User1);
00124     setButtonText(KDialog::User1, i18n("Print"));
00125     setButtonIcon(KDialog::User1, KIcon("document-print"));
00126     setModal(true);
00127     d->m_keyChooser = new KShortcutsEditor( this, types, allowLetterShortcuts );
00128     setMainWidget( d->m_keyChooser );
00129     setButtonText(Reset,i18n("Reset to Defaults"));
00130 
00131     d->m_schemeEditor = new KShortcutSchemesEditor(this);
00132     connect( d->m_schemeEditor, SIGNAL(shortcutsSchemeChanged(const QString&)),
00133              this, SLOT(changeShortcutScheme(const QString&)) );
00134     setDetailsWidget(d->m_schemeEditor);
00135 
00136     connect( this, SIGNAL(resetClicked()), d->m_keyChooser, SLOT(allDefault()) );
00137     connect( this, SIGNAL(user1Clicked()), d->m_keyChooser, SLOT(printShortcuts()) );
00138     connect(this, SIGNAL(cancelClicked()), SLOT(undoChanges()));
00139 
00140     KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
00141     resize( group.readEntry( "Dialog Size", sizeHint() ) );
00142 }
00143 
00144 
00145 KShortcutsDialog::~KShortcutsDialog()
00146 {
00147     KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
00148     group.writeEntry( "Dialog Size", size(), KConfigGroup::Persistent|KConfigGroup::Global );
00149     delete d;
00150 }
00151 
00152 
00153 void KShortcutsDialog::addCollection(KActionCollection *collection, const QString &title)
00154 {
00155     d->m_keyChooser->addCollection(collection, title);
00156     d->m_collections << collection;
00157 }
00158 
00159 
00160 QList<KActionCollection*> KShortcutsDialog::actionCollections() const
00161 {
00162     return d->m_collections;
00163 }
00164 
00165 //FIXME should there be a setSaveSettings method?
00166 bool KShortcutsDialog::configure(bool saveSettings)
00167 {
00168     disconnect(this, SIGNAL(okClicked()), this, SLOT(save()));
00169     if (saveSettings) {
00170         connect(this, SIGNAL(okClicked()), this, SLOT(save()));
00171     }
00172     if (isModal()) {
00173         int retcode = exec();
00174         return retcode;
00175     } else {
00176         show();
00177         return false;
00178     }
00179 }
00180 
00181 QSize KShortcutsDialog::sizeHint() const
00182 {
00183     return QSize(600, 480);
00184 }
00185 
00186 int KShortcutsDialog::configure(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts,
00187                           QWidget *parent, bool saveSettings)
00188 {
00189     kDebug(125) << "KShortcutsDialog::configureKeys( KActionCollection*, " << saveSettings << " )";
00190     KShortcutsDialog dlg(KShortcutsEditor::AllActions, allowLetterShortcuts, parent);
00191     dlg.d->m_keyChooser->addCollection(collection);
00192     return dlg.configure(saveSettings);
00193 }
00194 
00195 #include "kshortcutsdialog.moc"
00196 #include "kshortcutsdialog_p.moc"
00197 
00198 //kate: space-indent on; indent-width 4; replace-tabs on;tab-width 4;

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal