1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qquickitemdelegate_p.h"
38#include "qquickitemdelegate_p_p.h"
39#include "qquickcontrol_p_p.h"
40
41#include <QtGui/qpa/qplatformtheme.h>
42
43QT_BEGIN_NAMESPACE
44
45/*!
46 \qmltype ItemDelegate
47 \inherits AbstractButton
48//! \instantiates QQuickItemDelegate
49 \inqmlmodule QtQuick.Controls
50 \since 5.7
51 \brief Basic item delegate that can be used in various views and controls.
52
53 \image qtquickcontrols2-itemdelegate.gif
54
55 ItemDelegate presents a standard view item. It can be used as a delegate
56 in various views and controls, such as \l ListView and \l ComboBox.
57
58 ItemDelegate inherits its API from AbstractButton. For instance, you can set
59 \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon},
60 and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API.
61
62 \snippet qtquickcontrols2-itemdelegate.qml 1
63
64 \sa {Customizing ItemDelegate}, {Delegate Controls}
65*/
66
67QQuickItemDelegate::QQuickItemDelegate(QQuickItem *parent)
68 : QQuickAbstractButton(*(new QQuickItemDelegatePrivate), parent)
69{
70 setFocusPolicy(Qt::NoFocus);
71}
72
73QQuickItemDelegate::QQuickItemDelegate(QQuickItemDelegatePrivate &dd, QQuickItem *parent)
74 : QQuickAbstractButton(dd, parent)
75{
76 setFocusPolicy(Qt::NoFocus);
77}
78
79/*!
80 \qmlproperty bool QtQuick.Controls::ItemDelegate::highlighted
81
82 This property holds whether the delegate is highlighted.
83
84 A delegate can be highlighted in order to draw the user's attention towards
85 it. It has no effect on keyboard interaction. For example, you can
86 highlight the current item in a ListView using the following code:
87
88 \code
89 ListView {
90 id: listView
91 model: 10
92 delegate: ItemDelegate {
93 text: modelData
94 highlighted: ListView.isCurrentItem
95 onClicked: listView.currentIndex = index
96 }
97 }
98 \endcode
99
100 The default value is \c false.
101*/
102bool QQuickItemDelegate::isHighlighted() const
103{
104 Q_D(const QQuickItemDelegate);
105 return d->highlighted;
106}
107
108void QQuickItemDelegate::setHighlighted(bool highlighted)
109{
110 Q_D(QQuickItemDelegate);
111 if (highlighted == d->highlighted)
112 return;
113
114 d->highlighted = highlighted;
115 emit highlightedChanged();
116}
117
118QFont QQuickItemDelegate::defaultFont() const
119{
120 return QQuickTheme::font(scope: QQuickTheme::ItemView);
121}
122
123QPalette QQuickItemDelegate::defaultPalette() const
124{
125 return QQuickTheme::palette(scope: QQuickTheme::ItemView);
126}
127
128#if QT_CONFIG(accessibility)
129QAccessible::Role QQuickItemDelegate::accessibleRole() const
130{
131 return QAccessible::ListItem;
132}
133#endif
134
135QT_END_NAMESPACE
136

source code of qtquickcontrols2/src/quicktemplates2/qquickitemdelegate.cpp