Skip to content

Commit

Permalink
chore: add ControlGroup
Browse files Browse the repository at this point in the history
add ControlGroup

Log:
  • Loading branch information
wangfei committed Jul 22, 2024
1 parent a6ccd0f commit d9588d7
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
52 changes: 52 additions & 0 deletions examples/exhibition/ControlGroup.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.0
import QtQuick.Window 2.11
import QtQuick.Layouts 1.11
import org.deepin.dtk 1.0
import ".."

ControlGroup {
title: "磁盘"
ControlGroupItem {
Label {
visible: true
text: "test0111111111111"
}
Label {
visible: true
text: "test13333333333"
}
}
ControlGroupItem {
Rectangle {
width: 100
height: 100
color: "red"
border.color: "black"
border.width: 5
radius: 10
}
Switch {
checked: true
Layout.alignment: Qt.AlignHCenter
}
}
ControlGroupItem {
Rectangle {
width: 100
height: 100
color: "green"
border.color: "black"
border.width: 5
radius: 10
}
Button {
width: 100
height: 100
Layout.alignment: Qt.AlignHCenter
}
}
}
1 change: 1 addition & 0 deletions examples/exhibition/qml-qt6.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<file>ToolBar.qml</file>
<file>Dialog.qml</file>
<file>ProgressBar.qml</file>
<file>ControlGroup.qml</file>
</qresource>
</RCC>
2 changes: 2 additions & 0 deletions qt6/src/dtkdeclarative_qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
<file>qml/ButtonIndicator.qml</file>
<file>qml/EmbeddedProgressBar.qml</file>
<file>qml/WaterProgressBar.qml</file>
<file>qml/ControlGroup.qml</file>
<file>qml/ControlGroupItem.qml</file>
<file>qml/private/ProgressBarImpl.qml</file>
<file>qml/private/ProgressBarPanel.qml</file>
<file>qml/PlaceholderText.qml</file>
Expand Down
2 changes: 2 additions & 0 deletions qt6/src/qml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ set(QML_DTK_CONTROLS
"qml/EmbeddedProgressBar.qml"
"qml/WaterProgressBar.qml"
"qml/PlaceholderText.qml"
"qml/ControlGroup.qml"
"qml/ControlGroupItem.qml"
)

foreach(QML_FILE ${QML_DTK_CONTROLS})
Expand Down
67 changes: 67 additions & 0 deletions qt6/src/qml/ControlGroup.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.0
import QtQuick.Layouts 1.11
import org.deepin.dtk 1.0

ColumnLayout {
id: root
spacing: 10
clip: true

property string title
property bool isExpanded: true
property int interval: 400 / (itemLayout.children.length)
property int duration: 0
property int index: 0
property int titleHeight: 36
default property alias childItem: itemLayout.children

ItemDelegate {
id: titleBar
Layout.fillWidth: true; Layout.preferredHeight: titleHeight
text: title
icon.name: isExpanded ? "go-down": "go-next"
display: IconLabel.IconBesideText
checkable: false
font: DTK.fontManager.t5
backgroundVisible: hovered
MouseArea {
anchors.fill: parent
onClicked: {
root.isExpanded = !root.isExpanded
}
}
}

Timer {
id: timer
}

ColumnLayout {
id: itemLayout
}

onIsExpandedChanged: (isExpanded) => {
delay(interval, timeout)
}

function timeout() {
itemLayout.children[index].isExpanded = !itemLayout.children[index].isExpanded
++index
if (index === itemLayout.children.length) {
timer.stop()
timer.triggered.disconnect(timeout)
index = 0
}
}

function delay(delayTime, cb) {
timer.interval = delayTime
timer.repeat = true
timer.triggered.connect(cb)
timer.restart()
}
}
39 changes: 39 additions & 0 deletions qt6/src/qml/ControlGroupItem.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.0
import QtQuick.Layouts 1.11
import QtQml.Models 2.11
import org.deepin.dtk 1.0

RowLayout {
id: root

property int initY
property bool isExpanded: true

y: isExpanded ? initY : - parent.parent.titleHeight
opacity: isExpanded ? 1.0 : 0.0
visible: opacity === 0.0 ? false : true

Layout.fillWidth: true
Layout.fillHeight: true

Behavior on y {
NumberAnimation {
duration: parent.parent.interval
easing.type: Easing.Linear
}
}
Behavior on opacity {
NumberAnimation {
duration: parent.parent.interval
easing.type: Easing.Linear
}
}

Component.onCompleted: {
root.initY = root.y
}
}

0 comments on commit d9588d7

Please sign in to comment.