Update ChatView properly on style changes
[quassel.git] / src / qtui / chatscene.cpp
index 2f145e9..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)));
+  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);
@@ -388,9 +396,15 @@ void ChatScene::updateForViewport(qreal width, qreal height) {
 void ChatScene::setWidth(qreal width) {
   if(width == _sceneRect.width())
     return;
+  layout(width);
+}
 
+void ChatScene::layout(qreal width) {
   // clock_t startT = clock();
 
+  if(width < 0)
+    width = _sceneRect.width();
+
   // disabling the index while doing this complex updates is about
   // 2 to 10 times faster!
   //setItemIndexMethod(QGraphicsScene::NoIndex);