From 14dbd6c44d159c7ca96db9424923962011f7b861 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 25 Aug 2008 15:12:13 +0200 Subject: [PATCH] URL recognition (WiP) --- src/qtui/chatitem.cpp | 22 ++++++++++++++++++++++ src/qtui/chatitem.h | 15 +++++++++++++++ 2 files changed, 37 insertions(+) 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; } -- 2.20.1