1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickitemdelegate_p.h"
5#include "qquickitemdelegate_p_p.h"
6#include "qquickcontrol_p_p.h"
7
8#include <QtGui/qpa/qplatformtheme.h>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \qmltype ItemDelegate
14 \inherits AbstractButton
15//! \instantiates QQuickItemDelegate
16 \inqmlmodule QtQuick.Controls
17 \since 5.7
18 \ingroup qtquickcontrols-delegates
19 \brief Basic item delegate that can be used in various views and controls.
20
21 \image qtquickcontrols-itemdelegate.gif
22
23 ItemDelegate presents a standard view item. It can be used as a delegate
24 in various views and controls, such as \l ListView and \l ComboBox.
25
26 ItemDelegate inherits its API from AbstractButton. For instance, you can set
27 \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon},
28 and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API.
29
30 \snippet qtquickcontrols-itemdelegate.qml 1
31
32 \sa {Customizing ItemDelegate}, {Delegate Controls}
33*/
34
35QQuickItemDelegate::QQuickItemDelegate(QQuickItem *parent)
36 : QQuickAbstractButton(*(new QQuickItemDelegatePrivate), parent)
37{
38 setFocusPolicy(Qt::NoFocus);
39}
40
41QQuickItemDelegate::QQuickItemDelegate(QQuickItemDelegatePrivate &dd, QQuickItem *parent)
42 : QQuickAbstractButton(dd, parent)
43{
44 setFocusPolicy(Qt::NoFocus);
45}
46
47/*!
48 \qmlproperty bool QtQuick.Controls::ItemDelegate::highlighted
49
50 This property holds whether the delegate is highlighted.
51
52 A delegate can be highlighted in order to draw the user's attention towards
53 it. It has no effect on keyboard interaction. For example, you can
54 highlight the current item in a ListView using the following code:
55
56 \code
57 ListView {
58 id: listView
59 model: 10
60 delegate: ItemDelegate {
61 text: index
62 highlighted: ListView.isCurrentItem
63
64 required property int index
65
66 onClicked: listView.currentIndex = index
67 }
68 }
69 \endcode
70
71 The default value is \c false.
72*/
73bool QQuickItemDelegate::isHighlighted() const
74{
75 Q_D(const QQuickItemDelegate);
76 return d->highlighted;
77}
78
79void QQuickItemDelegate::setHighlighted(bool highlighted)
80{
81 Q_D(QQuickItemDelegate);
82 if (highlighted == d->highlighted)
83 return;
84
85 d->highlighted = highlighted;
86 emit highlightedChanged();
87}
88
89QFont QQuickItemDelegate::defaultFont() const
90{
91 return QQuickTheme::font(scope: QQuickTheme::ItemView);
92}
93
94#if QT_CONFIG(accessibility)
95QAccessible::Role QQuickItemDelegate::accessibleRole() const
96{
97 return QAccessible::ListItem;
98}
99#endif
100
101QPalette QQuickItemDelegatePrivate::defaultPalette() const
102{
103 return QQuickTheme::palette(scope: QQuickTheme::ItemView);
104}
105
106QT_END_NAMESPACE
107
108#include "moc_qquickitemdelegate_p.cpp"
109

source code of qtdeclarative/src/quicktemplates/qquickitemdelegate.cpp