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

KDEUI

  • kdeui
  • dialogs
kshortcuteditwidget.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
2 Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org>
3 Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org>
4 Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
5 Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
6 Copyright (C) 2007 Roberto Raggi <roberto@kdevelop.org>
7 Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23*/
24
25#include "kshortcutsdialog_p.h"
26
27#include <QPainter>
28#include <QPen>
29#include <QGridLayout>
30#include <QRadioButton>
31#include <QLabel>
32
33#include "kkeysequencewidget.h"
34#include "klocale.h"
35
36void TabConnectedWidget::paintEvent(QPaintEvent *e)
37{
38 QWidget::paintEvent(e);
39 QPainter p(this);
40 QPen pen(QPalette().highlight().color());
41 pen.setWidth(6);
42 p.setPen(pen);
43 p.drawLine(0, 0, width(), 0);
44 if (qApp->isLeftToRight()) {
45 p.drawLine(0, 0, 0, height());
46 } else {
47 p.drawLine(width(), 0, width(), height());
48 }
49}
50
51ShortcutEditWidget::ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq,
52 const QKeySequence &activeSeq, bool allowLetterShortcuts)
53 : TabConnectedWidget(viewport),
54 m_defaultKeySequence(defaultSeq),
55 m_isUpdating(false)
56{
57 QGridLayout *layout = new QGridLayout(this);
58
59 m_defaultRadio = new QRadioButton(i18n("Default:"), this);
60 m_defaultLabel = new QLabel(i18nc("No shortcut defined", "None"), this);
61 QString defaultText = defaultSeq.toString(QKeySequence::NativeText);
62 if (defaultText.isEmpty())
63 defaultText = i18nc("No shortcut defined", "None");
64 m_defaultLabel->setText(defaultText);
65
66 m_customRadio = new QRadioButton(i18n("Custom:"), this);
67 m_customEditor = new KKeySequenceWidget(this);
68 m_customEditor->setModifierlessAllowed(allowLetterShortcuts);
69
70 layout->addWidget(m_defaultRadio, 0, 0);
71 layout->addWidget(m_defaultLabel, 0, 1);
72 layout->addWidget(m_customRadio, 1, 0);
73 layout->addWidget(m_customEditor, 1, 1);
74 layout->setColumnStretch(2, 1);
75
76 setKeySequence(activeSeq);
77
78 connect(m_defaultRadio, SIGNAL(toggled(bool)),
79 this, SLOT(defaultToggled(bool)));
80 connect(m_customEditor, SIGNAL(keySequenceChanged(QKeySequence)),
81 this, SLOT(setCustom(QKeySequence)));
82 connect(m_customEditor, SIGNAL(stealShortcut(QKeySequence,KAction*)),
83 this, SIGNAL(stealShortcut(QKeySequence,KAction*)));
84}
85
86
87KKeySequenceWidget::ShortcutTypes ShortcutEditWidget::checkForConflictsAgainst() const
88{
89 return m_customEditor->checkForConflictsAgainst();
90}
91
92//slot
93void ShortcutEditWidget::defaultToggled(bool checked)
94{
95 if (m_isUpdating)
96 return;
97
98 m_isUpdating = true;
99 if (checked) {
100 // The default key sequence should be activated. We check first if this is
101 // possible.
102 if (m_customEditor->isKeySequenceAvailable(m_defaultKeySequence)) {
103 // Clear the customs widget
104 m_customEditor->clearKeySequence();
105 emit keySequenceChanged(m_defaultKeySequence);
106 } else {
107 // We tried to switch to the default key sequence and failed. Go
108 // back.
109 m_customRadio->setChecked(true);
110 }
111 } else {
112 // The empty key sequence is always valid
113 emit keySequenceChanged(QKeySequence());
114 }
115 m_isUpdating = false;
116}
117
118
119void ShortcutEditWidget::setCheckActionCollections(
120 const QList<KActionCollection*> checkActionCollections)
121{
122 // We just forward them to out KKeySequenceWidget.
123 m_customEditor->setCheckActionCollections(checkActionCollections);
124}
125
126
127void ShortcutEditWidget::setCheckForConflictsAgainst(KKeySequenceWidget::ShortcutTypes types)
128{
129 m_customEditor->setCheckForConflictsAgainst(types);
130}
131
132
133void ShortcutEditWidget::setComponentName(const QString componentName)
134{
135 m_customEditor->setComponentName(componentName);
136}
137
138
139void ShortcutEditWidget::setMultiKeyShortcutsAllowed(bool allowed)
140{
141 // We just forward them to out KKeySequenceWidget.
142 m_customEditor->setMultiKeyShortcutsAllowed(allowed);
143}
144
145
146bool ShortcutEditWidget::multiKeyShortcutsAllowed() const
147{
148 return m_customEditor->multiKeyShortcutsAllowed();
149}
150
151//slot
152void ShortcutEditWidget::setCustom(const QKeySequence &seq)
153{
154 if (m_isUpdating)
155 return;
156
157 // seq is a const reference to a private variable of KKeySequenceWidget.
158 // Somewhere below we possible change that one. But we want to emit seq
159 // whatever happens. So we make a copy.
160 QKeySequence original = seq;
161
162 m_isUpdating = true;
163
164 // Check if the user typed in the default sequence into the custom field.
165 // We do this by calling setKeySequence which will do the right thing.
166 setKeySequence(original);
167
168 emit keySequenceChanged(original);
169 m_isUpdating = false;
170}
171
172
173void ShortcutEditWidget::setKeySequence(const QKeySequence &activeSeq)
174{
175 if (activeSeq == m_defaultLabel->text()) {
176 m_defaultRadio->setChecked(true);
177 m_customEditor->clearKeySequence();
178 } else {
179 m_customRadio->setChecked(true);
180 // m_customEditor->setKeySequence does some stuff we only want to
181 // execute when the sequence really changes.
182 if (activeSeq!=m_customEditor->keySequence()) {
183 m_customEditor->setKeySequence(activeSeq);
184 }
185 }
186}
187
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KKeySequenceWidget
A widget to input a QKeySequence.
Definition: kkeysequencewidget.h:52
QLabel
QList
QWidget
kkeysequencewidget.h
klocale.h
i18n
QString i18n(const char *text)
i18nc
QString i18nc(const char *ctxt, const char *text)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal