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, "
Download Raw File
"); + html.insert(index + 33, "
Download to MITK
"); 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 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 @@ MitkWebViewControls 0 0 279 395 0 0 QmitkTemplate 0 0 URL load Web content -20 -20 261 154 0 0 + + + QmitkHTMLWidget QWidget
QmitkHTMLWidget.h
1
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 #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(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); }