Commit 6191b915 authored by Jonathan Colman's avatar Jonathan Colman Committed by Dmitry Kazakov
Browse files

Add Fit To Height zooming and shortcut

Added Fit to Height option in zoom drop-down, and ability to shortcut
via "Configure Krita..." Set ZOOM_HEIGHT enum value to 16,
so ZOOM_HEIGHT is a unique mask in KoZoomController::Private
(see KoZoomController_p.h line 41)

This commit resolves: https://bugs.kde.org/show_bug.cgi?id=410929

BUG:410929
parent 2229f6dd
......@@ -127,6 +127,7 @@ KisZoomAction::KisZoomAction()
shortcuts.insert(i18n("Reset Zoom to 100%"), ZoomResetShortcut);
shortcuts.insert(i18n("Fit to Page"), ZoomToPageShortcut);
shortcuts.insert(i18n("Fit to Width"), ZoomToWidthShortcut);
shortcuts.insert(i18n("Fit to Height"), ZoomToHeightShortcut);
setShortcutIndexes(shortcuts);
}
......@@ -191,6 +192,9 @@ void KisZoomAction::begin(int shortcut, QEvent *event)
case ZoomToWidthShortcut:
inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_WIDTH, 1.0);
break;
case ZoomToHeightShortcut:
inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_HEIGHT, 1.0);
break;
}
}
......
......@@ -40,6 +40,7 @@ public:
ZoomResetShortcut, ///< Reset zoom to 100%.
ZoomToPageShortcut, ///< Zoom fit to page.
ZoomToWidthShortcut, ///< Zoom fit to width.
ZoomToHeightShortcut, ///< Zoom fit to height.
RelativeZoomModeShortcut, ///< Toggle zoom mode relative to cursor
RelativeDiscreteZoomModeShortcut ///< Toggle discrete zoom mode relative to cursor
};
......
......@@ -195,6 +195,9 @@ void KoZoomAction::regenerateItems(const qreal zoom)
if(d->zoomModes & KoZoomMode::ZOOM_PAGE) {
values << KoZoomMode::toString(KoZoomMode::ZOOM_PAGE);
}
if(d->zoomModes & KoZoomMode::ZOOM_HEIGHT) {
values << KoZoomMode::toString(KoZoomMode::ZOOM_HEIGHT);
}
Q_FOREACH (qreal value, zoomLevels) {
const qreal valueInPercent = value * 100;
......
......@@ -92,6 +92,8 @@ void KoZoomController::setPageSize(const QSizeF &pageSize)
setZoom(KoZoomMode::ZOOM_WIDTH, 0);
if(d->zoomHandler->zoomMode() == KoZoomMode::ZOOM_PAGE)
setZoom(KoZoomMode::ZOOM_PAGE, 0);
if(d->zoomHandler->zoomMode() == KoZoomMode::ZOOM_HEIGHT)
setZoom(KoZoomMode::ZOOM_HEIGHT, 0);
}
QSizeF KoZoomController::pageSize() const
......@@ -165,6 +167,13 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resoluti
d->action->setSelectedZoomMode(mode);
d->action->setEffectiveZoom(zoom);
}
else if(mode == KoZoomMode::ZOOM_HEIGHT) {
zoom = (d->canvasController->viewportSize().height() - 2 * d->fitMargin)
/ (oldPageViewportSize.height() / d->zoomHandler->zoom());
d->action->setSelectedZoomMode(mode);
d->action->setEffectiveZoom(zoom);
}
d->zoomHandler->setZoomMode(mode);
d->zoomHandler->setZoom(d->action->effectiveZoom());
......@@ -190,7 +199,7 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resoluti
// Finally ask the canvasController to recenter
QPointF documentCenter;
if (mode == KoZoomMode::ZOOM_WIDTH || mode == KoZoomMode::ZOOM_PAGE) {
if (mode == KoZoomMode::ZOOM_WIDTH || mode == KoZoomMode::ZOOM_PAGE || mode == KoZoomMode::ZOOM_HEIGHT) {
documentCenter = QRectF(QPointF(), documentViewportSize).center();
}
else {
......
......@@ -38,7 +38,7 @@ public:
Private(KoZoomController *p)
: canvasController(0), zoomHandler(0), action(0), textMinX(1), textMaxX(600), fitMargin(0), parent(p)
{
action = new KoZoomAction(KoZoomMode::ZOOM_WIDTH | KoZoomMode::ZOOM_PAGE, i18n("Zoom"), p);
action = new KoZoomAction(KoZoomMode::ZOOM_WIDTH | KoZoomMode::ZOOM_PAGE | KoZoomMode::ZOOM_HEIGHT, i18n("Zoom"), p);
}
~Private()
{
......
......@@ -31,7 +31,15 @@ const char* const KoZoomMode::modes[] =
0,
0,
0,
I18N_NOOP("Fit Text Width")
I18N_NOOP("Fit Text Width"),
0,
0,
0,
0,
0,
0,
0,
I18N_NOOP("Fit Page Height")
};
qreal KoZoomMode::minimumZoomValue = 0.2;
......@@ -53,7 +61,10 @@ KoZoomMode::Mode KoZoomMode::toMode(const QString& mode)
if (mode == i18n(modes[ZOOM_PIXELS]))
return ZOOM_PIXELS;
else
return ZOOM_CONSTANT;
if (mode == i18n(modes[ZOOM_HEIGHT]))
return ZOOM_HEIGHT;
else
return ZOOM_CONSTANT;
// we return ZOOM_CONSTANT else because then we can pass '10%' or '15%'
// or whatever, it's automatically converted. ZOOM_CONSTANT is
// changeable, whereas all other zoom modes (non-constants) are normal
......
......@@ -36,6 +36,7 @@ public:
ZOOM_CONSTANT = 0, ///< zoom x %
ZOOM_WIDTH = 1, ///< zoom pagewidth
ZOOM_PAGE = 2, ///< zoom to pagesize
ZOOM_HEIGHT = 16, ///< zoom pageheight
ZOOM_PIXELS = 4 ///< zoom to actual pixels
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment