X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fwebpreviewitem.cpp;h=8a24d6f69210a59161d2f45b934fe33a946b25b6;hp=4941fa229ea79d2c3ecd802d10c3863710c347a6;hb=e8a39b4c3c92e193ab861a3fea84a261bb6fbd24;hpb=138e6d461c259df8052497d7228391ce6548bd5f diff --git a/src/qtui/webpreviewitem.cpp b/src/qtui/webpreviewitem.cpp index 4941fa22..8a24d6f6 100644 --- a/src/qtui/webpreviewitem.cpp +++ b/src/qtui/webpreviewitem.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -33,14 +33,39 @@ #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) override { + 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 + : QGraphicsItem(nullptr), // needs to be a top level item as we otherwise cannot guarantee that it's on top of other chatlines _boundingRect(0, 0, 400, 300) { qreal frameWidth = 5; + QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget(this); #ifdef HAVE_WEBENGINE - QWebEngineView *webView = new QWebEngineView; + QWebEngineView *webView = new CustomWebView(proxyItem); webView->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); #elif defined HAVE_WEBKIT QWebView *webView = new QWebView; @@ -49,7 +74,6 @@ WebPreviewItem::WebPreviewItem(const QUrl &url) webView->load(url); webView->setDisabled(true); webView->resize(1000, 750); - QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget(this); proxyItem->setWidget(webView); proxyItem->setAcceptHoverEvents(false);