Krita Source Code Documentation
Loading...
Searching...
No Matches
KisInputProfileMigrator.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Sharaf Zaman <shzam@sdf.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8
9#include <QDebug>
10
11#include <KisMpl.h>
12
13#include <KConfig>
14#include <KConfigGroup>
15#include <KoResourcePaths.h>
16
17#include <kis_assert.h>
18
22#include "kis_pan_action.h"
24
28
30 : m_manager(manager)
31{
32 // FIXME(sh_zam): Should we declare this as "the default profile" somewhere?
33 const QStringList profiles =
35 .filter("kritadefault.profile");
36
37 if (!profiles.empty()) {
38 // This will be from the install location, so *has* to be the default, see KoResourcePaths for the
39 // order in which it returns locations.
40 m_defaultProfile = profiles.last();
41 } else {
42 qWarning() << "Default profile does not exist anywhere!";
43 }
44}
45
49
60
61template <typename Func>
63{
64 auto it = shortcuts.begin();
65 while (it != shortcuts.end()) {
66 KisShortcutConfiguration shortcut = *it;
67 if (pred(shortcut)) {
68 ++it;
69 } else {
70 it = shortcuts.erase(it);
71 }
72 }
73}
74
76{
78
79 KConfig config(profile, KConfig::SimpleConfig);
80
81 const QList<KisAbstractInputAction *> actions = manager->actions();
82 for (const auto action : actions) {
83 if (!config.hasGroup(action->id())) {
84 continue;
85 }
86
87 KConfigGroup group = config.group(action->id());
88 for (const auto &groupEntry : group.entryMap()) {
90
91 shortcut.setAction(action);
92 if (shortcut.unserialize(groupEntry)) {
93 shortcuts.append(shortcut);
94 }
95 }
96 }
97 return shortcuts;
98}
99
101{
103
104 // we ignore the touch shortcuts, because they're from an older version
105 filterShortcuts(shortcuts, [](KisShortcutConfiguration shortcut) {
108 });
109
110 // now we add the default new shortcuts -- this should complete the migration.
111 shortcuts.append(defaultTouchShortcuts());
112
113 return shortcuts;
114}
115
116
122
127
129{
135 auto shortcuts = getShortcutsFromProfile(profile.fullpath, m_manager);
136 for (auto it = shortcuts.begin(); it != shortcuts.end();) {
138 it = shortcuts.erase(it);
139 } else {
140 ++it;
141 }
142 }
143
144 for (auto it = shortcuts.begin(); it != shortcuts.end();) {
147 it = shortcuts.erase(it);
148 } else {
149 ++it;
150 }
151 }
152
153 auto actions = m_manager->actions();
154
155 {
161 auto it = std::find_if(actions.begin(), actions.end(), kismpl::mem_equal_to(&KisAbstractInputAction::id, "Zoom and Rotate Canvas"));
162 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(it != actions.end(), shortcuts);
163
164 KisShortcutConfiguration newNativeGestureShortcut;
165 newNativeGestureShortcut.setAction(*it);
169 shortcuts.append(newNativeGestureShortcut);
170 }
171
172 {
178 auto it = std::find_if(actions.begin(), actions.end(), kismpl::mem_equal_to(&KisAbstractInputAction::id, "Pan Canvas"));
179 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(it != actions.end(), shortcuts);
180
181 KisShortcutConfiguration newNativeGestureShortcut;
182 newNativeGestureShortcut.setAction(*it);
185 newNativeGestureShortcut.setMode(KisPanAction::PanModeShortcut);
186 shortcuts.append(newNativeGestureShortcut);
187 }
188
189 return shortcuts;
190}
A class to manage a list of profiles and actions.
QList< KisAbstractInputAction * > actions
QList< KisShortcutConfiguration > migrate(const ProfileEntry &profile) override
KisInputProfileMigratorFrom5(KisInputProfileManager *manager)
KisInputProfileManager * m_manager
void filterShortcuts(QList< KisShortcutConfiguration > &shortcuts, Func func)
QList< KisShortcutConfiguration > defaultTouchShortcuts()
QList< KisShortcutConfiguration > migrate(const ProfileEntry &profile) override
KisInputProfileManager * m_manager
KisInputProfileMigratorFrom6(KisInputProfileManager *manager)
static QList< KisShortcutConfiguration > getShortcutsFromProfile(QString profile, KisInputProfileManager *manager)
@ PanModeShortcut
Toggle the pan mode.
A class encapsulating all settings for a single shortcut.
void setNativeGesture(NativeGestureAction type)
@ MouseWheelType
Mouse wheel movement, possibly with key modifiers.
bool unserialize(const QString &serialized)
void setAction(KisAbstractInputAction *newAction)
void setType(ShortcutType newType)
@ TouchpadScroll
Two-dimensional pixel scrolling on a touchpad, supported on MacOS and Wayland only.
@ PinchGesture
Pinch gesture, a two finger gesture used for navigating the canvas.
@ WheelReserved_0
Do not use! Previously was used for TouchpadScroll shortcut.
static QStringList findAllAssets(const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
auto mem_equal_to(MemTypeNoRef Class::*ptr, MemType &&value)
mem_equal_to is an unary functor that compares a member of the object to a given value
Definition KisMpl.h:233