• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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         QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00073         m_keyChooser->clearCollections();
00074 
00075         foreach (KActionCollection *collection, m_collections)
00076         {
00077             // passing an empty stream forces the clients to reread the XML
00078             KXMLGUIClient *client = const_cast<KXMLGUIClient *>(collection->parentGUIClient());
00079             client->setXMLGUIBuildDocument( QDomDocument() );
00080         }
00081 
00082         //get xmlguifactory
00083         if (!m_collections.isEmpty())
00084         {
00085             const KXMLGUIClient *client = m_collections.first()->parentGUIClient();
00086             if (client)
00087             {
00088                 KXMLGUIFactory *factory = client->factory();
00089                 if (factory)
00090                     factory->changeShortcutScheme(scheme);
00091             }
00092         }
00093         foreach (KActionCollection *collection, m_collections)
00094             m_keyChooser->addCollection(collection);
00095         QApplication::restoreOverrideCursor();
00096      }
00097 
00098     void undoChanges()
00099     {
00100         m_keyChooser->undoChanges();
00101     }
00102 
00103     void save()
00104     {
00105         m_keyChooser->save();
00106         emit q->saved();
00107     }
00108 
00109     KShortcutsDialog *q;
00110     KShortcutsEditor* m_keyChooser; // ### move
00111     KShortcutSchemesEditor* m_schemeEditor;
00112 };
00113 
00114 
00115 KShortcutsDialog::KShortcutsDialog( KShortcutsEditor::ActionTypes types, KShortcutsEditor::LetterShortcuts allowLetterShortcuts, QWidget *parent )
00116 : KDialog( parent ), d(new KShortcutsDialogPrivate(this))
00117 {
00118     setCaption(i18n("Configure Shortcuts"));
00119     setButtons(Details|Reset|Ok|Cancel|KDialog::User1);
00120     setButtonText(KDialog::User1, i18n("Print"));
00121     setButtonIcon(KDialog::User1, KIcon("document-print"));
00122     setModal(true);
00123     d->m_keyChooser = new KShortcutsEditor( this, types, allowLetterShortcuts );
00124     setMainWidget( d->m_keyChooser );
00125     setButtonText(Reset,i18n("Reset to Defaults"));
00126 
00127     d->m_schemeEditor = new KShortcutSchemesEditor(this);
00128     connect( d->m_schemeEditor, SIGNAL(shortcutsSchemeChanged(const QString&)),
00129              this, SLOT(changeShortcutScheme(const QString&)) );
00130     setDetailsWidget(d->m_schemeEditor);
00131 
00132     connect( this, SIGNAL(resetClicked()), d->m_keyChooser, SLOT(allDefault()) );
00133     connect( this, SIGNAL(user1Clicked()), d->m_keyChooser, SLOT(printShortcuts()) );
00134     connect(this, SIGNAL(cancelClicked()), SLOT(undoChanges()));
00135 
00136     KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
00137     resize( group.readEntry( "Dialog Size", sizeHint() ) );
00138 }
00139 
00140 
00141 KShortcutsDialog::~KShortcutsDialog()
00142 {
00143     KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
00144     group.writeEntry( "Dialog Size", size(), KConfigGroup::Persistent|KConfigGroup::Global );
00145     delete d;
00146 }
00147 
00148 
00149 void KShortcutsDialog::addCollection(KActionCollection *collection, const QString &title)
00150 {
00151     d->m_keyChooser->addCollection(collection, title);
00152     d->m_collections << collection;
00153 }
00154 
00155 
00156 QList<KActionCollection*> KShortcutsDialog::actionCollections() const
00157 {
00158     return d->m_collections;
00159 }
00160 
00161 //FIXME should there be a setSaveSettings method?
00162 bool KShortcutsDialog::configure(bool saveSettings)
00163 {
00164     disconnect(this, SIGNAL(okClicked()), this, SLOT(save()));
00165     if (saveSettings) {
00166         connect(this, SIGNAL(okClicked()), this, SLOT(save()));
00167     }
00168     if (isModal()) {
00169         int retcode = exec();
00170         return retcode;
00171     } else {
00172         show();
00173         return false;
00174     }
00175 }
00176 
00177 QSize KShortcutsDialog::sizeHint() const
00178 {
00179     return QSize(600, 480);
00180 }
00181 
00182 int KShortcutsDialog::configure(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts,
00183                           QWidget *parent, bool saveSettings)
00184 {
00185     kDebug(125) << "KShortcutsDialog::configureKeys( KActionCollection*, " << saveSettings << " )";
00186     KShortcutsDialog dlg(KShortcutsEditor::AllActions, allowLetterShortcuts, parent);
00187     dlg.d->m_keyChooser->addCollection(collection);
00188     return dlg.configure(saveSettings);
00189 }
00190 
00191 #include "kshortcutsdialog.moc"
00192 #include "kshortcutsdialog_p.moc"
00193 
00194 //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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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