Quellcode durchsuchen

ENH: CLI/Frontend/QtWekKit: Preliminary work toward supporting WebEngine in Qt5

See http://doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.html

Co-authored-by: Steve Pieper <pieper@isomics.com>
Jean-Christophe Fillion-Robin vor 8 Jahren
Ursprung
Commit
fe489e99d7

+ 6 - 1
CMake/ctkMacroSetupQt.cmake

@@ -32,12 +32,17 @@ macro(ctkMacroSetupQt)
 
   if(CTK_QT_VERSION VERSION_GREATER "4")
     cmake_minimum_required(VERSION 2.8.12)
+    find_package(Qt5 COMPONENTS Core)
     set(CTK_QT5_COMPONENTS Core Xml XmlPatterns Concurrent Sql Test)
     if(CTK_LIB_Widgets OR CTK_LIB_CommandLineModules/Frontend/QtGui OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
       list(APPEND CTK_QT5_COMPONENTS Widgets OpenGL UiTools)
     endif()
     if(CTK_LIB_CommandLineModules/Frontend/QtWebKit OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
-      list(APPEND CTK_QT5_COMPONENTS WebKitWidgets)
+      if(TARGET Qt5::WebKitWidgets)
+        list(APPEND CTK_QT5_COMPONENTS WebKitWidgets)
+      else()
+        list(APPEND CTK_QT5_COMPONENTS WebEngineWidgets)
+      endif()
     endif()
     if(CTK_LIB_XNAT/Core OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
       list(APPEND CTK_QT5_COMPONENTS Script)

+ 5 - 1
Libs/CommandLineModules/Frontend/QtWebKit/CMakeLists.txt

@@ -37,7 +37,11 @@ set(KIT_resources
 ctkFunctionGetTargetLibraries(KIT_target_libraries)
 
 if(CTK_QT_VERSION VERSION_GREATER "4")
-  list(APPEND KIT_target_libraries Qt5::WebKitWidgets)
+  if(TARGET Qt5::WebKitWidgets)
+    list(APPEND KIT_target_libraries Qt5::WebKitWidgets)
+  else()
+    list(APPEND KIT_target_libraries Qt5::WebEngineWidgets)
+  endif()
 else()
   set(QT_USE_QTWEBKIT 1)
   include(${QT_USE_FILE})

+ 25 - 1
Libs/CommandLineModules/Frontend/QtWebKit/ctkCmdLineModuleFrontendQtWebKit.cpp

@@ -24,9 +24,14 @@
 #include "ctkCmdLineModuleXslTransform.h"
 #include "ctkCmdLineModuleReference.h"
 
+#include <QtGlobal>
+#if QT_VERSION < QT_VERSION_CHECK(5,6,0)
 #include <QWebView>
 #include <QWebFrame>
 #include <QWebElement>
+#else
+#include <QWebEngineView>
+#endif
 #include <QBuffer>
 #include <QFile>
 
@@ -45,6 +50,7 @@ QObject* ctkCmdLineModuleFrontendQtWebKit::guiHandle() const
 {
   if (WebView) return WebView;
 
+#if QT_VERSION < QT_VERSION_CHECK(5,6,0)
   QBuffer input;
   input.setData(moduleReference().rawXmlDescription());
 
@@ -64,19 +70,30 @@ QObject* ctkCmdLineModuleFrontendQtWebKit::guiHandle() const
   this->WebView = new QWebView;
   QByteArray htmlContent = htmlOutput.readAll();
   this->WebView->setHtml(htmlContent);
+#else
+  qWarning() << "ctkCmdLineModuleFrontendQtWebKit::guiHandle() "
+                "is *NOT* implemented";
+#endif
   return this->WebView;
 }
 
 //----------------------------------------------------------------------------
 QVariant ctkCmdLineModuleFrontendQtWebKit::value(const QString &parameter, int role) const
 {
-  Q_UNUSED(role)
+  Q_UNUSED(role);
+#if QT_VERSION < QT_VERSION_CHECK(5,6,0)
   QWebElement webElement = this->WebView->page()->currentFrame()->findFirstElement("input[name=" + parameter + "]");
   if (webElement.isNull()) return QVariant();
   // Work around bug https://bugs.webkit.org/show_bug.cgi?id=32865 for input elements
   QVariant value = webElement.evaluateJavaScript("this.value");
   qDebug() << "Found element" << webElement.tagName() << "with value" << value;
   return value;
+#else
+  Q_UNUSED(parameter);
+  qWarning() << "ctkCmdLineModuleFrontendQtWebKit::value() "
+                "is *NOT* implemented";
+  return QVariant();
+#endif
 }
 
 //----------------------------------------------------------------------------
@@ -84,9 +101,16 @@ void ctkCmdLineModuleFrontendQtWebKit::setValue(const QString &parameter, const
 {
   if (!this->WebView || role != DisplayRole) return;
 
+#if QT_VERSION < QT_VERSION_CHECK(5,6,0)
   QWebElement webElement = this->WebView->page()->currentFrame()->findFirstElement("input[name=" + parameter + "]");
   if (webElement.isNull()) return;
 
   // Work around bug https://bugs.webkit.org/show_bug.cgi?id=32865 for input elements
   webElement.evaluateJavaScript(QString("this.value='%1'").arg(value.toString()));
+#else
+  Q_UNUSED(parameter);
+  Q_UNUSED(value);
+  qWarning() << "ctkCmdLineModuleFrontendQtWebKit::setValue() "
+                "is *NOT* implemented";
+#endif
 }

+ 9 - 1
Libs/CommandLineModules/Frontend/QtWebKit/ctkCmdLineModuleFrontendQtWebKit_p.h

@@ -24,7 +24,12 @@
 
 #include "ctkCmdLineModuleFrontend.h"
 
+#include <QtGlobal>
+#if QT_VERSION < QT_VERSION_CHECK(5,6,0)
 class QWebView;
+#else
+class QWebEngineView;
+#endif
 
 /**
  * \class ctkCmdLineModuleFrontendQtWebKit
@@ -48,8 +53,11 @@ public:
   //virtual QList<QString> parameterNames() const;
 
 private:
-
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
   mutable QWebView* WebView;
+#else
+  mutable QWebEngineView* WebView;
+#endif
 };
 
 #endif // CTKCMDLINEMODULEFRONTENDQTWEBKIT_H