33#include < QScrollBar>
44#include < QTextCursor>
55#include < QRegExp>
6+ #include < QDebug>
67
78AOTextArea::AOTextArea (QWidget *p_parent) : QTextBrowser(p_parent)
89{
@@ -19,6 +20,63 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message)
1920
2021 this ->append (p_name + " : " );
2122
23+ QRegExp regExp (" ((([A-Za-z]{3,9}:(?:\\ /\\ /)?)(?:[\\ -;:&=\\ +\\ $,\\ w]+@)?[A-Za-z0-9\\ .\\ -]+|(?:www\\ .|[\\ -;:&=\\ +\\ $,\\ w]+@)[A-Za-z0-9\\ .\\ -]+)((?:\\ /[\\ +~%\\ /\\ .\\ w\\ -]*)?\\ ??(?:[\\ -\\ +=&;%@\\ .\\ w]*)#?(?:[\\ .\\ !\\ /\\\\\\ w]*))?)" );
24+
25+ QString result = p_message.toHtmlEscaped ().replace (" \n " , " <br>" ).replace (regExp, " <a href='\\ 1'>\\ 1</a>" );
26+
27+ this ->insertHtml (result);
28+
29+
30+ /*
31+ QRegExp rx("\\bhttp://\\S+");
32+
33+ int first_index = rx.indexIn(p_message);
34+
35+ qDebug() << "number of rx indices: " << rx.captureCount();
36+
37+ if (first_index < 0)
38+ {
39+ this->insertPlainText(p_message);
40+ qDebug() << "NO REGEX MATCHES";
41+ return;
42+ }
43+
44+ //indices where we found a regex match
45+ QVector<int> rx_indices;
46+ QStringList links = rx.capturedTexts();
47+
48+ qDebug() << "link size" << links.size();
49+
50+ rx_indices.append(first_index);
51+
52+
53+ //start at one because first_index is already appended
54+ for (int n_pos = 1 ; n_pos < rx.captureCount() ; ++n_pos)
55+ rx_indices.append(rx.indexIn(p_message));
56+
57+ for (int msg_pos = 0 ; msg_pos < p_message.size() ; ++msg_pos)
58+ {
59+ int tag_index = rx_indices.indexOf(msg_pos);
60+ if (tag_index < 0)
61+ {
62+ this->insertPlainText(p_message.at(msg_pos));
63+ continue;
64+ }
65+
66+ QString link = links.at(tag_index);
67+ QString html_string = "<a href=\"" + link + "\">" + link + "</a>";
68+ qDebug() << "html: " << html_string;
69+
70+ this->insertHtml(html_string);
71+
72+ msg_pos += link.size() - 1;
73+
74+ }
75+
76+ */
77+
78+ /*
79+
2280 QStringList word_list = p_message.split(" ");
2381
2482 for (QString i_word : word_list)
@@ -31,6 +89,7 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message)
3189 else
3290 this->insertPlainText(i_word + " ");
3391 }
92+ */
3493
3594 if (old_cursor.hasSelection () || !is_scrolled_down)
3695 {
0 commit comments