Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPanAction Class Reference

Pan Canvas implementation of KisAbstractInputAction. More...

#include <kis_pan_action.h>

+ Inheritance diagram for KisPanAction:

Classes

class  Private
 

Public Types

enum  Shortcut {
  PanModeShortcut , PanLeftShortcut , PanRightShortcut , PanUpShortcut ,
  PanDownShortcut
}
 

Public Member Functions

void activate (int shortcut) override
 
void begin (int shortcut, QEvent *event) override
 
void cursorMovedAbsolute (const QPointF &lastPos, const QPointF &pos) override
 
void deactivate (int shortcut) override
 
void end (QEvent *event) override
 
KisInputActionGroup inputActionGroup (int shortcut) const override
 
void inputEvent (QEvent *event) override
 
bool isShortcutRequired (int shortcut) const override
 
 KisPanAction ()
 
int priority () const override
 
bool supportsHiResInputEvents (int shortcut) const override
 
 ~KisPanAction () override
 
- Public Member Functions inherited from KisAbstractInputAction
virtual bool canIgnoreModifiers () const
 
virtual QString description () const
 
virtual QString id () const
 
virtual bool isAvailable () const
 
 KisAbstractInputAction (const QString &id)
 
virtual QString name () const
 
virtual QHash< QString, int > shortcutIndexes () const
 
virtual bool trySwitchShortcut (int oldShortcut, int newShortcut)
 
virtual ~KisAbstractInputAction ()
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Public Attributes inherited from KisAbstractInputAction
QString description
 
QString id
 
QHash< QString, int > indexes
 
QPointF lastCursorPosition
 
QString name
 
QPointF startCursorPosition
 
- Static Public Attributes inherited from KisAbstractInputAction
static KisInputManager * inputManager
 
- Protected Member Functions inherited from KisAbstractInputAction
virtual void cursorMoved (const QPointF &lastPos, const QPointF &pos)
 
QPoint eventPos (const QEvent *event)
 
QPointF eventPosF (const QEvent *event)
 
KisInputManager * inputManager () const
 
void setDescription (const QString &description)
 
void setName (const QString &name)
 
void setShortcutIndexes (const QHash< QString, int > &indexes)
 

Detailed Description

Pan Canvas implementation of KisAbstractInputAction.

The Pan Canvas action pans the canvas.

Definition at line 17 of file kis_pan_action.h.

Member Enumeration Documentation

◆ Shortcut

The different behaviours for this action.

Enumerator
PanModeShortcut 

Toggle the pan mode.

PanLeftShortcut 

Pan left by a fixed amount.

PanRightShortcut 

Pan right by a fixed amount.

PanUpShortcut 

Pan up by a fixed amount.

PanDownShortcut 

Pan down by a fixed amount.

Definition at line 23 of file kis_pan_action.h.

23 {
29 };
@ PanRightShortcut
Pan right by a fixed amount.
@ PanModeShortcut
Toggle the pan mode.
@ PanUpShortcut
Pan up by a fixed amount.
@ PanDownShortcut
Pan down by a fixed amount.
@ PanLeftShortcut
Pan left by a fixed amount.

Constructor & Destructor Documentation

◆ KisPanAction()

KisPanAction::KisPanAction ( )
explicit

Definition at line 38 of file kis_pan_action.cpp.

39 : KisAbstractInputAction("Pan Canvas")
40 , d(new Private)
41{
42 setName(i18n("Pan Canvas"));
43 setDescription(i18n("The <i>Pan Canvas</i> action pans the canvas."));
44
45 QHash<QString, int> shortcuts;
46 shortcuts.insert(i18n("Pan Mode"), PanModeShortcut);
47 shortcuts.insert(i18n("Pan Left"), PanLeftShortcut);
48 shortcuts.insert(i18n("Pan Right"), PanRightShortcut);
49 shortcuts.insert(i18n("Pan Up"), PanUpShortcut);
50 shortcuts.insert(i18n("Pan Down"), PanDownShortcut);
51 setShortcutIndexes(shortcuts);
52}
KisAbstractInputAction(const QString &id)
void setShortcutIndexes(const QHash< QString, int > &indexes)
void setName(const QString &name)
void setDescription(const QString &description)
Private *const d

References PanDownShortcut, PanLeftShortcut, PanModeShortcut, PanRightShortcut, PanUpShortcut, KisAbstractInputAction::setDescription(), KisAbstractInputAction::setName(), and KisAbstractInputAction::setShortcutIndexes().

◆ ~KisPanAction()

KisPanAction::~KisPanAction ( )
override

Definition at line 54 of file kis_pan_action.cpp.

55{
56 delete d;
57}

References d.

Member Function Documentation

◆ activate()

void KisPanAction::activate ( int shortcut)
overridevirtual

The method is called when the action is yet to be started, that is, e.g. the user has pressed all the modifiers for the action but hasn't started painting yet. This method is a right place to show the user what is going to happen, e.g. change the cursor.

Reimplemented from KisAbstractInputAction.

Definition at line 64 of file kis_pan_action.cpp.

65{
66 Q_UNUSED(shortcut);
67 QApplication::setOverrideCursor(Qt::OpenHandCursor);
68}

◆ begin()

void KisPanAction::begin ( int shortcut,
QEvent * event )
overridevirtual

Begin the action.

Parameters
shortcutThe index of the behaviour to trigger.
eventThe mouse event that has triggered this action. Is null for keyboard-activated actions.

Firstly, try to handle native gestures and touch events

Reimplemented from KisAbstractInputAction.

Definition at line 76 of file kis_pan_action.cpp.

77{
78 KisAbstractInputAction::begin(shortcut, event);
79
83 if (event
84 && (event->type() == QEvent::NativeGesture || event->type() == QEvent::TouchBegin
85 || event->type() == QEvent::TouchUpdate)
86 && shortcut == PanModeShortcut) {
87
89 using Flags = KisCanvasNavigationActionStrategyNativeGesture::Flags;
90
91 Flags flags;
92 flags.setFlag(Flag::PanEnabled);
93
94 if (event->type() == QEvent::NativeGesture) {
96 } else {
97 const QTouchEvent *tevent = static_cast<const QTouchEvent*>(event);
99 }
100
101 // native gestures don't have cursor tracking by the OS, so they shouldn't show any cursor
102 QApplication::restoreOverrideCursor();
103 return;
104 }
105
106 bool overrideCursor = true;
107
108 switch (shortcut) {
109 case PanModeShortcut: {
110 if (event->type() == QEvent::Wheel) {
111 // Some QT wheel events are actually be touch pad pan events. From the QT docs:
112 // "Wheel events are generated for both mouse wheels and trackpad scroll gestures."
113 QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);
114 inputManager()->canvas()->canvasController()->pan(-wheelEvent->pixelDelta());
115
116 // native gestures don't have cursor tracking by the OS, so they shouldn't show any cursor
117 QApplication::restoreOverrideCursor();
118
119 return;
120 } else {
122 }
123
124 break;
125 }
126 case PanLeftShortcut:
127 inputManager()->canvas()->canvasController()->pan(QPoint(d->panDistance, 0));
128 break;
129 case PanRightShortcut:
130 inputManager()->canvas()->canvasController()->pan(QPoint(-d->panDistance, 0));
131 break;
132 case PanUpShortcut:
133 inputManager()->canvas()->canvasController()->pan(QPoint(0, d->panDistance));
134 break;
135 case PanDownShortcut:
136 inputManager()->canvas()->canvasController()->pan(QPoint(0, -d->panDistance));
137 break;
138 }
139
140 if (overrideCursor) {
141 QApplication::setOverrideCursor(Qt::ClosedHandCursor);
142 }
143}
static KisInputManager * inputManager
QPointF eventPosF(const QEvent *event)
virtual void begin(int shortcut, QEvent *event)
KisCanvas2 * canvas() const
std::unique_ptr< KisCanvasNavigationActionStrategy > actionStrategy
KoCanvasController * canvasController() const
virtual QPointF preferredCenter() const =0
Returns the currently set preferred center point in view coordinates (pixels)
virtual void pan(const QPoint &distance)=0
KisCanvas2 * canvas

References KisPanAction::Private::actionStrategy, KisAbstractInputAction::begin(), Private::canvas, KisInputManager::canvas(), KoCanvasBase::canvasController(), d, KisAbstractInputAction::eventPosF(), KisAbstractInputAction::inputManager, KisPanAction::Private::originalPreferredCenter, KoCanvasController::pan(), KisPanAction::Private::panDistance, PanDownShortcut, PanLeftShortcut, PanModeShortcut, PanRightShortcut, PanUpShortcut, and KoCanvasController::preferredCenter().

◆ cursorMovedAbsolute()

void KisPanAction::cursorMovedAbsolute ( const QPointF & lastPos,
const QPointF & pos )
overridevirtual

◆ deactivate()

void KisPanAction::deactivate ( int shortcut)
overridevirtual

The method is called when the action is not a candidate for the starting anymore. The action should revert everything that was done in activate() method.

See also
activate()

Reimplemented from KisAbstractInputAction.

Definition at line 70 of file kis_pan_action.cpp.

71{
72 Q_UNUSED(shortcut);
73 QApplication::restoreOverrideCursor();
74}

◆ end()

void KisPanAction::end ( QEvent * event)
overridevirtual

End the action.

Parameters
eventThe mouse event that has finished this action. Is null for keyboard-activated actions.

Reimplemented from KisAbstractInputAction.

Definition at line 145 of file kis_pan_action.cpp.

146{
147 d->actionStrategy.reset();
148 QApplication::restoreOverrideCursor();
150}
virtual void end(QEvent *event)

References KisPanAction::Private::actionStrategy, d, and KisAbstractInputAction::end().

◆ inputActionGroup()

KisInputActionGroup KisPanAction::inputActionGroup ( int shortcut) const
overridevirtual
Returns
the group of the action the specified shortcut belongs to

Reimplemented from KisAbstractInputAction.

Definition at line 178 of file kis_pan_action.cpp.

179{
180 Q_UNUSED(shortcut);
182}
@ ViewTransformActionGroup

References ViewTransformActionGroup.

◆ inputEvent()

void KisPanAction::inputEvent ( QEvent * event)
overridevirtual

Process an input event.

By default handles MouseMove events and passes the data to a convenience cursorMoved() method

Parameters
eventAn event to process.

Reimplemented from KisAbstractInputAction.

Definition at line 152 of file kis_pan_action.cpp.

153{
154 if(!event) {
155 return;
156 }
157
158 if (d->actionStrategy && d->actionStrategy->supportsEvent(event)) {
159 d->actionStrategy->inputEvent(event);
160 } else if (event->type() == QEvent::Wheel) {
161 QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);
162 inputManager()->canvas()->canvasController()->pan(-wheelEvent->pixelDelta());
163 } else {
165 }
166}
virtual void inputEvent(QEvent *event)

References KisPanAction::Private::actionStrategy, KisInputManager::canvas(), KoCanvasBase::canvasController(), d, KisAbstractInputAction::inputEvent(), KisAbstractInputAction::inputManager, and KoCanvasController::pan().

◆ isShortcutRequired()

bool KisPanAction::isShortcutRequired ( int shortcut) const
overridevirtual

Return true when the specified shortcut is required for basic user interaction. This is used by the configuration system to prevent basic actions like painting from being removed.

Parameters
shortcutThe shortcut index to check.
Returns
True if the shortcut is required, false if not.

Reimplemented from KisAbstractInputAction.

Definition at line 173 of file kis_pan_action.cpp.

174{
175 return shortcut == PanModeShortcut;
176}

References PanModeShortcut.

◆ priority()

int KisPanAction::priority ( ) const
overridevirtual

The priority for this action.

Priority determines how "important" the action is and is used to resolve conflicts when multiple actions can be activated.

Reimplemented from KisAbstractInputAction.

Definition at line 59 of file kis_pan_action.cpp.

60{
61 return 5;
62}

◆ supportsHiResInputEvents()

bool KisPanAction::supportsHiResInputEvents ( int shortcut) const
overridevirtual

Returns true if the action can handle HiRes flow of move events which is generated by the tablet. If the function returns false, some of the events will be dropped or postponed. For most of the actions in Krita (except of real painting) it is perfectly acceptable, so 'false' is the default value.

Reimplemented from KisAbstractInputAction.

Definition at line 184 of file kis_pan_action.cpp.

185{
186 Q_UNUSED(shortcut);
187 return true;
188}

Member Data Documentation

◆ d

Private* const KisPanAction::d
private

Definition at line 52 of file kis_pan_action.h.


The documentation for this class was generated from the following files: