- }
-
- // update existing items
- for(int i = end+1; i < _lines.count(); i++) {
- _lines[i]->setRow(i);
- }
-
- // update selection
- if(_selectionStart >= 0) {
- int offset = end - start + 1;
- int oldStart = _selectionStart;
- if(_selectionStart >= start)
- _selectionStart += offset;
- if(_selectionEnd >= start) {
- _selectionEnd += offset;
- if(_selectionStart == oldStart)
- for(int i = start; i < start + offset; i++)
- _lines[i]->setSelected(true);
+
+ 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);
+ }
+ }
+
+ // update existing items
+ for (int i = end+1; i < _lines.count(); i++) {
+ _lines[i]->setRow(i);
+ }
+
+ // update selection
+ if (_selectionStart >= 0) {
+ int offset = end - start + 1;
+ int oldStart = _selectionStart;
+ if (_selectionStart >= start)
+ _selectionStart += offset;
+ if (_selectionEnd >= start) {
+ _selectionEnd += offset;
+ if (_selectionStart == oldStart)
+ for (int i = start; i < start + offset; i++)
+ _lines[i]->setSelected(true);
+ }
+ if (_firstSelectionRow >= start)
+ _firstSelectionRow += offset;