/** SPDX-FileCopyrightText: 2021 Mikel Johnson <mikel5764@gmail.com>* SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>** SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport org.kde.ksvg as KSvgimport org.kde.plasma.components as PC3import org.kde.plasma.extras as PlasmaExtrasimport org.kde.kirigami as KirigamiPlasmaExtras.PlasmoidHeading {id: rootreadonly property alias tabBar: tabBarproperty real preferredTabBarWidth: 0readonly property alias leaveButtons: leaveButtonscontentWidth: tabBar.implicitWidth + spacingcontentHeight: leaveButtons.implicitHeight// We use an increased vertical padding to improve touch usabilityleftPadding: kickoff.backgroundMetrics.leftPaddingrightPadding: kickoff.backgroundMetrics.rightPaddingtopPadding: Kirigami.Units.smallSpacing * 2bottomPadding: Kirigami.Units.smallSpacing * 2topInset: 0leftInset: 0rightInset: 0bottomInset: 0spacing: kickoff.backgroundMetrics.spacingposition: PC3.ToolBar.FooterPC3.TabBar {id: tabBarproperty real tabWidth: Math.max(applicationsTab.implicitWidth, placesTab.implicitWidth)focus: truewidth: root.preferredTabBarWidth > 0 ? root.preferredTabBarWidth : undefinedimplicitWidth: contentWidth + leftPadding + rightPaddingimplicitHeight: contentHeight + topPadding + bottomPadding// This is needed to keep the separators horizontally alignedleftPadding: mirrored ? root.spacing : 0rightPadding: !mirrored ? root.spacing : 0anchors {top: parent.topleft: parent.leftbottom: parent.bottom}position: PC3.TabBar.FootercontentItem: ListView {id: tabBarListViewfocus: truemodel: tabBar.contentModelcurrentIndex: tabBar.currentIndexspacing: tabBar.spacingorientation: ListView.HorizontalboundsBehavior: Flickable.StopAtBoundsflickableDirection: Flickable.AutoFlickIfNeededsnapMode: ListView.SnapToItemhighlightMoveDuration: Kirigami.Units.longDurationhighlightRangeMode: ListView.ApplyRangepreferredHighlightBegin: tabBar.tabWidthpreferredHighlightEnd: width - tabBar.tabWidthhighlight: KSvg.FrameSvgItem {anchors.top: tabBarListView.contentItem.topanchors.bottom: tabBarListView.contentItem.bottomanchors.topMargin: -root.topPaddinganchors.bottomMargin: -root.bottomPaddingimagePath: "widgets/tabbar"prefix: tabBar.position === PC3.TabBar.Header ? "north-active-tab" : "south-active-tab"}keyNavigationEnabled: false}PC3.TabButton {id: applicationsTabfocus: truewidth: tabBar.tabWidthanchors.top: tabBarListView.contentItem.topanchors.bottom: tabBarListView.contentItem.bottomanchors.topMargin: -root.topPaddinganchors.bottomMargin: -root.bottomPaddingicon.width: Kirigami.Units.iconSizes.smallMediumicon.height: Kirigami.Units.iconSizes.smallMediumicon.name: "applications-all-symbolic"text: i18nc("@title:tab kickoff sidebar tab", "Applications")Keys.onBacktabPressed: event => {(kickoff.lastCentralPane || nextItemInFocusChain(false)).forceActiveFocus(Qt.BacktabFocusReason)}}PC3.TabButton {id: placesTabwidth: tabBar.tabWidthanchors.top: tabBarListView.contentItem.topanchors.bottom: tabBarListView.contentItem.bottomanchors.topMargin: -root.topPaddinganchors.bottomMargin: -root.bottomPaddingicon.width: Kirigami.Units.iconSizes.smallMediumicon.height: Kirigami.Units.iconSizes.smallMediumicon.name: "compass"text: i18nc("@title:tab kickoff sidebar tab", "Places") //Explore?}Connections {target: kickofffunction onExpandedChanged() {if (!kickoff.expanded) {tabBar.currentIndex = 0}}}Keys.onPressed: event => {const Key_Next = Application.layoutDirection === Qt.RightToLeft ? Qt.Key_Left : Qt.Key_Rightconst Key_Prev = Application.layoutDirection === Qt.RightToLeft ? Qt.Key_Right : Qt.Key_Leftif (event.key === Key_Next) {if (currentIndex === count - 1) {leaveButtons.nextItemInFocusChain().forceActiveFocus(Qt.TabFocusReason)} else {incrementCurrentIndex()currentItem.forceActiveFocus(Qt.TabFocusReason)}event.accepted = true} else if (event.key === Key_Prev && currentIndex > 0) {decrementCurrentIndex()currentItem.forceActiveFocus(Qt.BacktabFocusReason)event.accepted = true}}Keys.onUpPressed: event => {kickoff.firstCentralPane.forceActiveFocus(Qt.BacktabFocusReason);}}LeaveButtons {id: leaveButtonsanchors {top: parent.topright: parent.rightbottom: parent.bottom}// available width for leaveButtonsmaximumWidth: root.availableWidth - tabBar.width - root.spacingKeys.onUpPressed: event => {kickoff.lastCentralPane.forceActiveFocus(Qt.BacktabFocusReason);}}Behavior on height {enabled: kickoff.expandedNumberAnimation {duration: Kirigami.Units.longDurationeasing.type: Easing.InQuad}}// Using item containing WheelHandler instead of MouseArea because// MouseArea doesn't keep track to the total amount of rotation.// Keeping track of the total amount of rotation makes it work// better for touch pads.Item {id: mouseItemparent: rootanchors.left: parent.leftheight: root.heightwidth: tabBar.widthz: 1 // Has to be above contentItem to receive mouse wheel eventsWheelHandler {id: tabScrollHandleracceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPadonWheel: {const shouldDec = rotation >= 15const shouldInc = rotation <= -15const shouldReset = (rotation > 0 && tabBar.currentIndex === 0) || (rotation < 0 && tabBar.currentIndex === tabBar.count - 1)if (shouldDec) {tabBar.decrementCurrentIndex();rotation = 0} else if (shouldInc) {tabBar.incrementCurrentIndex();rotation = 0} else if (shouldReset) {rotation = 0}}}}Shortcut {sequences: ["Ctrl+Tab", "Ctrl+Shift+Tab", StandardKey.NextChild, StandardKey.PreviousChild]onActivated: {tabBar.currentIndex = (tabBar.currentIndex === 0) ? 1 : 0;}}}