From: Manuel Nickschas Date: Mon, 25 Aug 2008 13:12:13 +0000 (+0200) Subject: URL recognition (WiP) X-Git-Tag: 0.3.1~281 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=14dbd6c44d159c7ca96db9424923962011f7b861;hp=3d79857f0a0c8574f6397731f8aed1825d0a8414 URL recognition (WiP) --- diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 7dd7aba8..aea98dbe 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -295,6 +295,28 @@ void ContentsChatItem::updateLayout() { h += line.height() + fontMetrics()->leading(); } layout()->endLayout(); + + analyze(); +} + +void ContentsChatItem::analyze() { + // Match an URL + static QString urlEnd("(?:>|[,.;:]?\\s|\\b)"); + static QString urlChars("(?:[\\w\\-~@/?&=+$()!%#]|[,.;:]\\w)"); + static QRegExp urlExp(QString("((?:(?:https?://|ftp://|irc://|mailto:)|www)%1+)%2").arg(urlChars, urlEnd)); + + // Match a channel name + // We don't match for channel names starting with + or &, because that gives us a lot of false positives. + static QRegExp chanExp("((?:#|![A-Z0-9]{5})[^,:\\s]+(?::[^,:\\s]+)?)\\b"); + QString str = data(ChatLineModel::DisplayRole).toString(); + quint16 idx = 0; + // first, we split on characters that might be URL separators + int i = str.indexOf(chanExp); + if(i >= 0) { + qDebug() << i << chanExp.cap(1); + } + + } void ContentsChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { diff --git a/src/qtui/chatitem.h b/src/qtui/chatitem.h index 8e15c9f9..116041cc 100644 --- a/src/qtui/chatitem.h +++ b/src/qtui/chatitem.h @@ -141,15 +141,30 @@ protected: private: struct LayoutData; + struct Clickable; class WrapColumnFinder; qreal computeHeight(); + void analyze(); LayoutData *_layoutData; }; +struct ContentsChatItem::Clickable { + enum Type { + Url, + Channel, + Nick + }; + + quint16 start; + quint16 length; + Type type; +}; + struct ContentsChatItem::LayoutData { QTextLayout *layout; + QList clickables; LayoutData() { layout = 0; } ~LayoutData() { delete layout; }