Warning, file /graphics/krita/libs/ui/input/config/kis_input_mode_delegate.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * This file is part of the KDE project 0003 * SPDX-FileCopyrightText: 2013 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "kis_input_mode_delegate.h" 0009 #include "../kis_abstract_input_action.h" 0010 0011 #include <kcombobox.h> 0012 #include <klocalizedstring.h> 0013 0014 class KisInputModeDelegate::Private 0015 { 0016 public: 0017 Private() { } 0018 0019 KisAbstractInputAction *action {nullptr}; 0020 }; 0021 0022 KisInputModeDelegate::KisInputModeDelegate(QObject *parent) 0023 : QStyledItemDelegate(parent), d(new Private) 0024 { 0025 } 0026 0027 KisInputModeDelegate::~KisInputModeDelegate() 0028 { 0029 delete d; 0030 0031 } 0032 0033 QWidget *KisInputModeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const 0034 { 0035 KComboBox *combo = new KComboBox(parent); 0036 QStringList sorted = d->action->shortcutIndexes().keys(); 0037 std::sort(sorted.begin(), sorted.end()); 0038 combo->addItems(sorted); 0039 return combo; 0040 } 0041 0042 void KisInputModeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const 0043 { 0044 KComboBox *combo = qobject_cast<KComboBox *>(editor); 0045 Q_ASSERT(combo); 0046 0047 int i = combo->findText(d->action->shortcutIndexes().key(index.data(Qt::EditRole).toUInt())); 0048 combo->setCurrentIndex(i); 0049 } 0050 0051 void KisInputModeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const 0052 { 0053 KComboBox *combo = qobject_cast<KComboBox *>(editor); 0054 Q_ASSERT(combo); 0055 0056 int i = d->action->shortcutIndexes().value(combo->currentText()); 0057 model->setData(index, i, Qt::EditRole); 0058 } 0059 0060 void KisInputModeDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const 0061 { 0062 editor->setGeometry(option.rect); 0063 } 0064 0065 void KisInputModeDelegate::setAction(KisAbstractInputAction *action) 0066 { 0067 d->action = action; 0068 }