Skip to content

Commit

Permalink
feat(ui): add shortcuts for zooming webview content (fixes #767) (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
knixeur authored and trollixx committed Oct 19, 2018
1 parent d9bb3c5 commit 241b695
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libs/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) :
connect(ui->actionForward, &QAction::triggered, this, [this]() { currentTab()->forward(); });
addAction(ui->actionForward);

shortcut = new QShortcut(QKeySequence::ZoomIn, this);
connect(shortcut, &QShortcut::activated, this, [this]() { currentTab()->zoomIn(); });
shortcut = new QShortcut(QStringLiteral("Ctrl+="), this);
connect(shortcut, &QShortcut::activated, this, [this]() { currentTab()->zoomIn(); });
shortcut = new QShortcut(QKeySequence::ZoomOut, this);
connect(shortcut, &QShortcut::activated, this, [this]() { currentTab()->zoomOut(); });
shortcut = new QShortcut(QStringLiteral("Ctrl+0"), this);
connect(shortcut, &QShortcut::activated, this, [this]() { currentTab()->resetZoom(); });

// Tools Menu
connect(ui->actionDocsets, &QAction::triggered, [this]() {
QScopedPointer<DocsetsDialog> dialog(new DocsetsDialog(m_application, this));
Expand Down
15 changes: 15 additions & 0 deletions src/libs/ui/widgets/webviewtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ void WebViewTab::setZoomLevel(int level)
m_webView->setZoomLevel(level);
}

void WebViewTab::zoomIn()
{
m_webView->zoomIn();
}

void WebViewTab::zoomOut()
{
m_webView->zoomOut();
}

void WebViewTab::resetZoom()
{
m_webView->resetZoom();
}

void WebViewTab::setJavaScriptEnabled(bool enabled)
{
m_webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled, enabled);
Expand Down
4 changes: 4 additions & 0 deletions src/libs/ui/widgets/webviewtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public slots:
void activateSearchBar();
void back();
void forward();

void zoomIn();
void zoomOut();
void resetZoom();

protected:
void keyPressEvent(QKeyEvent *event) override;
Expand Down

0 comments on commit 241b695

Please sign in to comment.