1 /***************************************************************************
2 * Copyright (C) 2005-2015 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "webpreviewitem.h"
24 #include <QWebEngineView>
25 #include <QWebEngineSettings>
26 #elif defined HAVE_WEBKIT
28 #include <QWebSettings>
31 #if defined HAVE_WEBKIT || defined HAVE_WEBENGINE
33 #include <QGraphicsProxyWidget>
36 WebPreviewItem::WebPreviewItem(const QUrl &url)
37 : QGraphicsItem(0), // needs to be a top level item as we otherwise cannot guarantee that it's on top of other chatlines
38 _boundingRect(0, 0, 400, 300)
43 QWebEngineView *webView = new QWebEngineView;
44 webView->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
45 #elif defined HAVE_WEBKIT
46 QWebView *webView = new QWebView;
47 webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
50 webView->setDisabled(true);
51 webView->resize(1000, 750);
52 QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget(this);
53 proxyItem->setWidget(webView);
54 proxyItem->setAcceptHoverEvents(false);
56 qreal xScale = (_boundingRect.width() - 2 * frameWidth) / webView->width();
57 qreal yScale = (_boundingRect.height() - 2 * frameWidth) / webView->height();
58 proxyItem->setTransform(QTransform::fromScale(xScale, yScale), true);
59 proxyItem->setPos(frameWidth, frameWidth);
65 void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
67 Q_UNUSED(option); Q_UNUSED(widget);
68 painter->setClipRect(boundingRect());
69 painter->setPen(QPen(Qt::black, 5));
70 painter->setBrush(Qt::black);
71 painter->setRenderHints(QPainter::Antialiasing);
72 painter->drawRoundedRect(boundingRect(), 10, 10);
76 #endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE