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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/* url_link_delegate.cpp
* Delegates for displaying links as links, including elide model
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <ui/qt/models/url_link_delegate.h>
#include <QPainter>
#include <QRegExp>
UrlLinkDelegate::UrlLinkDelegate(QObject *parent)
: QStyledItemDelegate(parent),
re_col_(-1),
url_re_(new QRegExp())
{}
UrlLinkDelegate::~UrlLinkDelegate()
{
delete url_re_;
}
void UrlLinkDelegate::setColCheck(int column, QString &pattern)
{
re_col_ = column;
url_re_->setPattern(pattern);
}
void UrlLinkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
if (re_col_ >= 0 && url_re_) {
QModelIndex re_idx = index.model()->index(index.row(), re_col_);
QString col_text = index.model()->data(re_idx).toString();
if (url_re_->indexIn(col_text) < 0) {
QStyledItemDelegate::paint(painter, option, index);
return;
}
}
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
opt.font.setUnderline(true);
opt.palette.setColor(QPalette::Text, opt.palette.link().color());
QStyledItemDelegate::paint(painter, opt, index);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
|