Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_input_type_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 <kcombobox.h>
11#include <klocalizedstring.h>
12
14{
15public:
16 Private() { }
17};
18
20 : QStyledItemDelegate(parent), d(new Private)
21{
22
23}
24
30
31QWidget *KisInputTypeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
32{
33 KComboBox *combo = new KComboBox(parent);
34 combo->addItems(QStringList()
35 << i18n("Key Combination")
36 << i18n("Mouse Button")
37 << i18n("Mouse Wheel")
38 << i18n("Gesture")
39 );
40 combo->setCurrentIndex(0);
41
42 return combo;
43}
44
45void KisInputTypeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
46{
47 KComboBox *combo = qobject_cast<KComboBox *>(editor);
48 Q_ASSERT(combo);
49
50 combo->setCurrentIndex(index.data(Qt::EditRole).toUInt() - 1);
51}
52
53void KisInputTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
54{
55 KComboBox *combo = qobject_cast<KComboBox *>(editor);
56 Q_ASSERT(combo);
57 model->setData(index, combo->currentIndex() + 1, Qt::EditRole);
58}
59
60void KisInputTypeDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
61{
62 editor->setGeometry(option.rect);
63}
QList< QString > QStringList
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const override
void setEditorData(QWidget *editor, const QModelIndex &index) const override
KisInputTypeDelegate(QObject *parent=0)