diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-08-19 14:29:17 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-09-02 17:53:22 +0000 |
commit | e5ca1ed5fd43796dd7623663f4aace4181899a0f (patch) | |
tree | 14bc5c82f7b0010c93cd57cb2b0764c4a373b64c | |
parent | 58c7a36f5cf5ec70433e644522e8afe4509a1eb1 (diff) |
Material: add TreeViewDelegate.qml
Add a version of TreeViewDelegate.qml to the Material
style, that looks more at home for that style (rather
than using the one in the Basic style).
This version is using the arrow-indicator from the
Material style as expand/collapse indicator, and
makes the height of each row match the height of a
normal Material button.
Change-Id: I084532ca6e527593e5711d66aa53f240f0356d99
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit 55fab9a73e720a84d0f0a86cc4175f34a4573188)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
4 files changed, 65 insertions, 2 deletions
diff --git a/src/quickcontrols2/material/CMakeLists.txt b/src/quickcontrols2/material/CMakeLists.txt index 19c68ebff9..2ca69fcad9 100644 --- a/src/quickcontrols2/material/CMakeLists.txt +++ b/src/quickcontrols2/material/CMakeLists.txt @@ -53,6 +53,7 @@ set(qml_files "ToolButton.qml" "ToolSeparator.qml" "ToolTip.qml" + "TreeViewDelegate.qml" "Tumbler.qml" "VerticalHeaderView.qml" ) diff --git a/src/quickcontrols2/material/TreeViewDelegate.qml b/src/quickcontrols2/material/TreeViewDelegate.qml new file mode 100644 index 0000000000..a7be36a555 --- /dev/null +++ b/src/quickcontrols2/material/TreeViewDelegate.qml @@ -0,0 +1,62 @@ +// Copyright (C) 2022 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 + +import QtQuick +import QtQuick.Templates as T +import QtQuick.Controls.impl +import QtQuick.Controls.Material + +T.TreeViewDelegate { + id: control + + implicitWidth: leftMargin + __contentIndent + implicitContentWidth + rightPadding + rightMargin + implicitHeight: Math.max(implicitBackgroundHeight, implicitContentHeight, implicitIndicatorHeight) + + indentation: indicator ? indicator.width : 12 + leftMargin: 16 + rightMargin: 16 + spacing: 14 + + topPadding: contentItem ? (height - contentItem.implicitHeight) / 2 : 0 + leftPadding: !mirrored ? leftMargin + __contentIndent : width - leftMargin - __contentIndent - implicitContentWidth + + highlighted: control.selected || control.current + || ((control.treeView.selectionBehavior === TableView.SelectRows + || control.treeView.selectionBehavior === TableView.SelectionDisabled) + && control.row === control.treeView.currentRow) + + required property int row + required property var model + readonly property real __contentIndent: !isTreeNode ? 0 : (depth * indentation) + (indicator ? indicator.width + spacing : 0) + + indicator: Item { + readonly property real __indicatorIndent: control.leftMargin + (control.depth * control.indentation) + x: !control.mirrored ? __indicatorIndent : control.width - __indicatorIndent - width + y: (control.height - height) / 2 + implicitWidth: Math.max(arrow.implicitWidth, 20) + implicitHeight: control.Material.buttonHeight + + property ColorImage arrow : ColorImage { + parent: control.indicator + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + rotation: control.expanded ? 90 : (control.mirrored ? 180 : 0) + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Material/images/arrow-indicator.png" + color: control.palette.windowText + defaultColor: "#353637" + } + } + + background: Rectangle { + implicitHeight: control.Material.buttonHeight + color: control.highlighted + ? control.palette.highlight + : (control.treeView.alternatingRows && control.row % 2 !== 0 + ? control.palette.alternateBase : control.palette.base) + } + + contentItem: Label { + text: control.model.display + elide: Text.ElideRight + } +} diff --git a/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp b/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp index 60e55506fb..660be4ad4a 100644 --- a/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp +++ b/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp @@ -125,7 +125,7 @@ void tst_CreationTime::material_data() QTest::addColumn<QUrl>("url"); addTestRowForEachControl(styleHelper.engine.data(), QQC2_IMPORT_PATH, "material", "QtQuick/Controls/Material", QStringList() << "ApplicationWindow" << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" - << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); + << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate" << "TreeViewDelegate"); } void tst_CreationTime::universal() diff --git a/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp b/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp index c14b341c51..dbda2048b4 100644 --- a/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp +++ b/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp @@ -72,7 +72,7 @@ static void initTestRows(QQmlEngine *engine) addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "imagine", "QtQuick/Controls/Imagine"); addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "material", "QtQuick/Controls/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" - << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); + << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate" << "TreeViewDelegate"); addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "universal", "QtQuick/Controls/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } |