X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fwebpreviewitem.cpp;h=a3c76915839f1de9c82c3a7e54b802422ed66fa6;hp=d5032cd3cce073723088c960a885d90049cdd2fd;hb=8fe8accd73abf77ab21d2d1c1346d2bc5c4de2ff;hpb=9d54503555534a2c554f09a33df6afa33d6308ec diff --git a/src/qtui/webpreviewitem.cpp b/src/qtui/webpreviewitem.cpp index d5032cd3..a3c76915 100644 --- a/src/qtui/webpreviewitem.cpp +++ b/src/qtui/webpreviewitem.cpp @@ -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 * @@ -20,12 +20,42 @@ #include "webpreviewitem.h" -#ifdef HAVE_WEBKIT +#ifdef HAVE_WEBENGINE +#include +#include +#elif defined HAVE_WEBKIT +#include +#include +#endif + +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE #include #include -#include -#include + + +#ifdef HAVE_WEBENGINE +// QGraphicsProxyWidget does not stay synced with QWebEngineView, therefore we modify QWebEngineView +// and manually trigger an update of the proxyItem on UpdateRequest Event. See: http://stackoverflow.com/a/30920209 +// and http://lists.qt-project.org/pipermail/development/2016-March/025280.html (At least in Qt5.6) +class CustomWebView : public QWebEngineView { + +private: + QGraphicsProxyWidget *proxyItem; +public: + CustomWebView(QGraphicsProxyWidget *pItem) { + proxyItem = pItem; + } + bool event(QEvent *event) { + if (event->type() == QEvent::UpdateRequest) + { + proxyItem->update(); + } + + return QWebEngineView::event(event); + } +}; +#endif 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,17 +63,23 @@ WebPreviewItem::WebPreviewItem(const QUrl &url) { qreal frameWidth = 5; + QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget(this); +#ifdef HAVE_WEBENGINE + QWebEngineView *webView = new CustomWebView(proxyItem); + 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); - QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget(this); proxyItem->setWidget(webView); proxyItem->setAcceptHoverEvents(false); 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); @@ -61,4 +97,4 @@ void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op } -#endif //#ifdef HAVE_WEBKIT +#endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE