Skip to content

Commit 569a3dd

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 bcba9f6 commit 569a3dd

File tree

3 files changed

+72
-44
lines changed

3 files changed

+72
-44
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: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,43 @@ import QtQuick.Layouts
99

1010
Item {
1111
id: root
12-
12+
1313
required property PersistentProperties visibilities
1414
required property PersistentProperties state
1515
readonly property real nonAnimWidth: view.implicitWidth + viewWrapper.anchors.margins * 2
16+
readonly property bool showTabs: Config.dashboard.enableMedia || Config.dashboard.enablePerformance
1617

1718
implicitWidth: nonAnimWidth
18-
implicitHeight: tabs.implicitHeight + tabs.anchors.topMargin + view.implicitHeight + viewWrapper.anchors.margins * 2
19+
implicitHeight: (showTabs ? tabs.implicitHeight + tabs.anchors.topMargin : 0) + view.implicitHeight + viewWrapper.anchors.margins * 2
1920

20-
Tabs {
21+
Loader {
2122
id: tabs
22-
23+
asynchronous: true
2324
anchors.top: parent.top
2425
anchors.left: parent.left
2526
anchors.right: parent.right
2627
anchors.topMargin: Appearance.padding.normal
2728
anchors.margins: Appearance.padding.large
2829

29-
nonAnimWidth: root.nonAnimWidth - anchors.margins * 2
30-
state: root.state
30+
sourceComponent: showTabs ? tabsComponent : null
31+
}
32+
33+
Component {
34+
id: tabsComponent
35+
Tabs {
36+
nonAnimWidth: root.nonAnimWidth - parent.anchors.margins * 2
37+
state: root.state
38+
}
3139
}
3240

3341
ClippingRectangle {
3442
id: viewWrapper
3543

36-
anchors.top: tabs.bottom
44+
anchors.top: showTabs ? tabs.bottom : parent.top
3745
anchors.left: parent.left
3846
anchors.right: parent.right
3947
anchors.bottom: parent.bottom
48+
anchors.topMargin: !showTabs ? Appearance.padding.normal : Appearance.padding.large
4049
anchors.margins: Appearance.padding.large
4150

4251
radius: Appearance.rounding.normal
@@ -46,19 +55,42 @@ Item {
4655
id: view
4756

4857
readonly property int currentIndex: root.state.currentTab
49-
readonly property Item currentItem: row.children[currentIndex]
50-
58+
readonly property Item currentItem: panelGenerator.count > 0 ? panelGenerator.itemAt(currentIndex) : null
59+
property list<Component> panelModel: [
60+
dash,
61+
Config.dashboard.enableMedia ? media : null,
62+
Config.dashboard.enablePerformance ? performance : null
63+
].filter(panel => panel != null)
64+
5165
anchors.fill: parent
5266

5367
flickableDirection: Flickable.HorizontalFlick
5468

55-
implicitWidth: currentItem.implicitWidth
56-
implicitHeight: currentItem.implicitHeight
69+
implicitWidth: currentItem?.implicitWidth ?? 0
70+
implicitHeight: currentItem?.implicitHeight ?? 0
5771

58-
contentX: currentItem.x
72+
contentX: currentItem?.x ?? 0
5973
contentWidth: row.implicitWidth
6074
contentHeight: row.implicitHeight
6175

76+
Component {
77+
id: dash
78+
Dash {
79+
visibilities: root.visibilities
80+
state: root.state
81+
}
82+
}
83+
84+
Component {
85+
id: media
86+
Media { visibilities: root.visibilities }
87+
}
88+
89+
Component {
90+
id: performance
91+
Performance {}
92+
}
93+
6294
onContentXChanged: {
6395
if (!moving)
6496
return;
@@ -80,25 +112,20 @@ Item {
80112
contentX = Qt.binding(() => currentItem.x);
81113
}
82114

115+
onPanelModelChanged: {
116+
panelGenerator.model = panelModel
117+
}
118+
83119
RowLayout {
84120
id: row
85-
86-
Pane {
87-
sourceComponent: Dash {
88-
visibilities: root.visibilities
89-
state: root.state
121+
122+
Repeater {
123+
id: panelGenerator
124+
delegate: Pane {
125+
required property Component modelData
126+
sourceComponent: modelData
90127
}
91-
}
92-
93-
Pane {
94-
sourceComponent: Media {
95-
visibilities: root.visibilities
96-
}
97-
}
98-
99-
Pane {
100-
sourceComponent: Performance {}
101-
}
128+
}
102129
}
103130

104131
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)