X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=7a11a6653a8c3cd863ce1cdabbc7757b03dfd83e;hb=16192b6fb8ddce1f3c1202eef709edc45e0e2c27;hp=f09553b565a9c0447d9675be3ed8faf4b94f8c09;hpb=4256ac4821446383da9a9dcda3532fbfa3eb6beb;p=quassel.git diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index f09553b5..7a11a665 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -31,12 +31,18 @@ #include "chatlinemodel.h" #include "qtui.h" -ChatItem::ChatItem(const QPersistentModelIndex &index_, QGraphicsItem *parent) : QGraphicsItem(parent), _index(index_) { - _fontMetrics = QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value().at(0).second); - _layout = 0; - _lines = 0; - _selectionStart = -1; - _selectionMode = NoSelection; +ChatItem::ChatItem(int col, QAbstractItemModel *model, QGraphicsItem *parent) + : QGraphicsItem(parent), + _fontMetrics(0), + _col(col), + _lines(0), + _layout(0), + _selectionMode(NoSelection), + _selectionStart(-1) +{ + Q_ASSERT(model); + QModelIndex index = model->index(row(), col); + _fontMetrics = QtUi::style()->fontMetrics(model->data(index, ChatLineModel::FormatRole).value().at(0).second); setAcceptHoverEvents(true); setZValue(20); } @@ -46,11 +52,12 @@ ChatItem::~ChatItem() { } QVariant ChatItem::data(int role) const { - if(!_index.isValid()) { - qWarning() << "ChatItem::data(): Model index is invalid!" << _index; + QModelIndex index = model()->index(row(), column()); + if(!index.isValid()) { + qWarning() << "ChatItem::data(): model index is invalid!" << index; return QVariant(); } - return _index.data(role); + return model()->data(index, role); } qreal ChatItem::setWidth(qreal w) { @@ -197,7 +204,7 @@ void ChatItem::continueSelecting(const QPointF &pos) { } void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(event->buttons() & Qt::LeftButton) { + if(event->buttons() == Qt::LeftButton) { if(_selectionMode == NoSelection) { chatScene()->setSelectingItem(this); // removes earlier selection if exists _selectionStart = _selectionEnd = posToCursor(event->pos()); @@ -214,20 +221,25 @@ void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { } void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(contains(event->pos())) { - qint16 end = posToCursor(event->pos()); - if(end != _selectionEnd) { - _selectionEnd = end; - update(); + if(event->buttons() == Qt::LeftButton) { + if(contains(event->pos())) { + qint16 end = posToCursor(event->pos()); + if(end != _selectionEnd) { + _selectionEnd = end; + update(); + } + } else { + setFullSelection(); + chatScene()->startGlobalSelection(this, event->pos()); } + event->accept(); } else { - setFullSelection(); - chatScene()->startGlobalSelection(this, event->pos()); + event->ignore(); } } void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if(_selectionMode != NoSelection) { + if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) { _selectionEnd = posToCursor(event->pos()); QString selection = data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd)); @@ -241,7 +253,7 @@ void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { void ChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { // FIXME dirty and fast hack to make http:// urls klickable - QRegExp regex("\\b((?:h|f)t{1,2}ps?://[^\\s]+)\\b"); + QRegExp regex("\\b([hf]t{1,2}ps?://[^\\s]+)\\b"); QString str = data(ChatLineModel::DisplayRole).toString(); int idx = posToCursor(event->pos()); int mi = 0; @@ -252,23 +264,24 @@ void ChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { QDesktopServices::openUrl(QUrl(regex.capturedTexts()[1])); break; } + mi += regex.matchedLength(); } while(mi >= 0); event->accept(); } void ChatItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { //qDebug() << (void*)this << "entering"; - + event->ignore(); } void ChatItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { //qDebug() << (void*)this << "leaving"; - + event->ignore(); } void ChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { //qDebug() << (void*)this << event->pos(); - + event->ignore(); }