Akonadi Contacts

addressdelegate.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "addressdelegate.h"
10
11#include <QAbstractTextDocumentLayout>
12#include <QPainter>
13#include <QTextDocument>
14
15using namespace Akonadi;
16
17AddressDelegate::AddressDelegate(QObject *parent)
18 : QStyledItemDelegate(parent)
19{
20}
21
22QSize AddressDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
23{
24 QStyleOptionViewItem options = option;
25 initStyleOption(&options, index);
26
27 QTextDocument doc;
28 doc.setHtml(options.text);
29 doc.setTextWidth(options.rect.width());
30 return QSize(doc.idealWidth(), doc.size().height());
31}
32
33void AddressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
34{
35 QStyleOptionViewItem options = option;
36 initStyleOption(&options, index);
37
38 painter->save();
39 QTextDocument doc;
40 doc.setHtml(options.text);
41 options.text = QString();
42 options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
43 painter->translate(options.rect.left(), options.rect.top());
44
45 const QRect clip(0, 0, options.rect.width(), options.rect.height());
47 ctx.clip = clip;
48 if (option.state & QStyle::State_Selected) {
49 ctx.palette.setColor(QPalette::Text, options.palette.color(QPalette::HighlightedText));
50 }
51 doc.documentLayout()->draw(painter, ctx);
52 painter->restore();
53}
54
55#include "moc_addressdelegate.cpp"
A widget for editing the display name of a contact.
virtual void draw(QPainter *painter, const PaintContext &context)=0
void restore()
void save()
void translate(const QPoint &offset)
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const const
QAbstractTextDocumentLayout * documentLayout() const const
qreal idealWidth() const const
void setHtml(const QString &html)
void setTextWidth(qreal width)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.