optimize: F12 improve

when close inspected windows,the inspect is still working .
This commit is contained in:
yifang 2022-03-04 23:25:11 +08:00
parent e1730ab5f8
commit ae8c2df4a8
5 changed files with 58 additions and 16 deletions

25
article_inspect.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "article_inspect.h"
#include <QCloseEvent>
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 );
}

24
article_inspect.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef ARTICLE_INSPECT_H
#define ARTICLE_INSPECT_H
#include <QDialog>
#include <QWebEngineView>
#include <QWebEnginePage>
#include <QVBoxLayout>
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

View file

@ -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 )

View file

@ -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

View file

@ -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 \