From d7a7c6e5242fd0f500b2c1c75579c9db81a91d0c Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 30 Jul 2009 17:45:52 +0200 Subject: [PATCH] Update ChatView properly on style changes Since we have the cached wraplists back for the moment, we need to invalidate the caches for all ChatLineModelItems before relayouting the scene. So instead of having each ChatView trigger the layout change for his scene, we now inform the ChatLineModel itself, which invalidates its items' caches and then emits a dataChanged() signal that is caught by the scenes. --- src/qtui/chatlinemodel.cpp | 11 +++++++++++ src/qtui/chatlinemodel.h | 3 +++ src/qtui/chatlinemodelitem.h | 2 ++ src/qtui/chatscene.cpp | 8 ++++++++ src/qtui/chatscene.h | 1 + src/qtui/chatview.cpp | 5 ----- src/qtui/chatview.h | 1 - 7 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/qtui/chatlinemodel.cpp b/src/qtui/chatlinemodel.cpp index 72af95c1..720f9b42 100644 --- a/src/qtui/chatlinemodel.cpp +++ b/src/qtui/chatlinemodel.cpp @@ -19,12 +19,16 @@ ***************************************************************************/ #include "chatlinemodel.h" +#include "qtui.h" +#include "qtuistyle.h" ChatLineModel::ChatLineModel(QObject *parent) : MessageModel(parent) { qRegisterMetaType("ChatLineModel::WrapList"); qRegisterMetaTypeStreamOperators("ChatLineModel::WrapList"); + + connect(QtUi::style(), SIGNAL(changed()), SLOT(styleChanged())); } // MessageModelItem *ChatLineModel::createMessageModelItem(const Message &msg) { @@ -44,6 +48,13 @@ Message ChatLineModel::takeMessageAt(int i) { return msg; } +void ChatLineModel::styleChanged() { + foreach(ChatLineModelItem item, _messageList) { + item.invalidateWrapList(); + } + emit dataChanged(index(0,0), index(rowCount()-1, columnCount()-1)); +} + QDataStream &operator<<(QDataStream &out, const ChatLineModel::WrapList wplist) { out << wplist.count(); ChatLineModel::WrapList::const_iterator it = wplist.begin(); diff --git a/src/qtui/chatlinemodel.h b/src/qtui/chatlinemodel.h index 74f0aceb..c089cb40 100644 --- a/src/qtui/chatlinemodel.h +++ b/src/qtui/chatlinemodel.h @@ -58,6 +58,9 @@ protected: virtual inline void removeAllMessages() { _messageList.clear(); } virtual Message takeMessageAt(int i); +protected slots: + virtual void styleChanged(); + private: QList _messageList; }; diff --git a/src/qtui/chatlinemodelitem.h b/src/qtui/chatlinemodelitem.h index b7a3a858..6eae1af1 100644 --- a/src/qtui/chatlinemodelitem.h +++ b/src/qtui/chatlinemodelitem.h @@ -39,6 +39,8 @@ public: virtual inline Message::Type msgType() const { return _styledMsg.type(); } virtual inline Message::Flags msgFlags() const { return _styledMsg.flags(); } + virtual inline void invalidateWrapList() { _wrapList.clear(); } + /// Used to store information about words to be used for wrapping struct Word { quint16 start; diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index e20f3d63..bcfea000 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -96,6 +96,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w this, SLOT(rowsInserted(const QModelIndex &, int, int))); connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), this, SLOT(rowsAboutToBeRemoved(const QModelIndex &, int, int))); + connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex))); if(model->rowCount() > 0) rowsInserted(QModelIndex(), 0, model->rowCount() - 1); @@ -380,6 +381,13 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e updateSceneRect(); } +void ChatScene::dataChanged(const QModelIndex &tl, const QModelIndex &br) { + // This should only be sent (currently) if the style is reloaded -> re-layout the whole scene + // TODO: Check range and only do partial relayouts, if appropriate + + layout(); +} + void ChatScene::updateForViewport(qreal width, qreal height) { _viewportHeight = height; setWidth(width); diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 78cce78e..82ccacc2 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -142,6 +142,7 @@ protected: protected slots: void rowsInserted(const QModelIndex &, int, int); void rowsAboutToBeRemoved(const QModelIndex &, int, int); + void dataChanged(const QModelIndex &, const QModelIndex &); private slots: void firstHandlePositionChanged(qreal xpos); diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 440cc4da..85fb48ac 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -73,7 +73,6 @@ void ChatView::init(MessageFilter *filter) { setScene(_scene); connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int))); - connect(QtUi::style(), SIGNAL(changed()), this, SLOT(styleChanged())); } bool ChatView::event(QEvent *event) { @@ -172,10 +171,6 @@ void ChatView::verticalScrollbarChanged(int newPos) { vbar->setValue(vbar->maximum()); } -void ChatView::styleChanged() { - scene()->layout(); -} - MsgId ChatView::lastMsgId() const { if(!scene()) return MsgId(); diff --git a/src/qtui/chatview.h b/src/qtui/chatview.h index 6f385bb7..5969f728 100644 --- a/src/qtui/chatview.h +++ b/src/qtui/chatview.h @@ -68,7 +68,6 @@ private slots: void lastLineChanged(QGraphicsItem *chatLine, qreal offset); void mouseMoveWhileSelecting(const QPointF &scenePos); void scrollTimerTimeout(); - void styleChanged(); private: void init(MessageFilter *filter); -- 2.20.1