diff --git a/Modules/WebInteraction/include/mitkWebInteractionRegistry.h b/Modules/WebInteraction/include/mitkWebInteractionRegistry.h index fb4de08f4c..bfdd62560f 100644 --- a/Modules/WebInteraction/include/mitkWebInteractionRegistry.h +++ b/Modules/WebInteraction/include/mitkWebInteractionRegistry.h @@ -1,39 +1,41 @@ /*=================================================================== 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 MITKWEBINTERACTINREGISTRY_H -#define MITKWEBINTERACTINREGISTRY_H +#ifndef MITKWEBINTERACTIONREGISTRY_H +#define MITKWEBINTERACTIONREGISTRY_H #include "MitkWebInteractionExports.h" namespace mitk { class MITKWEBINTERACTION_EXPORT WebInteractionRegistry { public: WebInteractionRegistry(); + void LoadPage(); + 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 83d9bb43a3..34cf754f51 100644 --- a/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp +++ b/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp @@ -1,27 +1,32 @@ /*=================================================================== 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() + { + MITK_INFO << "Loaded"; + } } // end of namespace mitk diff --git a/Plugins/org.mitk.gui.qt.webview/CMakeLists.txt b/Plugins/org.mitk.gui.qt.webview/CMakeLists.txt index 7f21099107..1091836784 100644 --- a/Plugins/org.mitk.gui.qt.webview/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.webview/CMakeLists.txt @@ -1,8 +1,8 @@ project(org_mitk_gui_qt_webview) mitk_create_plugin( EXPORT_DIRECTIVE WEBVIEW_EXPORT EXPORTED_INCLUDE_SUFFIXES src - MODULE_DEPENDS MitkQtWidgetsExt + MODULE_DEPENDS MitkQtWidgetsExt MitkWebInteraction PACKAGE_DEPENDS Qt5|WebEngineWidgets ) 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 36cad5fbaf..ce016c200d 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp @@ -1,43 +1,49 @@ /*=================================================================== 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 <mitkWebInteractionRegistry.h> 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())); } void MitkWebView::OnLoadURLPushButtonClicked() { - QString url = m_Controls.URLLineEdit->text(); - m_Controls.contentHTMLWidget->loadUrl(url); - m_Controls.groupBox->setTitle(m_Controls.contentHTMLWidget->getTitle()); + QString url = m_Controls.URLLineEdit->text(); + m_Controls.contentHTMLWidget->loadUrl(url); + m_Controls.groupBox->setTitle(m_Controls.contentHTMLWidget->getTitle()); +} + +void MitkWebView::OnPageLoad() +{ + MITK_INFO << "OnPageLaod()"; } 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 30b44aecce..7eea4257d4 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.h +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.h @@ -1,51 +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 <QmitkAbstractView.h> #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(); 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 f28f22c5ca..7a5572ee69 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.cpp +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.cpp @@ -1,65 +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 <mitkLogMacros.h> #include <QGridLayout> 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))); + } 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(); +} 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 1a79d465ca..8e3dbf441d 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.h +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/QmitkHTMLWidget.h @@ -1,66 +1,85 @@ /*=================================================================== 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 <QWebEngineView> #include <QPlainTextEdit> #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<typename Arg, typename R, typename C> struct InvokeWrapper { R *receiver; void (C::*memberFun)(Arg); void operator()(Arg result) { (receiver->*memberFun)(result); } }; template<typename Arg, typename R, typename C> InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg)) { InvokeWrapper<Arg, R, C> 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(); + +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