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
16#include "kis_input_button.h"
20#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
61 default:
62 break;
63 }
64
65 return editor;
66}
67
68void KisInputEditorDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
69{
70 KisShortcutConfiguration *s = index.model()->data(index, Qt::EditRole).value<KisShortcutConfiguration *>();
71
72 switch (s->type()) {
74 KisKeyInputEditor *e = qobject_cast<KisKeyInputEditor *>(editor);
75 e->setKeys(s->keys());
76 break;
77 }
78
80 KisMouseInputEditor *e = qobject_cast<KisMouseInputEditor *>(editor);
81 e->setKeys(s->keys());
82 e->setButtons(s->buttons());
83 break;
84 }
85
87 KisWheelInputEditor *e = qobject_cast<KisWheelInputEditor *>(editor);
88 e->setKeys(s->keys());
89 e->setWheel(s->wheel());
90 break;
91 }
93 KisGestureSelector *e = qobject_cast<KisGestureSelector *>(editor);
94 e->setGesture(s->gesture());
95 break;
96 }
97
98 default:
99 break;
100 }
101}
102
103void KisInputEditorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
104{
105 KisShortcutConfiguration *s = model->data(index, Qt::EditRole).value<KisShortcutConfiguration *>();
106
107 switch (s->type()) {
109 KisKeyInputEditor *e = qobject_cast<KisKeyInputEditor *>(editor);
110 s->setKeys(e->keys());
111 break;
112 }
113
115 KisMouseInputEditor *e = qobject_cast<KisMouseInputEditor *>(editor);
116 s->setKeys(e->keys());
117 s->setButtons(e->buttons());
118 break;
119 }
120
122 KisWheelInputEditor *e = qobject_cast<KisWheelInputEditor *>(editor);
123 s->setKeys(e->keys());
124 s->setWheel(e->wheel());
125 break;
126 }
128 KisGestureSelector *e = qobject_cast<KisGestureSelector *>(editor);
129 s->setGesture(e->gesture());
130 break;
131 }
132 break;
133
134 default:
135 break;
136 }
137
138 model->setData(index, QVariant::fromValue(s), Qt::EditRole);
139}
140
141void KisInputEditorDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
142{
143 editor->setGeometry(option.rect);
144}
145
146QSize KisInputEditorDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
147{
148 return QStyledItemDelegate::sizeHint(option, index) + QSize(6, 6);
149}
void setGesture(KisShortcutConfiguration::GestureAction gestureAction)
KisShortcutConfiguration::GestureAction gesture()
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)
A class encapsulating all settings for a single shortcut.
void setButtons(Qt::MouseButtons newButtons)
void setWheel(MouseWheelMovement 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 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