diff options
-rw-r--r-- | lib/addressbar/addressbar.cpp | 5 | ||||
-rw-r--r-- | lib/addressbar/addressbar.h | 3 | ||||
-rw-r--r-- | lib/addressbar/urllineedit.cpp | 5 | ||||
-rw-r--r-- | lib/addressbar/urllineedit.h | 3 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 37 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.ui | 6 | ||||
-rw-r--r-- | src/webengine/webview.cpp | 4 | ||||
-rw-r--r-- | src/webengine/webview.h | 9 | ||||
-rw-r--r-- | src/webengine/widgets/pagetoolsmenu.cpp | 62 | ||||
-rw-r--r-- | src/webengine/widgets/pagetoolsmenu.h | 32 |
11 files changed, 39 insertions, 129 deletions
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 <QLineEdit> #include <QTextLayout> -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 <QPrinterInfo> #include <QPrintDialog> #include "profilemanager.h" - +#include <QVBoxLayout> #ifdef PLASMA_BLUR #include <KWindowEffects> #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<Configuration> &config, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -148,6 +174,11 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &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 @@ <addaction name="actionPrintPage"/> <addaction name="actionPrintPageToPdf"/> <addaction name="separator"/> + <addaction name="actionDeveloperTools"/> </widget> <addaction name="menusmolbote"/> <addaction name="menuSession"/> @@ -143,6 +144,11 @@ <string>P&rint to PDF</string> </property> </action> + <action name="actionDeveloperTools"> + <property name="text"> + <string>Developer Tools</string> + </property> + </action> </widget> <resources/> <connections/> 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 <QContextMenuEvent> #include <QDialog> #include <QSlider> @@ -21,6 +20,7 @@ #include <QWebEngineHistoryItem> #include <QWidgetAction> #include "profilemanager.h" +#include <QMenu> 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 <QWebEngineView> -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 <QDialog> -#include <QVBoxLayout> -#include <QWebEnginePage> -#include <QWebEngineProfile> -#include <QWebEngineScriptCollection> -#include <QWebEngineView> - -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 <QMenu> - -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 |