Update ChatView properly on style changes
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 30 Jul 2009 15:45:52 +0000 (17:45 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 6 Aug 2009 18:25:58 +0000 (20:25 +0200)
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
src/qtui/chatlinemodel.h
src/qtui/chatlinemodelitem.h
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/chatview.cpp
src/qtui/chatview.h

index 72af95c..720f9b4 100644 (file)
  ***************************************************************************/
 
 #include "chatlinemodel.h"
  ***************************************************************************/
 
 #include "chatlinemodel.h"
+#include "qtui.h"
+#include "qtuistyle.h"
 
 ChatLineModel::ChatLineModel(QObject *parent)
   : MessageModel(parent)
 {
   qRegisterMetaType<WrapList>("ChatLineModel::WrapList");
   qRegisterMetaTypeStreamOperators<WrapList>("ChatLineModel::WrapList");
 
 ChatLineModel::ChatLineModel(QObject *parent)
   : MessageModel(parent)
 {
   qRegisterMetaType<WrapList>("ChatLineModel::WrapList");
   qRegisterMetaTypeStreamOperators<WrapList>("ChatLineModel::WrapList");
+
+  connect(QtUi::style(), SIGNAL(changed()), SLOT(styleChanged()));
 }
 
 // MessageModelItem *ChatLineModel::createMessageModelItem(const Message &msg) {
 }
 
 // MessageModelItem *ChatLineModel::createMessageModelItem(const Message &msg) {
@@ -44,6 +48,13 @@ Message ChatLineModel::takeMessageAt(int i) {
   return msg;
 }
 
   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();
 QDataStream &operator<<(QDataStream &out, const ChatLineModel::WrapList wplist) {
   out << wplist.count();
   ChatLineModel::WrapList::const_iterator it = wplist.begin();
index 74f0ace..c089cb4 100644 (file)
@@ -58,6 +58,9 @@ protected:
   virtual inline void removeAllMessages() { _messageList.clear(); }
   virtual Message takeMessageAt(int i);
 
   virtual inline void removeAllMessages() { _messageList.clear(); }
   virtual Message takeMessageAt(int i);
 
+protected slots:
+  virtual void styleChanged();
+
 private:
   QList<ChatLineModelItem> _messageList;
 };
 private:
   QList<ChatLineModelItem> _messageList;
 };
index b7a3a85..6eae1af 100644 (file)
@@ -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 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;
   /// Used to store information about words to be used for wrapping
   struct Word {
     quint16 start;
index e20f3d6..bcfea00 100644 (file)
@@ -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)));
           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);
 
   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();
 }
 
   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);
 void ChatScene::updateForViewport(qreal width, qreal height) {
   _viewportHeight = height;
   setWidth(width);
index 78cce78..82ccacc 100644 (file)
@@ -142,6 +142,7 @@ protected:
 protected slots:
   void rowsInserted(const QModelIndex &, int, int);
   void rowsAboutToBeRemoved(const QModelIndex &, int, int);
 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);
 
 private slots:
   void firstHandlePositionChanged(qreal xpos);
index 440cc4d..85fb48a 100644 (file)
@@ -73,7 +73,6 @@ void ChatView::init(MessageFilter *filter) {
   setScene(_scene);
 
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
   setScene(_scene);
 
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
-  connect(QtUi::style(), SIGNAL(changed()), this, SLOT(styleChanged()));
 }
 
 bool ChatView::event(QEvent *event) {
 }
 
 bool ChatView::event(QEvent *event) {
@@ -172,10 +171,6 @@ void ChatView::verticalScrollbarChanged(int newPos) {
     vbar->setValue(vbar->maximum());
 }
 
     vbar->setValue(vbar->maximum());
 }
 
-void ChatView::styleChanged() {
-  scene()->layout();
-}
-
 MsgId ChatView::lastMsgId() const {
   if(!scene())
     return MsgId();
 MsgId ChatView::lastMsgId() const {
   if(!scene())
     return MsgId();
index 6f385bb..5969f72 100644 (file)
@@ -68,7 +68,6 @@ private slots:
   void lastLineChanged(QGraphicsItem *chatLine, qreal offset);
   void mouseMoveWhileSelecting(const QPointF &scenePos);
   void scrollTimerTimeout();
   void lastLineChanged(QGraphicsItem *chatLine, qreal offset);
   void mouseMoveWhileSelecting(const QPointF &scenePos);
   void scrollTimerTimeout();
-  void styleChanged();
 
 private:
   void init(MessageFilter *filter);
 
 private:
   void init(MessageFilter *filter);