diff --git a/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp b/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp index b3d168bc91..60afc86dd1 100644 --- a/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp +++ b/Modules/WebInteraction/src/mitkWebInteractionRegistry.cpp @@ -1,43 +1,43 @@ /*=================================================================== 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() { } QString WebInteractionRegistry::PageLoaded(QString address, QString html) { QString target = "Download Raw File"; QString urlPattern = "https://phabricator.mitk.org/diffusion/"; if (address.contains(urlPattern)) { int index = html.indexOf(target); if (index > 0) { - html.insert(index + 34, "<div class=\"phui - header - action - links\"><a class=\"button grey has - icon msl phui - header - action - link\" href=\" / F16690\"><span class=\"visual - only phui - icon - view phui - font - fa fa - download\" aria-hidden=\"true\"></span><div class=\"phui - button - text\">Download Raw File</div></a></div>"); + html.insert(index + 33, "<div class=\"phui - header - action - links\"><a class=\"button grey has - icon msl phui - header - action - link\" href=\" / F16690\"><span class=\"visual - only phui - icon - view phui - font - fa fa - download\" aria-hidden=\"true\"></span><div class=\"phui - button - text\">Download to MITK</div></a></div>"); MITK_INFO << html.toStdString(); } } return html; } } // 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 9a44de6d23..b7e77f367d 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebView.cpp @@ -1,58 +1,60 @@ /*=================================================================== 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())); 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::OnLoadFinished(QString htmlContent) { + m_Controls.plainTextEdit->document()->setPlainText(htmlContent); if (!preventReload) { preventReload = true; + QString result = mitk::WebInteractionRegistry::PageLoaded(m_Controls.URLLineEdit->text(), htmlContent); - this->m_Controls.contentHTMLWidget->setHTMLContent(result); + if (result != htmlContent) this->m_Controls.contentHTMLWidget->setHTMLContent(result); } else { preventReload = false; } } diff --git a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebViewControls.ui b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebViewControls.ui index 10617bc95a..b2ba51b9ee 100644 --- a/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebViewControls.ui +++ b/Plugins/org.mitk.gui.qt.webview/src/internal/MitkWebViewControls.ui @@ -1,82 +1,85 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MitkWebViewControls</class> <widget class="QWidget" name="MitkWebViewControls"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>279</width> <height>395</height> </rect> </property> <property name="minimumSize"> <size> <width>0</width> <height>0</height> </size> </property> <property name="windowTitle"> <string>QmitkTemplate</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QLabel" name="label"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string>URL</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="URLLineEdit"/> </item> <item> <widget class="QPushButton" name="loadURLPushButton"> <property name="text"> <string>load</string> </property> </widget> </item> <item> <widget class="QGroupBox" name="groupBox"> <property name="title"> <string>Web content</string> </property> <widget class="QmitkHTMLWidget" name="contentHTMLWidget" native="true"> <property name="geometry"> <rect> <x>-20</x> <y>-20</y> <width>261</width> <height>154</height> </rect> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> </widget> </widget> </item> + <item> + <widget class="QPlainTextEdit" name="plainTextEdit"/> + </item> </layout> </widget> <layoutdefault spacing="6" margin="11"/> <customwidgets> <customwidget> <class>QmitkHTMLWidget</class> <extends>QWidget</extends> <header>QmitkHTMLWidget.h</header> <container>1</container> </customwidget> </customwidgets> <resources/> <connections/> </ui> 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 d21f2d8af0..b0eae1d488 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,76 @@ /*=================================================================== 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(bool))); } QmitkHTMLWidget::~QmitkHTMLWidget() { - delete m_WebEngineView; - delete m_htmlContent; + 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); + //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(); + 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); + auto webPage = m_WebEngineView->page(); + webPage->setHtml(content, webPage->url()); } QString QmitkHTMLWidget::getTitle() const { - return m_WebEngineView->page()->title(); + return m_WebEngineView->page()->title(); } void QmitkHTMLWidget::LoadFinished(bool ok) { QString content = getHTMLContent(); emit OnLoadFinished(content); }