From 514e28135038076a91d3b4853b41b258551bd196 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Wed, 15 Oct 2008 01:28:05 +0200 Subject: [PATCH] Finally fixing the WebPreview crash bug. As a result BspTreeIndexing has been reenabled. Also the WebPreview is now cached, so if you hover out and hover in in less then 10 minutes, the webview will not be reloaded. --- src/qtui/chatscene.cpp | 31 +++++++++++++++++-------------- src/qtui/chatscene.h | 6 +++--- src/qtui/webpreviewitem.cpp | 4 ---- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 49bb89f4..d02bfc64 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -94,9 +94,8 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w webPreview.delayTimer.setSingleShot(true); connect(&webPreview.delayTimer, SIGNAL(timeout()), this, SLOT(showWebPreview())); - - // installEventFilter(this); - setItemIndexMethod(QGraphicsScene::NoIndex); + webPreview.deleteTimer.setInterval(600000); + connect(&webPreview.deleteTimer, SIGNAL(timeout()), this, SLOT(deleteWebPreview())); } ChatScene::~ChatScene() { @@ -591,12 +590,17 @@ void ChatScene::loadWebPreview(ChatItem *parentItem, const QString &url, const Q if(webPreview.url != url) { webPreview.url = url; // load a new web view and delete the old one (if exists) - if(webPreview.previewItem) { + if(webPreview.previewItem && webPreview.previewItem->scene()) { removeItem(webPreview.previewItem); delete webPreview.previewItem; } webPreview.previewItem = new WebPreviewItem(url); webPreview.delayTimer.start(2000); + webPreview.deleteTimer.stop(); + } else if(webPreview.previewItem && !webPreview.previewItem->scene()) { + // we just have to readd the item to the scene + webPreview.delayTimer.start(2000); + webPreview.deleteTimer.stop(); } if(webPreview.urlRect != urlRect) { webPreview.urlRect = urlRect; @@ -635,21 +639,20 @@ void ChatScene::showWebPreview() { void ChatScene::clearWebPreviewEvent(ClearWebPreviewEvent *event) { #ifdef HAVE_WEBKIT event->accept(); + if(webPreview.previewItem && webPreview.previewItem->scene()) { + removeItem(webPreview.previewItem); + webPreview.deleteTimer.start(); + } + webPreview.delayTimer.stop(); +#endif +} + +void ChatScene::deleteWebPreview() { if(webPreview.previewItem) { - if(webPreview.previewItem->scene()) { - removeItem(webPreview.previewItem); - } delete webPreview.previewItem; webPreview.previewItem = 0; } webPreview.parentItem = 0; webPreview.url = QString(); webPreview.urlRect = QRectF(); -#endif } - -bool ChatScene::eventFilter(QObject *watched, QEvent *event) { - qDebug() << watched << event; - return false; -} - diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 2204d667..637dfe11 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -59,8 +59,6 @@ public: inline ColumnHandleItem *firstColumnHandle() const { return firstColHandle; } inline ColumnHandleItem *secondColumnHandle() const { return secondColHandle; } - virtual bool eventFilter(QObject *watched, QEvent *event); - public slots: void updateForViewport(qreal width, qreal height); void setWidth(qreal, bool forceReposition = false); @@ -93,6 +91,7 @@ private slots: void handlePositionChanged(qreal xpos); void showWebPreview(); void clearWebPreviewEvent(ClearWebPreviewEvent *event); + void deleteWebPreview(); private: void setHandleXLimits(); @@ -127,10 +126,11 @@ private: struct WebPreview { ChatItem *parentItem; - WebPreviewItem *previewItem; + QGraphicsItem *previewItem; QString url; QRectF urlRect; QTimer delayTimer; + QTimer deleteTimer; WebPreview() : parentItem(0), previewItem(0) {} }; WebPreview webPreview; diff --git a/src/qtui/webpreviewitem.cpp b/src/qtui/webpreviewitem.cpp index 29dfedec..eb12eea8 100644 --- a/src/qtui/webpreviewitem.cpp +++ b/src/qtui/webpreviewitem.cpp @@ -54,10 +54,6 @@ void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op 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 -- 2.20.1