diff --git a/article_inspect.cpp b/article_inspect.cpp new file mode 100644 index 00000000..8521698e --- /dev/null +++ b/article_inspect.cpp @@ -0,0 +1,25 @@ +#include "article_inspect.h" +#include +article_inspect::article_inspect( QWidget * parent ) : QDialog( parent, Qt::WindowType::Window ) +{ + setAttribute( Qt::WidgetAttribute::WA_DeleteOnClose, false ); + QVBoxLayout * v = new QVBoxLayout( this ); + v->setSpacing( 0 ); + v->setContentsMargins( 0, 0, 0, 0 ); + inspectView = new QWebEngineView(); + v->addWidget( inspectView ); +} + +void article_inspect::setInspectPage( QWebEnginePage * page ) +{ + this->inspectedPage = page; + page->setDevToolsPage( inspectView->page() ); + page->triggerAction( QWebEnginePage::InspectElement ); + raise(); + show(); +} + +void article_inspect::closeEvent( QCloseEvent * ev ) +{ + inspectedPage->setDevToolsPage( nullptr ); +} diff --git a/article_inspect.h b/article_inspect.h new file mode 100644 index 00000000..0c55d2d1 --- /dev/null +++ b/article_inspect.h @@ -0,0 +1,24 @@ +#ifndef ARTICLE_INSPECT_H +#define ARTICLE_INSPECT_H + +#include +#include +#include +#include + +class article_inspect : public QDialog +{ + Q_OBJECT + QWebEngineView * inspectView = nullptr; + QWebEnginePage * inspectedPage = nullptr; +public: + article_inspect( QWidget * parent = nullptr ); + + void setInspectPage( QWebEnginePage * page ); + +private: + + virtual void closeEvent( QCloseEvent * ); +}; + +#endif // ARTICLE_INSPECT_H diff --git a/articleview.cc b/articleview.cc index da069488..a4815311 100644 --- a/articleview.cc +++ b/articleview.cc @@ -507,21 +507,12 @@ void ArticleView::showAnticipation() void ArticleView::inspectElement(){ QWebEnginePage *page = ui.definition->page(); - if (inspectView == nullptr) { - inspectView = new QWebEngineView(); - page->setDevToolsPage( inspectView->page() ); - devDialog = new QDialog( this ); - devDialog->setWindowTitle( tr( "Inspect" ) ); - devDialog->setWindowFlags( Qt::Window ); - devDialog->setAttribute( Qt::WidgetAttribute::WA_DeleteOnClose, false ); - QVBoxLayout * v = new QVBoxLayout( devDialog ); - v->setSpacing( 0 ); - v->setContentsMargins( 0, 0, 0, 0 ); - v->addWidget( inspectView ); + if( inspector == nullptr ) + { + inspector = new article_inspect( this ); + inspector->setWindowTitle( tr( "Inspect" ) ); } - page->triggerAction( QWebEnginePage::InspectElement ); - devDialog->raise(); - devDialog->show(); + inspector->setInspectPage( page ); } void ArticleView::loadFinished( bool result ) diff --git a/articleview.hh b/articleview.hh index 1fb0c86c..c1eeb37b 100644 --- a/articleview.hh +++ b/articleview.hh @@ -15,6 +15,7 @@ #include "groupcombobox.hh" #include "ui_articleview.h" #include "globalbroadcaster.h" +#include "article_inspect.h" class ResourceToSaveHandler; class ArticleViewAgent ; @@ -45,8 +46,7 @@ class ArticleView: public QFrame QString rangeVarName; //used to hold the F12 inspect source view. - QWebEngineView *inspectView = nullptr; - QDialog * devDialog = nullptr; + article_inspect * inspector = nullptr; /// Any resource we've decided to download off the dictionary gets stored here. /// Full vector capacity is used for search requests, where we have to make diff --git a/goldendict.pro b/goldendict.pro index 731e7fc7..2834caca 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -217,6 +217,7 @@ DEFINES += PROGRAM_VERSION=\\\"$$VERSION\\\" # Input HEADERS += folding.hh \ + article_inspect.h \ globalbroadcaster.h \ inc_case_folding.hh \ inc_diacritic_folding.hh \ @@ -356,6 +357,7 @@ FORMS += groups.ui \ fulltextsearch.ui SOURCES += folding.cc \ + article_inspect.cpp \ globalbroadcaster.cpp \ main.cc \ dictionary.cc \