From 4e8c5025fef997fcee75673c7bb1ca0a786e064b Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Sun, 28 Sep 2008 16:30:32 +0200 Subject: [PATCH 1/1] added missing files --- src/qtui/webpreviewitem.cpp | 63 +++++++++++++++++++++++++++++++++++++ src/qtui/webpreviewitem.h | 39 +++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/qtui/webpreviewitem.cpp create mode 100644 src/qtui/webpreviewitem.h diff --git a/src/qtui/webpreviewitem.cpp b/src/qtui/webpreviewitem.cpp new file mode 100644 index 00000000..7070c116 --- /dev/null +++ b/src/qtui/webpreviewitem.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "webpreviewitem.h" + +#ifdef HAVE_WEBKIT + +#include +#include +#include + +WebPreviewItem::WebPreviewItem(const QString &url) + : QGraphicsItem(0), // 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; + + QWebView *webView = new QWebView; + webView->load(url); + 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->setPos(frameWidth, frameWidth); + + setZValue(30); +} + +void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + Q_UNUSED(option); Q_UNUSED(widget); + painter->setClipRect(boundingRect()); + painter->setPen(QPen(Qt::black, 5)); + painter->setBrush(Qt::black); + painter->setRenderHints(QPainter::Antialiasing); + painter->drawRoundedRect(boundingRect(), 10, 10); + + painter->setPen(QPen(Qt::green)); + QString text = QString::number(zValue()); + painter->drawText(_boundingRect.center(), text); +} + +#endif //#ifdef HAVE_WEBKIT diff --git a/src/qtui/webpreviewitem.h b/src/qtui/webpreviewitem.h new file mode 100644 index 00000000..adb6641f --- /dev/null +++ b/src/qtui/webpreviewitem.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef WEBPREVIEWITEM_H +#define WEBPREVIEWITEM_H + +#ifdef HAVE_WEBKIT + +#include + +class WebPreviewItem : public QGraphicsItem { +public: + WebPreviewItem(const QString &url); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + virtual inline QRectF boundingRect() const { return _boundingRect; } + +private: + QRectF _boundingRect; +}; +#endif //#ifdef HAVE_WEBKIT + +#endif //WEBPREVIEWITEM_H -- 2.20.1