Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_input_editor_delegate.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the KDE project
3 * SPDX-FileCopyrightText: 2013 Arjen Hiemstra <ahiemstra@heimr.nl>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
9
10#include <QApplication>
11
12#include <KLocalizedString>
13
19#include "KisGestureSelector.h"
21
23{
24public:
25 Private() { }
26};
27
29 : QStyledItemDelegate(parent), d(new Private())
30{
31}
32
38
39QWidget *KisInputEditorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
40{
41 QWidget *editor = 0;
42 KisShortcutConfiguration *s = index.data(Qt::EditRole).value<KisShortcutConfiguration *>();
43
44 switch (s->type()) {
46 editor = new KisKeyInputEditor(parent);
47 break;
48
50 editor = new KisMouseInputEditor(parent);
51 break;
52
54 editor = new KisWheelInputEditor(parent);
55 break;
56
58 editor = new KisGestureSelector(parent);
59 break;
60
62 editor = new KisNativeGestureSelector(parent);
63 break;
64
65 default:
66 break;
67 }
68
69 return editor;
70}
71
72void KisInputEditorDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
73{
74 KisShortcutConfiguration *s = index.model()->data(index, Qt::EditRole).value<KisShortcutConfiguration *>();
75
76 switch (s->type()) {
78 KisKeyInputEditor *e = qobject_cast<KisKeyInputEditor *>(editor);
79 e->setKeys(s->keys());
80 break;
81 }
82
84 KisMouseInputEditor *e = qobject_cast<KisMouseInputEditor *>(editor);
85 e->setKeys(s->keys());
86 e->setButtons(s->buttons());
87 break;
88 }
89
91 KisWheelInputEditor *e = qobject_cast<KisWheelInputEditor *>(editor);
92 e->setKeys(s->keys());
93 e->setWheel(s->wheel());
94 break;
95 }
97 KisGestureSelector *e = qobject_cast<KisGestureSelector *>(editor);
99 break;
100 }
102 KisNativeGestureSelector *e = qobject_cast<KisNativeGestureSelector *>(editor);
104 break;
105 }
106
107 default:
108 break;
109 }
110}
111
112void KisInputEditorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
113{
114 KisShortcutConfiguration *s = model->data(index, Qt::EditRole).value<KisShortcutConfiguration *>();
115
116 switch (s->type()) {
118 KisKeyInputEditor *e = qobject_cast<KisKeyInputEditor *>(editor);
119 s->setKeys(e->keys());
120 break;
121 }
122
124 KisMouseInputEditor *e = qobject_cast<KisMouseInputEditor *>(editor);
125 s->setKeys(e->keys());
126 s->setButtons(e->buttons());
127 break;
128 }
129
131 KisWheelInputEditor *e = qobject_cast<KisWheelInputEditor *>(editor);
132 s->setKeys(e->keys());
133 s->setWheel(e->wheel());
134 break;
135 }
137 KisGestureSelector *e = qobject_cast<KisGestureSelector *>(editor);
139 break;
140 }
142 KisNativeGestureSelector *e = qobject_cast<KisNativeGestureSelector *>(editor);
144 break;
145 }
146 break;
147
148 default:
149 break;
150 }
151
152 model->setData(index, QVariant::fromValue(s), Qt::EditRole);
153}
154
155void KisInputEditorDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
156{
157 editor->setGeometry(option.rect);
158}
159
160QSize KisInputEditorDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
161{
162 return QStyledItemDelegate::sizeHint(option, index) + QSize(6, 6);
163}
void setTouchGesture(KisShortcutConfiguration::TouchGestureAction gestureAction)
KisShortcutConfiguration::TouchGestureAction touchGesture()
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override
void setEditorData(QWidget *editor, const QModelIndex &index) const override
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const override
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
KisInputEditorDelegate(QObject *parent=0)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
An editor widget for a list of keys.
QList< Qt::Key > keys() const
void setKeys(const QList< Qt::Key > &newKeys)
An editor widget for mouse buttons with modifiers.
Qt::MouseButtons buttons() const
QList< Qt::Key > keys() const
void setButtons(Qt::MouseButtons newButtons)
void setKeys(const QList< Qt::Key > &newKeys)
KisShortcutConfiguration::NativeGestureAction nativeGesture()
void setNativeGesture(KisShortcutConfiguration::NativeGestureAction gestureAction)
A class encapsulating all settings for a single shortcut.
void setButtons(Qt::MouseButtons newButtons)
void setWheel(MouseWheelMovement type)
void setNativeGesture(NativeGestureAction type)
@ MouseButtonType
A mouse button, possibly with key modifiers.
@ MouseWheelType
Mouse wheel movement, possibly with key modifiers.
@ KeyCombinationType
A list of keys that should be pressed.
void setTouchGesture(TouchGestureAction type)
NativeGestureAction nativeGesture() const
TouchGestureAction touchGesture() const
void setKeys(const QList< Qt::Key > &newKeys)
An editor widget for mouse wheel input with modifiers.
void setWheel(KisShortcutConfiguration::MouseWheelMovement newWheel)
KisShortcutConfiguration::MouseWheelMovement wheel() const
void setKeys(const QList< Qt::Key > &newKeys)
QList< Qt::Key > keys() const