aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmniTroid <davidskoland@gmail.com>2017-05-24 12:46:37 +0200
committerOmniTroid <davidskoland@gmail.com>2017-05-24 12:46:37 +0200
commit819034e5ad85e9d1bc367bb74723f0cef7c6e4ac (patch)
tree5ced87d921719aea91dfaf15343187e05db9214a
parentfbcdf051190670141511387dce291988168a01e7 (diff)
fixed the hyperlink issue. ready for 2.4.0
-rw-r--r--aotextarea.cpp59
-rw-r--r--evidence.cpp4
2 files changed, 59 insertions, 4 deletions
diff --git a/aotextarea.cpp b/aotextarea.cpp
index 06ae81e4..bbdf946e 100644
--- a/aotextarea.cpp
+++ b/aotextarea.cpp
@@ -3,6 +3,7 @@
#include <QScrollBar>
#include <QTextCursor>
#include <QRegExp>
+#include <QDebug>
AOTextArea::AOTextArea(QWidget *p_parent) : QTextBrowser(p_parent)
{
@@ -19,6 +20,63 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message)
this->append(p_name + ": ");
+ QRegExp regExp("((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:&=\\+\\$,\\w]+@)[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%\\/\\.\\w\\-]*)?\\??(?:[\\-\\+=&;%@\\.\\w]*)#?(?:[\\.\\!\\/\\\\\\w]*))?)");
+
+ QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(regExp, "<a href='\\1'>\\1</a>" );
+
+ this->insertHtml(result);
+
+
+ /*
+ QRegExp rx("\\bhttp://\\S+");
+
+ int first_index = rx.indexIn(p_message);
+
+ qDebug() << "number of rx indices: " << rx.captureCount();
+
+ if (first_index < 0)
+ {
+ this->insertPlainText(p_message);
+ qDebug() << "NO REGEX MATCHES";
+ return;
+ }
+
+ //indices where we found a regex match
+ QVector<int> rx_indices;
+ QStringList links = rx.capturedTexts();
+
+ qDebug() << "link size" << links.size();
+
+ rx_indices.append(first_index);
+
+
+ //start at one because first_index is already appended
+ for (int n_pos = 1 ; n_pos < rx.captureCount() ; ++n_pos)
+ rx_indices.append(rx.indexIn(p_message));
+
+ for (int msg_pos = 0 ; msg_pos < p_message.size() ; ++msg_pos)
+ {
+ int tag_index = rx_indices.indexOf(msg_pos);
+ if (tag_index < 0)
+ {
+ this->insertPlainText(p_message.at(msg_pos));
+ continue;
+ }
+
+ QString link = links.at(tag_index);
+ QString html_string = "<a href=\"" + link + "\">" + link + "</a>";
+ qDebug() << "html: " << html_string;
+
+ this->insertHtml(html_string);
+
+ msg_pos += link.size() - 1;
+
+ }
+
+ */
+
+ /*
+
QStringList word_list = p_message.split(" ");
for (QString i_word : word_list)
@@ -31,6 +89,7 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message)
else
this->insertPlainText(i_word + " ");
}
+ */
if (old_cursor.hasSelection() || !is_scrolled_down)
{
diff --git a/evidence.cpp b/evidence.cpp
index 7f91c58d..b4cb9f16 100644
--- a/evidence.cpp
+++ b/evidence.cpp
@@ -121,16 +121,12 @@ void Courtroom::set_evidence_page()
else
evidence_on_page = max_evidence_on_page;
- qDebug() << "total pages: " << total_pages;
-
if (total_pages > current_evidence_page + 1)
ui_evidence_right->show();
if (current_evidence_page > 0)
ui_evidence_left->show();
- qDebug() << "evidence_on_page: " << evidence_on_page;
-
for (int n_evidence_button = 0 ; n_evidence_button < evidence_on_page ; ++n_evidence_button)
{
int n_real_evidence = n_evidence_button + current_evidence_page * max_evidence_on_page;