X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatline-old.cpp;h=b7ebf9b53685ba17eb69a6190a5b91e4871a7d83;hp=d2f55be962f1df5641cf9bdd04adf744a788fbac;hb=738bf5577d00b61f99493fdc889fd14f48fffb0b;hpb=e733408e4759473bf38831f498f48a0f2f5e6dc7 diff --git a/src/qtui/chatline-old.cpp b/src/qtui/chatline-old.cpp index d2f55be9..b7ebf9b5 100644 --- a/src/qtui/chatline-old.cpp +++ b/src/qtui/chatline-old.cpp @@ -19,6 +19,8 @@ ***************************************************************************/ #include "chatline-old.h" +#include "client.h" +#include "network.h" #include "qtui.h" //! Construct a ChatLine object from a message. @@ -31,6 +33,7 @@ ChatLine::ChatLine(Message m) { //bufferName = m.buffer.buffer(); msg = m; selectionMode = None; + isHighlight = false; formatMsg(msg); } @@ -39,6 +42,7 @@ ChatLine::~ChatLine() { } void ChatLine::formatMsg(Message msg) { + isHighlight = msg.flags() & Message::Highlight; QTextOption tsOption, senderOption, textOption; styledTimeStamp = QtUi::style()->styleString(msg.formattedTimestamp()); styledSender = QtUi::style()->styleString(msg.formattedSender()); @@ -48,12 +52,32 @@ void ChatLine::formatMsg(Message msg) { // This function is almost obsolete, since with the new style engine, we already get a list of formats... // We don't know yet if we keep this implementation of ChatLine, so I won't bother making this actually nice. -// Also, the additional format is ignored for now, which means that you won't see a selection... -// FIXME TODO -QList ChatLine::calcFormatRanges(const UiStyle::StyledText &fs, QTextLayout::FormatRange additional) { +QList ChatLine::calcFormatRanges(UiStyle::StyledText fs, QTextLayout::FormatRange additional) { QList ranges; + if(additional.length > 0) { + for(int i = 0; i < fs.formats.count(); i++) { + int oldend = fs.formats[i].start + fs.formats[i].length - 1; + int addend = additional.start + additional.length - 1; + if(oldend < additional.start) continue; + fs.formats[i].length = additional.start - fs.formats[i].start; + QTextLayout::FormatRange addfmtrng = fs.formats[i]; + addfmtrng.format.merge(additional.format); + addfmtrng.start = additional.start; + addfmtrng.length = qMin(oldend, addend) - additional.start + 1; + fs.formats.insert(++i, addfmtrng); + if(addend == oldend) break; + if(addend < oldend) { + QTextLayout::FormatRange restfmtrng = fs.formats[i-1]; + restfmtrng.start = addend + 1; + restfmtrng.length = oldend - addend; + fs.formats.insert(++i, restfmtrng); + break; + } + } + } foreach(QTextLayout::FormatRange f, fs.formats) { + if(f.length <= 0) continue; FormatRange range; range.start = f.start; range.length = f.length; @@ -62,36 +86,6 @@ QList ChatLine::calcFormatRanges(const UiStyle::StyledTex range.height = metrics.lineSpacing(); ranges.append(range); } - /* - QList formats = fs.formats; - formats.append(additional); - int cur = -1; - FormatRange range, lastrange; - for(int i = 0; i < fs.text.length(); i++) { - QTextCharFormat format; - foreach(QTextLayout::FormatRange f, formats) { - if(i >= f.start && i < f.start + f.length) format.merge(f.format); - } - if(cur < 0) { - range.start = 0; range.length = 1; range.format= format; - cur = 0; - } else { - if(format == range.format) range.length++; - else { - QFontMetrics metrics(range.format.font()); - range.height = metrics.lineSpacing(); - ranges.append(range); - range.start = i; range.length = 1; range.format = format; - cur++; - } - } - } - if(cur >= 0) { - QFontMetrics metrics(range.format.font()); - range.height = metrics.lineSpacing(); - ranges.append(range); - } - */ return ranges; } @@ -112,9 +106,7 @@ void ChatLine::setSelection(SelectionMode mode, int start, int end) { textSel.format.setBackground(pal.brush(QPalette::Highlight)); textSel.start = selectionStart; textSel.length = selectionEnd - selectionStart; - //textFormat.append(textSel); textFormat = calcFormatRanges(styledText, textSel); - foreach(FormatRange fr, textFormat); break; case Full: tsSel.format.setForeground(pal.brush(QPalette::HighlightedText)); @@ -138,7 +130,7 @@ MsgId ChatLine::msgId() const { } BufferInfo ChatLine::bufferInfo() const { - return msg.buffer(); + return msg.bufferInfo(); } QDateTime ChatLine::timestamp() const { @@ -314,8 +306,15 @@ void ChatLine::draw(QPainter *p, const QPointF &pos) { p->setPen(Qt::NoPen); p->setBrush(pal.brush(QPalette::Highlight)); p->drawRect(QRectF(pos, QSizeF(tsWidth + QtUi::style()->sepTsSender() + senderWidth + QtUi::style()->sepSenderText() + textWidth, height()))); - } else if(selectionMode == Partial) { + } else { + if(isHighlight) { + p->setPen(Qt::NoPen); + p->setBrush(QColor("lightcoral") /*pal.brush(QPalette::AlternateBase) */); + p->drawRect(QRectF(pos, QSizeF(tsWidth + QtUi::style()->sepTsSender() + senderWidth + QtUi::style()->sepSenderText() + textWidth, height()))); + } + if(selectionMode == Partial) { + } } /* p->setClipRect(QRectF(pos, QSizeF(tsWidth, height()))); tsLayout.draw(p, pos, tsFormat); @@ -345,6 +344,7 @@ void ChatLine::draw(QPainter *p, const QPointF &pos) { } QPointF tpos = pos + QPointF(tsWidth + QtUi::style()->sepTsSender() + senderWidth + QtUi::style()->sepSenderText(), 0); qreal h = 0; int l = 0; + if(lineLayouts.count() == 0) return; // how can this happen? rect = QRectF(tpos + QPointF(0, h), QSizeF(textWidth, lineLayouts[l].height)); int offset = 0; foreach(FormatRange fr, textFormat) {