• Skip to content
  • Skip to link menu
KDE 4.2 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 
00011     This library is free software; you can redistribute it and/or
00012     modify it under the terms of the GNU Library General Public
00013     License as published by the Free Software Foundation; either
00014     version 2 of the License, or (at your option) any later version.
00015 
00016     This library is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019     Library General Public License for more details.
00020 
00021     You should have received a copy of the GNU Library General Public License
00022     along with this library; see the file COPYING.LIB.  If not, write to
00023     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00024     Boston, MA 02110-1301, USA.
00025 */
00026 
00027 #include "kshortcutsdialog.h"
00028 #include "kshortcutsdialog_p.h"
00029 #include "kshortcutschemeshelper_p.h"
00030 
00031 #include "kdebug.h"
00032 #include "klocale.h"
00033 
00034 #include <QApplication>
00035 #include <QDomDocument>
00036 
00037 #include <kmessagebox.h>
00038 #include <kxmlguiclient.h>
00039 #include <kxmlguifactory.h>
00040 #include <kactioncollection.h>
00041 
00042 /************************************************************************/
00043 /* KShortcutsDialog                                                     */
00044 /*                                                                      */
00045 /* Originally by Nicolas Hadacek <hadacek@via.ecp.fr>                   */
00046 /*                                                                      */
00047 /* Substantially revised by Mark Donohoe <donohoe@kde.org>              */
00048 /*                                                                      */
00049 /* And by Espen Sand <espen@kde.org> 1999-10-19                         */
00050 /* (by using KDialog there is almost no code left ;)                    */
00051 /*                                                                      */
00052 /************************************************************************/
00053 
00054 class KShortcutsDialog::KShortcutsDialogPrivate
00055 {
00056 public:
00057 
00058     KShortcutsDialogPrivate(KShortcutsDialog *q): q(q), m_keyChooser(0), m_schemeEditor(0)
00059         {}
00060 
00061     QList<KActionCollection*> m_collections;
00062 
00063     void changeShortcutScheme(const QString &scheme)
00064     {
00065         if (m_keyChooser->isModified() && KMessageBox::questionYesNo(q,
00066                 i18n("The current shortcut scheme is modified. Save before switching to the new one?")) == KMessageBox::Yes)
00067             m_keyChooser->save();
00068         else
00069             m_keyChooser->undoChanges();
00070 
00071         QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00072         m_keyChooser->clearCollections();
00073 
00074         foreach (KActionCollection *collection, m_collections)
00075         {
00076             // passing an empty stream forces the clients to reread the XML
00077             KXMLGUIClient *client = const_cast<KXMLGUIClient *>(collection->parentGUIClient());
00078             client->setXMLGUIBuildDocument( QDomDocument() );
00079         }
00080 
00081         //get xmlguifactory
00082         if (!m_collections.isEmpty())
00083         {
00084             const KXMLGUIClient *client = m_collections.first()->parentGUIClient();
00085             if (client)
00086             {
00087                 KXMLGUIFactory *factory = client->factory();
00088                 if (factory)
00089                     factory->changeShortcutScheme(scheme);
00090             }
00091         }
00092         foreach (KActionCollection *collection, m_collections)
00093             m_keyChooser->addCollection(collection);
00094         QApplication::restoreOverrideCursor();
00095      }
00096 
00097     KShortcutsDialog *q;
00098     KShortcutsEditor* m_keyChooser; // ### move
00099     KShortcutSchemesEditor* m_schemeEditor;
00100 };
00101 
00102 
00103 KShortcutsDialog::KShortcutsDialog( KShortcutsEditor::ActionTypes types, KShortcutsEditor::LetterShortcuts allowLetterShortcuts, QWidget *parent )
00104 : KDialog( parent ), d(new KShortcutsDialogPrivate(this))
00105 {
00106     setCaption(i18n("Configure Shortcuts"));
00107     setButtons(Details|Reset|Ok|Cancel|KDialog::User1);
00108     setButtonText(KDialog::User1, i18n("Print"));
00109     setButtonIcon(KDialog::User1, KIcon("document-print"));
00110     setModal(true);
00111     d->m_keyChooser = new KShortcutsEditor( this, types, allowLetterShortcuts );
00112     setMainWidget( d->m_keyChooser );
00113     setButtonText(Reset,i18n("Reset to Defaults"));
00114 
00115     d->m_schemeEditor = new KShortcutSchemesEditor(this);
00116     connect( d->m_schemeEditor, SIGNAL(shortcutsSchemeChanged(const QString&)),
00117              this, SLOT(changeShortcutScheme(const QString&)) );
00118     setDetailsWidget(d->m_schemeEditor);
00119 
00120     connect( this, SIGNAL(resetClicked()), d->m_keyChooser, SLOT(allDefault()) );
00121     connect( this, SIGNAL(user1Clicked()), d->m_keyChooser, SLOT(printShortcuts()) );
00122 
00123     KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
00124     resize( group.readEntry( "Dialog Size", sizeHint() ) );
00125 }
00126 
00127 
00128 KShortcutsDialog::~KShortcutsDialog()
00129 {
00130     KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
00131     group.writeEntry( "Dialog Size", size(), KConfigGroup::Global );
00132     delete d;
00133 }
00134 
00135 
00136 void KShortcutsDialog::addCollection(KActionCollection *collection, const QString &title)
00137 {
00138     d->m_keyChooser->addCollection(collection, title);
00139     d->m_collections << collection;
00140 }
00141 
00142 
00143 QList<KActionCollection*> KShortcutsDialog::actionCollections() const
00144 {
00145     return d->m_collections;
00146 }
00147 
00148 bool KShortcutsDialog::configure(bool saveSettings)
00149 {
00150     int retcode = exec();
00151     if (retcode != Accepted)
00152         d->m_keyChooser->undoChanges();
00153     else if (saveSettings)
00154         d->m_keyChooser->save();
00155 
00156     return retcode;
00157 }
00158 
00159 QSize KShortcutsDialog::sizeHint() const
00160 {
00161     return QSize(500, 400);
00162 }
00163 
00164 int KShortcutsDialog::configure(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts,
00165                           QWidget *parent, bool saveSettings)
00166 {
00167     kDebug(125) << "KShortcutsDialog::configureKeys( KActionCollection*, " << saveSettings << " )";
00168     KShortcutsDialog dlg(KShortcutsEditor::AllActions, allowLetterShortcuts, parent);
00169     dlg.d->m_keyChooser->addCollection(collection);
00170     return dlg.configure(saveSettings);
00171 }
00172 
00173 #include "kshortcutsdialog.moc"
00174 #include "kshortcutsdialog_p.moc"
00175 
00176 //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
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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