Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_alternate_invocation_action.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QApplication>
10#include <QMouseEvent>
11
12#include <klocalizedstring.h>
13
14#include <kis_tool_proxy.h>
15#include <kis_canvas2.h>
16
17#include "kis_input_manager.h"
18#include "kis_cursor.h"
19
24
26 : KisAbstractInputAction("Alternate Invocation")
27 , m_d(new Private)
28{
29 setName(i18n("Alternate Invocation"));
30 setDescription(i18n("The <i>Alternate Invocation</i> action performs an alternate action with the current tool. For example, using the brush tool it samples a color from the canvas."));
31 QHash<QString, int> shortcuts;
32 shortcuts.insert(i18n("Primary Mode"), PrimaryAlternateModeShortcut);
33 shortcuts.insert(i18n("Secondary Mode"), SecondaryAlternateModeShortcut);
34 shortcuts.insert(i18n("Tertiary Mode"), TertiaryAlternateModeShortcut);
35
36
37 shortcuts.insert(i18n("Sample Foreground Color from Current Layer"), SampleColorFgLayerModeShortcut);
38 shortcuts.insert(i18n("Sample Background Color from Current Layer"), SampleColorBgLayerModeShortcut);
39
40 shortcuts.insert(i18n("Sample Foreground Color from Merged Image"), SampleColorFgImageModeShortcut);
41 shortcuts.insert(i18n("Sample Background Color from Merged Image"), SampleColorBgImageModeShortcut);
42
43 setShortcutIndexes(shortcuts);
44}
45
49
80
82{
84 inputManager()->toolProxy()->activateToolAction(action);
85}
86
88{
90 inputManager()->toolProxy()->deactivateToolAction(action);
91}
92
94{
95 return 9;
96}
97
98void KisAlternateInvocationAction::begin(int shortcut, QEvent *event)
99{
100 if (!event) return;
101
102 KisAbstractInputAction::begin(shortcut, event);
103
104 QMouseEvent targetEvent(QEvent::MouseButtonPress, eventPosF(event), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); // There must be a better way
105
106 m_d->savedAction = shortcutToToolAction(shortcut);
107
108 inputManager()->toolProxy()->forwardEvent(KisToolProxy::BEGIN, m_d->savedAction, &targetEvent, event);
109}
110
112{
113 if (!event) return;
114
115 Qt::KeyboardModifiers modifiers;
116
117 switch (m_d->savedAction) {
119 modifiers = Qt::ControlModifier;
120 break;
122 modifiers = Qt::ControlModifier | Qt::AltModifier;
123 break;
124 default:
125 ;
126 }
127
128 QMouseEvent targetEvent = QMouseEvent(QEvent::MouseButtonRelease, eventPosF(event), Qt::LeftButton, Qt::LeftButton, modifiers);
129 inputManager()->toolProxy()->forwardEvent(KisToolProxy::END, m_d->savedAction, &targetEvent, event);
130
132}
133
135{
136 if (event
137 && ((event->type() == QEvent::MouseMove) || (event->type() == QEvent::TabletMove)
138 || (event->type() == QEvent::TouchUpdate))) {
139 Qt::KeyboardModifiers modifiers;
140 switch (m_d->savedAction) {
142 modifiers = Qt::ControlModifier;
143 break;
145 modifiers = Qt::ControlModifier | Qt::AltModifier;
146 break;
147 default:
148 modifiers = Qt::ShiftModifier;
149 }
150
151 QMouseEvent targetEvent(QEvent::MouseMove, eventPosF(event), Qt::LeftButton, Qt::LeftButton, modifiers);
152 inputManager()->toolProxy()->forwardEvent(KisToolProxy::CONTINUE, m_d->savedAction, &targetEvent, event);
153 }
154}
155
157{
158 return inputManager()->toolProxy()->alternateActionSupportsHiResEvents(
160}
Abstract base class for input actions.
static KisInputManager * inputManager
void setShortcutIndexes(const QHash< QString, int > &indexes)
QPointF eventPosF(const QEvent *event)
void setName(const QString &name)
virtual void end(QEvent *event)
void setDescription(const QString &description)
virtual void begin(int shortcut, QEvent *event)
@ SecondaryAlternateModeShortcut
Toggle Secondary mode.
@ TertiaryAlternateModeShortcut
Warning: don't reorder the items of this enum, it breaks user configs!
const QScopedPointer< Private > m_d
bool supportsHiResInputEvents(int shortcut) const override
void begin(int shortcut, QEvent *event) override
KisTool::ToolAction shortcutToToolAction(int shortcut) const
QPointer< KisToolProxy > toolProxy() const
@ AlternateFourth
Definition kis_tool.h:127
@ AlternateSampleFgImage
Definition kis_tool.h:123
@ AlternateSecondary
Definition kis_tool.h:125
@ Alternate_NONE
Definition kis_tool.h:129
@ AlternateSampleBgNode
Definition kis_tool.h:122
@ AlternateSampleBgImage
Definition kis_tool.h:124
@ AlternateThird
Definition kis_tool.h:126
@ AlternateSampleFgNode
Definition kis_tool.h:121
static AlternateAction actionToAlternateAction(ToolAction action)
Definition kis_tool.cc:416