From 2f1779ee9bc3aa2a6d14e67dd70db7d188dc0c52 Mon Sep 17 00:00:00 2001 From: Gres Date: Wed, 1 Apr 2020 19:58:20 +0300 Subject: [PATCH] Add ability to show debug page from translator window Also always enable chromium debug mode --- README.md | 4 +++- recources.qrc | 2 ++ share/images/debug.png | Bin 0 -> 641 bytes share/images/debug@2x.png | Bin 0 -> 1113 bytes src/translate/translator.cpp | 22 +++++++++++++++++----- src/translate/translator.h | 4 ++++ 6 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 share/images/debug.png create mode 100644 share/images/debug@2x.png diff --git a/README.md b/README.md index 26867ce..9fd742c 100644 --- a/README.md +++ b/README.md @@ -34,5 +34,7 @@ Basically it is a combination of screen capture, OCR and translation tools. ## Attributions -* icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) +* icons made by +[Smashicons](https://www.flaticon.com/authors/smashicons), +[Freepik](https://www.flaticon.com/authors/freepik), from [Flaticon](https://www.flaticon.com/) diff --git a/recources.qrc b/recources.qrc index bed4977..38245c2 100644 --- a/recources.qrc +++ b/recources.qrc @@ -6,6 +6,8 @@ share/images/STIconRed.png share/images/loadImages.png share/images/loadImages@2x.png + share/images/debug.png + share/images/debug@2x.png share/translations/screentranslator_ru.qm diff --git a/share/images/debug.png b/share/images/debug.png new file mode 100644 index 0000000000000000000000000000000000000000..b0b1fd808c50de244ff46f4b2b92c27c6998ed1e GIT binary patch literal 641 zcmV-{0)G98P)icXVCo1BEA2MoYSN*iV{-nQzXoIaIp%#H;1$|fWiQbqlM7l z$UgkJS0#g3cq_Se0saLFYbGhr!p)1(8NyfIY(~y1gUe$zRwE!KD~`rhr^eAiH38&D zry}$DX&5D{TmCyx82E(7%O0<(4rq%nq0nLljfdHMZ5u#pMies^QznD3;J8aV1=E?YBYk zbv)!hCL$xro2~~HE(eg78pt}#(=`a9GqWK&Jrg-kjxayL4t_Q40rUWR02P{$_5xU@ b=|q13f8{m!_@g9w00000NkvXXu0mjfj}je3 literal 0 HcmV?d00001 diff --git a/share/images/debug@2x.png b/share/images/debug@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..bef29f71cd5aa025d94047d436dcf45e55b4479c GIT binary patch literal 1113 zcmV-f1g86mP)HiruV$vGrXC;&7`X&MEGcE zqbRnf$?Puh@d*G!1(429I=0=l?liN2UkH?>4~LT^+OLq7&E9 z^7pa|{sY94O{s1{17L`6}JN{7IjF&s{0|+T2I|poLde4{*MB5dl-`;TaJZo z%lAWV|5sc7PNcEt({Sq0nZy9dHhZCN-Q$6p$M~1s3|W>M>h@XEMMQJf+23Me+w&T* z(EtFL>Va>kusy#nS^&)X-TUJQkgK;q-MS~D z1}G^`YF&??;F#C2m}mhSdOZVsk~Hx>2V|Q(P+E8z%*TgB3}84rg#b{l=pGe-W_EYT z*s>a*4taGI@Jc=*0FIx!5Cs4~FN65>czNj!t?T`L9>GEc01)`;(LMP+VF6f<4JOtX zZW<>nfa=Y!wXI*$8TKYu@Ew4h2WV1OQ`hF{3;>HewXUt&`c6c}CQG)H05WMJOoR>* z0OUOIUIc1ct4iNO{NHqPRPctSJ7{x3%*jJ%6JaLk!_gOgCU{fJOz>*M#Q)0jk5dc7 znP9J{=rh4VZ^4e7+60*j=N|+A@>?i#!3SEV!g%9!dC4{S_nOTwBMhZ5oC??Ue?9P> zU+-t(#Ni8xFcl^rkSs?BfKU8U>w5vW{Cg-VzC=DnmS=-1Z8PK;Y$0Ea96gZ%`sx3* zz8A1e`W=dwO@O_Z)a=brj9~x_fB`T72EYIq00UqE41fVJ00v+XDuB2c8m|KU#32Hw f%^y(yzrW1@i5t{O1p!f100000NkvXXu0mjf(&7W- literal 0 HcmV?d00001 diff --git a/src/translate/translator.cpp b/src/translate/translator.cpp index 56c2e46..6a7fa97 100644 --- a/src/translate/translator.cpp +++ b/src/translate/translator.cpp @@ -41,19 +41,18 @@ Translator::Translator(Manager &manager, const Settings &settings) , url_(new QLineEdit(this)) , loadImages_( new QAction(QIcon(":/icons/loadImages.png"), tr("Load images"), this)) + , showDebugAction_(new QAction(QIcon(":/icons/debug.png"), tr("Debug"), this)) , tabs_(new QTabWidget(this)) { -#ifdef DEVELOP { QTcpSocket socket; if (socket.bind()) { - quint16 port = socket.localPort(); - LTRACE() << "debug port" << port; - qputenv("QTWEBENGINE_REMOTE_DEBUGGING", QString::number(port).toUtf8()); + debugPort_ = socket.localPort(); + qputenv("QTWEBENGINE_REMOTE_DEBUGGING", + QString::number(debugPort_).toUtf8()); socket.close(); } } -#endif setObjectName("Translator"); @@ -65,6 +64,7 @@ Translator::Translator(Manager &manager, const Settings &settings) toolBar->addWidget(new QLabel(tr("Url:"), this)); toolBar->addWidget(url_); toolBar->addAction(loadImages_); + toolBar->addAction(showDebugAction_); auto layout = new QVBoxLayout(detailsFrame); layout->addWidget(toolBar); @@ -85,6 +85,8 @@ Translator::Translator(Manager &manager, const Settings &settings) loadImages_->setCheckable(true); connect(loadImages_, &QAction::toggled, // this, &Translator::setPageLoadImages); + connect(showDebugAction_, &QAction::triggered, // + this, &Translator::showDebugView); connect(tabs_, &QTabWidget::currentChanged, // this, &Translator::udpateCurrentPage); @@ -171,6 +173,16 @@ void Translator::createPage(const QString &scriptName, log->document()->setMaximumBlockCount(1000); } +void Translator::showDebugView() +{ + if (!debugView_) + debugView_ = std::make_unique(); + debugView_->load( + QUrl::fromUserInput("http://localhost:" + QString::number(debugPort_))); + debugView_->show(); + debugView_->activateWindow(); +} + WebPage *Translator::currentPage() const { const auto index = tabs_->currentIndex(); diff --git a/src/translate/translator.h b/src/translate/translator.h index 25a4f8f..1bccd37 100644 --- a/src/translate/translator.h +++ b/src/translate/translator.h @@ -35,13 +35,17 @@ private: void processQueue(); void markTranslated(const TaskPtr &task); void createPage(const QString &scriptName, const QString &scriptText); + void showDebugView(); Manager &manager_; const Settings &settings_; QWebEngineView *view_; + std::unique_ptr debugView_; QLineEdit *url_; QAction *loadImages_; + QAction *showDebugAction_; QTabWidget *tabs_; std::vector queue_; std::map> pages_; + quint16 debugPort_{0}; };