12#include <QKeySequence>
13#include <KLocalizedString>
15#include <boost/preprocessor/repeat_from_to.hpp>
86 QString serialized(
"{");
88 serialized.append(QString::number(
d->
mode, 16));
89 serialized.append(
';');
90 serialized.append(QString::number(
d->
type, 16));
91 serialized.append(
";[");
94 serialized.append(QString::number(*itr, 16));
96 if (itr + 1 !=
d->
keys.end()) {
97 serialized.append(
',');
101 serialized.append(
"];");
103 serialized.append(QString::number(
d->
buttons, 16));
104 serialized.append(
';');
105 serialized.append(QString::number(
d->
wheel, 16));
106 serialized.append(
';');
112 serialized.append(
'}');
119 if (!serialized.startsWith(
'{'))
123 QString remainder = serialized;
126 remainder.remove(
'{').remove(
'}');
131 if (parts.size() < 6)
135 d->
mode = parts.at(0).toUInt(
nullptr, 16);
146 QString serializedKeys = parts.at(2);
148 serializedKeys.remove(
'[').remove(
']');
151 Q_FOREACH(QString key, keylist) {
152 if (!key.isEmpty()) {
153 d->
keys.append(
static_cast<Qt::Key
>(key.toUInt(
nullptr, 16)));
158 d->
buttons =
static_cast<Qt::MouseButtons
>(parts.at(3).toInt(
nullptr, 16));
162 qWarning() <<
"WARNING: input profile contains deprecated Mouse Wheel shortcut (WheelReserved_0), skipping...";
194 if (
d->
type != newType) {
206 if (
d->
mode != newMode) {
218 if (
d->
keys != newKeys) {
300 QString sep = i18nc(
"Separator in the list of mouse buttons for shortcut",
" + ");
304 if (
buttons & Qt::LeftButton) {
305 text.append(i18nc(
"Left Mouse Button",
"Left"));
309 if (
buttons & Qt::RightButton) {
310 if (buttonCount++ > 0) {
314 text.append(i18nc(
"Right Mouse Button",
"Right"));
317 if (
buttons & Qt::MiddleButton) {
318 if (buttonCount++ > 0) {
322 text.append(i18nc(
"Middle Mouse Button",
"Middle"));
325 if (
buttons & Qt::BackButton) {
326 if (buttonCount++ > 0) {
330 text.append(i18nc(
"Mouse Back Button",
"Back"));
333 if (
buttons & Qt::ForwardButton) {
334 if (buttonCount++ > 0) {
338 text.append(i18nc(
"Mouse Forward Button",
"Forward"));
341 if (
buttons & Qt::TaskButton) {
342 if (buttonCount++ > 0) {
346 text.append(i18nc(
"Mouse Task Button",
"Task"));
350#define EXTRA_BUTTON(z, n, _)\
351 if (buttons & Qt::ExtraButton##n) { \
352 if (buttonCount++ > 0) { text.append(sep); } \
353 text.append(i18nc("Mouse Button", "Mouse %1", n + 3)); \
358 if (buttonCount == 0) {
359 text.append(i18nc(
"No mouse buttons for shortcut",
"None"));
363 "%1 = List of mouse buttons for shortcut. "
364 "Plural form is chosen upon the number of buttons in that list.",
365 "%1 Button",
"%1 Buttons", text, buttonCount);
375 Q_FOREACH (Qt::Key key,
keys) {
379 output.append(QKeySequence(key).toString(QKeySequence::NativeText));
381 if (output.size() > 0) {
382 output.append(i18nc(
"Separator in the list of keys for shortcut",
" + "));
386 case Qt::Key_Control:
387 output.append(i18nc(
"Ctrl key",
"Ctrl"));
391 output.append(i18nc(
"Meta key",
"Meta"));
395 output.append(i18nc(
"Alt key",
"Alt"));
399 output.append(i18nc(
"Shift key",
"Shift"));
404 output.append(s.toString(QKeySequence::NativeText));
410 if (output.size() == 0) {
411 output = i18nc(
"No keys for shortcut",
"None");
421 return i18n(
"Mouse Wheel Up");
425 return i18n(
"Mouse Wheel Down");
429 return i18n(
"Mouse Wheel Left");
433 return i18n(
"Mouse Wheel Right");
437 return i18nc(
"No mouse wheel buttons for shortcut",
"None");
446 if (
keys.size() > 0) {
448 "%1 = modifier keys in shortcut; %2 = mouse buttons in shortcut",
462 if (
keys.size() > 0) {
464 "%1 = modifier keys in shortcut; %2 = mouse wheel buttons in shortcut",
478 return i18n(
"Pinch Gesture");
480 return i18n(
"Smart Zoom Gesture");
482 return i18n(
"Touchpad Scroll Gesture");
484 return i18n(
"No Gesture");
492 return i18n(
"One Finger Tap");
494 return i18n(
"Two Finger Tap");
496 return i18n(
"Three Finger Tap");
498 return i18n(
"Four Finger Tap");
500 return i18n(
"Five Finger Tap");
502 return i18n(
"One Finger Drag");
504 return i18n(
"Two Finger Drag");
506 return i18n(
"Three Finger Drag");
508 return i18n(
"Four Finger Drag");
510 return i18n(
"Five Finger Drag");
512 return i18n(
"One Finger Hold");
514 return i18n(
"No Gesture");
522 return i18nc(
"Shortcut type",
"Key Combination");
525 return i18nc(
"Shortcut type",
"Mouse Button");
528 return i18nc(
"Shortcut type",
"Mouse Wheel");
531 return i18nc(
"Shortcut type",
"Touch Gesture");
534 return i18nc(
"Shortcut type",
"Touchpad Gesture");
537 return i18n(
"Unknown Input");
TouchGestureAction touchGesture
NativeGestureAction nativeGesture
KisAbstractInputAction * action
A class encapsulating all settings for a single shortcut.
void setButtons(Qt::MouseButtons newButtons)
void setWheel(MouseWheelMovement type)
bool operator==(const KisShortcutConfiguration &other) const
static QString buttonsToText(Qt::MouseButtons buttons)
MouseWheelMovement wheel() const
static QString keysToText(const QList< Qt::Key > &keys)
void setNativeGesture(NativeGestureAction type)
ShortcutType type() const
KisAbstractInputAction * action() const
static QString shortcutTypeToText(ShortcutType type)
@ NativeGestureType
A macOS gesture.
@ MouseButtonType
A mouse button, possibly with key modifiers.
@ MouseWheelType
Mouse wheel movement, possibly with key modifiers.
@ TouchGestureType
A touch gesture.
@ KeyCombinationType
A list of keys that should be pressed.
@ UnknownType
Unknown, empty shortcut.
KisShortcutConfiguration & operator=(const KisShortcutConfiguration &other)
virtual ~KisShortcutConfiguration()
Qt::MouseButtons buttons() const
static QString wheelInputToText(const QList< Qt::Key > &keys, MouseWheelMovement wheel)
bool unserialize(const QString &serialized)
void setTouchGesture(TouchGestureAction type)
KisShortcutConfiguration()
QList< Qt::Key > keys() const
static QString wheelToText(MouseWheelMovement wheel)
static QString nativeGestureToText(NativeGestureAction action)
void setAction(KisAbstractInputAction *newAction)
static QString touchGestureToText(TouchGestureAction action)
NativeGestureAction nativeGesture() const
void setType(ShortcutType newType)
QString getInputText() const
TouchGestureAction touchGesture() const
void setKeys(const QList< Qt::Key > &newKeys)
@ TouchpadScroll
Two-dimensional pixel scrolling on a touchpad, supported on MacOS and Wayland only.
@ NoNativeGesture
No gesture.
@ SmartZoomGesture
Smart zoom gesture, typically a double tap that is a boolean zoom/unzoom.
@ PinchGesture
Pinch gesture, a two finger gesture used for navigating the canvas.
void setMode(uint newMode)
@ WheelDown
Downwards movement, toward the user.
@ WheelUp
Upwards movement, away from the user.
@ WheelLeft
Left movement.
@ WheelRight
Right movement.
@ WheelReserved_0
Do not use! Previously was used for TouchpadScroll shortcut.
static QString buttonsInputToText(const QList< Qt::Key > &keys, Qt::MouseButtons buttons)
QString buttons(const T &ev)