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 ~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 KisInputManagerinputManager
 
- 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)
 
KisInputManagerinputManager () 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 36 of file kis_pan_action.cpp.

37 : KisAbstractInputAction("Pan Canvas")
38 , d(new Private)
39{
40 setName(i18n("Pan Canvas"));
41 setDescription(i18n("The <i>Pan Canvas</i> action pans the canvas."));
42
43 QHash<QString, int> shortcuts;
44 shortcuts.insert(i18n("Pan Mode"), PanModeShortcut);
45 shortcuts.insert(i18n("Pan Left"), PanLeftShortcut);
46 shortcuts.insert(i18n("Pan Right"), PanRightShortcut);
47 shortcuts.insert(i18n("Pan Up"), PanUpShortcut);
48 shortcuts.insert(i18n("Pan Down"), PanDownShortcut);
49 setShortcutIndexes(shortcuts);
50}
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 52 of file kis_pan_action.cpp.

53{
54 delete d;
55}

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 62 of file kis_pan_action.cpp.

63{
64 Q_UNUSED(shortcut);
65 QApplication::setOverrideCursor(Qt::OpenHandCursor);
66}

◆ 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.

Reimplemented from KisAbstractInputAction.

Definition at line 74 of file kis_pan_action.cpp.

75{
76 KisAbstractInputAction::begin(shortcut, event);
77
78 bool overrideCursor = true;
79
80 switch (shortcut) {
81 case PanModeShortcut: {
82 QTouchEvent *tevent = dynamic_cast<QTouchEvent*>(event);
83 if (tevent) {
85 break;
86 }
87
88 // Some QT wheel events are actually be touch pad pan events. From the QT docs:
89 // "Wheel events are generated for both mouse wheels and trackpad scroll gestures."
90 QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent*>(event);
91 if (wheelEvent) {
92 inputManager()->canvas()->canvasController()->pan(-wheelEvent->pixelDelta());
93 overrideCursor = false;
94 break;
95 }
96
98
99 break;
100 }
101 case PanLeftShortcut:
102 inputManager()->canvas()->canvasController()->pan(QPoint(d->panDistance, 0));
103 break;
104 case PanRightShortcut:
105 inputManager()->canvas()->canvasController()->pan(QPoint(-d->panDistance, 0));
106 break;
107 case PanUpShortcut:
108 inputManager()->canvas()->canvasController()->pan(QPoint(0, d->panDistance));
109 break;
110 case PanDownShortcut:
111 inputManager()->canvas()->canvasController()->pan(QPoint(0, -d->panDistance));
112 break;
113 }
114
115 if (overrideCursor) {
116 QApplication::setOverrideCursor(Qt::ClosedHandCursor);
117 }
118}
static KisInputManager * inputManager
virtual void begin(int shortcut, QEvent *event)
KisCanvas2 * canvas() const
QPointF averagePoint(QTouchEvent *event, int *outCount=nullptr)
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

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

◆ 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 68 of file kis_pan_action.cpp.

69{
70 Q_UNUSED(shortcut);
71 QApplication::restoreOverrideCursor();
72}

◆ 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 120 of file kis_pan_action.cpp.

121{
122 QApplication::restoreOverrideCursor();
124}
virtual void end(QEvent *event)

References 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 193 of file kis_pan_action.cpp.

194{
195 Q_UNUSED(shortcut);
197}
@ 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 126 of file kis_pan_action.cpp.

127{
128 switch (event->type()) {
129 case QEvent::Gesture: {
130 QGestureEvent *gevent = static_cast<QGestureEvent*>(event);
131 if (gevent->activeGestures().at(0)->gestureType() == Qt::PanGesture) {
132 QPanGesture *pan = static_cast<QPanGesture*>(gevent->activeGestures().at(0));
133 inputManager()->canvas()->canvasController()->pan(-pan->delta().toPoint() * 0.2);
134 }
135 return;
136 }
137 case QEvent::TouchUpdate: {
138 QTouchEvent *tevent = static_cast<QTouchEvent*>(event);
139 int newTouchPointsCount;
140 QPointF newPos = d->averagePoint(tevent, &newTouchPointsCount);
141 // When the number of touch points have changed, the average point
142 // of the touch points will produce a huge jump which we don't want
143 // to happen when panning. This can happen when ending a 3-finger
144 // pan gesture. So we only pan the canvas if the number of touch
145 // points have not changed.
146 if (newTouchPointsCount == d->touchPointsCount) {
147 QPointF delta = newPos - d->lastPosition;
148 inputManager()->canvas()->canvasController()->pan(-delta.toPoint());
149 }
150 d->lastPosition = newPos;
151 d->touchPointsCount = newTouchPointsCount;
152 return;
153 }
154 default:
155 break;
156 }
158}
virtual void inputEvent(QEvent *event)

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

◆ 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 188 of file kis_pan_action.cpp.

189{
190 return shortcut == PanModeShortcut;
191}

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 57 of file kis_pan_action.cpp.

58{
59 return 5;
60}

◆ 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 199 of file kis_pan_action.cpp.

200{
201 Q_UNUSED(shortcut);
202 return true;
203}

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: