1// Copyright (C) 2021 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 "qquickstyleitemtreeindicator.h"
5
6QT_BEGIN_NAMESPACE
7
8void QQuickStyleItemTreeIndicator::connectToControl() const
9{
10 QQuickStyleItem::connectToControl();
11 auto delegate = control<QQuickTreeViewDelegate>();
12 connect(sender: delegate, signal: &QQuickTreeViewDelegate::expandedChanged, context: this, slot: &QQuickStyleItem::markImageDirty);
13}
14
15StyleItemGeometry QQuickStyleItemTreeIndicator::calculateGeometry()
16{
17 QStyleOptionViewItem styleOption;
18 initStyleOption(styleOption);
19 StyleItemGeometry geometry;
20
21 geometry.minimumSize = QSize(20, 20);
22 geometry.implicitSize = geometry.minimumSize;
23 styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
24
25 return geometry;
26}
27
28void QQuickStyleItemTreeIndicator::paintEvent(QPainter *painter) const
29{
30 QStyleOptionViewItem styleOption;
31 initStyleOption(styleOption);
32 style()->drawPrimitive(pe: QStyle::PE_IndicatorBranch, opt: &styleOption, p: painter);
33}
34
35void QQuickStyleItemTreeIndicator::initStyleOption(QStyleOptionViewItem &styleOption) const
36{
37 initStyleOptionBase(styleOption);
38 auto delegate = control<QQuickTreeViewDelegate>();
39
40 styleOption.state |= QStyle::State_Children;
41
42 if (delegate->expanded())
43 styleOption.state |= QStyle::State_Open;
44}
45
46QT_END_NAMESPACE
47
48#include "moc_qquickstyleitemtreeindicator.cpp"
49

source code of qtdeclarative/src/quicknativestyle/items/qquickstyleitemtreeindicator.cpp