Highlight URLs in TimelineView
This commit is contained in:
parent
f2ce910b16
commit
ff611c1b39
@ -41,8 +41,8 @@ public:
|
|||||||
TimelineItem(const events::MessageEvent<msgs::Text> &e, bool with_sender, const QString &color, QWidget *parent = 0);
|
TimelineItem(const events::MessageEvent<msgs::Text> &e, bool with_sender, const QString &color, QWidget *parent = 0);
|
||||||
|
|
||||||
// For local messages.
|
// For local messages.
|
||||||
TimelineItem(const QString &userid, const QString &color, const QString &body, QWidget *parent = 0);
|
TimelineItem(const QString &userid, const QString &color, QString body, QWidget *parent = 0);
|
||||||
TimelineItem(const QString &body, QWidget *parent = 0);
|
TimelineItem(QString body, QWidget *parent = 0);
|
||||||
|
|
||||||
TimelineItem(ImageItem *img, const events::MessageEvent<msgs::Image> &e, const QString &color, QWidget *parent);
|
TimelineItem(ImageItem *img, const events::MessageEvent<msgs::Image> &e, const QString &color, QWidget *parent);
|
||||||
TimelineItem(ImageItem *img, const events::MessageEvent<msgs::Image> &e, QWidget *parent);
|
TimelineItem(ImageItem *img, const events::MessageEvent<msgs::Image> &e, QWidget *parent);
|
||||||
|
@ -17,25 +17,33 @@
|
|||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
#include "ImageItem.h"
|
#include "ImageItem.h"
|
||||||
#include "TimelineItem.h"
|
#include "TimelineItem.h"
|
||||||
#include "TimelineViewManager.h"
|
#include "TimelineViewManager.h"
|
||||||
|
|
||||||
|
static const QRegExp URL_REGEX("((?:https?|ftp)://\\S+)");
|
||||||
|
static const QString URL_HTML = "<a href=\"\\1\" style=\"color: #333333\">\\1</a>";
|
||||||
|
|
||||||
namespace events = matrix::events;
|
namespace events = matrix::events;
|
||||||
namespace msgs = matrix::events::messages;
|
namespace msgs = matrix::events::messages;
|
||||||
|
|
||||||
TimelineItem::TimelineItem(const QString &userid, const QString &color, const QString &body, QWidget *parent)
|
TimelineItem::TimelineItem(const QString &userid, const QString &color, QString body, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
|
body.replace(URL_REGEX, URL_HTML);
|
||||||
|
|
||||||
generateTimestamp(QDateTime::currentDateTime());
|
generateTimestamp(QDateTime::currentDateTime());
|
||||||
generateBody(TimelineViewManager::displayName(userid), color, body);
|
generateBody(TimelineViewManager::displayName(userid), color, body);
|
||||||
setupLayout();
|
setupLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineItem::TimelineItem(const QString &body, QWidget *parent)
|
TimelineItem::TimelineItem(QString body, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
|
body.replace(URL_REGEX, URL_HTML);
|
||||||
|
|
||||||
generateTimestamp(QDateTime::currentDateTime());
|
generateTimestamp(QDateTime::currentDateTime());
|
||||||
generateBody(body);
|
generateBody(body);
|
||||||
setupLayout();
|
setupLayout();
|
||||||
@ -85,6 +93,7 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Notice> &event, bool
|
|||||||
|
|
||||||
generateTimestamp(timestamp);
|
generateTimestamp(timestamp);
|
||||||
|
|
||||||
|
body.replace(URL_REGEX, URL_HTML);
|
||||||
body = "<i style=\"color: #565E5E\">" + body + "</i>";
|
body = "<i style=\"color: #565E5E\">" + body + "</i>";
|
||||||
|
|
||||||
if (with_sender)
|
if (with_sender)
|
||||||
@ -103,6 +112,8 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Text> &event, bool w
|
|||||||
|
|
||||||
generateTimestamp(timestamp);
|
generateTimestamp(timestamp);
|
||||||
|
|
||||||
|
body.replace(URL_REGEX, URL_HTML);
|
||||||
|
|
||||||
if (with_sender)
|
if (with_sender)
|
||||||
generateBody(TimelineViewManager::displayName(event.sender()), color, body);
|
generateBody(TimelineViewManager::displayName(event.sender()), color, body);
|
||||||
else
|
else
|
||||||
@ -127,7 +138,8 @@ void TimelineItem::generateBody(const QString &body)
|
|||||||
"</body>"
|
"</body>"
|
||||||
"</html>");
|
"</html>");
|
||||||
content_label_->setText(content.arg(replaceEmoji(body)));
|
content_label_->setText(content.arg(replaceEmoji(body)));
|
||||||
content_label_->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
content_label_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction);
|
||||||
|
content_label_->setOpenExternalLinks(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineItem::generateBody(const QString &userid, const QString &color, const QString &body)
|
void TimelineItem::generateBody(const QString &userid, const QString &color, const QString &body)
|
||||||
@ -155,7 +167,8 @@ void TimelineItem::generateBody(const QString &userid, const QString &color, con
|
|||||||
"</body>"
|
"</body>"
|
||||||
"</html>");
|
"</html>");
|
||||||
content_label_->setText(content.arg(color).arg(sender).arg(replaceEmoji(body)));
|
content_label_->setText(content.arg(color).arg(sender).arg(replaceEmoji(body)));
|
||||||
content_label_->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
content_label_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction);
|
||||||
|
content_label_->setOpenExternalLinks(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineItem::generateTimestamp(const QDateTime &time)
|
void TimelineItem::generateTimestamp(const QDateTime &time)
|
||||||
|
Loading…
Reference in New Issue
Block a user