11#include <QKeySequence>
12#include <KLocalizedString>
14#include <boost/preprocessor/repeat_from_to.hpp>
81 QString serialized(
"{");
83 serialized.append(QString::number(
d->
mode, 16));
84 serialized.append(
';');
89 serialized.append(QString::number(
d->
type, 16));
92 serialized.append(QString::number(
d->
type, 16));
94 serialized.append(
";[");
97 serialized.append(QString::number(*itr, 16));
99 if (itr + 1 !=
d->
keys.end()) {
100 serialized.append(
',');
104 serialized.append(
"];");
106 serialized.append(QString::number(
d->
buttons, 16));
107 serialized.append(
';');
108 serialized.append(QString::number(
d->
wheel, 16));
109 serialized.append(
';');
110 serialized.append(QString::number(
d->
gesture, 16));
111 serialized.append(
'}');
118 if (!serialized.startsWith(
'{'))
122 QString remainder = serialized;
125 remainder.remove(
'{').remove(
'}');
130 if (parts.size() < 6)
134 d->
mode = parts.at(0).toUInt(
nullptr, 16);
161 QString serializedKeys = parts.at(2);
163 serializedKeys.remove(
'[').remove(
']');
166 Q_FOREACH(QString key, keylist) {
167 if (!key.isEmpty()) {
168 d->
keys.append(
static_cast<Qt::Key
>(key.toUInt(
nullptr, 16)));
173 d->
buttons =
static_cast<Qt::MouseButtons
>(parts.at(3).toInt(
nullptr, 16));
199 if (
d->
type != newType) {
211 if (
d->
mode != newMode) {
223 if (
d->
keys != newKeys) {
293 QString sep = i18nc(
"Separator in the list of mouse buttons for shortcut",
" + ");
297 if (
buttons & Qt::LeftButton) {
298 text.append(i18nc(
"Left Mouse Button",
"Left"));
302 if (
buttons & Qt::RightButton) {
303 if (buttonCount++ > 0) {
307 text.append(i18nc(
"Right Mouse Button",
"Right"));
310 if (
buttons & Qt::MiddleButton) {
311 if (buttonCount++ > 0) {
315 text.append(i18nc(
"Middle Mouse Button",
"Middle"));
318 if (
buttons & Qt::BackButton) {
319 if (buttonCount++ > 0) {
323 text.append(i18nc(
"Mouse Back Button",
"Back"));
326 if (
buttons & Qt::ForwardButton) {
327 if (buttonCount++ > 0) {
331 text.append(i18nc(
"Mouse Forward Button",
"Forward"));
334 if (
buttons & Qt::TaskButton) {
335 if (buttonCount++ > 0) {
339 text.append(i18nc(
"Mouse Task Button",
"Task"));
343#define EXTRA_BUTTON(z, n, _)\
344 if (buttons & Qt::ExtraButton##n) { \
345 if (buttonCount++ > 0) { text.append(sep); } \
346 text.append(i18nc("Mouse Button", "Mouse %1", n + 3)); \
351 if (buttonCount == 0) {
352 text.append(i18nc(
"No mouse buttons for shortcut",
"None"));
356 "%1 = List of mouse buttons for shortcut. "
357 "Plural form is chosen upon the number of buttons in that list.",
358 "%1 Button",
"%1 Buttons", text, buttonCount);
368 Q_FOREACH (Qt::Key key,
keys) {
372 output.append(QKeySequence(key).toString(QKeySequence::NativeText));
374 if (output.size() > 0) {
375 output.append(i18nc(
"Separator in the list of keys for shortcut",
" + "));
379 case Qt::Key_Control:
380 output.append(i18nc(
"Ctrl key",
"Ctrl"));
384 output.append(i18nc(
"Meta key",
"Meta"));
388 output.append(i18nc(
"Alt key",
"Alt"));
392 output.append(i18nc(
"Shift key",
"Shift"));
397 output.append(s.toString(QKeySequence::NativeText));
403 if (output.size() == 0) {
404 output = i18nc(
"No keys for shortcut",
"None");
414 return i18n(
"Mouse Wheel Up");
418 return i18n(
"Mouse Wheel Down");
422 return i18n(
"Mouse Wheel Left");
426 return i18n(
"Mouse Wheel Right");
430 return i18n(
"Trackpad Pan");
434 return i18nc(
"No mouse wheel buttons for shortcut",
"None");
443 if (
keys.size() > 0) {
445 "%1 = modifier keys in shortcut; %2 = mouse buttons in shortcut",
459 if (
keys.size() > 0) {
461 "%1 = modifier keys in shortcut; %2 = mouse wheel buttons in shortcut",
476 return i18n(
"Pinch Gesture");
478 return i18n(
"Pan Gesture");
480 return i18n(
"Rotate Gesture");
481 case SmartZoomGesture:
482 return i18n(
"Smart Zoom Gesture");
485 return i18n(
"One Finger Tap");
487 return i18n(
"Two Finger Tap");
489 return i18n(
"Three Finger Tap");
491 return i18n(
"Four Finger Tap");
493 return i18n(
"Five Finger Tap");
495 return i18n(
"One Finger Drag");
497 return i18n(
"Two Finger Drag");
499 return i18n(
"Three Finger Drag");
501 return i18n(
"Four Finger Drag");
503 return i18n(
"Five Finger Drag");
506 return i18n(
"No Gesture");
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)
ShortcutType type() const
KisAbstractInputAction * action() const
@ MacOSGestureType
A macOS gesture.
@ 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.
@ UnknownType
Unknown, empty shortcut.
@ GestureType
A touch gesture.
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)
KisShortcutConfiguration()
QList< Qt::Key > keys() const
void setGesture(GestureAction type)
GestureAction gesture() const
static QString wheelToText(MouseWheelMovement wheel)
void setAction(KisAbstractInputAction *newAction)
void setType(ShortcutType newType)
QString getInputText() const
void setKeys(const QList< Qt::Key > &newKeys)
void setMode(uint newMode)
@ WheelTrackpad
A pan movement on a trackpad.
@ WheelDown
Downwards movement, toward the user.
@ WheelUp
Upwards movement, away from the user.
@ WheelLeft
Left movement.
@ WheelRight
Right movement.
static QString gestureToText(GestureAction action)
static QString buttonsInputToText(const QList< Qt::Key > &keys, Qt::MouseButtons buttons)
QString buttons(const T &ev)