+/*************************************************************************************************/
+
+/*************************************************************************************************/
+
+void SenderChatItem::updateLayout() {
+ if(!haveLayout()) setLayout(createLayout(QTextOption::WrapAnywhere, Qt::AlignRight));
+ ChatItem::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);
+ while(finder.nextWrapColumn() > 0) lines++;
+ return lines * fontMetrics()->lineSpacing();
+}
+
+void ContentsChatItem::setLayout(QTextLayout *layout) {
+ if(!_layoutData) {
+ _layoutData = new LayoutData;
+ _layoutData->clickables = findClickables();
+ } else {
+ delete _layoutData->layout;
+ }
+ _layoutData->layout = layout;
+}
+
+void ContentsChatItem::clearLayout() {
+ delete _layoutData;
+ _layoutData = 0;
+}
+
+void ContentsChatItem::updateLayout() {
+ if(!haveLayout()) setLayout(createLayout(QTextOption::WrapAnywhere));
+
+ // Now layout
+ ChatLineModel::WrapList wrapList = data(ChatLineModel::WrapListRole).value<ChatLineModel::WrapList>();
+ if(!wrapList.count()) return; // empty chatitem
+
+ qreal h = 0;
+ WrapColumnFinder finder(this);
+ layout()->beginLayout();
+ forever {
+ QTextLine line = layout()->createLine();
+ if(!line.isValid())
+ break;
+
+ int col = finder.nextWrapColumn();
+ line.setNumColumns(col >= 0 ? col - line.textStart() : layout()->text().length());
+ line.setPosition(QPointF(0, h));
+ h += fontMetrics()->lineSpacing();
+ }
+ layout()->endLayout();
+}
+
+// NOTE: This method is not threadsafe and not reentrant!
+// (RegExps are not constant while matching, and they are static here for efficiency)
+QList<ContentsChatItem::Clickable> ContentsChatItem::findClickables() {
+ // For matching URLs
+ static QString urlEnd("(?:>|[,.;:\"]*\\s|\\b|$)");
+ static QString urlChars("(?:[\\w\\-~@/?&=+$()!%#]|[,.;:]\\w)");
+
+ static QRegExp regExp[] = {
+ // URL
+ // QRegExp(QString("((?:https?://|s?ftp://|irc://|mailto:|www\\.)%1+|%1+\\.[a-z]{2,4}(?:?=/%1+|\\b))%2").arg(urlChars, urlEnd)),
+ QRegExp(QString("((?:(?:https?://|s?ftp://|irc://|mailto:)|www)%1+)%2").arg(urlChars, urlEnd)),
+
+ // Channel name
+ // We don't match for channel names starting with + or &, because that gives us a lot of false positives.
+ QRegExp("((?:#|![A-Z0-9]{5})[^,:\\s]+(?::[^,:\\s]+)?)\\b")
+
+ // TODO: Nicks, we'll need a filtering for only matching known nicknames further down if we do this
+ };
+
+ static const int regExpCount = 2; // number of regexps in the array above
+
+ qint16 matches[] = { 0, 0, 0 };
+ qint16 matchEnd[] = { 0, 0, 0 };