diff --git a/articleview.cc b/articleview.cc index 4f58038d..9d5f5924 100644 --- a/articleview.cc +++ b/articleview.cc @@ -41,6 +41,7 @@ #endif #include "globalbroadcaster.h" +#include "articleviewagent.hh" using std::map; using std::list; @@ -1077,7 +1078,7 @@ void ArticleView::attachToJavaScript() { ui.definition->page()->setWebChannel(channel, QWebEngineScript::MainWorld); // register QObjects to be exposed to JavaScript - channel->registerObject(QStringLiteral("articleview"), this); + channel->registerObject(QStringLiteral("articleview"), new ArticleViewAgent(this)); } void ArticleView::linkClicked( QUrl const & url_ ) diff --git a/articleviewagent.cc b/articleviewagent.cc new file mode 100644 index 00000000..0317f791 --- /dev/null +++ b/articleviewagent.cc @@ -0,0 +1,20 @@ +#include "articleviewagent.hh" + +ArticleViewAgent::ArticleViewAgent(QObject *parent) + : QObject{parent} +{ + +} +ArticleViewAgent::ArticleViewAgent(ArticleView *articleView) + : articleView(articleView) +{ + +} + +void ArticleViewAgent::onJsActiveArticleChanged(QString const & id){ + articleView->onJsActiveArticleChanged(id); +} + +void ArticleViewAgent::linkClickedInHtml(QUrl const & url){ + articleView->linkClickedInHtml(url); +} diff --git a/articleviewagent.hh b/articleviewagent.hh new file mode 100644 index 00000000..5e1a6069 --- /dev/null +++ b/articleviewagent.hh @@ -0,0 +1,23 @@ +#ifndef ARTICLEVIEWAGENT_HH +#define ARTICLEVIEWAGENT_HH + +#include +#include "articleview.hh" + +class ArticleViewAgent : public QObject +{ + Q_OBJECT + ArticleView* articleView; + public: + explicit ArticleViewAgent(QObject *parent = nullptr); + ArticleViewAgent(ArticleView* articleView); + + signals: + + public slots: + Q_INVOKABLE void onJsActiveArticleChanged(QString const & id); + Q_INVOKABLE void linkClickedInHtml( QUrl const & ); + +}; + +#endif // ARTICLEVIEWAGENT_HH diff --git a/goldendict.pro b/goldendict.pro index 756cde39..ec85ff21 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -239,6 +239,7 @@ DEFINES += PROGRAM_VERSION=\\\"$$VERSION\\\" # Input HEADERS += folding.hh \ + articleviewagent.hh \ globalbroadcaster.h \ inc_case_folding.hh \ inc_diacritic_folding.hh \ @@ -380,6 +381,7 @@ FORMS += groups.ui \ fulltextsearch.ui SOURCES += folding.cc \ + articleviewagent.cc \ globalbroadcaster.cpp \ main.cc \ dictionary.cc \