? net->networkName() + ":"
: QString();
QString sender = networkName + msg.bufferInfo().bufferName() + ":" + msg.sender();
- Message mmsg = Message(msg.timestamp(), msg.bufferInfo(), msg.type(), msg.text(), sender, msg.flags());
+ Message mmsg = Message(msg.timestamp(), msg.bufferInfo(), msg.type(), msg.contents(), sender, msg.flags());
monitorBuffer()->appendMsg(mmsg);
}
emit messageReceived(msg);
QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$");
if((msg.type() & (Message::Plain | Message::Notice | Message::Action))
&& !(msg.flags() & Message::Self)
- && nickRegExp.exactMatch(msg.text())) {
+ && nickRegExp.exactMatch(msg.contents())) {
msg.setFlags(msg.flags() | Message::Highlight);
return;
}
}
if((msg.type() & (Message::Plain | Message::Notice | Message::Action))
&& !(msg.flags() & Message::Self)
- && userRegExp.exactMatch(msg.text())) {
+ && userRegExp.exactMatch(msg.contents())) {
msg.setFlags(msg.flags() | Message::Highlight);
return;
}
#include <QDataStream>
-Message::Message(BufferInfo bufferInfo, Type type, QString text, QString sender, Flags flags)
+Message::Message(const BufferInfo &bufferInfo, Type type, const QString &contents, const QString &sender, Flags flags)
: _timestamp(QDateTime::currentDateTime().toUTC()),
_bufferInfo(bufferInfo),
- _text(text),
+ _contents(contents),
_sender(sender),
_type(type),
_flags(flags)
{
}
-Message::Message(QDateTime ts,BufferInfo bufferInfo, Type type, QString text, QString sender, Flags flags)
+Message::Message(const QDateTime &ts, const BufferInfo &bufferInfo, Type type, const QString &contents, const QString &sender, Flags flags)
: _timestamp(ts),
_bufferInfo(bufferInfo),
- _text(text),
+ _contents(contents),
_sender(sender),
_type(type),
_flags(flags)
QString user = userFromMask(sender());
QString host = hostFromMask(sender());
QString nick = nickFromMask(sender());
- QString txt = mircToInternal(text());
+ QString txt = mircToInternal(contents());
QString bufferName = bufferInfo().bufferName();
_formattedTimestamp = tr("%DT[%1]").arg(timestamp().toLocalTime().toString("hh:mm:ss"));
break;
case Message::Nick:
s = tr("%Dr<->");
- if(nick == text()) t = tr("%DrYou are now known as %DN%1%DN").arg(txt);
+ if(nick == contents()) t = tr("%DrYou are now known as %DN%1%DN").arg(txt);
else t = tr("%Dr%DN%1%DN is now known as %DN%2%DN").arg(nick, txt);
break;
case Message::Mode:
s = tr("%Dm***");
- if(nick.isEmpty()) t = tr("%DmUser mode: %DM%1%DM").arg(text());
+ if(nick.isEmpty()) t = tr("%DmUser mode: %DM%1%DM").arg(contents());
else t = tr("%DmMode %DM%1%DM by %DN%2%DN").arg(txt, nick);
break;
case Message::Action:
QDataStream &operator<<(QDataStream &out, const Message &msg) {
out << msg.msgId() << (quint32)msg.timestamp().toTime_t() << (quint32)msg.type() << (quint8)msg.flags()
- << msg.bufferInfo() << msg.sender().toUtf8() << msg.text().toUtf8();
+ << msg.bufferInfo() << msg.sender().toUtf8() << msg.contents().toUtf8();
return out;
}
msg._bufferInfo = buf;
msg._timestamp = QDateTime::fromTime_t(ts);
msg._sender = QString::fromUtf8(s);
- msg._text = QString::fromUtf8(m);
+ msg._contents = QString::fromUtf8(m);
return in;
}
Q_DECLARE_FLAGS(Flags, Flag)
- Message(BufferInfo bufferInfo = BufferInfo(), Type type = Plain, QString text = "", QString sender = "", Flags flags = None);
-
- Message(QDateTime ts, BufferInfo buffer = BufferInfo(), Type type = Plain, QString text = "", QString sender = "", Flags flags = None);
+ Message(const BufferInfo &bufferInfo = BufferInfo(), Type type = Plain, const QString &contents = "", const QString &sender = "", Flags flags = None);
+ Message(const QDateTime &ts, const BufferInfo &buffer = BufferInfo(), Type type = Plain,
+ const QString &contents = "", const QString &sender = "", Flags flags = None);
inline MsgId msgId() const { return _msgId; }
inline void setMsgId(MsgId id) { _msgId = id; }
inline BufferInfo bufferInfo() const { return _bufferInfo; }
- inline QString text() const { return _text; }
+ inline QString contents() const { return _contents; }
inline QString sender() const { return _sender; }
inline Type type() const { return _type; }
inline Flags flags() const { return _flags; }
QDateTime _timestamp;
MsgId _msgId;
BufferInfo _bufferInfo;
- QString _text;
+ QString _contents;
QString _sender;
Type _type;
Flags _flags;
logMessageQuery->bindValue(":type", msg.type());
logMessageQuery->bindValue(":flags", (int)msg.flags());
logMessageQuery->bindValue(":sender", msg.sender());
- logMessageQuery->bindValue(":message", msg.text());
+ logMessageQuery->bindValue(":message", msg.contents());
logMessageQuery->exec();
if(logMessageQuery->lastError().isValid()) {
ChatLine::ChatLine(Message msg) {
_styledSender = QtopiaUi::style()->styleString(msg.formattedSender());
- _styledText = QtopiaUi::style()->styleString(msg.formattedText());
+ _styledContents = QtopiaUi::style()->styleString(msg.formattedText());
_timestamp = msg.timestamp();
_msgId = msg.msgId();
_bufferInfo = msg.bufferInfo();
return _styledSender;
}
-UiStyle::StyledText ChatLine::styledText() const {
- return _styledText;
+UiStyle::StyledText ChatLine::styledContents() const {
+ return _styledContents;
}
QDateTime timestamp() const;
UiStyle::StyledText styledSender() const;
- UiStyle::StyledText styledText() const;
+ UiStyle::StyledText styledContents() const;
private:
QString _sender, _text, _htmlSender, _htmlText, _htmlTimestamp;
- UiStyle::StyledText _styledSender, _styledText;
+ UiStyle::StyledText _styledSender, _styledContents;
MsgId _msgId;
BufferInfo _bufferInfo;
QDateTime _timestamp;
if(!document()->isEmpty()) insertPlainText("\n");
insertStyledText(line->styledSender());
insertPlainText(" ");
- insertStyledText(line->styledText());
+ insertStyledText(line->styledContents());
setTextCursor(cursor);
}
bool flg = document()->isEmpty();
insertStyledText(line->styledSender());
insertPlainText(" ");
- insertStyledText(line->styledText());
+ insertStyledText(line->styledContents());
if(!flg) insertPlainText("\n");
setTextCursor(cursor);
}
if(!document()->isEmpty()) insertPlainText("\n");
insertStyledText(line->styledSender());
insertPlainText(" ");
- insertStyledText(line->styledText());
+ insertStyledText(line->styledContents());
}
void ChatWidget::insertStyledText(const QtopiaUiStyle::StyledText &stext) {
QTextCursor cursor = textCursor();
- foreach(QTextLayout::FormatRange format, stext.formats) {
+ foreach(QTextLayout::FormatRange format, stext.formatList) {
cursor.setCharFormat(format.format);
setTextCursor(cursor);
- insertPlainText(stext.text.mid(format.start, format.length));
+ insertPlainText(stext.plainText.mid(format.start, format.length));
}
}
void ChatItem::setText(const UiStyle::StyledText &text) {
_layout.setText(text.text);
- _layout.setAdditionalFormats(text.formats);
+ _layout.setAdditionalFormats(text.formatList);
layout();
}
QTextOption tsOption, senderOption, textOption;
styledTimeStamp = QtUi::style()->styleString(msg.formattedTimestamp());
styledSender = QtUi::style()->styleString(msg.formattedSender());
- styledText = QtUi::style()->styleString(msg.formattedText());
+ styledContents = QtUi::style()->styleString(msg.formattedText());
precomputeLine();
}
QList<FormatRange> 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;
+ for(int i = 0; i < fs.formatList.count(); i++) {
+ int oldend = fs.formatList[i].start + fs.formatList[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];
+ fs.formatList[i].length = additional.start - fs.formatList[i].start;
+ QTextLayout::FormatRange addfmtrng = fs.formatList[i];
addfmtrng.format.merge(additional.format);
addfmtrng.start = additional.start;
addfmtrng.length = qMin(oldend, addend) - additional.start + 1;
- fs.formats.insert(++i, addfmtrng);
+ fs.formatList.insert(++i, addfmtrng);
if(addend == oldend) break;
if(addend < oldend) {
- QTextLayout::FormatRange restfmtrng = fs.formats[i-1];
+ QTextLayout::FormatRange restfmtrng = fs.formatList[i-1];
restfmtrng.start = addend + 1;
restfmtrng.length = oldend - addend;
- fs.formats.insert(++i, restfmtrng);
+ fs.formatList.insert(++i, restfmtrng);
break;
}
}
}
- foreach(QTextLayout::FormatRange f, fs.formats) {
+ foreach(QTextLayout::FormatRange f, fs.formatList) {
if(f.length <= 0) continue;
FormatRange range;
range.start = f.start;
case None:
tsFormat = calcFormatRanges(styledTimeStamp);
senderFormat = calcFormatRanges(styledSender);
- textFormat = calcFormatRanges(styledText);
+ textFormat = calcFormatRanges(styledContents);
break;
case Partial:
selectionStart = qMin(start, end); selectionEnd = qMax(start, end);
textSel.format.setBackground(pal.brush(QPalette::Highlight));
textSel.start = selectionStart;
textSel.length = selectionEnd - selectionStart;
- textFormat = calcFormatRanges(styledText, textSel);
+ textFormat = calcFormatRanges(styledContents, textSel);
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();
+ tsSel.start = 0; tsSel.length = styledTimeStamp.plainText.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();
+ senderSel.start = 0; senderSel.length = styledSender.plainText.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);
+ textSel.start = 0; textSel.length = styledContents.plainText.length();
+ textFormat = calcFormatRanges(styledContents, textSel);
break;
}
}
}
QString ChatLineOld::sender() const {
- return styledSender.text;
+ return styledSender.plainText;
}
QString ChatLineOld::text() const {
- return styledText.text;
+ return styledContents.plainText;
}
bool ChatLineOld::isUrl(int c) const {
QUrl ChatLineOld::getUrl(int c) const {
if(c < 0 || c >= charUrlIdx.count()) return QUrl();
int i = charUrlIdx[c];
- if(i >= 0) return styledText.urls[i].url;
+ if(i >= 0) return styledContents.urls[i].url;
else return QUrl();
}
void ChatLineOld::precomputeLine() {
tsFormat = calcFormatRanges(styledTimeStamp);
senderFormat = calcFormatRanges(styledSender);
- textFormat = calcFormatRanges(styledText);
+ textFormat = calcFormatRanges(styledContents);
minHeight = 0;
foreach(FormatRange fr, tsFormat) minHeight = qMax(minHeight, fr.height);
foreach(FormatRange fr, senderFormat) minHeight = qMax(minHeight, fr.height);
words.clear();
- charPos.resize(styledText.text.length() + 1);
- charHeights.resize(styledText.text.length());
- charUrlIdx.fill(-1, styledText.text.length());
- for(int i = 0; i < styledText.urls.count(); i++) {
- QtUiStyle::UrlInfo url = styledText.urls[i];
+ charPos.resize(styledContents.plainText.length() + 1);
+ charHeights.resize(styledContents.plainText.length());
+ charUrlIdx.fill(-1, styledContents.plainText.length());
+ for(int i = 0; i < styledContents.urls.count(); i++) {
+ QtUiStyle::UrlInfo url = styledContents.urls[i];
for(int j = url.start; j < url.end; j++) charUrlIdx[j] = i;
}
if(!textFormat.count()) return;
QFontMetrics metrics(textFormat[0].format.font());
Word wr;
wr.start = -1; wr.trailing = -1;
- for(int i = 0; i < styledText.text.length(); ) {
+ for(int i = 0; i < styledContents.plainText.length(); ) {
charPos[i] = w; charHeights[i] = textFormat[idx].height;
- w += metrics.charWidth(styledText.text, i);
- if(!styledText.text[i].isSpace()) {
+ w += metrics.charWidth(styledContents.plainText, i);
+ if(!styledContents.plainText[i].isSpace()) {
if(wr.trailing >= 0) {
// new word after space
words.append(wr);
wr.trailing++;
}
}
- if(++i < styledText.text.length() && ++cnt >= textFormat[idx].length) {
+ if(++i < styledContents.plainText.length() && ++cnt >= textFormat[idx].length) {
cnt = 0; idx++;
Q_ASSERT(idx < textFormat.count());
metrics = QFontMetrics(textFormat[idx].format.font());
}
}
- charPos[styledText.text.length()] = w;
+ charPos[styledContents.plainText.length()] = w;
if(wr.start >= 0) words.append(wr);
}
foreach(FormatRange fr, tsFormat) {
p->setFont(fr.format.font());
p->setPen(QPen(fr.format.foreground(), 0)); p->setBackground(fr.format.background());
- p->drawText(rect, Qt::AlignLeft|Qt::TextSingleLine, styledTimeStamp.text.mid(fr.start, fr.length), &brect);
+ p->drawText(rect, Qt::AlignLeft|Qt::TextSingleLine, styledTimeStamp.plainText.mid(fr.start, fr.length), &brect);
rect.setLeft(brect.right());
}
rect = QRectF(pos + QPointF(tsWidth + QtUi::style()->sepTsSender(), 0), QSizeF(senderWidth, minHeight));
for(int i = senderFormat.count() - 1; i >= 0; i--) {
FormatRange fr = senderFormat[i];
p->setFont(fr.format.font()); p->setPen(QPen(fr.format.foreground(), 0)); p->setBackground(fr.format.background());
- p->drawText(rect, Qt::AlignRight|Qt::TextSingleLine, styledSender.text.mid(fr.start, fr.length), &brect);
+ p->drawText(rect, Qt::AlignRight|Qt::TextSingleLine, styledSender.plainText.mid(fr.start, fr.length), &brect);
rect.setRight(brect.left());
}
QPointF tpos = pos + QPointF(tsWidth + QtUi::style()->sepTsSender() + senderWidth + QtUi::style()->sepSenderText(), 0);
llend = lineLayouts[l].start + lineLayouts[l].length;
start = qMax(fr.start, lineLayouts[l].start); end = qMin(frend, llend);
rect.setLeft(tpos.x() + charPos[start] - offset);
- p->drawText(rect, Qt::AlignLeft|Qt::TextSingleLine, styledText.text.mid(start, end - start), &brect);
+ p->drawText(rect, Qt::AlignLeft|Qt::TextSingleLine, styledContents.plainText.mid(start, end - start), &brect);
if(llend <= end) {
h += lineLayouts[l].height;
l++;
qreal hght;
Message msg;
qreal tsWidth, senderWidth, textWidth;
- UiStyle::StyledText styledTimeStamp, styledSender, styledText;
+ UiStyle::StyledText styledTimeStamp, styledSender, styledContents;
struct FormatRange {
int start;
ChatlineModelItem::ChatlineModelItem(const Message &msg) : MessageModelItem(msg) {
QtUiStyle::StyledMessage m = QtUi::style()->styleMessage(msg);
- _timestamp.plainText = m.timestamp.text;
- _sender.plainText = m.sender.text;
- _contents.plainText = m.text.text;
+ _timestamp.plainText = m.timestamp.plainText;
+ _sender.plainText = m.sender.plainText;
+ _contents.plainText = m.contents.plainText;
- _timestamp.formatList = m.timestamp.formats;
- _sender.formatList = m.sender.formats;
- _contents.formatList = m.text.formats;
+ _timestamp.formatList = m.timestamp.formatList;
+ _sender.formatList = m.sender.formatList;
+ _contents.formatList = m.contents.formatList;
}
#ifndef SPUTDEV
if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
// FIXME don't invoke style engine for this!
- QString text = QtUi::style()->styleString(Message::mircToInternal(msg.text())).text;
+ QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText;
displayTrayIconMessage(title, text);
}
#endif
QRect drawRect = rect();
QRect brect;
QString textPart;
- foreach(QTextLayout::FormatRange fr, styledText.formats) {
- textPart = styledText.text.mid(fr.start, fr.length);
+ foreach(QTextLayout::FormatRange fr, styledContents.formatList) {
+ textPart = styledContents.plainText.mid(fr.start, fr.length);
painter.setFont(fr.format.font());
painter.setPen(QPen(fr.format.foreground(), 0));
painter.setBackground(fr.format.background());
setText(text); // this triggers a repaint event
#ifndef SPUTDEV
- styledText = QtUi::style()->styleString(Message::mircToInternal(text));
+ styledContents = QtUi::style()->styleString(Message::mircToInternal(text));
int height = 1;
- foreach(QTextLayout::FormatRange fr, styledText.formats) {
+ foreach(QTextLayout::FormatRange fr, styledContents.formatList) {
height = qMax(height, QFontMetrics(fr.format.font()).height());
}
private:
#ifndef SPUTDEV
- UiStyle::StyledText styledText;
+ UiStyle::StyledText styledContents;
#endif
QSize _sizeHint;
};
QTextLayout::FormatRange curFmtRng;
curFmtRng.format = format(None);
curFmtRng.start = 0;
- result.formats.append(curFmtRng);
+ result.formatList.append(curFmtRng);
int pos = 0; int length = 0;
int fgCol = -1, bgCol = -1; // marks current mIRC color
for(;;) {
}
s.remove(pos, length); // remove format code from string
// now see if something changed and else insert the format
- if(curFmtRng.format == result.formats.last().format) continue; // no change, so we just ignore
+ if(curFmtRng.format == result.formatList.last().format) continue; // no change, so we just ignore
curFmtRng.start = pos;
- if(pos == result.formats.last().start) {
+ if(pos == result.formatList.last().start) {
// same starting point -> we just overwrite the old format
- result.formats.last() = curFmtRng;
+ result.formatList.last() = curFmtRng;
} else {
// fix length of last format
- result.formats.last().length = pos - result.formats.last().start;
- result.formats.append(curFmtRng);
+ result.formatList.last().length = pos - result.formatList.last().start;
+ result.formatList.append(curFmtRng);
}
}
- result.formats.last().length = s.length() - result.formats.last().start;
- if(result.formats.last().length == 0) result.formats.removeLast();
- result.text = s;
+ result.formatList.last().length = s.length() - result.formatList.last().start;
+ if(result.formatList.last().length == 0) result.formatList.removeLast();
+ result.plainText = s;
return result;
}
};
struct StyledText {
- QString text;
- QList<QTextLayout::FormatRange> formats;
+ QString plainText;
+ QList<QTextLayout::FormatRange> formatList;
QList<UrlInfo> urls;
};
UiStyle::StyledString UiStyle::styleString(const QString &s_) {
QString s = s_;
StyledString result;
- result.formats.append(qMakePair(0, (quint32)None));
+ result.formatList.append(qMakePair(0, (quint32)None));
quint32 curfmt = (quint32)None;
int pos = 0; int length = 0;
for(;;) {
length = code.length();
}
s.remove(pos, length);
- if(pos == result.formats.last().first)
- result.formats.last().second = curfmt;
+ if(pos == result.formatList.last().first)
+ result.formatList.last().second = curfmt;
else
- result.formats.append(qMakePair(pos, curfmt));
+ result.formatList.append(qMakePair(pos, curfmt));
}
- result.text = s;
+ result.plainText = s;
return result;
}
QString user = userFromMask(msg.sender());
QString host = hostFromMask(msg.sender());
QString nick = nickFromMask(msg.sender());
- QString txt = mircToInternal(msg.text());
+ QString txt = mircToInternal(msg.contents());
QString bufferName = msg.bufferInfo().bufferName();
StyledMessage result;
break;
case Message::Nick:
s = tr("%Dr<->");
- if(nick == msg.text()) t = tr("%DrYou are now known as %DN%1%DN").arg(txt);
+ if(nick == msg.contents()) t = tr("%DrYou are now known as %DN%1%DN").arg(txt);
else t = tr("%Dr%DN%1%DN is now known as %DN%2%DN").arg(nick, txt);
break;
case Message::Mode:
t = tr("%De[%1]").arg(txt);
}
result.sender = styleString(s);
- result.text = styleString(t);
+ result.contents = styleString(t);
return result;
}
};
struct StyledString {
- QString text;
- FormatList formats; // starting pos, ftypes
+ QString plainText;
+ FormatList formatList; // starting pos, ftypes
};
struct StyledMessage {
StyledString timestamp;
StyledString sender;
- StyledString text;
+ StyledString contents;
};
StyledString styleString(const QString &);