X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fwebpreviewitem.cpp;h=a388494873f37338e4722b0543c2afcbbb2dfd4a;hb=518cd2bc478ab3675a60ec46d3ef183cace0cae7;hp=37b5fa7719c9e45f31ab9bc441a10a23b5387dce;hpb=68878dc8366f2f4a0afe132847aad9a51a80cdbf;p=quassel.git diff --git a/src/qtui/webpreviewitem.cpp b/src/qtui/webpreviewitem.cpp index 37b5fa77..a3884948 100644 --- a/src/qtui/webpreviewitem.cpp +++ b/src/qtui/webpreviewitem.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,56 +21,55 @@ #include "webpreviewitem.h" #ifdef HAVE_WEBENGINE -#include -#include +# include +# include #elif defined HAVE_WEBKIT -#include -#include +# include +# include #endif #if defined HAVE_WEBKIT || defined HAVE_WEBENGINE -#include -#include +# include +# include - -#ifdef HAVE_WEBENGINE +# 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 { - +class CustomWebView : public QWebEngineView +{ private: - QGraphicsProxyWidget *proxyItem; + QGraphicsProxyWidget* proxyItem; + public: - CustomWebView(QGraphicsProxyWidget *pItem) { - proxyItem = pItem; - } - bool event(QEvent *event) { - if (event->type() == QEvent::UpdateRequest) - { + CustomWebView(QGraphicsProxyWidget* pItem) { proxyItem = pItem; } + bool event(QEvent* event) override + { + if (event->type() == QEvent::UpdateRequest) { proxyItem->update(); } return QWebEngineView::event(event); } }; -#endif +# 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 +WebPreviewItem::WebPreviewItem(const QUrl& url) + : 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 CustomWebView(proxyItem); + 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; +# elif defined HAVE_WEBKIT + QWebView* webView = new QWebView; webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, false); -#endif +# endif webView->load(url); webView->setDisabled(true); webView->resize(1000, 750); @@ -85,10 +84,10 @@ WebPreviewItem::WebPreviewItem(const QUrl &url) setZValue(30); } - -void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void WebPreviewItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - Q_UNUSED(option); Q_UNUSED(widget); + Q_UNUSED(option); + Q_UNUSED(widget); painter->setClipRect(boundingRect()); painter->setPen(QPen(Qt::black, 5)); painter->setBrush(Qt::black); @@ -96,5 +95,4 @@ void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op painter->drawRoundedRect(boundingRect(), 10, 10); } - -#endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE +#endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE