First implementation

This commit is contained in:
Yury Shuvakin
2025-07-02 18:00:35 +09:00
commit 6cf2010c08
107 changed files with 10803 additions and 0 deletions

192
Qml/Battery.qml Normal file
View File

@@ -0,0 +1,192 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Core 1.0
import Controls 1.0 as CustomControls
import Palette 1.0
Rectangle {
radius: 14
color: Palette.controlBackgroundColor
property BatteryController battery: null
property int batteryIndex: 0
onBatteryIndexChanged: {
if (battery) {
battery.batteryIndex = batteryIndex
}
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 20
spacing: 10
RowLayout {
CustomControls.Label {
text: "АКБ %1".arg(batteryIndex + 1)
font.pixelSize: 20
font.weight: Font.DemiBold
Layout.fillWidth: true
}
CustomControls.Button {
text: chargeTypeToString(battery ? battery.chargeType : 0)
backgroundColor: workingModeToColor(battery ? battery.workingMode : 0)
Layout.preferredWidth: 180
onClicked: battery ? battery.actionButtonClicked() : null
}
}
GridLayout {
columns: 2
rowSpacing: 8
columnSpacing: 16
Layout.fillWidth: true
CustomControls.Label {
text: "КП"
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
Layout.preferredWidth: 1
}
CustomControls.Label {
text: "УКБП"
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
Layout.preferredWidth: 1
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.controlCurrent) : "—"
indicatorText: "А"
Layout.fillWidth: true
Layout.preferredWidth: 1
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.measuredCurrent) : "—"
indicatorText: "А"
Layout.fillWidth: true
Layout.preferredWidth: 1
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.controlVoltage) : "—"
indicatorText: "В"
implicitWidth: 1
Layout.fillWidth: true
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.measuredVoltage) : "—"
indicatorText: "В"
Layout.fillWidth: true
Layout.preferredWidth: 1
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.controlTemperature) : "—"
indicatorText: "°C"
Layout.fillWidth: true
Layout.preferredWidth: 1
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.measuredTemperature) : "—"
indicatorText: "°C"
implicitWidth: 1
Layout.fillWidth: true
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.controlCapacity) : "—"
indicatorText: "Ач"
Layout.fillWidth: true
Layout.preferredWidth: 1
}
CustomControls.TextField {
text: battery ? convertDoubleToString(battery.measuredCapacity) : "—"
indicatorText: "Ач"
Layout.fillWidth: true
Layout.preferredWidth: 1
}
}
ListView {
id: statusView
clip: true
spacing: 5
boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.HorizontalAndVerticalFlick
model: battery ? battery.statues : null
delegate: CustomControls.ColoredLabel {
text: modelData.description
backgroundColor: Palette.neutralColor
font.pixelSize: 11
onWidthChanged: {
if (width > statusView.contentWidth) {
statusView.contentWidth = width
}
}
}
ScrollBar.vertical: ScrollBar {}
ScrollBar.horizontal: ScrollBar {}
Layout.fillWidth: true
Layout.fillHeight: true
}
}
function convertIntToString(value) {
if (value === undefined || value === null) {
return "—"
}
return parseInt(value).toString()
}
function convertDoubleToString(value) {
if (value === undefined || value === null) {
return "—"
}
return parseFloat(value).toFixed(1)
}
function chargeTypeToString(type) {
switch (type) {
case 1:
return "Контрольный разряд"
case 2:
return "Повторный заряд"
case 3:
return "Завершение заряда"
case 0:
default:
return "Первичный подзаряд"
}
}
function workingModeToColor(mode) {
switch (mode) {
case 1:
return Palette.greenButtonColor
case 2:
return Palette.redButtonColor
case 3:
return Palette.yellowButtonColor
case 0:
default:
return Palette.blueButtonColor
}
}
}

31
Qml/Controls/Button.qml Normal file
View File

@@ -0,0 +1,31 @@
import QtQuick 2.12
import QtQuick.Controls 2.12 as Controls
import Palette 1.0
Controls.Button {
id: control
leftPadding: 12
rightPadding: 12
topPadding: 8
bottomPadding: 8
property color backgroundColor: Palette.blueButtonColor
contentItem: Text {
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: Palette.alternativeTextColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
color: control.pressed ? Qt.darker(control.backgroundColor, 1.4) :
control.backgroundColor
radius: 8
}
}

View File

@@ -0,0 +1,26 @@
import QtQuick 2.12
import QtQuick.Controls 2.12 as Controls
import Palette 1.0
Controls.Label {
id: control
font.family: "Roboto"
font.pixelSize: 14
font.weight: Font.Normal
color: Palette.labelTextColor
leftPadding: 12
rightPadding: 12
topPadding: 8
bottomPadding: 8
property color backgroundColor: Palette.backgroundColor
property int backgroundRadius: 15
background: Rectangle {
color: control.backgroundColor
radius: control.backgroundRadius
}
}

11
Qml/Controls/Label.qml Normal file
View File

@@ -0,0 +1,11 @@
import QtQuick 2.12
import QtQuick.Controls 2.12 as Controls
import Palette 1.0
Controls.Label {
font.family: "Roboto"
font.pixelSize: 14
font.weight: Font.Normal
color: Palette.labelTextColor
}

View File

@@ -0,0 +1,55 @@
import QtQuick 2.12
import QtQuick.Controls 2.12 as Controls
import Palette 1.0
Controls.TextField {
id: control
readOnly: true
selectByMouse: true
implicitHeight: 34
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
topPadding: 6
bottomPadding: 6
leftPadding: 12
rightPadding: 12 + Math.ceil(indicatorLabel.width) + (indicatorLabel.visible ? 12 : 0)
font.family: "Roboto"
font.pixelSize: 22
font.weight: Font.Bold
color: Palette.labelTextColor
property string indicatorText
background: Rectangle {
radius: 8
color: Palette.controlBackgroundColor
border.width: 1
border.color: Palette.borderColor
width: control.width
height: control.height
Controls.Label {
id: indicatorLabel
visible: control.indicatorText.length > 0
text: control.indicatorText
anchors.right: parent.right
anchors.rightMargin: 12
anchors.bottom: parent.bottom
anchors.bottomMargin: 6
font.family: "Roboto"
font.pixelSize: 17
font.weight: Font.Normal
color: Palette.descriptionTextColor
}
}
}

5
Qml/Controls/qmldir Normal file
View File

@@ -0,0 +1,5 @@
module Controls
Button 1.0 Button.qml
ColoredLabel 1.0 ColoredLabel.qml
Label 1.0 Label.qml
TextField 1.0 TextField.qml

93
Qml/Main.qml Normal file
View File

@@ -0,0 +1,93 @@
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "."
import Core 1.0
import Controls 1.0 as CustomControls
import Palette 1.0
ApplicationWindow {
width: 1280
height: 1024
visible: true
title: qsTr("Stand Battery View")
color: Palette.backgroundColor
font.pixelSize: 14
GridLayout {
anchors.fill: parent
anchors.margins: 10
columns: 4
columnSpacing: 10
rowSpacing: 10
Frame {
Layout.fillWidth: true
Layout.columnSpan: 4
Layout.preferredHeight: statusBarLayout.implicitHeight + 20
leftPadding: 20
rightPadding: 20
topPadding: 10
bottomPadding: 10
background: Rectangle {
color: Palette.controlBackgroundColor
radius: 14
}
RowLayout {
id: statusBarLayout
spacing: 10
width: parent.width
CustomControls.ColoredLabel {
text: CanController.isConnected ? "Штатный режим" : "Отсутствует связь с БМФ2"
backgroundColor: CanController.isConnected ? Palette.goodColor : Palette.invalidColor
}
Item {
Layout.fillWidth: true
}
CustomControls.Label {
id: dateLabel
}
CustomControls.ColoredLabel {
id: timeLabel
backgroundColor: "#EAEAEA"
backgroundRadius: 8
}
Timer {
interval: 1000
repeat: true
running: true
triggeredOnStart: true
onTriggered: {
let date = new Date()
dateLabel.text = Qt.formatDate(date, "dd.MM.yyyy")
timeLabel.text = Qt.formatTime(date, "hh:mm:ss")
}
}
}
}
Repeater {
model: CanController.batteries
delegate: Battery {
battery: modelData
batteryIndex: index
Layout.fillWidth: true
Layout.fillHeight: true
}
}
}
}

23
Qml/Palette/Palette.qml Normal file
View File

@@ -0,0 +1,23 @@
pragma Singleton
import QtQuick 2.12
QtObject {
property color labelTextColor: "#232323"
property color descriptionTextColor: "#757575"
property color alternativeTextColor: "#FCFCFC"
property color backgroundColor: "#EEEEEE"
property color controlBackgroundColor: "#FCFCFC"
property color borderColor: "#D0D0D0"
property color blueButtonColor: "#3069FE"
property color greenButtonColor: "#4FBA5A"
property color redButtonColor: "#E74245"
property color yellowButtonColor: "#F4BB44"
property color informationColor: "#E2EAFF"
property color invalidColor: "#FFEDE3"
property color goodColor: "#C4FFCA"
property color neutralColor: "#FEFBC6"
}

2
Qml/Palette/qmldir Normal file
View File

@@ -0,0 +1,2 @@
module Palette
singleton Palette 1.0 Palette.qml

13
Qml/qml.qrc Normal file
View File

@@ -0,0 +1,13 @@
<RCC>
<qresource prefix="/">
<file>Main.qml</file>
<file>Battery.qml</file>
<file>Controls/Label.qml</file>
<file>Controls/qmldir</file>
<file>Controls/TextField.qml</file>
<file>Palette/Palette.qml</file>
<file>Palette/qmldir</file>
<file>Controls/Button.qml</file>
<file>Controls/ColoredLabel.qml</file>
</qresource>
</RCC>