aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-08-24 11:28:00 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-31 22:48:31 +0000
commitd26d6baeccc608aecf27115cd7c3ec8fe761653f (patch)
tree010286aeaaa2b57a74ed94a44b8674f3cad0ccdb
parent0faa066bb1609c8135c8e5c800bcae25aaff437d (diff)
Fusion: add TreeViewDelegate
Add a version of TreeViewDelegate.qml to the Fusion 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 Fusion style as expand/collapse indicator, and makes the height of each row match the height of a normal Fusion button. Change-Id: I153bb5776e23476cf8c383fb6f76e63981e28639 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 13a8df4a878a4f62e626b577cb92a2e0d0ba54c9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quickcontrols2/fusion/CMakeLists.txt1
-rw-r--r--src/quickcontrols2/fusion/TreeViewDelegate.qml62
-rw-r--r--tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp2
-rw-r--r--tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp3
4 files changed, 66 insertions, 2 deletions
diff --git a/src/quickcontrols2/fusion/CMakeLists.txt b/src/quickcontrols2/fusion/CMakeLists.txt
index 86a389822c..49bd660a65 100644
--- a/src/quickcontrols2/fusion/CMakeLists.txt
+++ b/src/quickcontrols2/fusion/CMakeLists.txt
@@ -51,6 +51,7 @@ set(qml_files
"ToolButton.qml"
"ToolSeparator.qml"
"ToolTip.qml"
+ "TreeViewDelegate.qml"
"Tumbler.qml"
"VerticalHeaderView.qml"
)
diff --git a/src/quickcontrols2/fusion/TreeViewDelegate.qml b/src/quickcontrols2/fusion/TreeViewDelegate.qml
new file mode 100644
index 0000000000..5223361872
--- /dev/null
+++ b/src/quickcontrols2/fusion/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.Fusion
+
+T.TreeViewDelegate {
+ id: control
+
+ implicitWidth: leftMargin + __contentIndent + implicitContentWidth + rightPadding + rightMargin
+ implicitHeight: Math.max(implicitBackgroundHeight, implicitContentHeight, implicitIndicatorHeight)
+
+ indentation: indicator ? indicator.width : 12
+ leftMargin: 5
+ rightMargin: 5
+ spacing: 5
+
+ 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: 24 // same as Button.qml
+
+ property ColorImage arrow : ColorImage {
+ parent: control.indicator
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ rotation: control.expanded ? 0 : (control.mirrored ? 90 : -90)
+ source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png"
+ color: control.palette.windowText
+ defaultColor: "#353637"
+ }
+ }
+
+ background: Rectangle {
+ implicitHeight: 24 // same as Button.qml
+ 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 2e37d00dd8..60e55506fb 100644
--- a/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp
+++ b/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp
@@ -98,7 +98,7 @@ void tst_CreationTime::fusion_data()
QTest::addColumn<QUrl>("url");
addTestRowForEachControl(styleHelper.engine.data(), QQC2_IMPORT_PATH, "fusion", "QtQuick/Controls/Fusion",
QStringList() << "ApplicationWindow" << "ButtonPanel" << "CheckIndicator"
- << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator");
+ << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator" << "TreeViewDelegate");
}
void tst_CreationTime::imagine()
diff --git a/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp b/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp
index aad8e7d571..c14b341c51 100644
--- a/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp
+++ b/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp
@@ -67,7 +67,8 @@ static void initTestRows(QQmlEngine *engine)
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "basic", "QtQuick/Controls/Basic",
QStringList() << "Calendar" << "TreeViewDelegate");
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "fusion", "QtQuick/Controls/Fusion",
- QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator");
+ QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove"
+ << "SliderHandle" << "SwitchIndicator" << "TreeViewDelegate");
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "imagine", "QtQuick/Controls/Imagine");
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "material", "QtQuick/Controls/Material",
QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator"