~ubuntu-branches/ubuntu/saucy/quassel/saucy-proposed

« back to all changes in this revision

Viewing changes to src/qtui/chatscene.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-02-17 12:49:50 UTC
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: james.westby@ubuntu.com-20100217124950-v9hajw5d2xa6fszn
Tags: upstream-0.6~beta1
ImportĀ upstreamĀ versionĀ 0.6~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright (C) 2005-09 by the Quassel Project                          *
 
2
 *   Copyright (C) 2005-2010 by the Quassel Project                        *
3
3
 *   devel@quassel-irc.org                                                 *
4
4
 *                                                                         *
5
5
 *   This program is free software; you can redistribute it and/or modify  *
138
138
}
139
139
 
140
140
ChatItem *ChatScene::chatItemAt(const QPointF &scenePos) const {
141
 
  QGraphicsItem *item = itemAt(scenePos);
142
 
  return dynamic_cast<ChatItem *>(item);
 
141
  ChatLine *line = qgraphicsitem_cast<ChatLine*>(itemAt(scenePos));
 
142
  if(line)
 
143
    return line->itemAt(line->mapFromScene(scenePos));
 
144
  return 0;
143
145
}
144
146
 
145
147
bool ChatScene::containsBuffer(const BufferId &id) const {
499
501
void ChatScene::setHandleXLimits() {
500
502
  _firstColHandle->setXLimits(0, _secondColHandle->sceneLeft());
501
503
  _secondColHandle->setXLimits(_firstColHandle->sceneRight(), width() - minContentsWidth);
 
504
  update();
502
505
}
503
506
 
504
507
void ChatScene::setSelectingItem(ChatItem *item) {
759
762
    QString result;
760
763
    for(int l = start; l <= end; l++) {
761
764
      if(_selectionMinCol == ChatLineModel::TimestampColumn)
762
 
        result += _lines[l]->item(ChatLineModel::TimestampColumn).data(MessageModel::DisplayRole).toString() + " ";
 
765
        result += _lines[l]->item(ChatLineModel::TimestampColumn)->data(MessageModel::DisplayRole).toString() + " ";
763
766
      if(_selectionMinCol <= ChatLineModel::SenderColumn)
764
 
        result += _lines[l]->item(ChatLineModel::SenderColumn).data(MessageModel::DisplayRole).toString() + " ";
765
 
      result += _lines[l]->item(ChatLineModel::ContentsColumn).data(MessageModel::DisplayRole).toString() + "\n";
 
767
        result += _lines[l]->item(ChatLineModel::SenderColumn)->data(MessageModel::DisplayRole).toString() + " ";
 
768
      result += _lines[l]->item(ChatLineModel::ContentsColumn)->data(MessageModel::DisplayRole).toString() + "\n";
766
769
    }
767
770
    return result;
768
771
  } else if(selectingItem())
816
819
}
817
820
 
818
821
int ChatScene::rowByScenePos(qreal y) const {
819
 
  // This is somewhat hacky... we look at the contents item that is at the given y position, since
820
 
  // it has the full height. From this item, we can then determine the row index and hence the ChatLine.
821
 
  // ChatItems cover their ChatLine, so we won't get to the latter directly.
822
 
  ChatItem *contentItem = static_cast<ChatItem *>(itemAt(QPointF(_secondColHandle->sceneRight() + 1, y)));
823
 
  if(!contentItem) return -1;
824
 
  return contentItem->row();
 
822
  QList<QGraphicsItem*> itemList = items(QPointF(0, y));
 
823
 
 
824
  // ChatLine should be at the bottom of the list
 
825
  for(int i = itemList.count()-1; i >= 0; i--) {
 
826
    ChatLine *line = qgraphicsitem_cast<ChatLine *>(itemList.at(i));
 
827
    if(line)
 
828
      return line->row();
 
829
  }
 
830
  return -1;
825
831
}
826
832
 
827
833
void ChatScene::updateSceneRect(qreal width) {
892
898
    // prepare to load a different URL
893
899
    if(webPreview.previewItem) {
894
900
      if(webPreview.previewItem->scene())
895
 
        removeItem(webPreview.previewItem);
 
901
        removeItem(webPreview.previewItem);
896
902
      delete webPreview.previewItem;
897
903
      webPreview.previewItem = 0;
898
904
    }
940
946
      qreal previewY = webPreview.urlRect.bottom();
941
947
      qreal previewX = webPreview.urlRect.x();
942
948
      if(previewY + webPreview.previewItem->boundingRect().height() > sceneRect().bottom())
943
 
        previewY = webPreview.urlRect.y() - webPreview.previewItem->boundingRect().height();
 
949
        previewY = webPreview.urlRect.y() - webPreview.previewItem->boundingRect().height();
944
950
 
945
951
      if(previewX + webPreview.previewItem->boundingRect().width() > sceneRect().width())
946
 
        previewX = sceneRect().right() - webPreview.previewItem->boundingRect().width();
 
952
        previewX = sceneRect().right() - webPreview.previewItem->boundingRect().width();
947
953
 
948
954
      webPreview.previewItem->setPos(previewX, previewY);
949
955
    }
978
984
  case WebPreview::ShowPreview:
979
985
    if(parentItem == 0 || webPreview.parentItem == parentItem) {
980
986
      if(webPreview.previewItem && webPreview.previewItem->scene())
981
 
        removeItem(webPreview.previewItem);
 
987
        removeItem(webPreview.previewItem);
982
988
    }
983
989
    // fall through into to set hidden state
984
990
  case WebPreview::DelayPreview: