Use QtWebEngine instead of QtWebKit if available
[quassel.git] / src / qtui / webpreviewitem.cpp
index 99bb553..4941fa2 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2014 by the Quassel Project                        *
+ *   Copyright (C) 2005-2016 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 
 #include "webpreviewitem.h"
 
-#ifdef HAVE_WEBKIT
+#ifdef HAVE_WEBENGINE
+#include <QWebEngineView>
+#include <QWebEngineSettings>
+#elif defined HAVE_WEBKIT
+#include <QWebView>
+#include <QWebSettings>
+#endif
+
+#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE
 
 #include <QGraphicsProxyWidget>
 #include <QPainter>
-#include <QWebView>
-#include <QWebSettings>
 
 WebPreviewItem::WebPreviewItem(const QUrl &url)
     : QGraphicsItem(0), // needs to be a top level item as we otherwise cannot guarantee that it's on top of other chatlines
@@ -33,8 +39,13 @@ WebPreviewItem::WebPreviewItem(const QUrl &url)
 {
     qreal frameWidth = 5;
 
+#ifdef HAVE_WEBENGINE
+    QWebEngineView *webView = new QWebEngineView;
+    webView->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
+#elif defined HAVE_WEBKIT
     QWebView *webView = new QWebView;
     webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
+#endif
     webView->load(url);
     webView->setDisabled(true);
     webView->resize(1000, 750);
@@ -44,7 +55,7 @@ WebPreviewItem::WebPreviewItem(const QUrl &url)
 
     qreal xScale = (_boundingRect.width() - 2 * frameWidth) / webView->width();
     qreal yScale = (_boundingRect.height() - 2 * frameWidth) / webView->height();
-    proxyItem->scale(xScale, yScale);
+    proxyItem->setTransform(QTransform::fromScale(xScale, yScale), true);
     proxyItem->setPos(frameWidth, frameWidth);
 
     setZValue(30);
@@ -62,4 +73,4 @@ void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
 }
 
 
-#endif //#ifdef HAVE_WEBKIT
+#endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE