aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicknativestyle/items/qquickstyleitemtreeindicator.cpp
blob: 1b0bd39b20ca06b5962bc69cfed2068d6405f8a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qquickstyleitemtreeindicator.h"

QT_BEGIN_NAMESPACE

void QQuickStyleItemTreeIndicator::connectToControl() const
{
    QQuickStyleItem::connectToControl();
    auto delegate = control<QQuickTreeViewDelegate>();
    connect(delegate, &QQuickTreeViewDelegate::expandedChanged, this, &QQuickStyleItem::markImageDirty);
}

StyleItemGeometry QQuickStyleItemTreeIndicator::calculateGeometry()
{
    QStyleOptionViewItem styleOption;
    initStyleOption(styleOption);
    StyleItemGeometry geometry;

    geometry.minimumSize = QSize(20, 20);
    geometry.implicitSize = geometry.minimumSize;
    styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);

    return geometry;
}

void QQuickStyleItemTreeIndicator::paintEvent(QPainter *painter) const
{
    QStyleOptionViewItem styleOption;
    initStyleOption(styleOption);
    style()->drawPrimitive(QStyle::PE_IndicatorBranch, &styleOption, painter);
}

void QQuickStyleItemTreeIndicator::initStyleOption(QStyleOptionViewItem &styleOption) const
{
    initStyleOptionBase(styleOption);
    auto delegate = control<QQuickTreeViewDelegate>();

    styleOption.state |= QStyle::State_Children;

    if (delegate->expanded())
        styleOption.state |= QStyle::State_Open;
}

QT_END_NAMESPACE

#include "moc_qquickstyleitemtreeindicator.cpp"