From 8aa707cfe56604f95c6d5c75e146b70a5272cc5d Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 11 Jul 2018 14:39:08 +0200 Subject: Remove PageToolsMenu --- lib/addressbar/addressbar.cpp | 5 --- lib/addressbar/addressbar.h | 3 -- lib/addressbar/urllineedit.cpp | 5 --- lib/addressbar/urllineedit.h | 3 -- src/CMakeLists.txt | 2 -- src/mainwindow/mainwindow.cpp | 37 +++++++++++++++++--- src/mainwindow/mainwindow.ui | 6 ++++ src/webengine/webview.cpp | 4 +-- src/webengine/webview.h | 9 ----- src/webengine/widgets/pagetoolsmenu.cpp | 62 --------------------------------- src/webengine/widgets/pagetoolsmenu.h | 32 ----------------- 11 files changed, 39 insertions(+), 129 deletions(-) delete mode 100644 src/webengine/widgets/pagetoolsmenu.cpp delete mode 100644 src/webengine/widgets/pagetoolsmenu.h diff --git a/lib/addressbar/addressbar.cpp b/lib/addressbar/addressbar.cpp index d570507..355393e 100644 --- a/lib/addressbar/addressbar.cpp +++ b/lib/addressbar/addressbar.cpp @@ -70,8 +70,3 @@ void AddressBar::setUrl(const QUrl &url) void AddressBar::setProgress(int value) { progressBar->setValue(std::min(value, 100)); } - -void AddressBar::setToolsMenu(QMenu *menu) -{ - urlBar->toolsMenu = menu; -} diff --git a/lib/addressbar/addressbar.h b/lib/addressbar/addressbar.h index f1d93c7..6ee9b74 100644 --- a/lib/addressbar/addressbar.h +++ b/lib/addressbar/addressbar.h @@ -14,7 +14,6 @@ class UrlLineEdit; class QProgressBar; -class QMenu; class AddressBar : public QWidget { Q_OBJECT @@ -34,8 +33,6 @@ public slots: void setUrl(const QUrl &url); void setProgress(int value); - void setToolsMenu(QMenu *menu); - private: UrlLineEdit *urlBar; QProgressBar *progressBar; diff --git a/lib/addressbar/urllineedit.cpp b/lib/addressbar/urllineedit.cpp index c106ea4..71b600a 100644 --- a/lib/addressbar/urllineedit.cpp +++ b/lib/addressbar/urllineedit.cpp @@ -58,11 +58,6 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) menu->setAttribute(Qt::WA_DeleteOnClose, true); menu->setMinimumWidth(240); menu->addActions(actions); - menu->addSeparator(); - - if(toolsMenu) { - menu->addMenu(toolsMenu); - } menu->exec(this->mapToGlobal(QPoint(0, height()))); }); diff --git a/lib/addressbar/urllineedit.h b/lib/addressbar/urllineedit.h index d5ab33d..e9868ea 100644 --- a/lib/addressbar/urllineedit.h +++ b/lib/addressbar/urllineedit.h @@ -15,7 +15,6 @@ #include #include -class QMenu; class WebView; class UrlLineEdit : public QLineEdit { @@ -30,8 +29,6 @@ public slots: public: QAction *menuAction = nullptr; - // devMenu action: scripts, etc - QMenu *toolsMenu = nullptr; protected: void focusInEvent(QFocusEvent *event) override; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 16a21f1..8095cd6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,8 +40,6 @@ set(poi_SRC webengine/webpage.h webengine/webview.cpp webengine/webview.h - webengine/widgets/pagetoolsmenu.cpp - webengine/widgets/pagetoolsmenu.h # plugin interfaces plugin.h diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index ff8c911..6cf3f84 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -36,11 +36,37 @@ #include #include #include "profilemanager.h" - +#include #ifdef PLASMA_BLUR #include #endif +inline QDialog *createDevToolsDialog(QWebEnginePage *page) +{ + Q_CHECK_PTR(page); + + auto *popup = new QDialog(nullptr); + popup->setWindowTitle(QObject::tr("Developer Tools")); + popup->setAttribute(Qt::WA_DeleteOnClose, true); + popup->resize(800, 600); + + auto *view = new QWebEngineView(popup); + auto *devPage = new QWebEnginePage(view); + + view->setPage(devPage); + page->setDevToolsPage(devPage); + + QObject::connect(popup, &QDialog::destroyed, [page]() { + page->setDevToolsPage(nullptr); + }); + + auto *l = new QVBoxLayout(popup); + l->setContentsMargins(0, 0, 0, 0); + l->addWidget(view); + + return popup; +} + MainWindow::MainWindow(const std::unique_ptr &config, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -148,6 +174,11 @@ MainWindow::MainWindow(const std::unique_ptr &config, QWidget *pa } }); + connect(ui->actionDeveloperTools, &QAction::triggered, this, [this]() { + if(currentView != nullptr) + createDevToolsDialog(currentView->page())->show(); + }); + pageLoadProfileMenu = ui->menuPage->addMenu(tr("Load Profile")); connect(pageLoadProfileMenu, &QMenu::aboutToShow, this, &MainWindow::updatePageLoadProfileMenu); } @@ -326,8 +357,6 @@ void MainWindow::setView(WebView *view) currentView = view; if(view) { - addressBar->setToolsMenu(view->toolsMenu()); - connect(view, &WebView::urlChanged, addressBar, &AddressBar::setUrl); addressBar->setUrl(view->url()); @@ -335,8 +364,6 @@ void MainWindow::setView(WebView *view) addressBar->setProgress(100); } else { - addressBar->setToolsMenu(nullptr); - addressBar->setUrl(QUrl()); addressBar->setProgress(100); } diff --git a/src/mainwindow/mainwindow.ui b/src/mainwindow/mainwindow.ui index 698e1c4..d670b66 100644 --- a/src/mainwindow/mainwindow.ui +++ b/src/mainwindow/mainwindow.ui @@ -65,6 +65,7 @@ + @@ -143,6 +144,11 @@ P&rint to PDF + + + Developer Tools + + diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index a234f3a..8ae7eeb 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -10,7 +10,6 @@ #include "mainwindow/subwindow.h" #include "webpage.h" #include "webprofile.h" -#include "widgets/pagetoolsmenu.h" #include #include #include @@ -21,6 +20,7 @@ #include #include #include "profilemanager.h" +#include inline QAction *historyAction(QWebEngineView *view, const QWebEngineHistoryItem &item) { @@ -60,8 +60,6 @@ WebView::WebView(WebProfile *profile, QWidget *parent) } }); #endif - - m_toolsMenu = new PageToolsMenu(this); } void WebView::setProfile(WebProfile *profile) diff --git a/src/webengine/webview.h b/src/webengine/webview.h index 2d07244..7026610 100644 --- a/src/webengine/webview.h +++ b/src/webengine/webview.h @@ -12,7 +12,6 @@ #include "webpage.h" #include -class QMenu; class WebProfile; class SubWindow; class WebView : public QWebEngineView @@ -27,12 +26,6 @@ public: explicit WebView(WebProfile *profile = nullptr, QWidget *parent = nullptr); ~WebView() = default; - QMenu *toolsMenu() - { - Q_CHECK_PTR(m_toolsMenu); - return m_toolsMenu; - } - WebProfile *profile() { return m_profile; @@ -57,8 +50,6 @@ private: SubWindow *m_parentWindow = nullptr; WebProfile *m_profile = nullptr; - QMenu *m_toolsMenu = nullptr; - bool m_loaded; }; diff --git a/src/webengine/widgets/pagetoolsmenu.cpp b/src/webengine/widgets/pagetoolsmenu.cpp deleted file mode 100644 index 6e48798..0000000 --- a/src/webengine/widgets/pagetoolsmenu.cpp +++ /dev/null @@ -1,62 +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 "pagetoolsmenu.h" -#include "../webview.h" -#include -#include -#include -#include -#include -#include - -PageToolsMenu::PageToolsMenu(WebView *parent) - : QMenu(tr("Tools"), 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("Developer Tools")); - connect(devToolsAction, &QAction::triggered, this, [this]() { - createDevToolsDialog(parentView->page())->show(); - }); -} - -QDialog *PageToolsMenu::createDevToolsDialog(QWebEnginePage *page) -{ - Q_CHECK_PTR(page); - - auto *popup = new QDialog(nullptr); - popup->setWindowTitle(tr("Developer Tools")); - popup->setAttribute(Qt::WA_DeleteOnClose, true); - - auto *view = new QWebEngineView(popup); - auto *devPage = new QWebEnginePage(view); - - view->setPage(devPage); - // page->setDevToolsPage(devPage); - - auto *l = new QVBoxLayout(popup); - l->setContentsMargins(0, 0, 0, 0); - l->addWidget(view); - - return popup; -} diff --git a/src/webengine/widgets/pagetoolsmenu.h b/src/webengine/widgets/pagetoolsmenu.h deleted file mode 100644 index f234d0e..0000000 --- a/src/webengine/widgets/pagetoolsmenu.h +++ /dev/null @@ -1,32 +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_PAGETOOLSMENU_H -#define SMOLBOTE_PAGETOOLSMENU_H - -#include - -class WebView; -class QDialog; -class QWebEnginePage; -class PageToolsMenu : public QMenu -{ - Q_OBJECT -public: - explicit PageToolsMenu(WebView *parent = nullptr); - -public slots: - void createEntries(); - -private: - QDialog *createDevToolsDialog(QWebEnginePage *page); - - WebView *parentView; -}; - -#endif //SMOLBOTE_PAGETOOLSMENU_H -- cgit v1.2.1