Improve tab bar of Plasmoid (use footer and improve sizing of elements)

This commit is contained in:
Martchus 2021-12-01 18:53:23 +01:00
parent cb1071b3ad
commit b02a3a0c9b
2 changed files with 58 additions and 55 deletions

View File

@ -7,12 +7,48 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.components 3.0 as PlasmaComponents3
PlasmaComponents3.Page { PlasmaComponents3.Page {
// header ("toolbar" with buttons and combo box) and footer ("tabbar")
header: PlasmaExtras.PlasmoidHeading { header: PlasmaExtras.PlasmoidHeading {
ToolBar { ToolBar {
id: toolbar id: toolbar
width: parent.width width: parent.width
} }
} }
footer: PlasmaExtras.PlasmoidHeading {
spacing: 0
height: units.iconSizes.medium
PlasmaComponents3.TabBar {
id: tabBar
readonly property double buttonWidth: parent.width / count
position: PlasmaComponents3.TabBar.Footer
Layout.fillWidth: true
Layout.fillHeight: true
TabButton {
id: dirsTabButton
text: qsTr("Directories")
icon.source: "image://fa/folder"
width: tabBar.buttonWidth
}
TabButton {
id: devsTabButton
text: qsTr("Devices")
icon.source: "image://fa/sitemap"
width: tabBar.buttonWidth
}
TabButton {
id: downloadsTabButton
text: qsTr("Downloads")
icon.source: "image://fa/download"
width: tabBar.buttonWidth
}
TabButton {
id: recentChangesTabButton
text: qsTr("History")
icon.source: "image://fa/history"
width: tabBar.buttonWidth
}
}
}
// define functions to locate the current page and filter // define functions to locate the current page and filter
function findCurrentPage() { function findCurrentPage() {
@ -45,6 +81,7 @@ PlasmaComponents3.Page {
onActivated: clickCurrentItemButton("openButton") onActivated: clickCurrentItemButton("openButton")
} }
// main contents
FocusScope { FocusScope {
anchors.fill: parent anchors.fill: parent
anchors.topMargin: PlasmaCore.Units.smallSpacing * 2 anchors.topMargin: PlasmaCore.Units.smallSpacing * 2
@ -228,64 +265,23 @@ PlasmaComponents3.Page {
} }
} }
// tab "widget" // tab content
ColumnLayout { StackLayout {
id: tabWidget id: tabLayout
spacing: 0 currentIndex: tabBar.currentIndex
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
DirectoriesPage {
StackLayout { id: directoriesPage
id: tabLayout
currentIndex: tabBar.currentIndex
Layout.fillWidth: true
Layout.fillHeight: true
DirectoriesPage {
id: directoriesPage
}
DevicesPage {
id: devicesPage
}
DownloadsPage {
id: downloadsPage
}
RecentChangesPage {
id: recentChangesPage
}
} }
PlasmaCore.SvgItem { DevicesPage {
Layout.preferredHeight: 1 id: devicesPage
Layout.fillWidth: true
elementId: "horizontal-line"
svg: PlasmaCore.Svg {
imagePath: "widgets/line"
}
} }
PlasmaComponents3.TabBar { DownloadsPage {
id: tabBar id: downloadsPage
position: PlasmaComponents3.TabBar.Footer }
spacing: units.smallSpacing RecentChangesPage {
Layout.alignment: Qt.AlignBottom id: recentChangesPage
TabButton {
id: dirsTabButton
text: qsTr("Directories")
icon.source: "image://fa/folder"
}
TabButton {
id: devsTabButton
text: qsTr("Devices")
icon.source: "image://fa/sitemap"
}
TabButton {
id: downloadsTabButton
text: qsTr("Downloads")
icon.source: "image://fa/download"
}
TabButton {
id: recentChangesTabButton
text: qsTr("History")
icon.source: "image://fa/history"
}
} }
} }
} }

View File

@ -5,9 +5,14 @@ import org.kde.plasma.components 3.0 as PlasmaComponents3
PlasmaComponents3.TabButton { PlasmaComponents3.TabButton {
id: root id: root
spacing: 0
contentItem: RowLayout { contentItem: RowLayout {
spacing: label.visible ? units.smallSpacing : 0 spacing: label.visible ? units.smallSpacing : 0
PlasmaCore.ColorScope.inherit: true PlasmaCore.ColorScope.inherit: true
width: parent.width
Item {
Layout.fillWidth: true
}
Image { Image {
id: image id: image
Layout.preferredHeight: height Layout.preferredHeight: height
@ -22,8 +27,10 @@ PlasmaComponents3.TabButton {
font: root.parent.font font: root.parent.font
color: PlasmaCore.ColorScope.textColor color: PlasmaCore.ColorScope.textColor
elide: Text.ElideRight elide: Text.ElideRight
Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
} }
Item {
Layout.fillWidth: true
}
} }
} }