- qreal h = 0;
- qreal y = 0;
- qreal width = _sceneRect.width();
- bool atBottom = (start == _lines.count());
- bool atTop = !atBottom && (start == 0);
-
- if(start < _lines.count()) {
- y = _lines.value(start)->y();
- } else if(atBottom && !_lines.isEmpty()) {
- y = _lines.last()->y() + _lines.last()->height();
- }
-
- qreal contentsWidth = width - secondColumnHandle()->sceneRight();
- qreal senderWidth = secondColumnHandle()->sceneLeft() - firstColumnHandle()->sceneRight();
- qreal timestampWidth = firstColumnHandle()->sceneLeft();
- QPointF contentsPos(secondColumnHandle()->sceneRight(), 0);
- QPointF senderPos(firstColumnHandle()->sceneRight(), 0);
-
- if(atTop) {
- for(int i = end; i >= start; i--) {
- ChatLine *line = new ChatLine(i, model(),
- width,
- timestampWidth, senderWidth, contentsWidth,
- senderPos, contentsPos);
- h += line->height();
- line->setPos(0, y-h);
- _lines.insert(start, line);
- addItem(line);
+ qreal h = 0;
+ qreal y = 0;
+ qreal width = _sceneRect.width();
+ bool atBottom = (start == _lines.count());
+ bool atTop = !atBottom && (start == 0);
+
+ if (start < _lines.count()) {
+ y = _lines.value(start)->y();
+ }
+ else if (atBottom && !_lines.isEmpty()) {
+ y = _lines.last()->y() + _lines.last()->height();
+ }
+
+ qreal contentsWidth = width - secondColumnHandle()->sceneRight();
+ qreal senderWidth = secondColumnHandle()->sceneLeft() - firstColumnHandle()->sceneRight();
+ qreal timestampWidth = firstColumnHandle()->sceneLeft();
+ QPointF contentsPos(secondColumnHandle()->sceneRight(), 0);
+ QPointF senderPos(firstColumnHandle()->sceneRight(), 0);
+
+ if (atTop) {
+ for (int i = end; i >= start; i--) {
+ ChatLine *line = new ChatLine(i, model(),
+ width,
+ timestampWidth, senderWidth, contentsWidth,
+ senderPos, contentsPos);
+ h += line->height();
+ line->setPos(0, y-h);
+ _lines.insert(start, line);
+ addItem(line);
+ }
+ }
+ else {
+ for (int i = start; i <= end; i++) {
+ ChatLine *line = new ChatLine(i, model(),
+ width,
+ timestampWidth, senderWidth, contentsWidth,
+ senderPos, contentsPos);
+ line->setPos(0, y+h);
+ h += line->height();
+ _lines.insert(i, line);
+ addItem(line);
+ }