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

Zoom Canvas implementation of KisAbstractInputAction. More...

#include <kis_zoom_action.h>

+ Inheritance diagram for KisZoomAction:

Classes

class  Private
 

Public Types

enum  Shortcuts {
  ZoomModeShortcut , DiscreteZoomModeShortcut , ZoomInToCursorShortcut , ZoomOutFromCursorShortcut ,
  Zoom100PctShortcut , FitToViewShortcut , FitToWidthShortcut , RelativeZoomModeShortcut ,
  RelativeDiscreteZoomModeShortcut , FitToHeightShortcut , ZoomInShortcut , ZoomOutShortcut
}
 

Public Member Functions

void activate (int shortcut) override
 
void begin (int shortcut, QEvent *event=0) override
 
void cursorMovedAbsolute (const QPointF &startPos, 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
 
 KisZoomAction ()
 
int priority () const override
 
bool supportsHiResInputEvents (int shortcut) const override
 
 ~KisZoomAction () 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 {nullptr}
 

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

Zoom Canvas implementation of KisAbstractInputAction.

The Zoom Canvas action zooms the canvas.

Definition at line 17 of file kis_zoom_action.h.

Member Enumeration Documentation

◆ Shortcuts

The different behaviours for this action.

Enumerator
ZoomModeShortcut 

Toggle zoom mode.

DiscreteZoomModeShortcut 

Toggle discrete zoom mode.

ZoomInToCursorShortcut 

Zoom in to cursor.

ZoomOutFromCursorShortcut 

Zoom out from cursor.

Zoom100PctShortcut 

Reset zoom to 100%.

FitToViewShortcut 

Zoom fit to page.

FitToWidthShortcut 

Zoom fit to width.

RelativeZoomModeShortcut 

Toggle zoom mode relative to cursor.

RelativeDiscreteZoomModeShortcut 

Toggle discrete zoom mode relative to cursor.

FitToHeightShortcut 

Zoom fit to height.

ZoomInShortcut 

Zoom in by a fixed amount.

ZoomOutShortcut 

Zoom out by a fixed amount.

Definition at line 23 of file kis_zoom_action.h.

23 {
36 };
@ FitToHeightShortcut
Zoom fit to height.
@ ZoomInShortcut
Zoom in by a fixed amount.
@ RelativeDiscreteZoomModeShortcut
Toggle discrete zoom mode relative to cursor.
@ ZoomOutFromCursorShortcut
Zoom out from cursor.
@ ZoomInToCursorShortcut
Zoom in to cursor.
@ ZoomOutShortcut
Zoom out by a fixed amount.
@ DiscreteZoomModeShortcut
Toggle discrete zoom mode.
@ FitToViewShortcut
Zoom fit to page.
@ ZoomModeShortcut
Toggle zoom mode.
@ Zoom100PctShortcut
Reset zoom to 100%.
@ RelativeZoomModeShortcut
Toggle zoom mode relative to cursor.
@ FitToWidthShortcut
Zoom fit to width.

Constructor & Destructor Documentation

◆ KisZoomAction()

KisZoomAction::KisZoomAction ( )
explicit

Definition at line 45 of file kis_zoom_action.cpp.

46 : KisAbstractInputAction("Zoom Canvas")
47 , d(new Private(this))
48{
49 setName(i18n("Zoom Canvas"));
50 setDescription(i18n("The <i>Zoom Canvas</i> action zooms the canvas."));
51
52 QHash< QString, int > shortcuts;
53 shortcuts.insert(i18n("Zoom Mode"), ZoomModeShortcut);
54 shortcuts.insert(i18n("Discrete Zoom Mode"), DiscreteZoomModeShortcut);
55 shortcuts.insert(i18n("Relative Zoom Mode"), RelativeZoomModeShortcut);
56 shortcuts.insert(i18n("Relative Discrete Zoom Mode"), RelativeDiscreteZoomModeShortcut);
57 shortcuts.insert(i18n("Zoom In"), ZoomInShortcut);
58 shortcuts.insert(i18n("Zoom Out"), ZoomOutShortcut);
59 shortcuts.insert(i18n("Zoom In To Cursor"), ZoomInToCursorShortcut);
60 shortcuts.insert(i18n("Zoom Out From Cursor"), ZoomOutFromCursorShortcut);
61 shortcuts.insert(i18n("Zoom to 100%"), Zoom100PctShortcut);
62 shortcuts.insert(i18n("Fit to View"), FitToViewShortcut);
63 shortcuts.insert(i18n("Fit to View Width"), FitToWidthShortcut);
64 shortcuts.insert(i18n("Fit to View Height"), FitToHeightShortcut);
65 setShortcutIndexes(shortcuts);
66}
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 DiscreteZoomModeShortcut, FitToHeightShortcut, FitToViewShortcut, FitToWidthShortcut, RelativeDiscreteZoomModeShortcut, RelativeZoomModeShortcut, KisAbstractInputAction::setDescription(), KisAbstractInputAction::setName(), KisAbstractInputAction::setShortcutIndexes(), Zoom100PctShortcut, ZoomInShortcut, ZoomInToCursorShortcut, ZoomModeShortcut, ZoomOutFromCursorShortcut, and ZoomOutShortcut.

◆ ~KisZoomAction()

KisZoomAction::~KisZoomAction ( )
override

Definition at line 68 of file kis_zoom_action.cpp.

69{
70 delete d;
71}

References d.

Member Function Documentation

◆ activate()

void KisZoomAction::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 78 of file kis_zoom_action.cpp.

79{
80 if (shortcut == DiscreteZoomModeShortcut ||
82 QApplication::setOverrideCursor(KisCursor::zoomDiscreteCursor());
83 } else /* if (shortcut == SmoothZoomModeShortcut) */ {
84 QApplication::setOverrideCursor(KisCursor::zoomSmoothCursor());
85 }
86}
static QCursor zoomSmoothCursor()
static QCursor zoomDiscreteCursor()

References DiscreteZoomModeShortcut, RelativeDiscreteZoomModeShortcut, KisCursor::zoomDiscreteCursor(), and KisCursor::zoomSmoothCursor().

◆ begin()

void KisZoomAction::begin ( int shortcut,
QEvent * event = 0 )
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 94 of file kis_zoom_action.cpp.

95{
96 KisAbstractInputAction::begin(shortcut, event);
97
101 if (event
102 && (event->type() == QEvent::NativeGesture || event->type() == QEvent::TouchBegin
103 || event->type() == QEvent::TouchUpdate)
104 && (shortcut == ZoomModeShortcut || shortcut == RelativeZoomModeShortcut || shortcut == DiscreteZoomModeShortcut
105 || shortcut == RelativeDiscreteZoomModeShortcut)) {
107 using Flags = KisCanvasNavigationActionStrategyNativeGesture::Flags;
108
109 Flags flags;
110 flags.setFlag(Flag::PanEnabled);
111 flags.setFlag(Flag::ZoomEnabled);
112 flags.setFlag(Flag::ZoomDescrete,
114
115 if (event->type() == QEvent::NativeGesture) {
117 } else {
118 const QTouchEvent *tevent = static_cast<const QTouchEvent*>(event);
120 }
121
122 // native gestures don't have cursor tracking by the OS, so they shouldn't show any cursor
123 QApplication::restoreOverrideCursor();
124 return;
125 }
126
127 switch(shortcut) {
128 case ZoomModeShortcut:
131 d->mode = (Shortcuts)shortcut;
133 break;
134 }
139 d->mode = (Shortcuts)shortcut;
141 break;
142 case ZoomInShortcut:
143 case ZoomOutShortcut:
146 KoCanvasControllerWidget *controller =
149
150 QPoint pt;
151 if (shortcut == ZoomInToCursorShortcut || shortcut == ZoomOutFromCursorShortcut) {
152 pt = eventPos(event);
153 if (pt.isNull()) {
154 pt = controller->mapFromGlobal(QCursor::pos());
155 }
156 }
157
158 if (shortcut == ZoomInToCursorShortcut || shortcut == ZoomInShortcut) {
159 if (pt.isNull()) {
160 controller->zoomIn();
161 } else {
162 controller->zoomIn(inputManager()->canvas()->coordinatesConverter()->makeWidgetStillPoint(pt));
163 }
164 } else {
165 if (pt.isNull()) {
166 controller->zoomOut();
167 } else {
168 controller->zoomOut(inputManager()->canvas()->coordinatesConverter()->makeWidgetStillPoint(pt));
169 }
170 }
171 break;
172 }
173 case Zoom100PctShortcut: {
174 KoCanvasControllerWidget *controller =
176 controller->setZoom(KoZoomMode::ZOOM_CONSTANT, 1.0);
177 break;
178 }
179 case FitToViewShortcut: {
180 KoCanvasControllerWidget *controller =
182 controller->setZoom(KoZoomMode::ZOOM_PAGE, 1.0);
183 break;
184 }
185 case FitToWidthShortcut: {
186 KoCanvasControllerWidget *controller =
188 controller->setZoom(KoZoomMode::ZOOM_WIDTH, 1.0);
189 break;
190 }
191 case FitToHeightShortcut: {
192 KoCanvasControllerWidget *controller =
194 controller->setZoom(KoZoomMode::ZOOM_HEIGHT, 1.0);
195 break;
196 }
197 }
198}
static KisInputManager * inputManager
QPoint eventPos(const QEvent *event)
QPointF eventPosF(const QEvent *event)
virtual void begin(int shortcut, QEvent *event)
KisCoordinatesConverter * coordinatesConverter
KoViewTransformStillPoint makeWidgetStillPoint(const QPointF &viewPoint) const override
Creates a still point that links the viewPoint of the widget to the corresponding point of the image.
KisCanvas2 * canvas() const
KoViewTransformStillPoint actionStillPoint
std::unique_ptr< KisCanvasNavigationActionStrategy > actionStrategy
KoCanvasController * canvasController() const
void setZoom(KoZoomMode::Mode mode, qreal zoom) override
virtual void zoomIn(const KoViewTransformStillPoint &stillPoint)=0
zooms in keeping stillPoint not moved.
virtual void zoomOut(const KoViewTransformStillPoint &stillPoint)=0
zooms out keeping stillPoint not moved.
void zoom(qreal *zoomX, qreal *zoomY) const override
@ ZOOM_CONSTANT
zoom x %
Definition KoZoomMode.h:24
@ ZOOM_PAGE
zoom page
Definition KoZoomMode.h:25
@ ZOOM_WIDTH
zoom pagewidth
Definition KoZoomMode.h:26
@ ZOOM_HEIGHT
zoom pageheight
Definition KoZoomMode.h:27
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
KisCanvas2 * canvas

References KisZoomAction::Private::actionStillPoint, KisZoomAction::Private::actionStrategy, KisAbstractInputAction::begin(), Private::canvas, KisInputManager::canvas(), KoCanvasBase::canvasController(), KisCanvas2::coordinatesConverter, d, DiscreteZoomModeShortcut, KisAbstractInputAction::eventPos(), KisAbstractInputAction::eventPosF(), FitToHeightShortcut, FitToViewShortcut, FitToWidthShortcut, KisAbstractInputAction::inputManager, KIS_SAFE_ASSERT_RECOVER_RETURN, KisZoomAction::Private::lastDiscreteZoomDistance, KisCoordinatesConverter::makeWidgetStillPoint(), KisZoomAction::Private::mode, RelativeDiscreteZoomModeShortcut, RelativeZoomModeShortcut, KoCanvasControllerWidget::setZoom(), KisZoomAction::Private::startZoom, KoZoomHandler::zoom(), Zoom100PctShortcut, KoZoomMode::ZOOM_CONSTANT, KoZoomMode::ZOOM_HEIGHT, KoZoomMode::ZOOM_PAGE, KoZoomMode::ZOOM_WIDTH, KoCanvasController::zoomIn(), ZoomInShortcut, ZoomInToCursorShortcut, ZoomModeShortcut, KoCanvasController::zoomOut(), ZoomOutFromCursorShortcut, and ZoomOutShortcut.

◆ cursorMovedAbsolute()

void KisZoomAction::cursorMovedAbsolute ( const QPointF & startPos,
const QPointF & pos )
overridevirtual

Reimplemented from KisAbstractInputAction.

Definition at line 220 of file kis_zoom_action.cpp.

221{
222 QPointF diff = -(pos - startPos);
223
224 const int stepCont = 100;
225 const int stepDisc = 50;
226
227 if (d->mode == ZoomModeShortcut ||
229
230 KisConfig cfg(true);
231
232 const qreal logDistance = std::pow(2.0, qreal(cfg.zoomHorizontal() ? -diff.x() : diff.y()) / qreal(stepCont));
233
234 qreal newZoom = 1.0;
235 if (cfg.readEntry<bool>("InvertMiddleClickZoom", false)) {
236 newZoom = d->startZoom / logDistance;
237 } else {
238 newZoom = d->startZoom * logDistance;
239 }
240
241 KoCanvasControllerWidget *controller =
244
245 if (d->mode == ZoomModeShortcut) {
246 controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom);
247 } else {
248 controller->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom, d->actionStillPoint);
249 }
250
251 } else if (d->mode == DiscreteZoomModeShortcut ||
253
254 KoCanvasControllerWidget *controller =
257
258 KisConfig cfg(true);
259
260 qreal axisDiff = qreal(cfg.zoomHorizontal() ? -diff.x() : diff.y());
261 qreal currentDiff = axisDiff / stepDisc - d->lastDiscreteZoomDistance;
262
263 const bool zoomIn = currentDiff > 0;
264 while (qAbs(currentDiff) > 1.0) {
265 if (zoomIn) {
267 controller->zoomIn(d->actionStillPoint);
268 } else {
269 controller->zoomIn();
270 }
271 } else {
273 controller->zoomOut(d->actionStillPoint);
274 } else {
275 controller->zoomOut();
276 }
277 }
278 d->lastDiscreteZoomDistance += zoomIn ? 1.0 : -1.0;
279 currentDiff = axisDiff / stepDisc - d->lastDiscreteZoomDistance;
280 }
281 }
282}
QAction * zoomIn(const QObject *recvr, const char *slot, QObject *parent)

References KisZoomAction::Private::actionStillPoint, KisInputManager::canvas(), KoCanvasBase::canvasController(), d, DiscreteZoomModeShortcut, KisAbstractInputAction::inputManager, KIS_SAFE_ASSERT_RECOVER_RETURN, KisZoomAction::Private::lastDiscreteZoomDistance, KisZoomAction::Private::mode, KisConfig::readEntry(), RelativeDiscreteZoomModeShortcut, RelativeZoomModeShortcut, KoCanvasControllerWidget::setZoom(), KisZoomAction::Private::startZoom, KoZoomMode::ZOOM_CONSTANT, KisConfig::zoomHorizontal(), KoCanvasController::zoomIn(), ZoomModeShortcut, and KoCanvasController::zoomOut().

◆ deactivate()

void KisZoomAction::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 88 of file kis_zoom_action.cpp.

89{
90 Q_UNUSED(shortcut);
91 QApplication::restoreOverrideCursor();
92}

◆ end()

void KisZoomAction::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 200 of file kis_zoom_action.cpp.

201{
202 d->actionStrategy.reset();
204}
virtual void end(QEvent *event)

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

◆ inputActionGroup()

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

Reimplemented from KisAbstractInputAction.

Definition at line 295 of file kis_zoom_action.cpp.

296{
297 Q_UNUSED(shortcut);
299}
@ ViewTransformActionGroup

References ViewTransformActionGroup.

◆ inputEvent()

void KisZoomAction::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 206 of file kis_zoom_action.cpp.

207{
208 if(!event) {
209 return;
210 }
211
212 if (d->actionStrategy && d->actionStrategy->supportsEvent(event)) {
213 d->actionStrategy->inputEvent(event);
214 return;
215 } else {
217 }
218}
virtual void inputEvent(QEvent *event)

References KisZoomAction::Private::actionStrategy, d, and KisAbstractInputAction::inputEvent().

◆ isShortcutRequired()

bool KisZoomAction::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 284 of file kis_zoom_action.cpp.

285{
286 return shortcut == ZoomModeShortcut;
287}

References ZoomModeShortcut.

◆ priority()

int KisZoomAction::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 73 of file kis_zoom_action.cpp.

74{
75 return 4;
76}

◆ supportsHiResInputEvents()

bool KisZoomAction::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 289 of file kis_zoom_action.cpp.

290{
291 Q_UNUSED(shortcut);
292 return true;
293}

Member Data Documentation

◆ d

Private* const KisZoomAction::d {nullptr}
private

Definition at line 57 of file kis_zoom_action.h.

57{nullptr};

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