Implement zoom action.

This commit is contained in:
Matthieu Gautier 2018-09-03 16:12:25 +02:00
parent 089a1753eb
commit 67f2d1f067
2 changed files with 24 additions and 3 deletions

View File

@ -241,15 +241,12 @@ void KiwixApp::createAction()
CREATE_ACTION(ZoomInAction, "Zoom in");
SET_SHORTCUT(ZoomInAction, QKeySequence::ZoomIn);
HIDE_ACTION(ZoomInAction);
CREATE_ACTION(ZoomOutAction, "Zoom out");
SET_SHORTCUT(ZoomOutAction, QKeySequence::ZoomOut);
HIDE_ACTION(ZoomOutAction);
CREATE_ACTION(ZoomResetAction, "Zoom reset");
SET_SHORTCUT(ZoomResetAction, QKeySequence(Qt::CTRL+Qt::Key_0));
HIDE_ACTION(ZoomResetAction);
CREATE_ACTION(HelpAction, "Help");
SET_SHORTCUT(HelpAction, QKeySequence::HelpContents);

View File

@ -32,6 +32,30 @@ TabWidget::TabWidget(QWidget *parent) :
}
this->closeTab(index);
});
connect(app->getAction(KiwixApp::ZoomInAction), &QAction::triggered,
this, [=]() {
auto current = this->currentWidget();
QUITIFNULL(current);
auto zoomFactor = current->zoomFactor();
zoomFactor += 0.1;
zoomFactor = max(min(zoomFactor, 5.0), 0.25);
current->setZoomFactor(zoomFactor);
});
connect(app->getAction(KiwixApp::ZoomOutAction), &QAction::triggered,
this, [=]() {
auto current = this->currentWidget();
QUITIFNULL(current);
auto zoomFactor = current->zoomFactor();
zoomFactor -= 0.1;
zoomFactor = max(min(zoomFactor, 5.0), 0.25);
current->setZoomFactor(zoomFactor);
});
connect(app->getAction(KiwixApp::ZoomResetAction), &QAction::triggered,
this, [=]() {
auto current = this->currentWidget();
QUITIFNULL(current);
current->setZoomFactor(1.0);
});
}
WebView* TabWidget::createNewTab(bool setCurrent)