aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/widgets
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-04-01 13:19:07 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-04-01 13:19:07 +0200
commit74361f5b05dc0a255f489256bd25065ef20f5dee (patch)
tree279f45e5f2bd093cd6fbf1500fe476f91108bd1f /src/webengine/widgets
parentAdd keyboard shortcuts for address bar menus (diff)
downloadsmolbote-74361f5b05dc0a255f489256bd25065ef20f5dee.tar.xz
Page menus refactoring
- Split off menus into their own classes Page tools menu - Shows injected scripts - Shows dev tools page in another dialog
Diffstat (limited to 'src/webengine/widgets')
-rw-r--r--src/webengine/widgets/pagemenu.cpp99
-rw-r--r--src/webengine/widgets/pagemenu.h22
-rw-r--r--src/webengine/widgets/pagetoolsmenu.cpp37
-rw-r--r--src/webengine/widgets/pagetoolsmenu.h28
4 files changed, 186 insertions, 0 deletions
diff --git a/src/webengine/widgets/pagemenu.cpp b/src/webengine/widgets/pagemenu.cpp
new file mode 100644
index 0000000..a90d223
--- /dev/null
+++ b/src/webengine/widgets/pagemenu.cpp
@@ -0,0 +1,99 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "pagemenu.h"
+#include "../webview.h"
+#include <QApplication>
+#include <QClipboard>
+#include <QFileDialog>
+#include <QLabel>
+#include <QPrintDialog>
+#include <QPrinterInfo>
+#include <QSlider>
+#include <QStyle>
+#include <QToolButton>
+#include <QVBoxLayout>
+#include <QWidgetAction>
+
+PageMenu::PageMenu(WebView *parent)
+ : QMenu(parent)
+{
+ setMinimumWidth(240);
+
+ auto *copyUrlAction = addAction(tr("Copy page URL"));
+ connect(copyUrlAction, &QAction::triggered, parent, [parent]() {
+ qApp->clipboard()->setText(parent->url().toString());
+ });
+
+ auto *bookmarkAction = addAction(tr("Bookmark page"));
+ connect(bookmarkAction, &QAction::triggered, parent, [parent]() {
+ parent->triggerViewAction(WebView::BookmarkPage);
+ });
+
+ addSeparator();
+
+ auto *zoomWidgetAction = new QWidgetAction(this);
+ {
+ auto *widget = new QWidget(this);
+ zoomWidgetAction->setDefaultWidget(widget);
+
+ auto *layout = new QVBoxLayout(widget);
+ widget->setLayout(layout);
+
+ QLabel *zoomLabel = new QLabel(tr("Zoom: 1x"));
+ layout->addWidget(zoomLabel);
+
+ auto *zoomLayout = new QHBoxLayout();
+ layout->addLayout(zoomLayout);
+
+ auto *zoomSlider = new QSlider(Qt::Horizontal);
+ zoomSlider->setMinimum(5);
+ zoomSlider->setMaximum(50);
+ zoomSlider->setValue(10);
+ zoomLayout->addWidget(zoomSlider);
+
+ auto *zoomResetButton = new QToolButton(widget);
+ zoomResetButton->setIcon(widget->style()->standardIcon(QStyle::SP_BrowserReload));
+ zoomLayout->addWidget(zoomResetButton);
+
+ connect(zoomResetButton, &QToolButton::clicked, [zoomSlider]() {
+ zoomSlider->setValue(10);
+ });
+ connect(zoomSlider, &QSlider::valueChanged, parent, [parent, zoomLabel](int value) {
+ zoomLabel->setText(tr("Zoom: %1x").arg(static_cast<qreal>(value) / 10));
+ parent->setZoomFactor(static_cast<qreal>(value) / 10);
+ });
+ }
+ addAction(zoomWidgetAction);
+
+ addSeparator();
+
+ auto *savePageAction = addAction(tr("Save Page"));
+ connect(savePageAction, &QAction::triggered, parent, [parent]() {
+ parent->triggerPageAction(QWebEnginePage::SavePage);
+ });
+
+ auto *printAction = addAction(tr("Print Page"));
+ connect(printAction, &QAction::triggered, parent, [parent]() {
+ auto *printer = new QPrinter(QPrinterInfo::defaultPrinter());
+ auto *dlg = new QPrintDialog(printer, nullptr);
+ if(dlg->exec() == QDialog::Accepted) {
+ parent->page()->print(printer, [printer](bool success) {
+ qDebug("print %s", success ? "ok" : "failed");
+ delete printer;
+ });
+ }
+ delete dlg;
+ });
+
+ auto *printPdfAction = addAction(tr("Print to PDF"));
+ connect(printPdfAction, &QAction::triggered, parent, [parent]() {
+ const QString path = QFileDialog::getSaveFileName(parent, tr("Print to PDF"), QDir::homePath(), tr("PDF files (*.pdf)"));
+ parent->page()->printToPdf(path);
+ });
+}
diff --git a/src/webengine/widgets/pagemenu.h b/src/webengine/widgets/pagemenu.h
new file mode 100644
index 0000000..91f35e0
--- /dev/null
+++ b/src/webengine/widgets/pagemenu.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_PAGEMENU_H
+#define SMOLBOTE_PAGEMENU_H
+
+#include <QMenu>
+
+class WebView;
+class PageMenu : public QMenu
+{
+ Q_OBJECT
+public:
+ explicit PageMenu(WebView *parent = nullptr);
+};
+
+#endif //SMOLBOTE_PAGEMENU_H
diff --git a/src/webengine/widgets/pagetoolsmenu.cpp b/src/webengine/widgets/pagetoolsmenu.cpp
new file mode 100644
index 0000000..9a85f69
--- /dev/null
+++ b/src/webengine/widgets/pagetoolsmenu.cpp
@@ -0,0 +1,37 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "pagetoolsmenu.h"
+#include "../webview.h"
+#include <QWebEngineProfile>
+#include <QWebEngineScriptCollection>
+
+PageToolsMenu::PageToolsMenu(WebView *parent)
+ : QMenu(parent)
+{
+ Q_CHECK_PTR(parent);
+ parentView = parent;
+
+ connect(this, &QMenu::aboutToShow, this, &PageToolsMenu::createEntries);
+}
+
+void PageToolsMenu::createEntries()
+{
+ clear();
+
+ auto *scriptsMenu = new QMenu(tr("Injected scripts"), this);
+ for(const auto &script : parentView->page()->scripts().toList()) {
+ scriptsMenu->addAction(script.name())->setEnabled(false);
+ }
+ addMenu(scriptsMenu);
+
+ auto *devToolsAction = addAction(tr("Dev tools page"));
+ connect(devToolsAction, &QAction::triggered, this, [this]() {
+ parentView->popupPage(parentView->page()->devToolsPage());
+ });
+}
diff --git a/src/webengine/widgets/pagetoolsmenu.h b/src/webengine/widgets/pagetoolsmenu.h
new file mode 100644
index 0000000..010bb43
--- /dev/null
+++ b/src/webengine/widgets/pagetoolsmenu.h
@@ -0,0 +1,28 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_PAGETOOLSMENU_H
+#define SMOLBOTE_PAGETOOLSMENU_H
+
+#include <QMenu>
+
+class WebView;
+class PageToolsMenu : public QMenu
+{
+ Q_OBJECT
+public:
+ explicit PageToolsMenu(WebView *parent = nullptr);
+
+public slots:
+ void createEntries();
+
+private:
+ WebView *parentView;
+};
+
+#endif //SMOLBOTE_PAGETOOLSMENU_H