Krita Source Code Documentation
Loading...
Searching...
No Matches
KisShortcutEditWidget.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries SPDX-FileCopyrightText: 1998 Mark Donohoe <donohoe@kde.org>
2 SPDX-FileCopyrightText: 1997 Nicolas Hadacek <hadacek@kde.org>
3 SPDX-FileCopyrightText: 1998 Matthias Ettrich <ettrich@kde.org>
4 SPDX-FileCopyrightText: 2001 Ellis Whitehead <ellis@kde.org>
5 SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
6 SPDX-FileCopyrightText: 2007 Roberto Raggi <roberto@kdevelop.org>
7 SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11
13
14#include <QPainter>
15#include <QPen>
16#include <QGridLayout>
17#include <QRadioButton>
18#include <QLabel>
19#include <QApplication>
20
21#include <klocalizedstring.h>
22//#include <kglobalaccel.h>
23
24#include "kkeysequencewidget.h"
25
27{
28 QWidget::paintEvent(e);
29 QPainter p(this);
30 QPen pen(QPalette().highlight().color());
31 pen.setWidth(6);
32 p.setPen(pen);
33 p.drawLine(0, 0, width(), 0);
34 if (qApp->isLeftToRight()) {
35 p.drawLine(0, 0, 0, height());
36 } else {
37 p.drawLine(width(), 0, width(), height());
38 }
39}
40
41ShortcutEditWidget::ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq,
42 const QKeySequence &activeSeq, bool allowLetterShortcuts)
43 : QWidget(viewport),
44 m_defaultKeySequence(defaultSeq),
45 m_isUpdating(false),
46 m_action(0)
47{
48 QGridLayout *layout = new QGridLayout(this);
49
50 m_defaultRadio = new QRadioButton(i18n("Default:"), this);
51 m_defaultLabel = new QLabel(i18nc("No shortcut defined", "None"), this);
52 QString defaultText = defaultSeq.toString(QKeySequence::NativeText);
53 if (defaultText.isEmpty()) {
54 defaultText = i18nc("No shortcut defined", "None");
55 }
56 m_defaultLabel->setText(defaultText);
57
58 m_customRadio = new QRadioButton(i18n("Custom:"), this);
60 m_customEditor->setModifierlessAllowed(allowLetterShortcuts);
61
62 layout->addWidget(m_defaultRadio, 0, 0);
63 layout->addWidget(m_defaultLabel, 0, 1);
64 layout->addWidget(m_customRadio, 1, 0);
65 layout->addWidget(m_customEditor, 1, 1);
66 layout->setColumnStretch(2, 1);
67
68 setKeySequence(activeSeq);
69
70 connect(m_defaultRadio, SIGNAL(toggled(bool)),
71 this, SLOT(defaultToggled(bool)));
72 connect(m_customEditor, SIGNAL(keySequenceChanged(QKeySequence)),
73 this, SLOT(setCustom(QKeySequence)));
74 connect(m_customEditor, SIGNAL(stealShortcut(QKeySequence,QAction*)),
75 this, SIGNAL(stealShortcut(QKeySequence,QAction*)));
76}
77
78KisKKeySequenceWidget::ShortcutTypes ShortcutEditWidget::checkForConflictsAgainst() const
79{
81}
82
83//slot
85{
86 if (m_isUpdating) {
87 return;
88 }
89
90 m_isUpdating = true;
91 if (checked) {
92 // The default key sequence should be activated. We check first if this
93 // is possible.
95 // Clear the customs widget
98 } else {
99 // We tried to switch to the default key sequence and failed.
100 // Go back.
101 m_customRadio->setChecked(true);
102 }
103 } else {
104 // The empty key sequence is always valid
105 Q_EMIT keySequenceChanged(QKeySequence());
106 }
107 m_isUpdating = false;
108}
109
111 const QList<KisKActionCollection *> checkActionCollections)
112{
113 // We just forward them to out KisKKeySequenceWidget.
114 m_customEditor->setCheckActionCollections(checkActionCollections);
115}
116
117void ShortcutEditWidget::setCheckForConflictsAgainst(KisKKeySequenceWidget::ShortcutTypes types)
118{
120}
121
122void ShortcutEditWidget::setComponentName(const QString componentName)
123{
124 m_customEditor->setComponentName(componentName);
125}
126
128{
129 // We just forward them to out KisKKeySequenceWidget.
131}
132
137
138void ShortcutEditWidget::setAction(QObject *action)
139{
140 m_action = action;
141}
142
143//slot
144void ShortcutEditWidget::setCustom(const QKeySequence &seq)
145{
146 if (m_isUpdating) {
147 return;
148 }
149
150 // seq is a const reference to a private variable of KisKKeySequenceWidget.
151 // Somewhere below we possible change that one. But we want to Q_EMIT seq
152 // whatever happens. So we make a copy.
153 QKeySequence original = seq;
154
155 m_isUpdating = true;
156
157 // Check if the user typed in the default sequence into the custom field.
158 // We do this by calling setKeySequence which will do the right thing.
159 setKeySequence(original);
160
161 Q_EMIT keySequenceChanged(original);
162 m_isUpdating = false;
163}
164
165void ShortcutEditWidget::setKeySequence(const QKeySequence &activeSeq)
166{
167 if (activeSeq.toString(QKeySequence::NativeText) == m_defaultKeySequence.toString(QKeySequence::NativeText)) {
168 m_defaultRadio->setChecked(true);
170 } else {
171 m_customRadio->setChecked(true);
172 // m_customEditor->setKeySequence does some stuff we only want to
173 // execute when the sequence really changes.
174 if (activeSeq != m_customEditor->keySequence()) {
175 m_customEditor->setKeySequence(activeSeq);
176 }
177 }
178}
179
const Params2D p
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
A widget to input a QKeySequence.
void setComponentName(const QString &componentName)
ShortcutTypes checkForConflictsAgainst
void setModifierlessAllowed(bool allow)
void setCheckActionCollections(const QList< KisKActionCollection * > &actionCollections)
void setKeySequence(const QKeySequence &seq, Validation val=NoValidate)
QKeySequence keySequence() const
bool isKeySequenceAvailable(const QKeySequence &seq) const
void setCheckForConflictsAgainst(ShortcutTypes types)
void stealShortcut(const QKeySequence &seq, QAction *action)
void setCheckForConflictsAgainst(KisKKeySequenceWidget::ShortcutTypes)
void setAction(QObject *action)
ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq, const QKeySequence &activeSeq, bool allowLetterShortcuts)
void paintEvent(QPaintEvent *pe) override
KisKKeySequenceWidget * m_customEditor
QKeySequence m_defaultKeySequence
void setCustom(const QKeySequence &)
void keySequenceChanged(const QKeySequence &)
Emitted when the key sequence is changed.
void setCheckActionCollections(const QList< KisKActionCollection * > checkActionCollections)
KisKKeySequenceWidget::ShortcutTypes checkForConflictsAgainst() const
void setKeySequence(const QKeySequence &activeSeq)
Set the displayed sequences.
QRadioButton * m_defaultRadio
void setComponentName(const QString componentName)