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

163 lines
6.0 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 as Q
import QtQuick.Layouts
import QtQuick.Controls
import Qt5Compat.GraphicalEffects
import QtQuick.Shapes
import Nymea
import NymeaApp.Utils
import "qrc:/ui/components"
Item {
id: root
property NymeaEnergy nymeaEnergy
property Thing evCharger
property Thing car
property ChargingConfiguration chargingConfiguration
property ChargingState chargingState
property real handleSize: 36
property real trackWidth: 8
property color chargerStateColor: Style.gray
property alias sliderValue: sliderControl.value
property alias sliderMinValue: sliderControl.minValue
property alias sliderMaxValue: sliderControl.maxValue
property alias sliderStepSize: sliderControl.stepSize
property alias interactive: sliderControl.interactive
property alias enabled: sliderControl.enabled
property alias busy: sliderControl.busy
property alias sliderControl: sliderControl
readonly property bool spotmarketChargingAvailable: false
readonly property bool surplusChargingAvailable: false
readonly property StateType maxChargingCurrentStateType: evCharger ? evCharger.thingClass.stateTypes.findByName("maxChargingCurrent") : null
readonly property State maxChargingCurrentState: evCharger ? evCharger.stateByName("maxChargingCurrent") : null
readonly property State powerState: evCharger ? evCharger.stateByName("power") : null
readonly property State phaseCountState: evCharger ? evCharger.stateByName("phaseCount") : null
readonly property State carMinChargingCurrentState: car ? car.stateByName("minChargingCurrent") : null
readonly property State carPercentageState: car ? car.stateByName("batteryLevel") : null
// readonly property ActionType socActionType: car ? car.thingClass.actionTypes.findByName("batteryLevel") : null
readonly property double max: maxChargingCurrentState && nymeaEnergy ? Math.min(maxChargingCurrentState.maxValue, nymeaEnergy.phasePowerLimit) : 16
readonly property double min: maxChargingCurrentState && carMinChargingCurrentState ? Math.max(maxChargingCurrentState.minValue, carMinChargingCurrentState.value) : 6
readonly property State chargingThingState: evCharger ? evCharger.stateByName("charging") : null
readonly property bool charging: chargingThingState ? chargingThingState.value : false
//Rectangle { anchors.fill: parent; color: Style.green; opacity: 0.2 }
CircularSlider {
id: sliderControl
anchors.fill: parent
anchors.margins: root.handleSize / 2 - root.trackWidth / 2
trackWidth: root.trackWidth
trackColor: root.chargerStateColor
handle: handleComponent
handleWidth: root.handleSize
handleHeight: root.handleSize
showStartIndicator: true
startIndicatorColor: Style.backgroundColor
hideProgress: true
progressColor: Style.green
progressWidth: root.trackWidth
colorAnimationSpeed: Style.slowAnimationDuration
busy: root.charging && root.enabled
busySpeed: root.charging && maxChargingCurrentState ? ((maxChargingCurrentState.value - min) * 100 / (max - min)) / 100.0 : 0.5
//onBusySpeedChanged: console.warn("Speed", busySpeed, min, max, maxChargingCurrentState.value)
snap: true
minValue: root.min
maxValue: root.max
stepSize: 1 // Note: depedning on the discrete chargers
Component {
id: handleComponent
Item {
id: handleItem
property bool touched: false
width: root.handleSize
height: root.handleSize
// Rectangle {
// id: touchIndicator
// anchors.centerIn: parent
// width: touched ? parent.width * 1.4 : parent.width
// height: width
// radius: width / 2
// color: Qt.rgba(Style.foregroundColor.r, Style.foregroundColor.g, Style.foregroundColor.b, 0.3)
// border.color: Style.foregroundColor
// border.width: 2
// Behavior on width {
// SmoothedAnimation { duration: Style.slowAnimationDuration }
// }
// }
Rectangle {
id: handleRectangle
anchors.fill: parent
radius: root.handleSize / 2
//antialiasing: true
color: Style.backgroundColor
//border.color: Style.foregroundColor
//border.width: 2
ColorIcon {
anchors.centerIn: parent
width: parent.width * 0.7
height: width
source: "/images/circular-slider-handle.svg"
rotation: -90
color: Style.foregroundColor
}
}
}
}
}
}