forked from osmocom/wireshark
67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
/* html_text_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/html_text_delegate.h>
|
|
|
|
#include <QComboBox>
|
|
#include <QEvent>
|
|
#include <QLineEdit>
|
|
#include <QPainter>
|
|
#include <QTextDocument>
|
|
#include <QRect>
|
|
#include <QStyledItemDelegate>
|
|
#include <QStyleOptionViewItem>
|
|
#include <QString>
|
|
|
|
HTMLTextDelegate::HTMLTextDelegate(QObject *parent)
|
|
: QStyledItemDelegate(parent)
|
|
{}
|
|
|
|
void HTMLTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
|
QStyleOptionViewItem options = option;
|
|
initStyleOption(&options, index);
|
|
|
|
painter->save();
|
|
|
|
QTextDocument doc;
|
|
doc.setHtml(options.text);
|
|
|
|
options.text = QStringLiteral("");
|
|
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &option, painter);
|
|
|
|
painter->translate(options.rect.left(), options.rect.top());
|
|
QRect clip(0, 0, options.rect.width(), options.rect.height());
|
|
doc.drawContents(painter, clip);
|
|
|
|
painter->restore();
|
|
}
|
|
|
|
QSize HTMLTextDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
|
QStyleOptionViewItem options = option;
|
|
initStyleOption(&options, index);
|
|
|
|
QTextDocument doc;
|
|
doc.setHtml(options.text);
|
|
doc.setTextWidth(options.rect.width());
|
|
return QSize(doc.idealWidth(), doc.size().height());
|
|
}
|
|
|
|
/* * 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:
|
|
*/
|