Commit 33ca396d authored by Nate Graham's avatar Nate Graham 🔩

Create new "Zoom to 100%" action

Summary:
This patch implements a "Zoom to 100%" action and sticks it in the {nav View} menu. Since it's a `KStandardAction` with a `KStandardShortcut`, we automatically get the correct icon and keyboard shortcut, but we do override the name to be "Zoom to 100%" since that's clearer for Okular's use case.

FEATURE: 400048
FIXED-IN: 18.12.0

Test Plan:
- Action works to zoom the document to 100% scale when invoked
- Action is disabled when document is opened at 100% scale or is manually zoomed to 100% scale after being opened
- All other zoom modes and action still work

{F6341045}

Reviewers: #okular, #vdg, abetts

Reviewed By: #vdg, abetts

Subscribers: davidhurka, sander, tobiasdeiminger, veqz, abetts, aacid, okular-devel

Tags: #okular

Differential Revision: https://phabricator.kde.org/D16345
parent e7cd4bf9
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part_viewermode" version="3">
<kpartgui name="okular_part_viewermode" version="4">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
......@@ -22,6 +22,7 @@
<Separator group="viewer_menu_merge"/>
<Action name="view_zoom_in" group="viewer_menu_merge"/>
<Action name="view_zoom_out" group="viewer_menu_merge"/>
<Action name="view_actual_size" group="viewer_menu_merge"/>
<Action name="view_fit_to_width" group="viewer_menu_merge"/>
<Action name="view_fit_to_page" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part" version="38">
<kpartgui name="okular_part" version="39">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="get_new_stuff" group="file_open"/>
......@@ -31,6 +31,7 @@
<Separator/>
<Action name="view_zoom_in"/>
<Action name="view_zoom_out"/>
<Action name="view_actual_size"/>
<Action name="view_fit_to_width"/>
<Action name="view_fit_to_page"/>
<Action name="view_auto_fit"/>
......
......@@ -222,6 +222,7 @@ public:
KSelectAction * aZoom;
QAction * aZoomIn;
QAction * aZoomOut;
QAction * aZoomActual;
KToggleAction * aZoomFitWidth;
KToggleAction * aZoomFitPage;
KToggleAction * aZoomAutoFit;
......@@ -483,6 +484,9 @@ void PageView::setupBaseActions( KActionCollection * ac )
d->aZoomIn = KStandardAction::zoomIn( this, SLOT(slotZoomIn()), ac );
d->aZoomOut = KStandardAction::zoomOut( this, SLOT(slotZoomOut()), ac );
d->aZoomActual = KStandardAction::actualSize( this, &PageView::slotZoomActual, ac );
d->aZoomActual->setText(i18n("Zoom to 100%"));
}
void PageView::setupViewerActions( KActionCollection * ac )
......@@ -1204,6 +1208,8 @@ void PageView::updateActionState( bool haspages, bool documentChanged, bool hasf
d->aZoomIn->setEnabled( haspages );
if ( d->aZoomOut )
d->aZoomOut->setEnabled( haspages );
if ( d->aZoomActual )
d->aZoomActual->setEnabled( haspages && d->zoomFactor != 1.0 );
if ( d->mouseModeActionGroup )
d->mouseModeActionGroup->setEnabled( haspages );
......@@ -4001,6 +4007,10 @@ void PageView::updateZoom( ZoomMode newZoomMode )
}
}
break;
case ZoomActual:
newZoomMode = ZoomFixed;
newFactor = 1.0;
break;
case ZoomFitWidth:
checkedZoomAction = d->aZoomFitWidth;
break;
......@@ -4048,6 +4058,7 @@ void PageView::updateZoom( ZoomMode newZoomMode )
d->aZoomIn->setEnabled( d->zoomFactor < upperZoomLimit-0.001 );
d->aZoomOut->setEnabled( d->zoomFactor > 0.101 );
d->aZoomActual->setEnabled( d->zoomFactor != 1.0 );
}
void PageView::updateZoomText()
......@@ -4978,6 +4989,11 @@ void PageView::slotZoomOut()
updateZoom( ZoomOut );
}
void PageView::slotZoomActual()
{
updateZoom( ZoomActual );
}
void PageView::slotFitToWidthToggled( bool on )
{
if ( on ) updateZoom( ZoomFitWidth );
......
......@@ -62,9 +62,9 @@ Q_OBJECT
PageView( QWidget *parent, Okular::Document *document );
~PageView();
// Zoom mode ( last 3 are internally used only! )
// Zoom mode ( last 4 are internally used only! )
enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitAuto = 3,
ZoomIn, ZoomOut, ZoomRefreshCurrent };
ZoomIn, ZoomOut, ZoomRefreshCurrent, ZoomActual };
enum ClearMode { ClearAllSelection, ClearOnlyDividers };
......@@ -237,6 +237,7 @@ Q_OBJECT
void slotZoom();
void slotZoomIn();
void slotZoomOut();
void slotZoomActual();
void slotFitToWidthToggled( bool );
void slotFitToPageToggled( bool );
void slotAutoFitToggled( bool );
......
Markdown is supported
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