12#include <KLocalizedString>
13#include <QApplication>
14#include <QMetaClassInfo>
15#include <QKeySequence>
19#include <QApplication>
41 : QAbstractListModel(parent), d(new
Private)
52 if (!index.isValid()) {
56 if (index.row() ==
d->
shortcuts.count() && role == Qt::DisplayRole) {
57 if (index.column() == 0) {
58 return i18n(
"Add shortcut...");
65 if (role == Qt::DisplayRole) {
66 switch (index.column()) {
68 switch (
d->
shortcuts.at(index.row())->type()) {
70 return i18nc(
"Shortcut type",
"Key Combination");
73 return i18nc(
"Shortcut type",
"Mouse Button");
76 return i18nc(
"Shortcut type",
"Mouse Wheel");
79 return i18nc(
"Shortcut type",
"Gesture");
82 return i18n(
"Unknown Input");
127 else if (role == Qt::EditRole) {
141 switch (index.column()) {
146 return QVariant::fromValue(s);
161 if (parent.isValid()) {
175 if (orientation != Qt::Horizontal || role != Qt::DisplayRole) {
181 return i18nc(
"Type of shortcut",
"Type");
184 return i18nc(
"Input for shortcut",
"Input");
187 return i18nc(
"Action to trigger with shortcut",
"Action");
198 if (!index.isValid()) {
199 return Qt::ItemIsEnabled;
202 if (index.row() ==
d->
shortcuts.count() && index.column() != 0) {
203 return Qt::ItemIsEnabled;
207 return Qt::ItemIsEnabled | Qt::ItemIsEditable;
212 return Qt::ItemIsSelectable;
215 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
229 if (!index.isValid() || role != Qt::EditRole) {
246 switch (index.column()) {
255 if (newData == oldData) {
261 const bool isConflictingShortcut = std::find_if(conflictingShortcuts.begin(),
262 conflictingShortcuts.end(),
264 return *oldData == *shortcut;
266 != conflictingShortcuts.end();
268 if (isConflictingShortcut) {
269 QMessageBox::warning(qApp->activeWindow(),
271 i18n(
"A conflict exists between two or more shortcuts."));
274 Q_EMIT dataChanged(index, index);
278 oldData->setKeys(newData->
keys());
279 oldData->setButtons(newData->
buttons());
280 oldData->setWheel(newData->
wheel());
281 oldData->setGesture(newData->
gesture());
291 Q_EMIT dataChanged(index, index);
305 beginRemoveRows(QModelIndex(), 0,
d->
shortcuts.count() - 1);
313 beginInsertRows(QModelIndex(), 0,
d->
shortcuts.count() - 1);
328 beginRemoveRows(QModelIndex(), 0,
d->
shortcuts.count() - 1);
336 beginInsertRows(QModelIndex(), 0,
d->
shortcuts.count() - 1);
349 if (row < 0 || row >=
d->
shortcuts.count() || count == 0) {
353 beginRemoveRows(parent, row, row + count - 1);
355 for (
int i = row; i <
d->
shortcuts.count() && count > 0; ++i, count--) {
372 if(s->
mode() == mode) {
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisInputProfile * profile
QList< KisShortcutConfiguration * > shortcuts
KisShortcutConfiguration * temporaryShortcut
KisAbstractInputAction * action
int shortcutModeCount(uint mode)
void setProfile(KisInputProfile *profile)
void setAction(KisAbstractInputAction *action)
~KisActionShortcutsModel() override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
KisActionShortcutsModel(QObject *parent=0)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
bool canRemoveRow(int row) const
KisInputProfile * profile() const
int columnCount(const QModelIndex &) const override
KisAbstractInputAction * action() const
void currentProfileChanged()
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Qt::ItemFlags flags(const QModelIndex &index) const override
A class encapsulating all settings for a single shortcut.
MouseWheelMovement wheel() const
static QString keysToText(const QList< Qt::Key > &keys)
ShortcutType type() const
@ 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.
@ GestureType
A touch gesture.
Qt::MouseButtons buttons() const
static QString wheelInputToText(const QList< Qt::Key > &keys, MouseWheelMovement wheel)
QList< Qt::Key > keys() const
GestureAction gesture() const
void setAction(KisAbstractInputAction *newAction)
static QString gestureToText(GestureAction action)
static QString buttonsInputToText(const QList< Qt::Key > &keys, Qt::MouseButtons buttons)
QIcon loadIcon(const QString &name)