1 /* url_link_delegate.cpp
2 * Delegates for displaying links as links, including elide model
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include <ui/qt/models/url_link_delegate.h>
15 #include <ui/qt/utils/color_utils.h>
17 UrlLinkDelegate::UrlLinkDelegate(QObject
*parent
)
18 : QStyledItemDelegate(parent
),
20 url_re_(new QRegularExpression())
23 UrlLinkDelegate::~UrlLinkDelegate()
28 void UrlLinkDelegate::setColCheck(int column
, QString
&pattern
)
31 url_re_
->setPattern(pattern
);
34 void UrlLinkDelegate::paint(QPainter
*painter
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const {
35 if (re_col_
>= 0 && url_re_
) {
36 QModelIndex re_idx
= index
.model()->index(index
.row(), re_col_
);
37 QString col_text
= index
.model()->data(re_idx
).toString();
38 if (!url_re_
->match(col_text
).hasMatch()) {
39 QStyledItemDelegate::paint(painter
, option
, index
);
44 QStyleOptionViewItem opt
= option
;
45 initStyleOption(&opt
, index
);
47 opt
.font
.setUnderline(true);
48 opt
.palette
.setColor(QPalette::Text
, ColorUtils::themeLinkBrush().color());
50 QStyledItemDelegate::paint(painter
, opt
, index
);