nymea-app-energy-overlay/common/ui/components/PhaseCountSwitch.qml

85 lines
2.6 KiB
QML

// SPDX-License-Identifier: GPL-3.0-or-later
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (C) 2013 - 2024, nymea GmbH
* Copyright (C) 2024 - 2025, chargebyte austria GmbH
*
* This file is part of nymea-app-energy-overlay.
*
* nymea-app-energy-overlay 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.
*
* nymea-app-energy-overlay 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 nymea-app-energy-overlay. If not, see <https://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick
import QtQuick.Controls
import Nymea
Switch {
id: control
indicator: Rectangle {
implicitWidth: 48
implicitHeight: 26
x: control.leftPadding
y: parent.height / 2 - height / 2
radius: height / 2
color: Style.foregroundColor
border.color: Style.foregroundColor
// Label {
// text: "1"
// anchors.left: parent.left
// anchors.leftMargin: parent.height / 4
// anchors.verticalCenter: parent.verticalCenter
// color: Style.backgroundColor
// }
// Label {
// text: "3"
// anchors.right: parent.right
// anchors.rightMargin: parent.height / 4
// anchors.verticalCenter: parent.verticalCenter
// color: Style.backgroundColor
// }
Rectangle {
property real handleMargin: parent.radius - radius
x: control.checked ? parent.width - width - handleMargin : handleMargin
anchors.verticalCenter: parent.verticalCenter
width: 26
height: 26
radius: height / 2
color: Style.backgroundColor
border.color: Style.foregroundColor
Behavior on x {
enabled: !control.pressed
SmoothedAnimation {
duration: Style.slowAnimationDuration
}
}
Label {
text: control.checked ? "3" : "1"
anchors.centerIn: parent
font: Style.font
color: Style.foregroundColor
}
}
}
}