diff --git a/Modules/WebInteraction/include/mitkWebInteractionRegistry.h b/Modules/WebInteraction/include/mitkWebInteractionRegistry.h index bfdd62560f..c7eefd2e20 100644 --- a/Modules/WebInteraction/include/mitkWebInteractionRegistry.h +++ b/Modules/WebInteraction/include/mitkWebInteractionRegistry.h @@ -1,41 +1,44 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKWEBINTERACTIONREGISTRY_H #define MITKWEBINTERACTIONREGISTRY_H #include "MitkWebInteractionExports.h" +//QT +#include "qstring.h" + namespace mitk { class MITKWEBINTERACTION_EXPORT WebInteractionRegistry { public: WebInteractionRegistry(); - void LoadPage(); + static void PageLoaded(QString html); private: //us::ModuleContext* m_Context; }; } // end of namespace mitk #endif // MITKWEBINTERACTIONREGISTRY_H diff --git a/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp b/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp index 34cf754f51..7bcf0af17c 100644 --- a/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp +++ b/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp @@ -1,32 +1,33 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkWebInteractionRegistry.h" #include "mitkLogMacros.h" namespace mitk { WebInteractionRegistry::WebInteractionRegistry() { } - void WebInteractionRegistry::LoadPage() + void WebInteractionRegistry::PageLoaded(QString html) { - MITK_INFO << "Loaded"; + std::string s = html.toStdString(); + MITK_INFO << s; } } // end of namespace mitk diff --git a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp index ce016c200d..cc51a43214 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp @@ -1,49 +1,50 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Qmitk #include "MitkWebView.h" #include const std::string MitkWebView::VIEW_ID = "org.mitk.views.mitkwebview"; void MitkWebView::SetFocus() { m_Controls.loadURLPushButton->setFocus(); } void MitkWebView::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); m_Controls.URLLineEdit->setText("http://www.mitk.org"); connect(m_Controls.loadURLPushButton, SIGNAL( clicked() ), this, SLOT( OnLoadURLPushButtonClicked()) ); connect(m_Controls.URLLineEdit, SIGNAL(returnPressed()), this, SLOT(OnLoadURLPushButtonClicked())); + connect(m_Controls.contentHTMLWidget, SIGNAL(OnLoadFinished(QString)), this, SLOT(OnLoadFinished(QString))); } void MitkWebView::OnLoadURLPushButtonClicked() { QString url = m_Controls.URLLineEdit->text(); m_Controls.contentHTMLWidget->loadUrl(url); m_Controls.groupBox->setTitle(m_Controls.contentHTMLWidget->getTitle()); } -void MitkWebView::OnPageLoad() +void MitkWebView::OnLoadFinished(QString htmlContent) { - MITK_INFO << "OnPageLaod()"; + mitk::WebInteractionRegistry::PageLoaded(htmlContent); } diff --git a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.h b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.h index 7eea4257d4..796cc1d803 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.h +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.h @@ -1,52 +1,52 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MitkWebView_h #define MitkWebView_h #include #include "ui_MitkWebViewControls.h" /** \brief MitkWebView Simple web view for loading HTML and setting custom HTML content. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class MitkWebView : public QmitkAbstractView { Q_OBJECT public: static const std::string VIEW_ID; protected slots: void OnLoadURLPushButtonClicked(); - void OnPageLoad(); + void OnLoadFinished(QString htmlContent); protected: virtual void CreateQtPartControl(QWidget *parent) override; virtual void SetFocus() override; Ui::MitkWebViewControls m_Controls; }; #endif // MitkWebView_h diff --git a/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.cpp b/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.cpp index 7a5572ee69..d21f2d8af0 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.cpp +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.cpp @@ -1,75 +1,75 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkHTMLWidget.h" #include #include QmitkHTMLWidget::QmitkHTMLWidget(QWidget* parent) : m_WebEngineView(new QWebEngineView(parent)) { //Set the webengineview to an initial page. m_WebEngineView->setUrl(QUrl(QStringLiteral("http://www.mitk.org"))); m_htmlContent = new QPlainTextEdit(); auto layout = new QGridLayout(parent); layout->setMargin(0); layout->addWidget(m_WebEngineView); parent->setLayout(layout); MITK_INFO << "Connecting..."; - connect(m_WebEngineView, SIGNAL(loadFinished(bool)), this, SLOT(LoadFinished(ok))); + connect(m_WebEngineView, SIGNAL(loadFinished(bool)), this, SLOT(LoadFinished(bool))); } QmitkHTMLWidget::~QmitkHTMLWidget() { delete m_WebEngineView; delete m_htmlContent; } void QmitkHTMLWidget::loadUrl(const QString& url) { //QUrl::fromUserInput returns a valid URL. If the user provides a non existing URL, an error page is loaded QUrl urlToLoad = QUrl::fromUserInput(url); m_WebEngineView->load(urlToLoad); } QString QmitkHTMLWidget::getHTMLContent() const { auto webPage = m_WebEngineView->page(); //workaround from the Qt Examples (Qt Demo browser). It was not successful with setting QString webPage->toHtml(invoke(m_htmlContent, &QPlainTextEdit::setPlainText)); return m_htmlContent->toPlainText(); } void QmitkHTMLWidget::setHTMLContent(const QString& content) { m_WebEngineView->setHtml(content); } QString QmitkHTMLWidget::getTitle() const { return m_WebEngineView->page()->title(); } void QmitkHTMLWidget::LoadFinished(bool ok) { - MITK_INFO << "LoadFinished"; - emit OnLoadFinished(); + QString content = getHTMLContent(); + emit OnLoadFinished(content); } diff --git a/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.h b/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.h index 8e3dbf441d..b92996e610 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.h +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.h @@ -1,85 +1,84 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include "org_mitk_gui_qt_webview_Export.h" //originating from the Qt demo browser as a workaround to get the HTML content of a WebEngineView template struct InvokeWrapper { R *receiver; void (C::*memberFun)(Arg); void operator()(Arg result) { (receiver->*memberFun)(result); } }; template InvokeWrapper invoke(R *receiver, void (C::*memberFun)(Arg)) { InvokeWrapper wrapper = { receiver, memberFun }; return wrapper; } /** \brief QmitkHTMLWidget Widget for showing HTML content \ingroup ${plugin_target}_internal */ class WEBVIEW_EXPORT QmitkHTMLWidget : public QWidget { Q_OBJECT public: explicit QmitkHTMLWidget(QWidget* parent); ~QmitkHTMLWidget(); QmitkHTMLWidget(const QmitkHTMLWidget&) = delete; QmitkHTMLWidget& operator=(const QmitkHTMLWidget&) = delete; /** * @brief Loads the string url * url is passed to a special function to convert the string to a valid URL **/ void loadUrl(const QString& url); QString getHTMLContent() const; QString getTitle() const; void setHTMLContent(const QString& content); signals: -/** -* @brief Emitted when the webpage has loaded -**/ -void OnLoadFinished(); + /** + * @brief Emitted when the webpage has loaded + **/ + void OnLoadFinished(QString htmlContent); private slots: /** * @brief Used internally to catch the webEngineViews load event and emit an OnLoadFinished Signal. **/ void LoadFinished(bool ok); - private: QWebEngineView* m_WebEngineView; QPlainTextEdit* m_htmlContent; }; \ No newline at end of file