X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=ed90582c1642c4785b61fd3d3d4486f47636d007;hp=b748e1a8c0e5422f4b15d743bd280a21c55d795b;hb=6330f7fe3d19113cbf29944a9b6e8b503893d4a9;hpb=17492fb6c867296692b782227de660d352545f73 diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index b748e1a8..ed90582c 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2010 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -138,8 +138,10 @@ ColumnHandleItem *ChatScene::secondColumnHandle() const { } ChatItem *ChatScene::chatItemAt(const QPointF &scenePos) const { - QGraphicsItem *item = itemAt(scenePos); - return dynamic_cast(item); + ChatLine *line = qgraphicsitem_cast(itemAt(scenePos)); + if(line) + return line->itemAt(line->mapFromScene(scenePos)); + return 0; } bool ChatScene::containsBuffer(const BufferId &id) const { @@ -759,10 +761,10 @@ QString ChatScene::selection() const { QString result; for(int l = start; l <= end; l++) { if(_selectionMinCol == ChatLineModel::TimestampColumn) - result += _lines[l]->item(ChatLineModel::TimestampColumn).data(MessageModel::DisplayRole).toString() + " "; + result += _lines[l]->item(ChatLineModel::TimestampColumn)->data(MessageModel::DisplayRole).toString() + " "; if(_selectionMinCol <= ChatLineModel::SenderColumn) - 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"; } return result; } else if(selectingItem()) @@ -816,12 +818,15 @@ ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) const { } int ChatScene::rowByScenePos(qreal y) const { - // 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(itemAt(QPointF(_secondColHandle->sceneRight() + 1, y))); - if(!contentItem) return -1; - return contentItem->row(); + QList 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(itemList.at(i)); + if(line) + return line->row(); + } + return -1; } void ChatScene::updateSceneRect(qreal width) {