• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kshortcuteditwidget.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 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Library General Public
00011     License as published by the Free Software Foundation; either
00012     version 2 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Library General Public License for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with this library; see the file COPYING.LIB.  If not, write to
00021     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022     Boston, MA 02110-1301, USA.
00023 */
00024 
00025 #include "kshortcutsdialog_p.h"
00026 
00027 #include <QPainter>
00028 #include <QPen>
00029 #include <QGridLayout>
00030 #include <QRadioButton>
00031 #include <QLabel>
00032 
00033 #include "kkeysequencewidget.h"
00034 #include "klocale.h"
00035 
00036 void TabConnectedWidget::paintEvent(QPaintEvent *e)
00037 {
00038     QWidget::paintEvent(e);
00039     QPainter p(this);
00040     QPen pen(QPalette().highlight().color());
00041     pen.setWidth(6);
00042     p.setPen(pen);
00043     p.drawLine(0, 0, width(), 0);
00044     p.drawLine(0, 0, 0, height());
00045 }
00046 
00047 ShortcutEditWidget::ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq,
00048                                        const QKeySequence &activeSeq, bool allowLetterShortcuts)
00049  : TabConnectedWidget(viewport),
00050    m_defaultKeySequence(defaultSeq),
00051    m_isUpdating(false)
00052 {
00053     QGridLayout *layout = new QGridLayout(this);
00054 
00055     m_defaultRadio = new QRadioButton(i18n("Default:"), this);
00056     m_defaultLabel = new QLabel(i18nc("No shortcut defined", "None"), this);
00057     QString defaultText = defaultSeq.toString(QKeySequence::NativeText);
00058     if (defaultText.isEmpty()) 
00059         defaultText = i18nc("No shortcut defined", "None");
00060     m_defaultLabel->setText(defaultText);
00061 
00062     m_customRadio = new QRadioButton(i18n("Custom:"), this);
00063     m_customEditor = new KKeySequenceWidget(this);
00064     m_customEditor->setModifierlessAllowed(allowLetterShortcuts);
00065 
00066     layout->addWidget(m_defaultRadio, 0, 0);
00067     layout->addWidget(m_defaultLabel, 0, 1);
00068     layout->addWidget(m_customRadio, 1, 0);
00069     layout->addWidget(m_customEditor, 1, 1);
00070     layout->setColumnStretch(2, 1);
00071 
00072     setKeySequence(activeSeq);
00073 
00074     connect(m_defaultRadio, SIGNAL(toggled(bool)),
00075             this, SLOT(defaultToggled(bool)));
00076     connect(m_customEditor, SIGNAL(keySequenceChanged(const QKeySequence &)),
00077             this, SLOT(setCustom(const QKeySequence &)));
00078     connect(m_customEditor, SIGNAL(stealShortcut(const QKeySequence &, KAction *)),
00079         this, SIGNAL(stealShortcut(const QKeySequence &, KAction *)));
00080 }
00081 
00082 
00083 KKeySequenceWidget::ShortcutTypes ShortcutEditWidget::checkForConflictsAgainst() const
00084 {
00085     return m_customEditor->checkForConflictsAgainst();
00086 }
00087 
00088 //slot
00089 void ShortcutEditWidget::defaultToggled(bool checked)
00090 {
00091     if (m_isUpdating)
00092         return;
00093 
00094     m_isUpdating = true;
00095     if  (checked) {
00096         // The default key sequence should be activated. We check first if this is
00097         // possible.
00098         if (m_customEditor->isKeySequenceAvailable(m_defaultKeySequence)) {
00099             // Clear the customs widget
00100             m_customEditor->clearKeySequence();
00101             emit keySequenceChanged(m_defaultKeySequence);
00102         } else {
00103             // We tried to switch to the default key sequence and failed. Go
00104             // back.
00105             m_customRadio->setChecked(true);
00106         }
00107     } else {
00108         // The empty key sequence is always valid
00109         emit keySequenceChanged(QKeySequence());
00110     }
00111     m_isUpdating = false;
00112 }
00113 
00114 
00115 void ShortcutEditWidget::setCheckActionCollections( 
00116         const QList<KActionCollection*> checkActionCollections)
00117 {
00118     // We just forward them to out KKeySequenceWidget.
00119     m_customEditor->setCheckActionCollections(checkActionCollections);
00120 }
00121 
00122 
00123 void ShortcutEditWidget::setCheckForConflictsAgainst(KKeySequenceWidget::ShortcutTypes types)
00124 {
00125     m_customEditor->setCheckForConflictsAgainst(types);
00126 }
00127 
00128 
00129 void ShortcutEditWidget::setComponentName(const QString componentName)
00130 {
00131     m_customEditor->setComponentName(componentName);
00132 }
00133 
00134 
00135 void ShortcutEditWidget::setMultiKeyShortcutsAllowed(bool allowed)
00136 {
00137     // We just forward them to out KKeySequenceWidget.
00138     m_customEditor->setMultiKeyShortcutsAllowed(allowed);
00139 }
00140 
00141 
00142 bool ShortcutEditWidget::multiKeyShortcutsAllowed() const
00143 {
00144     return m_customEditor->multiKeyShortcutsAllowed();
00145 }
00146 
00147 //slot
00148 void ShortcutEditWidget::setCustom(const QKeySequence &seq)
00149 {
00150     if (m_isUpdating)
00151         return;
00152 
00153     // seq is a const reference to a private variable of KKeySequenceWidget.
00154     // Somewhere below we possible change that one. But we want to emit seq
00155     // whatever happens. So we make a copy.
00156     QKeySequence original = seq;
00157 
00158     m_isUpdating = true;
00159 
00160     // Check if the user typed in the default sequence into the custom field.
00161     // We do this by calling setKeySequence which will do the right thing.
00162     setKeySequence(original);
00163 
00164     emit keySequenceChanged(original);
00165     m_isUpdating = false;
00166 }
00167 
00168 
00169 void ShortcutEditWidget::setKeySequence(const QKeySequence &activeSeq)
00170 {
00171     if (activeSeq == m_defaultLabel->text()) {
00172         m_defaultRadio->setChecked(true);
00173         m_customEditor->clearKeySequence();
00174     } else {
00175         m_customRadio->setChecked(true);
00176         // m_customEditor->setKeySequence does some stuff we only want to
00177         // execute when the sequence really changes.
00178         if (activeSeq!=m_customEditor->keySequence()) {
00179             m_customEditor->setKeySequence(activeSeq);
00180         }
00181     }
00182 }
00183 

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