From: Marcus Eggenberger Date: Thu, 16 Oct 2008 16:07:02 +0000 (+0200) Subject: Disabling SceneIndex during resizing. X-Git-Tag: 0.3.1~168 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=9823b65b3a439e9f360c34dd8381d197f386ad63 Disabling SceneIndex during resizing. This makes resizing about 2 to 10 times faster. Neat. --- diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index d02bfc64..cbdc59d0 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -39,11 +39,6 @@ const qreal minContentsWidth = 200; -class ChatScene::ClearWebPreviewEvent : public QEvent { -public: - inline ClearWebPreviewEvent() : QEvent((QEvent::Type)ChatScene::ClearWebPreviewEventType) {} -}; - ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, QObject *parent) : QGraphicsScene(0, 0, width, 0, parent), _idString(idString), @@ -92,10 +87,12 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w if(model->rowCount() > 0) rowsInserted(QModelIndex(), 0, model->rowCount() - 1); +#ifdef HAVE_WEBKIT webPreview.delayTimer.setSingleShot(true); - connect(&webPreview.delayTimer, SIGNAL(timeout()), this, SLOT(showWebPreview())); + connect(&webPreview.delayTimer, SIGNAL(timeout()), this, SLOT(showWebPreviewEvent())); webPreview.deleteTimer.setInterval(600000); - connect(&webPreview.deleteTimer, SIGNAL(timeout()), this, SLOT(deleteWebPreview())); + connect(&webPreview.deleteTimer, SIGNAL(timeout()), this, SLOT(deleteWebPreviewEvent())); +#endif } ChatScene::~ChatScene() { @@ -309,6 +306,10 @@ void ChatScene::setWidth(qreal width, bool forceReposition) { // clock_t startT = clock(); + // disabling the index while doing this complex updates is about + // 2 to 10 times faster! + setItemIndexMethod(QGraphicsScene::NoIndex); + qreal linePos = _sceneRect.y() + _sceneRect.height(); QList::iterator lineIter = _lines.end(); QList::iterator lineIterBegin = _lines.begin(); @@ -337,6 +338,7 @@ void ChatScene::setWidth(qreal width, bool forceReposition) { line->setPos(0, linePos); } } + setItemIndexMethod(QGraphicsScene::BspTreeIndex); updateSceneRect(width); setHandleXLimits(); @@ -570,9 +572,6 @@ void ChatScene::updateSceneRect(const QRectF &rect) { void ChatScene::customEvent(QEvent *event) { switch(event->type()) { - case ClearWebPreviewEventType: - clearWebPreviewEvent((ClearWebPreviewEvent *)event); - break; default: return; } @@ -617,37 +616,29 @@ void ChatScene::loadWebPreview(ChatItem *parentItem, const QString &url, const Q #endif } -void ChatScene::clearWebPreview(ChatItem *parentItem) { -#ifndef HAVE_WEBKIT - Q_UNUSED(parentItem) -#else - if(parentItem == 0 || webPreview.parentItem == parentItem) { - // posting an event ensures that the item will not be removed as - // the result of another event. this could result in bad segfaults - QCoreApplication::postEvent(this, new ClearWebPreviewEvent()); - } -#endif -} - -void ChatScene::showWebPreview() { +void ChatScene::showWebPreviewEvent() { #ifdef HAVE_WEBKIT if(webPreview.previewItem) addItem(webPreview.previewItem); #endif } -void ChatScene::clearWebPreviewEvent(ClearWebPreviewEvent *event) { -#ifdef HAVE_WEBKIT - event->accept(); - if(webPreview.previewItem && webPreview.previewItem->scene()) { - removeItem(webPreview.previewItem); - webPreview.deleteTimer.start(); +void ChatScene::clearWebPreview(ChatItem *parentItem) { +#ifndef HAVE_WEBKIT + Q_UNUSED(parentItem) +#else + if(parentItem == 0 || webPreview.parentItem == parentItem) { + if(webPreview.previewItem && webPreview.previewItem->scene()) { + removeItem(webPreview.previewItem); + webPreview.deleteTimer.start(); + } + webPreview.delayTimer.stop(); } - webPreview.delayTimer.stop(); #endif } -void ChatScene::deleteWebPreview() { +void ChatScene::deleteWebPreviewEvent() { +#ifdef HAVE_WEBKIT if(webPreview.previewItem) { delete webPreview.previewItem; webPreview.previewItem = 0; @@ -655,4 +646,5 @@ void ChatScene::deleteWebPreview() { webPreview.parentItem = 0; webPreview.url = QString(); webPreview.urlRect = QRectF(); +#endif } diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 637dfe11..b7eca32e 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -39,11 +39,6 @@ class ChatScene : public QGraphicsScene { Q_OBJECT public: - enum MyEventTypes { - ClearWebPreviewEventType = QEvent::User - }; - class ClearWebPreviewEvent; - ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, QObject *parent); virtual ~ChatScene(); @@ -89,9 +84,8 @@ protected slots: private slots: void handlePositionChanged(qreal xpos); - void showWebPreview(); - void clearWebPreviewEvent(ClearWebPreviewEvent *event); - void deleteWebPreview(); + void showWebPreviewEvent(); + void deleteWebPreviewEvent(); private: void setHandleXLimits();