• Skip to content
  • Skip to link menu
KDE 4.1 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     QString defaultText = defaultSeq.toString(QKeySequence::NativeText);
00057     if (defaultText.isEmpty())
00058         defaultText = i18n("None");
00059     QLabel *defaultLabel = new QLabel(defaultText, this);
00060 
00061     m_customRadio = new QRadioButton(i18n("Custom:"), this);
00062     m_customEditor = new KKeySequenceWidget(this);
00063     m_customEditor->setModifierlessAllowed(allowLetterShortcuts);
00064 
00065     if (activeSeq == defaultSeq) {
00066         m_defaultRadio->setChecked(true);
00067     } else {
00068         m_customRadio->setChecked(true);
00069         m_customEditor->setKeySequence(activeSeq);
00070     }
00071 
00072     layout->addWidget(m_defaultRadio, 0, 0);
00073     layout->addWidget(defaultLabel, 0, 1);
00074     layout->addWidget(m_customRadio, 1, 0);
00075     layout->addWidget(m_customEditor, 1, 1);
00076     layout->setColumnStretch(2, 1);
00077 
00078     connect(m_defaultRadio, SIGNAL(toggled(bool)),
00079             this, SLOT(defaultToggled(bool)));
00080     connect(m_customEditor, SIGNAL(keySequenceChanged(const QKeySequence &)),
00081             this, SLOT(setCustom(const QKeySequence &)));
00082 }
00083 
00084 
00085 //slot
00086 void ShortcutEditWidget::defaultToggled(bool checked)
00087 {
00088     if (m_isUpdating)
00089         return;
00090 
00091     m_isUpdating = true;
00092     m_customEditor->clearKeySequence();
00093     if  (checked) {
00094         emit keySequenceChanged(m_defaultKeySequence);
00095     } else {
00096         //custom was checked
00097         emit keySequenceChanged(QKeySequence());
00098     }
00099     m_isUpdating = false;
00100 }
00101 
00102 
00103 //slot
00104 void ShortcutEditWidget::setCustom(const QKeySequence &seq)
00105 {
00106     if (m_isUpdating)
00107         return;
00108 
00109     m_isUpdating = true;
00110     if (seq != m_defaultKeySequence)
00111         m_customRadio->setChecked(true);
00112     else
00113         m_defaultRadio->setChecked(true);
00114     emit keySequenceChanged(seq);
00115     m_isUpdating = false;
00116 }
00117 

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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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