X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=8063a972365ace53da297ad7a1bdaa431373fb02;hp=20dad9daf9cd5d89d2aba6c2c979d2e6f0778fdc;hb=f9efdde7f3a6004af8f834c409cfa6ae1d877692;hpb=695758015a80eb8c158a9ac4c0f1c0b547e70df3 diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 20dad9da..8063a972 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,24 +18,29 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "chatitem.h" + +#include +#include + #include #include #include #include #include -#include #include #include #include #include +#include "action.h" #include "buffermodel.h" #include "bufferview.h" -#include "chatitem.h" #include "chatline.h" #include "chatlinemodel.h" #include "chatview.h" #include "contextmenuactionprovider.h" +#include "icon.h" #include "mainwin.h" #include "qtui.h" #include "qtuistyle.h" @@ -45,7 +50,7 @@ ChatItem::ChatItem(const QRectF &boundingRect, ChatLine *parent) _boundingRect(boundingRect), _selectionMode(NoSelection), _selectionStart(-1), - _cachedLayout(0) + _cachedLayout(nullptr) { } @@ -137,7 +142,7 @@ QTextLayout *ChatItem::layout() const void ChatItem::clearCache() { delete _cachedLayout; - _cachedLayout = 0; + _cachedLayout = nullptr; } @@ -153,7 +158,7 @@ void ChatItem::initLayoutHelper(QTextLayout *layout, QTextOption::WrapMode wrapM layout->setTextOption(option); QList formatRanges - = QtUi::style()->toTextLayoutList(formatList(), layout->text().length(), data(ChatLineModel::MsgLabelRole).toUInt()); + = QtUi::style()->toTextLayoutList(formatList(), layout->text().length(), data(ChatLineModel::MsgLabelRole).value()); layout->setAdditionalFormats(formatRanges); } @@ -245,7 +250,7 @@ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, // } // 2) draw MsgId over the time column // if(column() == 0) { -// QString msgIdString = QString::number(data(MessageModel::MsgIdRole).value().toInt()); +// QString msgIdString = QString::number(data(MessageModel::MsgIdRole).value().toLongLong()); // QPointF bottomPoint = boundingRect().bottomLeft(); // bottomPoint.ry() -= 2; // painter->drawText(bottomPoint, msgIdString); @@ -257,11 +262,11 @@ void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, } -void ChatItem::overlayFormat(UiStyle::FormatList &fmtList, int start, int end, quint32 overlayFmt) const +void ChatItem::overlayFormat(UiStyle::FormatList &fmtList, quint16 start, quint16 end, UiStyle::FormatType overlayFmt) const { - for (int i = 0; i < fmtList.count(); i++) { + for (size_t i = 0; i < fmtList.size(); i++) { int fmtStart = fmtList.at(i).first; - int fmtEnd = (i < fmtList.count()-1 ? fmtList.at(i+1).first : data(MessageModel::DisplayRole).toString().length()); + int fmtEnd = (i < fmtList.size()-1 ? fmtList.at(i+1).first : data(MessageModel::DisplayRole).toString().length()); if (fmtEnd <= start) continue; @@ -270,51 +275,107 @@ void ChatItem::overlayFormat(UiStyle::FormatList &fmtList, int start, int end, q // split the format if necessary if (fmtStart < start) { - fmtList.insert(i, fmtList.at(i)); + fmtList.insert(fmtList.begin() + i, fmtList.at(i)); fmtList[++i].first = start; } if (end < fmtEnd) { - fmtList.insert(i, fmtList.at(i)); + fmtList.insert(fmtList.begin() + i, fmtList.at(i)); fmtList[i+1].first = end; } - fmtList[i].second |= overlayFmt; + fmtList[i].second.type |= overlayFmt; } } QVector ChatItem::additionalFormats() const { - return selectionFormats(); -} + // Calculate formats to overlay (only) if there's a selection, and/or a hovered clickable + if (!hasSelection() && !hasActiveClickable()) { + return {}; + } + using Label = UiStyle::MessageLabel; + using Format = UiStyle::Format; -QVector ChatItem::selectionFormats() const -{ - if (!hasSelection()) - return QVector(); + auto itemLabel = data(ChatLineModel::MsgLabelRole).value