#include <QGraphicsSceneMouseEvent>
#include <QMenu>
#include <QPersistentModelIndex>
-#include <QWebView>
+
+#ifdef HAVE_WEBKIT
+# include <QWebView>
+#endif
#include "chatitem.h"
#include "chatline.h"
setHandleXLimits();
+ if(model->rowCount() > 0)
+ rowsInserted(QModelIndex(), 0, model->rowCount() - 1);
+
connect(model, SIGNAL(rowsInserted(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)));
-
- if(model->rowCount() > 0)
- rowsInserted(QModelIndex(), 0, model->rowCount() - 1);
+ connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex)));
#ifdef HAVE_WEBKIT
webPreview.timer.setSingleShot(true);
updateSceneRect();
}
+void ChatScene::dataChanged(const QModelIndex &tl, const QModelIndex &br) {
+ layout(tl.row(), br.row(), _sceneRect.width());
+}
+
void ChatScene::updateForViewport(qreal width, qreal height) {
_viewportHeight = height;
setWidth(width);
void ChatScene::setWidth(qreal width) {
if(width == _sceneRect.width())
return;
+ layout(0, _lines.count()-1, width);
+}
+void ChatScene::layout(int start, int end, qreal width) {
// clock_t startT = clock();
// disabling the index while doing this complex updates is about
// 2 to 10 times faster!
//setItemIndexMethod(QGraphicsScene::NoIndex);
- QList<ChatLine *>::iterator lineIter = _lines.end();
- QList<ChatLine *>::iterator lineIterBegin = _lines.begin();
- qreal linePos = _sceneRect.y() + _sceneRect.height();
- qreal contentsWidth = width - secondColumnHandle()->sceneRight();
- while(lineIter != lineIterBegin) {
- lineIter--;
- (*lineIter)->setGeometryByWidth(width, contentsWidth, linePos);
+ if(end >= 0) {
+ int row = end;
+ qreal linePos = _lines.at(row)->scenePos().y() + _lines.at(row)->height();
+ qreal contentsWidth = width - secondColumnHandle()->sceneRight();
+ while(row >= start) {
+ _lines.at(row--)->setGeometryByWidth(width, contentsWidth, linePos);
+ }
+
+ if(row >= 0) {
+ // remaining items don't need geometry changes, but maybe repositioning?
+ ChatLine *line = _lines.at(row);
+ qreal offset = linePos - (line->scenePos().y() + line->height());
+ if(offset != 0) {
+ while(row >= 0) {
+ line = _lines.at(row--);
+ line->setPos(0, line->scenePos().y() + offset);
+ }
+ }
+ }
}
+
//setItemIndexMethod(QGraphicsScene::BspTreeIndex);
updateSceneRect(width);
if(_firstColHandlePos == xpos)
return;
- _firstColHandlePos = xpos;
+ _firstColHandlePos = xpos >= 0 ? xpos : 0;
ChatViewSettings viewSettings(this);
viewSettings.setValue("FirstColumnHandlePos", _firstColHandlePos);
ChatViewSettings defaultSettings;