aboutsummaryrefslogtreecommitdiff
path: root/src/webengine
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-07-08 11:10:48 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-07-08 11:10:48 +0200
commitfc4c7943c79243ed027f7507c458d067a14bebb2 (patch)
tree38b066c73890145677a1f87f671ef30ed0eefe1c /src/webengine
parentIntegrate urlfilter with urlrequestinterceptor (diff)
downloadsmolbote-fc4c7943c79243ed027f7507c458d067a14bebb2.tar.xz
Remove PageMenu
Move zoom widget to WebView context menu Move the other page menu actions to main window menu
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/webview.cpp41
-rw-r--r--src/webengine/webview.h9
-rw-r--r--src/webengine/widgets/pagemenu.cpp122
-rw-r--r--src/webengine/widgets/pagemenu.h29
4 files changed, 36 insertions, 165 deletions
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index f1b52b7..9380b13 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -10,11 +10,13 @@
#include "mainwindow/subwindow.h"
#include "webpage.h"
#include "webprofile.h"
-#include "widgets/pagemenu.h"
#include "widgets/pagetoolsmenu.h"
#include <QDialog>
#include <QStatusBar>
#include <QVBoxLayout>
+#include <QContextMenuEvent>
+#include <QWidgetAction>
+#include <QSlider>
WebView::WebView(WebProfile *profile, QWidget *parent)
: QWebEngineView(parent)
@@ -41,15 +43,9 @@ WebView::WebView(WebProfile *profile, QWidget *parent)
});
#endif
- m_pageMenu = new PageMenu(this);
m_toolsMenu = new PageToolsMenu(this);
}
-WebView::~WebView()
-{
- delete m_pageMenu;
-}
-
void WebView::setProfile(WebProfile *profile)
{
m_profile = profile;
@@ -101,6 +97,37 @@ WebView *WebView::createWindow(QWebEnginePage::WebWindowType type)
return view;
}
+void WebView::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu *menu = page()->createStandardContextMenu();
+
+ // zoom widget
+ menu->addSeparator();
+ {
+ auto *zoomSlider = new QSlider(Qt::Horizontal);
+ zoomSlider->setMinimum(5);
+ zoomSlider->setMaximum(50);
+ zoomSlider->setValue(10);
+
+ auto *zoomAction = menu->addAction(tr("Zoom: %1x").arg(zoomFactor()));
+ connect(zoomAction, &QAction::triggered, this, [zoomSlider]() {
+ zoomSlider->setValue(10);
+ });
+
+ connect(zoomSlider, &QSlider::valueChanged, this, [this, zoomAction](int value) {
+ zoomAction->setText(tr("Zoom: %1x").arg(static_cast<qreal>(value) / 10));
+ setZoomFactor(static_cast<qreal>(value) / 10);
+ });
+
+ auto *zoomWidgetAction = new QWidgetAction(this);
+ zoomWidgetAction->setDefaultWidget(zoomSlider);
+
+ menu->addAction(zoomWidgetAction);
+ }
+
+ menu->popup(event->globalPos());
+}
+
void WebView::triggerViewAction(WebView::ViewAction action)
{
switch(action) {
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
index 0717e27..2d07244 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -25,13 +25,8 @@ public:
};
explicit WebView(WebProfile *profile = nullptr, QWidget *parent = nullptr);
- ~WebView() override;
+ ~WebView() = default;
- QMenu *pageMenu()
- {
- Q_CHECK_PTR(m_pageMenu);
- return m_pageMenu;
- }
QMenu *toolsMenu()
{
Q_CHECK_PTR(m_toolsMenu);
@@ -56,12 +51,12 @@ signals:
protected:
WebView *createWindow(QWebEnginePage::WebWindowType type) override;
+ void contextMenuEvent(QContextMenuEvent *event) override;
private:
SubWindow *m_parentWindow = nullptr;
WebProfile *m_profile = nullptr;
- QMenu *m_pageMenu = nullptr;
QMenu *m_toolsMenu = nullptr;
bool m_loaded;
diff --git a/src/webengine/widgets/pagemenu.cpp b/src/webengine/widgets/pagemenu.cpp
deleted file mode 100644
index deff511..0000000
--- a/src/webengine/widgets/pagemenu.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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 "browser.h"
-#include <QFileDialog>
-#include <QLabel>
-#include <QPrintDialog>
-#include <QPrinterInfo>
-#include <QSlider>
-#include <QStyle>
-#include <QToolButton>
-#include <QVBoxLayout>
-#include <QWidgetAction>
-#include <bookmarks/bookmarkswidget.h>
-#include <webprofile.h>
-#include "profilemanager.h"
-
-PageMenu::PageMenu(WebView *parent)
- : QMenu(tr("Page"), parent)
-{
- setMinimumWidth(240);
- view = parent;
-
- auto *bookmarkAction = addAction(tr("Bookmark page"));
- connect(bookmarkAction, &QAction::triggered, parent, [parent]() {
- auto *browser = qobject_cast<Browser *>(qApp);
- Q_CHECK_PTR(browser);
- browser->bookmarks()->addBookmark(parent->title(), parent->url().toString());
- });
-
- 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);
- });
-
- 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();
-
- loadProfile_menu = addMenu(tr("Load Profile"));
- connect(this, &PageMenu::aboutToShow, this, &PageMenu::updateLoadProfileMenu);
-}
-
-void PageMenu::updateLoadProfileMenu()
-{
- Q_CHECK_PTR(loadProfile_menu);
- loadProfile_menu->clear();
-
- auto *browser = qobject_cast<Browser *>(qApp);
- Q_CHECK_PTR(browser);
-
- ProfileIterator it(ProfileManager::profileList());
- while(it.hasNext()) {
- it.next();
- auto *profile =it.value();
- auto *loadAction = loadProfile_menu->addAction(profile->name());
-
- connect(loadAction, &QAction::triggered, this, [=]() {
- view->setProfile(profile);
- });
- }
-}
diff --git a/src/webengine/widgets/pagemenu.h b/src/webengine/widgets/pagemenu.h
deleted file mode 100644
index 23e0e20..0000000
--- a/src/webengine/widgets/pagemenu.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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);
-
-private slots:
- void updateLoadProfileMenu();
-
-private:
- QMenu *loadProfile_menu = nullptr;
- WebView *view = nullptr;
-};
-
-#endif //SMOLBOTE_PAGEMENU_H