Add --qss parameter to load a custom stylesheet
[quassel.git] / src / qtui / chatitem.cpp
index de96b2d..5c44815 100644 (file)
@@ -69,7 +69,7 @@ void ChatItem::initLayoutHelper(QTextLayout *layout, QTextOption::WrapMode wrapM
   layout->setTextOption(option);
 
   QList<QTextLayout::FormatRange> formatRanges
-         = QtUi::style()->toTextLayoutList(data(MessageModel::FormatRole).value<UiStyle::FormatList>(), layout->text().length());
+         = QtUi::style()->toTextLayoutList(data(MessageModel::FormatRole).value<UiStyle::FormatList>(), layout->text().length(), data(ChatLineModel::MsgLabelRole).toUInt());
   layout->setAdditionalFormats(formatRanges);
 }
 
@@ -89,6 +89,11 @@ void ChatItem::doLayout(QTextLayout *layout) const {
 void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
   Q_UNUSED(option); Q_UNUSED(widget);
   painter->setClipRect(boundingRect()); // no idea why QGraphicsItem clipping won't work
+
+  QVariant bgBrush = data(ChatLineModel::BackgroundRole);
+  if(bgBrush.isValid())
+    painter->fillRect(boundingRect(), bgBrush.value<QBrush>());
+
   QVector<QTextLayout::FormatRange> formats = additionalFormats();
   QTextLayout::FormatRange selectFmt = selectionFormat();
   if(selectFmt.format.isValid()) formats.append(selectFmt);
@@ -300,6 +305,11 @@ void SenderChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
   Q_UNUSED(option); Q_UNUSED(widget);
 
   painter->setClipRect(boundingRect()); // no idea why QGraphicsItem clipping won't work
+
+  QVariant bgBrush = data(ChatLineModel::BackgroundRole);
+  if(bgBrush.isValid())
+    painter->fillRect(boundingRect(), bgBrush.value<QBrush>());
+
   QTextLayout layout;
   initLayout(&layout);
   qreal layoutWidth = layout.minimumWidth();
@@ -413,12 +423,12 @@ void ContentsChatItem::doLayout(QTextLayout *layout) const {
 QList<ContentsChatItem::Clickable> ContentsChatItem::findClickables() const {
   // For matching URLs
   static QString urlEnd("(?:>|[,.;:\"]*\\s|\\b|$)");
-  static QString urlChars("(?:[,.;:]*[\\w\\-~@/?&=+$()!%#*|{}\\[\\]])");
+  static QString urlChars("(?:[,.;:]*[\\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://|gopher://|mailto:)|www)%1+)%2").arg(urlChars, urlEnd), Qt::CaseInsensitive),
+    QRegExp(QString("((?:(?:mailto:|\\w+://)|www\\.)%1+)%2").arg(urlChars, urlEnd), Qt::CaseInsensitive),
 
     // Channel name
     // We don't match for channel names starting with + or &, because that gives us a lot of false positives.
@@ -445,7 +455,7 @@ QList<ContentsChatItem::Clickable> ContentsChatItem::findClickables() const {
     for(int i = 0; i < regExpCount; i++) {
       if(matches[i] < 0 || matchEnd[i] > str.length()) continue;
       if(idx >= matchEnd[i]) {
-        matches[i] = str.indexOf(regExp[i], qMax(matchEnd[i], idx));
+        matches[i] = regExp[i].indexIn(str, qMax(matchEnd[i], idx));
         if(matches[i] >= 0) matchEnd[i] = matches[i] + regExp[i].cap(1).length();
       }
       if(matches[i] >= 0 && matches[i] < minidx) {