-
-//!\brief Construct a ChatLine object from a message.
-/**
- * \param m The message to be layouted and rendered
- * \param net The network name
- * \param buf The buffer name
- */
-ChatLine::ChatLine(Message m) {
- hght = 0;
- //networkName = m.buffer.network();
- //bufferName = m.buffer.buffer();
- msg = m;
- selectionMode = None;
- formatMsg(msg);
-}
-
-ChatLine::~ChatLine() {
-
-}
-
-void ChatLine::formatMsg(Message msg) {
- QTextOption tsOption, senderOption, textOption;
- styledTimeStamp = QtUi::style()->styleString(msg.formattedTimeStamp());
- styledSender = QtUi::style()->styleString(msg.formattedSender());
- styledText = QtUi::style()->styleString(msg.formattedText());
- precomputeLine();
-}
-
-// 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::FormatRange> ChatLine::calcFormatRanges(const UiStyle::StyledString &fs, QTextLayout::FormatRange additional) {
- QList<FormatRange> ranges;
-
- foreach(QTextLayout::FormatRange f, fs.formats) {
- FormatRange range;
- range.start = f.start;
- range.length = f.length;
- range.format = f.format;
- QFontMetrics metrics(range.format.font());
- range.height = metrics.lineSpacing();
- ranges.append(range);
- }
- /*
- QList<QTextLayout::FormatRange> 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;
-}
-
-void ChatLine::setSelection(SelectionMode mode, int start, int end) {
- selectionMode = mode;
- //tsFormat.clear(); senderFormat.clear(); textFormat.clear();
- QPalette pal = QApplication::palette();
- QTextLayout::FormatRange tsSel, senderSel, textSel;
- switch (mode) {
- case None:
- tsFormat = calcFormatRanges(styledTimeStamp);
- senderFormat = calcFormatRanges(styledSender);
- textFormat = calcFormatRanges(styledText);
- break;
- case Partial:
- selectionStart = qMin(start, end); selectionEnd = qMax(start, end);
- textSel.format.setForeground(pal.brush(QPalette::HighlightedText));
- 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));
- tsSel.format.setBackground(pal.brush(QPalette::Highlight));
- tsSel.start = 0; tsSel.length = styledTimeStamp.text.length();
- tsFormat = calcFormatRanges(styledTimeStamp, tsSel);
- senderSel.format.setForeground(pal.brush(QPalette::HighlightedText));
- senderSel.format.setBackground(pal.brush(QPalette::Highlight));
- senderSel.start = 0; senderSel.length = styledSender.text.length();
- senderFormat = calcFormatRanges(styledSender, senderSel);
- textSel.format.setForeground(pal.brush(QPalette::HighlightedText));
- textSel.format.setBackground(pal.brush(QPalette::Highlight));
- textSel.start = 0; textSel.length = styledText.text.length();
- textFormat = calcFormatRanges(styledText, textSel);
- break;
+#include "qtuisettings.h"
+
+ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
+ : QGraphicsItem(parent),
+ _row(row), // needs to be set before the items
+ _timestampItem(model, this),
+ _senderItem(model, this),
+ _contentsItem(model, this),
+ _width(0),
+ _height(0),
+ _selection(0)
+{
+ Q_ASSERT(model);
+ QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
+ setHighlighted(model->data(index, MessageModel::FlagsRole).toInt() & Message::Highlight);
+}
+
+QRectF ChatLine::boundingRect () const {
+ //return childrenBoundingRect();
+ return QRectF(0, 0, _width, _height);
+}
+
+ChatItem &ChatLine::item(ChatLineModel::ColumnType column) {
+ switch(column) {
+ case ChatLineModel::TimestampColumn:
+ return _timestampItem;
+ case ChatLineModel::SenderColumn:
+ return _senderItem;
+ case ChatLineModel::ContentsColumn:
+ return _contentsItem;
+ default:
+ return *(ChatItem *)0; // provoke an error