From f2a7411df60840ccda1a9708b2d9bdcb28c15975 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 2 Jan 2019 17:28:32 +0100 Subject: Connect Developer Tools and View Source actions --- src/mainwindow/mainwindow.cpp | 27 ---------------------- src/mainwindow/menubar.cpp | 52 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 5358fb6..a5f1c90 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -35,37 +35,10 @@ #include #include #include -#include #ifdef CONFIG_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) , configuration(config.get()) diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index e74069e..ed0eb8f 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -28,6 +28,7 @@ #include #include #include +#include inline void run_if(SubWindow *_subwindow, std::function f) { @@ -35,6 +36,31 @@ inline void run_if(SubWindow *_subwindow, std::function f f(_subwindow, _subwindow->currentTabIndex()); } +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); + + auto *l = new QVBoxLayout(popup); + l->setContentsMargins(0, 0, 0, 0); + l->addWidget(view); + + page->setDevToolsPage(devPage); + QObject::connect(popup, &QDialog::destroyed, [page]() { + page->setDevToolsPage(nullptr); + }); + + return popup; +} + MenuBar::MenuBar(const Configuration *config, MainWindow *parent) : QMenuBar(parent) { @@ -112,9 +138,8 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent) auto *actionAbout = smolbote->addAction(tr("About"), browser, &Browser::about); config->setShortcut(actionAbout, "mainwindow.shortcuts.about"); - smolbote->addAction(tr("Help")); - - //smolbote->addAction(tr("Check for updates")); +// smolbote->addAction(tr("Help")); +// smolbote->addAction(tr("Check for updates")); smolbote->addSeparator(); @@ -367,8 +392,25 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent) }); page->addSeparator(); - page->addAction(tr("Developer Tools")); - page->addAction(tr("View Source")); + page->addAction(tr("Developer Tools"), parent, [parent]() { + if(parent->currentView != nullptr) { + auto *dlg = createDevToolsDialog(parent->currentView->page()); + dlg->show(); + } + }); + page->addAction(tr("View Source"), parent, [parent]() { + if(parent->currentView != nullptr) { + parent->currentView->triggerPageAction(QWebEnginePage::ViewSource); + } + }); +#ifdef QT_DEBUG + // doesn't seem to do anything? + page->addAction(tr("Inspect Element"), parent, [parent]() { + if(parent->currentView != nullptr) { + parent->currentView->triggerPageAction(QWebEnginePage::InspectElement); + } + }); +#endif } } -- cgit v1.2.1