Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_input_mode_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
10
11#include <kcombobox.h>
12#include <klocalizedstring.h>
13
15{
16public:
17 Private() { }
18
20};
21
23 : QStyledItemDelegate(parent), d(new Private)
24{
25}
26
32
33QWidget *KisInputModeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
34{
35 KComboBox *combo = new KComboBox(parent);
36 QStringList sorted = d->action->shortcutIndexes().keys();
37 std::sort(sorted.begin(), sorted.end());
38 combo->addItems(sorted);
39 return combo;
40}
41
42void KisInputModeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
43{
44 KComboBox *combo = qobject_cast<KComboBox *>(editor);
45 Q_ASSERT(combo);
46
47 int i = combo->findText(d->action->shortcutIndexes().key(index.data(Qt::EditRole).toUInt()));
48 combo->setCurrentIndex(i);
49}
50
51void KisInputModeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
52{
53 KComboBox *combo = qobject_cast<KComboBox *>(editor);
54 Q_ASSERT(combo);
55
56 int i = d->action->shortcutIndexes().value(combo->currentText());
57 model->setData(index, i, Qt::EditRole);
58}
59
60void KisInputModeDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
61{
62 editor->setGeometry(option.rect);
63}
64
Abstract base class for input actions.
virtual QHash< QString, int > shortcutIndexes() const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
void setAction(KisAbstractInputAction *action)
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override
KisInputModeDelegate(QObject *parent=nullptr)
void setEditorData(QWidget *editor, const QModelIndex &index) const override
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const override