X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=127d3bad3843df0d40f78c226ad1d18343df5c71;hb=004eb4047a3ac94f53c9f489602cde5aa4e7134e;hp=6a9b14369eb33d520e51a39a1b4d4a7ffaa9f85a;hpb=603763515d61fc1cd3febbfd7c3268d5216df768;p=quassel.git diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 6a9b1436..127d3bad 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -34,9 +34,9 @@ ChatItem::ChatItem(ChatLineModel::ColumnType col, QAbstractItemModel *model, QGraphicsItem *parent) : QGraphicsItem(parent), _fontMetrics(0), - _layoutData(0), _selectionMode(NoSelection), - _selectionStart(-1) + _selectionStart(-1), + _layout(0) { Q_ASSERT(model); QModelIndex index = model->index(row(), col); @@ -46,7 +46,7 @@ ChatItem::ChatItem(ChatLineModel::ColumnType col, QAbstractItemModel *model, QGr } ChatItem::~ChatItem() { - delete _layoutData; + delete _layout; } QVariant ChatItem::data(int role) const { @@ -86,12 +86,6 @@ QTextLayout *ChatItem::createLayout(QTextOption::WrapMode wrapMode, Qt::Alignmen return layout; } -void ChatItem::setLayout(QTextLayout *layout) { - if(!_layoutData) - _layoutData = new LayoutData; - _layoutData->layout = layout; -} - void ChatItem::updateLayout() { if(!haveLayout()) setLayout(createLayout(QTextOption::WrapAnywhere, Qt::AlignLeft)); @@ -105,9 +99,9 @@ void ChatItem::updateLayout() { layout()->endLayout(); } -void ChatItem::clearLayoutData() { - delete _layoutData; - _layoutData = 0; +void ChatItem::clearLayout() { + delete _layout; + _layout = 0; } // NOTE: This is not the most time-efficient implementation, but it saves space by not caching unnecessary data @@ -159,10 +153,8 @@ void ChatItem::setFullSelection() { } void ChatItem::clearSelection() { - if(_selectionMode != NoSelection) { - _selectionMode = NoSelection; - update(); - } + _selectionMode = NoSelection; + update(); } void ChatItem::continueSelecting(const QPointF &pos) { @@ -199,18 +191,12 @@ QList ChatItem::findWords(const QString &searchWord, Qt::CaseSensitivity return resultList; } - void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if(event->buttons() == Qt::LeftButton) { - if(_selectionMode == NoSelection) { - chatScene()->setSelectingItem(this); // removes earlier selection if exists - _selectionStart = _selectionEnd = posToCursor(event->pos()); - //_selectionMode = PartialSelection; - } else { - chatScene()->setSelectingItem(0); - _selectionMode = NoSelection; - update(); - } + chatScene()->setSelectingItem(this); + _selectionStart = _selectionEnd = posToCursor(event->pos()); + _selectionMode = NoSelection; // will be set to PartialSelection by mouseMoveEvent + update(); event->accept(); } else { event->ignore(); @@ -223,8 +209,7 @@ void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { qint16 end = posToCursor(event->pos()); if(end != _selectionEnd) { _selectionEnd = end; - if(_selectionStart != _selectionEnd) _selectionMode = PartialSelection; - else _selectionMode = NoSelection; + _selectionMode = (_selectionStart != _selectionEnd ? PartialSelection : NoSelection); update(); } } else { @@ -249,40 +234,6 @@ void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { } } -void ChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { - // FIXME dirty and fast hack to make http:// urls klickable - - QRegExp regex("\\b([hf]t{1,2}ps?://[^\\s]+)\\b"); - QString str = data(ChatLineModel::DisplayRole).toString(); - int idx = posToCursor(event->pos()); - int mi = 0; - do { - mi = regex.indexIn(str, mi); - if(mi < 0) break; - if(idx >= mi && idx < mi + regex.matchedLength()) { - 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(); -} - /*************************************************************************************************/ /*************************************************************************************************/ @@ -294,6 +245,16 @@ void SenderChatItem::updateLayout() { /*************************************************************************************************/ +ContentsChatItem::ContentsChatItem(QAbstractItemModel *model, QGraphicsItem *parent) : ChatItem(column(), model, parent), + _layoutData(0) +{ + +} + +ContentsChatItem::~ContentsChatItem() { + delete _layoutData; +} + qreal ContentsChatItem::computeHeight() { int lines = 1; WrapColumnFinder finder(this); @@ -301,6 +262,17 @@ qreal ContentsChatItem::computeHeight() { return lines * fontMetrics()->lineSpacing(); } +void ContentsChatItem::setLayout(QTextLayout *layout) { + if(!_layoutData) + _layoutData = new LayoutData; + _layoutData->layout = layout; +} + +void ContentsChatItem::clearLayout() { + delete _layoutData; + _layoutData = 0; +} + void ContentsChatItem::updateLayout() { if(!haveLayout()) setLayout(createLayout(QTextOption::WrapAnywhere)); @@ -324,6 +296,39 @@ void ContentsChatItem::updateLayout() { layout()->endLayout(); } +void ContentsChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { + // FIXME dirty and fast hack to make http:// urls klickable + + QRegExp regex("\\b([hf]t{1,2}ps?://[^\\s]+)\\b"); + QString str = data(ChatLineModel::DisplayRole).toString(); + int idx = posToCursor(event->pos()); + int mi = 0; + do { + mi = regex.indexIn(str, mi); + if(mi < 0) break; + if(idx >= mi && idx < mi + regex.matchedLength()) { + QDesktopServices::openUrl(QUrl(regex.capturedTexts()[1])); + break; + } + mi += regex.matchedLength(); + } while(mi >= 0); + event->accept(); +} + +void ContentsChatItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { + //qDebug() << (void*)this << "entering"; + event->ignore(); +} + +void ContentsChatItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + //qDebug() << (void*)this << "leaving"; + event->ignore(); +} + +void ContentsChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { + //qDebug() << (void*)this << event->pos(); + event->ignore(); +} /*************************************************************************************************/