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)));
connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex)));
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)));
connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex)));
#ifdef HAVE_WEBKIT
webPreview.timer.setSingleShot(true);
connect(&webPreview.timer, SIGNAL(timeout()), this, SLOT(webPreviewNextStep()));
#ifdef HAVE_WEBKIT
webPreview.timer.setSingleShot(true);
connect(&webPreview.timer, SIGNAL(timeout()), this, SLOT(webPreviewNextStep()));
+ChatLine *ChatScene::chatLine(MsgId msgId) const {
+ if(!_lines.count())
+ return 0;
+
+ QList<ChatLine*>::ConstIterator start = _lines.begin();
+ QList<ChatLine*>::ConstIterator end = _lines.end();
+ QList<ChatLine*>::ConstIterator middle;
+
+ int n = int(end - start);
+ int half;
+
+ while(n > 0) {
+ half = n >> 1;
+ middle = start + half;
+ if((*middle)->msgId() < msgId) {
+ start = middle + 1;
+ n -= half + 1;
+ } else {
+ n = half;
+ }
+ }
+ if((*start)->msgId() == msgId)
+ return *start;
+
+ return 0;
+}
+
- QGraphicsItem *item = itemAt(scenePos);
- return dynamic_cast<ChatItem *>(item);
+ ChatLine *line = qgraphicsitem_cast<ChatLine*>(itemAt(scenePos));
+ if(line)
+ return line->itemAt(line->mapFromScene(scenePos));
+ return 0;
qreal width = _sceneRect.width();
bool atBottom = (start == _lines.count());
bool atTop = !atBottom && (start == 0);
qreal width = _sceneRect.width();
bool atBottom = (start == _lines.count());
bool atTop = !atBottom && (start == 0);
- // 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();
+ layout(tl.row(), br.row(), _sceneRect.width());
// disabling the index while doing this complex updates is about
// 2 to 10 times faster!
//setItemIndexMethod(QGraphicsScene::NoIndex);
// 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);
+ }
+ }
+ }
ChatViewSettings viewSettings(this);
viewSettings.setValue("FirstColumnHandlePos", _firstColHandlePos);
ChatViewSettings defaultSettings;
ChatViewSettings viewSettings(this);
viewSettings.setValue("FirstColumnHandlePos", _firstColHandlePos);
ChatViewSettings defaultSettings;
void ChatScene::setHandleXLimits() {
_firstColHandle->setXLimits(0, _secondColHandle->sceneLeft());
_secondColHandle->setXLimits(_firstColHandle->sceneRight(), width() - minContentsWidth);
void ChatScene::setHandleXLimits() {
_firstColHandle->setXLimits(0, _secondColHandle->sceneLeft());
_secondColHandle->setXLimits(_firstColHandle->sceneRight(), width() - minContentsWidth);
// no item -> default scene actions
GraphicalUi::contextMenuActionProvider()->addActions(&menu, filter(), BufferId());
// no item -> default scene actions
GraphicalUi::contextMenuActionProvider()->addActions(&menu, filter(), BufferId());
- result += _lines[l]->item(ChatLineModel::SenderColumn).data(MessageModel::DisplayRole).toString() + " ";
- result += _lines[l]->item(ChatLineModel::ContentsColumn).data(MessageModel::DisplayRole).toString() + "\n";
+ result += _lines[l]->item(ChatLineModel::SenderColumn)->data(MessageModel::DisplayRole).toString() + " ";
+ result += _lines[l]->item(ChatLineModel::ContentsColumn)->data(MessageModel::DisplayRole).toString() + "\n";
- // This is somewhat hacky... we look at the contents item that is at the given y position, since
- // it has the full height. From this item, we can then determine the row index and hence the ChatLine.
- // ChatItems cover their ChatLine, so we won't get to the latter directly.
- ChatItem *contentItem = static_cast<ChatItem *>(itemAt(QPointF(_secondColHandle->sceneRight() + 1, y)));
- if(!contentItem) return -1;
- return contentItem->row();
+ QList<QGraphicsItem*> itemList = items(QPointF(0, y));
+
+ // ChatLine should be at the bottom of the list
+ for(int i = itemList.count()-1; i >= 0; i--) {
+ ChatLine *line = qgraphicsitem_cast<ChatLine *>(itemList.at(i));
+ if(line)
+ return line->row();
+ }
+ return -1;
// prepare to load a different URL
if(webPreview.previewItem) {
if(webPreview.previewItem->scene())
// prepare to load a different URL
if(webPreview.previewItem) {
if(webPreview.previewItem->scene())
qreal previewY = webPreview.urlRect.bottom();
qreal previewX = webPreview.urlRect.x();
if(previewY + webPreview.previewItem->boundingRect().height() > sceneRect().bottom())
qreal previewY = webPreview.urlRect.bottom();
qreal previewX = webPreview.urlRect.x();
if(previewY + webPreview.previewItem->boundingRect().height() > sceneRect().bottom())
case WebPreview::ShowPreview:
if(parentItem == 0 || webPreview.parentItem == parentItem) {
if(webPreview.previewItem && webPreview.previewItem->scene())
case WebPreview::ShowPreview:
if(parentItem == 0 || webPreview.parentItem == parentItem) {
if(webPreview.previewItem && webPreview.previewItem->scene())