-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml_node_display.cpp
47 lines (38 loc) · 1.32 KB
/
xml_node_display.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "utils.h"
#include "xml_node_display.h"
namespace xml_viewer
{
XML_node_display::XML_node_display()
{
setReadOnly(true);
setOpenExternalLinks(true);
QFont font(this->font().family(), 25);
setFont(font);
setTextInteractionFlags(
Qt::TextBrowserInteraction | Qt::TextSelectableByKeyboard);
mappings_filter_ = make_unique<Editor_mappings>();
installEventFilter(mappings_filter_.get());
}
void XML_node_display::display_node_text(const QTreeWidgetItem* new_node)
{
if(new_node == nullptr){
clear();
return;
}
setHtml(highlighted_text(*new_node));
}
QString highlighted_text(const QTreeWidgetItem& item)
{
QString text{item.text(0).toHtmlEscaped()};
if(item.data(0, User_roles::is_element).toBool()){
text.replace(QRegularExpression("(\\S*?)=(\\S*)"),
QString("<font color=DarkOrange>\\1</font>=\\2"));
text.replace(QRegularExpression("^\\s*(\\S+)"),
QString("<b><font color=blue>\\1</font></b>"));
}
text.replace(
QRegularExpression("((https?|ftp|mailto)://\\S+)"),
QString("<a href='\\1'>\\1</a>"));
return QString("<html>%1</html>").arg(text);
}
}