2021-04-21 16:57:14 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2024-02-12 17:52:45 +01:00
|
|
|
* Copyright (C) 2021-2024 Tom Zander <tom@flowee.org>
|
2021-04-21 16:57:14 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2024-02-11 21:05:38 +01:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Controls as QQC2
|
2025-01-27 13:34:42 +01:00
|
|
|
import "../Flowee" as Flowee
|
2021-04-20 17:41:35 +02:00
|
|
|
|
2021-10-18 16:30:21 +02:00
|
|
|
FocusScope {
|
2021-04-20 17:41:35 +02:00
|
|
|
id: floweeTabBar
|
2021-04-21 16:57:14 +02:00
|
|
|
|
|
|
|
|
// This trick means any child items the FloweeTabBar are actually added to the 'stack' item's children.
|
|
|
|
|
default property alias content: stack.children
|
|
|
|
|
property int currentIndex: 0
|
2021-07-30 21:47:15 +02:00
|
|
|
property alias headerHeight: header.height
|
2021-04-21 16:57:14 +02:00
|
|
|
onCurrentIndexChanged: setOpacities()
|
|
|
|
|
Component.onCompleted: setOpacities()
|
|
|
|
|
|
|
|
|
|
function setOpacities() {
|
2021-11-04 23:16:50 +01:00
|
|
|
var visibleChild = null;
|
2024-02-12 17:52:45 +01:00
|
|
|
for (let i = 0; i < header.tabs.length; ++i) {
|
2021-04-21 16:57:14 +02:00
|
|
|
let on = i === currentIndex;
|
2024-02-12 17:52:45 +01:00
|
|
|
let child = header.tabs[i];
|
2021-04-21 16:57:14 +02:00
|
|
|
child.visible = on;
|
|
|
|
|
if (on)
|
2021-11-04 23:16:50 +01:00
|
|
|
visibleChild = child;
|
|
|
|
|
}
|
|
|
|
|
// try to make sure the current tab gets keyboard focus properly.
|
|
|
|
|
// We do some extra work in case the tab itself is a loader.
|
2024-02-12 17:52:45 +01:00
|
|
|
if (visibleChild) {
|
|
|
|
|
forceActiveFocus();
|
|
|
|
|
visibleChild.focus = true
|
|
|
|
|
if (visibleChild instanceof Loader) {
|
|
|
|
|
var child = visibleChild.item;
|
|
|
|
|
if (child !== null)
|
|
|
|
|
child.focus = true;
|
|
|
|
|
}
|
2021-04-20 17:41:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-21 16:57:14 +02:00
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
id: header
|
2024-02-12 17:52:45 +01:00
|
|
|
property var tabs: []
|
|
|
|
|
onTabsChanged: floweeTabBar.setOpacities();
|
2021-04-21 16:57:14 +02:00
|
|
|
Repeater {
|
2024-02-12 17:52:45 +01:00
|
|
|
model: header.tabs
|
2021-04-21 16:57:14 +02:00
|
|
|
delegate: Item {
|
2022-08-28 22:21:14 +02:00
|
|
|
height: payTabButtonText.height + 10
|
2024-02-12 17:52:45 +01:00
|
|
|
width: floweeTabBar.width / header.tabs.length
|
2021-04-21 16:57:14 +02:00
|
|
|
|
2024-02-12 17:52:45 +01:00
|
|
|
Item { // text + icon, centered together.
|
|
|
|
|
width: {
|
|
|
|
|
var w = payTabButtonText.implicitWidth;
|
|
|
|
|
if (tabIcon.visible)
|
|
|
|
|
w += 6 + tabIcon.width;
|
|
|
|
|
if (w > parent.width) // limit text to available space
|
|
|
|
|
w = parent.width
|
|
|
|
|
return w;
|
|
|
|
|
}
|
2021-04-21 16:57:14 +02:00
|
|
|
height: parent.height
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2024-02-12 17:52:45 +01:00
|
|
|
|
2021-04-21 16:57:14 +02:00
|
|
|
Image {
|
2024-02-12 17:52:45 +01:00
|
|
|
id: tabIcon
|
2025-01-27 13:34:42 +01:00
|
|
|
visible: source !== ""
|
2024-02-12 17:52:45 +01:00
|
|
|
source: enabled ? header.tabs[index].icon : ""
|
2021-04-29 15:18:10 +02:00
|
|
|
anchors.bottom: payTabButtonText.baseline
|
|
|
|
|
anchors.bottomMargin: -2
|
2022-08-28 22:21:14 +02:00
|
|
|
height: payTabButtonText.height
|
2024-02-12 17:52:45 +01:00
|
|
|
width: height
|
2021-04-21 16:57:14 +02:00
|
|
|
}
|
2025-01-27 13:34:42 +01:00
|
|
|
Flowee.Label {
|
2021-04-21 16:57:14 +02:00
|
|
|
id: payTabButtonText
|
2024-02-12 17:52:45 +01:00
|
|
|
y: 6
|
|
|
|
|
x: tabIcon.visible ? tabIcon.width + 6 : 0
|
|
|
|
|
width: parent.width - x;
|
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2021-04-21 16:57:14 +02:00
|
|
|
font.bold: true
|
2022-04-05 18:28:06 +02:00
|
|
|
color: {
|
2024-02-12 17:52:45 +01:00
|
|
|
if (!header.tabs[index].enabled)
|
2022-04-05 18:28:06 +02:00
|
|
|
return "#888"
|
|
|
|
|
return "white"
|
|
|
|
|
}
|
2024-02-12 17:52:45 +01:00
|
|
|
text: enabled ? header.tabs[index].title: ""
|
2021-04-21 16:57:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: highlight
|
|
|
|
|
width: parent.width - 6
|
2022-08-28 22:21:14 +02:00
|
|
|
x: 1
|
|
|
|
|
height: 2
|
2021-04-21 16:57:14 +02:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.bottomMargin: 1
|
|
|
|
|
property bool hover: false
|
|
|
|
|
color: {
|
|
|
|
|
if (index === floweeTabBar.currentIndex)
|
|
|
|
|
return mainWindow.floweeGreen
|
2024-02-12 17:52:45 +01:00
|
|
|
if (!header.tabs[index].enabled)
|
2022-04-05 18:28:06 +02:00
|
|
|
return "#888"
|
2021-11-02 19:29:14 +01:00
|
|
|
if (Pay.useDarkSkin) {
|
2022-04-05 18:28:06 +02:00
|
|
|
if (hover)
|
2021-04-21 16:57:14 +02:00
|
|
|
return mainWindow.floweeSalmon
|
|
|
|
|
return "#EEE"
|
|
|
|
|
}
|
|
|
|
|
// light skin
|
2022-04-05 18:28:06 +02:00
|
|
|
if (hover)
|
2021-04-21 16:57:14 +02:00
|
|
|
return mainWindow.floweeSalmon
|
|
|
|
|
return mainWindow.floweeBlue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MouseArea {
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
onEntered: highlight.hover = true
|
|
|
|
|
onExited: highlight.hover = false
|
2022-04-05 17:20:52 +02:00
|
|
|
onClicked: {
|
|
|
|
|
// respect 'disabled' bool and don't change to the tab
|
2024-02-12 17:52:45 +01:00
|
|
|
if (header.tabs[index].enabled)
|
2022-04-05 17:20:52 +02:00
|
|
|
floweeTabBar.currentIndex = index
|
|
|
|
|
}
|
2021-04-21 16:57:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: stack
|
2024-02-12 17:52:45 +01:00
|
|
|
onChildrenChanged: {
|
|
|
|
|
// copy the children, but skip Items that are not actually
|
|
|
|
|
// content. Like Repeaters
|
|
|
|
|
var copyOfChildren = [];
|
|
|
|
|
for (let i = 0; i < children.length; ++i) {
|
|
|
|
|
var item = children[i];
|
|
|
|
|
if (item instanceof Repeater)
|
|
|
|
|
continue;
|
|
|
|
|
copyOfChildren.push(item);
|
|
|
|
|
}
|
|
|
|
|
header.tabs = copyOfChildren;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-21 16:57:14 +02:00
|
|
|
width: floweeTabBar.width
|
|
|
|
|
anchors.top: header.bottom; anchors.bottom: floweeTabBar.bottom
|
|
|
|
|
}
|
2021-04-20 17:41:35 +02:00
|
|
|
}
|