Skip to content

Commit ab83821

Browse files
committed
making media and perf tabs toggleable
added two config options in the dashboard section to enable/disable the media tab and the performance tab. if both are disabled, the tab bar in the dashboard is hidden. still a bit of jerkiness when config values resolve, not sure how to fix that. also, the way i'm conditionally showing panels is kinda janky, i'm sure there are better ways to do this...
1 parent d90c4b6 commit ab83821

File tree

3 files changed

+73
-45
lines changed

3 files changed

+73
-45
lines changed

config/DashboardConfig.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ JsonObject {
77
property int dragThreshold: 50
88
property Sizes sizes: Sizes {}
99

10+
property bool enableMedia: true
11+
property bool enablePerformance: true
12+
1013
component Sizes: JsonObject {
1114
readonly property int tabIndicatorHeight: 3
1215
readonly property int tabIndicatorSpacing: 5

modules/dashboard/Content.qml

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,44 @@ import QtQuick.Layouts
1010

1111
Item {
1212
id: root
13-
13+
1414
required property PersistentProperties visibilities
1515
required property PersistentProperties state
1616
required property FileDialog facePicker
1717
readonly property real nonAnimWidth: view.implicitWidth + viewWrapper.anchors.margins * 2
18+
readonly property bool showTabs: Config.dashboard.enableMedia || Config.dashboard.enablePerformance
1819

1920
implicitWidth: nonAnimWidth
20-
implicitHeight: tabs.implicitHeight + tabs.anchors.topMargin + view.implicitHeight + viewWrapper.anchors.margins * 2
21+
implicitHeight: (showTabs ? tabs.implicitHeight + tabs.anchors.topMargin : 0) + view.implicitHeight + viewWrapper.anchors.margins * 2
2122

22-
Tabs {
23+
Loader {
2324
id: tabs
24-
25+
asynchronous: true
2526
anchors.top: parent.top
2627
anchors.left: parent.left
2728
anchors.right: parent.right
2829
anchors.topMargin: Appearance.padding.normal
2930
anchors.margins: Appearance.padding.large
3031

31-
nonAnimWidth: root.nonAnimWidth - anchors.margins * 2
32-
state: root.state
32+
sourceComponent: root.showTabs ? tabsComponent : null
33+
}
34+
35+
Component {
36+
id: tabsComponent
37+
Tabs {
38+
nonAnimWidth: root.nonAnimWidth - parent.anchors.margins * 2
39+
state: root.state
40+
}
3341
}
3442

3543
ClippingRectangle {
3644
id: viewWrapper
3745

38-
anchors.top: tabs.bottom
46+
anchors.top: root.showTabs ? tabs.bottom : parent.top
3947
anchors.left: parent.left
4048
anchors.right: parent.right
4149
anchors.bottom: parent.bottom
50+
anchors.topMargin: !root.showTabs ? Appearance.padding.normal : Appearance.padding.large
4251
anchors.margins: Appearance.padding.large
4352

4453
radius: Appearance.rounding.normal
@@ -48,19 +57,43 @@ Item {
4857
id: view
4958

5059
readonly property int currentIndex: root.state.currentTab
51-
readonly property Item currentItem: row.children[currentIndex]
52-
60+
readonly property Item currentItem: panelGenerator.count > 0 ? panelGenerator.itemAt(currentIndex) : null
61+
property list<Component> panelModel: [
62+
dash,
63+
Config.dashboard.enableMedia ? media : null,
64+
Config.dashboard.enablePerformance ? performance : null
65+
].filter(panel => panel != null)
66+
5367
anchors.fill: parent
5468

5569
flickableDirection: Flickable.HorizontalFlick
5670

57-
implicitWidth: currentItem.implicitWidth
58-
implicitHeight: currentItem.implicitHeight
71+
implicitWidth: currentItem?.implicitWidth ?? 0
72+
implicitHeight: currentItem?.implicitHeight ?? 0
5973

60-
contentX: currentItem.x
74+
contentX: currentItem?.x ?? 0
6175
contentWidth: row.implicitWidth
6276
contentHeight: row.implicitHeight
6377

78+
Component {
79+
id: dash
80+
Dash {
81+
visibilities: root.visibilities
82+
state: root.state
83+
facePicker: root.facePicker
84+
}
85+
}
86+
87+
Component {
88+
id: media
89+
Media { visibilities: root.visibilities }
90+
}
91+
92+
Component {
93+
id: performance
94+
Performance {}
95+
}
96+
6497
onContentXChanged: {
6598
if (!moving)
6699
return;
@@ -82,26 +115,20 @@ Item {
82115
contentX = Qt.binding(() => currentItem.x);
83116
}
84117

118+
onPanelModelChanged: {
119+
panelGenerator.model = panelModel
120+
}
121+
85122
RowLayout {
86123
id: row
87-
88-
Pane {
89-
sourceComponent: Dash {
90-
visibilities: root.visibilities
91-
state: root.state
92-
facePicker: root.facePicker
124+
125+
Repeater {
126+
id: panelGenerator
127+
delegate: Pane {
128+
required property Component modelData
129+
sourceComponent: modelData
93130
}
94-
}
95-
96-
Pane {
97-
sourceComponent: Media {
98-
visibilities: root.visibilities
99-
}
100-
}
101-
102-
Pane {
103-
sourceComponent: Performance {}
104-
}
131+
}
105132
}
106133

107134
Behavior on contentX {

modules/dashboard/Tabs.qml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ Item {
1515
required property real nonAnimWidth
1616
required property PersistentProperties state
1717
readonly property alias count: bar.count
18+
property list<var> tabsModel: [
19+
{ iconName: "dashboard", tabtext: qsTr("Dashboard") },
20+
Config.dashboard.enableMedia ? { iconName: "queue_music", tabtext: qsTr("Media") } : null,
21+
Config.dashboard.enablePerformance ? { iconName: "speed", tabtext: qsTr("Performance") } : null,
22+
].filter(tab => tab != null)
1823

1924
implicitHeight: bar.implicitHeight + indicator.implicitHeight + indicator.anchors.topMargin + separator.implicitHeight
2025

@@ -29,20 +34,13 @@ Item {
2934
background: null
3035

3136
onCurrentIndexChanged: root.state.currentTab = currentIndex
32-
33-
Tab {
34-
iconName: "dashboard"
35-
text: qsTr("Dashboard")
36-
}
37-
38-
Tab {
39-
iconName: "queue_music"
40-
text: qsTr("Media")
41-
}
42-
43-
Tab {
44-
iconName: "speed"
45-
text: qsTr("Performance")
37+
38+
Repeater {
39+
model: tabsModel
40+
Tab {
41+
required property string tabtext
42+
text: tabtext
43+
}
4644
}
4745

4846
// Tab {
@@ -57,13 +55,13 @@ Item {
5755
anchors.top: bar.bottom
5856
anchors.topMargin: Config.dashboard.sizes.tabIndicatorSpacing
5957

60-
implicitWidth: bar.currentItem.implicitWidth
58+
implicitWidth: count > 0 ? bar.currentItem.implicitWidth : 0
6159
implicitHeight: Config.dashboard.sizes.tabIndicatorHeight
6260

6361
x: {
6462
const tab = bar.currentItem;
6563
const width = (root.nonAnimWidth - bar.spacing * (bar.count - 1)) / bar.count;
66-
return width * tab.TabBar.index + (width - tab.implicitWidth) / 2;
64+
return width * (tab?.TabBar.index ?? 0) + (width - (tab?.implicitWidth ?? 0)) / 2;
6765
}
6866

6967
clip: true

0 commit comments

Comments
 (0)