+void ChatScene::updateSceneRect() {
+ if(_lines.isEmpty())
+ return;
+
+ // we hide day change messages at the top by making the scene rect smaller
+ int numRows = model()->rowCount();
+ int row = -1;
+ QModelIndex firstLineIdx;
+ do {
+ row++;
+ firstLineIdx = model()->index(row, 0);
+ } while((Message::Type)(model()->data(firstLineIdx, MessageModel::TypeRole).toInt()) == Message::DayChange && row < numRows);
+
+ // the following call should be safe. If it crashes something went wrong during insert/remove
+ ChatLine *firstLine = _lines.at(row);
+ ChatLine *lastLine = _lines.last();
+
+ updateSceneRect(QRectF(0, firstLine->pos().y(), _sceneRect.width(), lastLine->pos().y() + lastLine->height() - firstLine->pos().y()));
+}
+
+void ChatScene::updateSceneRect(qreal width) {
+ _sceneRect.setWidth(width);
+ updateSceneRect();
+}
+