From dce22c65d62ccba1d261f8fd6009c4d0aa7449f5 Mon Sep 17 00:00:00 2001 From: Yury Shuvakin Date: Mon, 15 Aug 2022 08:49:12 +0300 Subject: [PATCH] Implemented QML skeleton for the application --- ENNOID-BMS-Tool.pro | 11 +- bmsinterface.cpp | 10 ++ bmsinterface.h | 3 +- main.cpp | 144 +++++-------------- mobile/qml.qrc | 4 +- qml/Controls/AlternativeButton.qml | 6 + qml/Controls/Button.qml | 5 + qml/Controls/ComboBox.qml | 108 ++++++++++++++ qml/Controls/ContentLabel.qml | 10 ++ qml/Controls/DotSeparator.qml | 34 +++++ qml/Controls/Frame.qml | 13 ++ qml/Controls/Label.qml | 5 + qml/Controls/PaneItem.qml | 5 + qml/Controls/ScrollBar.qml | 6 + qml/Controls/SubtitleLabel.qml | 10 ++ qml/Controls/TextField.qml | 6 + qml/Controls/TitleLabel.qml | 10 ++ qml/Controls/qmldir | 13 ++ qml/Icons/akb-monitor.svg | 4 + qml/Icons/bms-configuration.svg | 5 + qml/Icons/bms-service.svg | 4 + qml/Icons/cell-monitor.svg | 18 +++ qml/Icons/cubo-logo.svg | 15 ++ qml/Icons/exit.svg | 4 + qml/Icons/hide-menu.svg | 4 + qml/Icons/history.svg | 3 + qml/Icons/visualization.svg | 4 + qml/MainWindow.qml | 220 +++++++++++++++++++++++++++++ qml/Screens/AkbMonitorScreen.qml | 105 ++++++++++++++ qml/Screens/CellMonitorScreen.qml | 5 + qml/Screens/ConnectionScreen.qml | 49 +++++++ qml/Screens/qmldir | 4 + qml/Utils/Palette.qml | 22 +++ qml/Utils/qmldir | 2 + qml/qml_icons.qrc | 13 ++ qml/qml_items.qrc | 24 ++++ 36 files changed, 791 insertions(+), 117 deletions(-) create mode 100644 qml/Controls/AlternativeButton.qml create mode 100644 qml/Controls/Button.qml create mode 100644 qml/Controls/ComboBox.qml create mode 100644 qml/Controls/ContentLabel.qml create mode 100644 qml/Controls/DotSeparator.qml create mode 100644 qml/Controls/Frame.qml create mode 100644 qml/Controls/Label.qml create mode 100644 qml/Controls/PaneItem.qml create mode 100644 qml/Controls/ScrollBar.qml create mode 100644 qml/Controls/SubtitleLabel.qml create mode 100644 qml/Controls/TextField.qml create mode 100644 qml/Controls/TitleLabel.qml create mode 100644 qml/Controls/qmldir create mode 100644 qml/Icons/akb-monitor.svg create mode 100644 qml/Icons/bms-configuration.svg create mode 100644 qml/Icons/bms-service.svg create mode 100644 qml/Icons/cell-monitor.svg create mode 100644 qml/Icons/cubo-logo.svg create mode 100644 qml/Icons/exit.svg create mode 100644 qml/Icons/hide-menu.svg create mode 100644 qml/Icons/history.svg create mode 100644 qml/Icons/visualization.svg create mode 100644 qml/MainWindow.qml create mode 100644 qml/Screens/AkbMonitorScreen.qml create mode 100644 qml/Screens/CellMonitorScreen.qml create mode 100644 qml/Screens/ConnectionScreen.qml create mode 100644 qml/Screens/qmldir create mode 100644 qml/Utils/Palette.qml create mode 100644 qml/Utils/qmldir create mode 100644 qml/qml_icons.qrc create mode 100644 qml/qml_items.qrc diff --git a/ENNOID-BMS-Tool.pro b/ENNOID-BMS-Tool.pro index bf032ef..446ff1c 100644 --- a/ENNOID-BMS-Tool.pro +++ b/ENNOID-BMS-Tool.pro @@ -13,8 +13,7 @@ DEFINES += DT_VERSION=$$DT_VERSION DEFINES += HAS_SERIALPORT } -CONFIG += c++11 -QMAKE_CXXFLAGS += -Wno-deprecated-copy +CONFIG += c++14 # Options #Build mobile GUI @@ -158,9 +157,13 @@ include(pages/pages.pri) include(widgets/widgets.pri) include(mobile/mobile.pri) -RESOURCES += res.qrc - +RESOURCES += res.qrc \ + qml/qml_icons.qrc \ + qml/qml_items.qrc +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH *= $$PWD/qml +QML2_IMPORT_PATH *= $$PWD/qml DISTFILES += \ android/AndroidManifest.xml \ diff --git a/bmsinterface.cpp b/bmsinterface.cpp index 27cc948..d83ac77 100644 --- a/bmsinterface.cpp +++ b/bmsinterface.cpp @@ -517,6 +517,16 @@ QList BMSInterface::listSerialPorts() return res; } +QStringList BMSInterface::serialPortNames() +{ + QStringList names; + for (const auto& info: listSerialPorts()) + { + names.append(info.systemPath); + } + return names; +} + void BMSInterface::connectTcp(QString server, int port) { mLastTcpServer = server; diff --git a/bmsinterface.h b/bmsinterface.h index fd5de25..ff67eab 100644 --- a/bmsinterface.h +++ b/bmsinterface.h @@ -106,8 +106,9 @@ public: Q_INVOKABLE bool reconnectLastPort(); Q_INVOKABLE bool autoconnect(); Q_INVOKABLE QString getConnectedPortName(); - bool connectSerial(QString port, int baudrate = 115200); + Q_INVOKABLE bool connectSerial(QString port, int baudrate = 115200); QList listSerialPorts(); + Q_INVOKABLE QStringList serialPortNames(); Q_INVOKABLE void connectTcp(QString server, int port); Q_INVOKABLE void connectBle(QString address); Q_INVOKABLE bool isAutoconnectOngoing() const; diff --git a/main.cpp b/main.cpp index a6ab6cb..9cb76e9 100644 --- a/main.cpp +++ b/main.cpp @@ -18,129 +18,55 @@ along with this program. If not, see . */ -#include "mainwindow.h" -#include "mainwindownew.h" -#include "connectandenterpage.h" +#include "bmsinterface.h" +#include "utility.h" +#include "mobile/fwhelper.h" -#include -#include -#include -#include +#include #include +#include -#include "mobile/qmlui.h" +QObject *bmsInterfaceSingletontypeProvider(QQmlEngine */*engine*/, QJSEngine */*scriptEngine*/) +{ + auto *interface = new BMSInterface(); + interface->bmsConfig()->loadParamsXml("://res/config.xml"); + interface->infoConfig()->loadParamsXml("://res/info.xml"); + return interface; +} -#define NEW_GUI 1 +QObject *utilitySingletontypeProvider(QQmlEngine */*engine*/, QJSEngine */*scriptEngine*/) +{ + auto *utility = new Utility(); + return utility; +} int main(int argc, char *argv[]) { - constexpr char const *APP_NAME = "ENNOID-BMS Tool"; - // Settings - QCoreApplication::setOrganizationName("DieBie"); - QCoreApplication::setOrganizationDomain("diebie.nl"); - QCoreApplication::setApplicationName(APP_NAME); + Q_INIT_RESOURCE(res); + Q_INIT_RESOURCE(qml_icons); + Q_INIT_RESOURCE(qml_items); - // DPI settings - // TODO: http://www.qcustomplot.com/index.php/support/forum/1344 - - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - -#ifdef USE_MOBILE QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); -#else - QCoreApplication::setAttribute(Qt::AA_Use96Dpi); + QCoreApplication::setOrganizationName("Cubo"); + QCoreApplication::setOrganizationDomain("Cubo.rus"); + QCoreApplication::setApplicationName("Cubo Verde BMS Tool"); - QSettings set; - bool scaleAuto = true; - double scale = 1.0; + QGuiApplication app(argc, argv); - if (set.contains("app_scale_auto")) { - scaleAuto = set.value("app_scale_auto").toBool(); - } else { - set.setValue("app_scale_auto", scaleAuto); - } - - if (scaleAuto) { - QApplication tmp(argc, argv); - QRect rec = tmp.desktop()->screenGeometry(); - int height = rec.height(); - int width = rec.width(); - double ptFont = tmp.font().pointSizeF(); - if (ptFont < 0.0) { - ptFont = tmp.font().pixelSize(); - } - - if (width > 3000 && height > 1700) { - scale = 1.5; - } else { - if (ptFont > 11.0) { - scale = ptFont / 11.0; - } - } - - set.setValue("app_scale_factor", scale); - } else if (set.contains("app_scale_factor")) { - scale = set.value("app_scale_factor").toDouble(); - } - - set.setValue("app_scale_factor", scale); - -#ifdef Q_OS_ANDROID - scale = 1.0; -#endif - - if (scale > 1.01) { - qputenv("QT_SCALE_FACTOR", QString::number(scale).toLocal8Bit()); - } -#endif - - QApplication a(argc, argv); - -#if NEW_GUI - // Fonts QFontDatabase::addApplicationFont("://res/fonts/Artifakt-Element.ttf"); + app.setFont(QFont("Artifakt Element", 16, QFont::Medium)); - qApp->setFont(QFont("Artifakt Element", 12)); + QQmlApplicationEngine engine; -#else - // Fonts - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans.ttf"); - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans-Bold.ttf"); - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans-BoldOblique.ttf"); - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans-Oblique.ttf"); - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono.ttf"); - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono-Bold.ttf"); - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono-BoldOblique.ttf"); - QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono-Oblique.ttf"); + qmlRegisterSingletonType("Cubo", 1, 0, "BmsInterface", bmsInterfaceSingletontypeProvider); + qmlRegisterSingletonType("Cubo", 1, 0, "Utility", utilitySingletontypeProvider); + qmlRegisterType("Cubo", 1, 0, "BleUart"); + qmlRegisterType("Cubo", 1, 0, "Commands"); + qmlRegisterType("Cubo", 1, 0, "ConfigParams"); + qmlRegisterType("Cubo", 1, 0, "FwHelper"); - qApp->setFont(QFont("DejaVu Sans", 11)); + engine.addImportPath(QStringLiteral("qrc:/")); + engine.load(QUrl(QStringLiteral("qrc:/MainWindow.qml"))); - // Style - a.setStyleSheet(""); - a.setStyle(QStyleFactory::create("Fusion")); -#endif - -#ifdef USE_MOBILE - QmlUi q; - q.startQmlUi(); -#else - -#if NEW_GUI - - MainWindowNew w; - w.setWindowTitle(APP_NAME); - w.show(); - - //} else { - // a.closeAllWindows(); - // return 0; - //} -#else - MainWindow w; - w.show(); -#endif - -#endif - - return a.exec(); + return app.exec(); } diff --git a/mobile/qml.qrc b/mobile/qml.qrc index 0c0357e..94c7764 100644 --- a/mobile/qml.qrc +++ b/mobile/qml.qrc @@ -1,7 +1,5 @@ - - qtquickcontrols2.conf - + main.qml ConnectBle.qml diff --git a/qml/Controls/AlternativeButton.qml b/qml/Controls/AlternativeButton.qml new file mode 100644 index 0000000..7c586f9 --- /dev/null +++ b/qml/Controls/AlternativeButton.qml @@ -0,0 +1,6 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +Button { + +} diff --git a/qml/Controls/Button.qml b/qml/Controls/Button.qml new file mode 100644 index 0000000..9c36e13 --- /dev/null +++ b/qml/Controls/Button.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/qml/Controls/ComboBox.qml b/qml/Controls/ComboBox.qml new file mode 100644 index 0000000..07cbab5 --- /dev/null +++ b/qml/Controls/ComboBox.qml @@ -0,0 +1,108 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +import Controls 1.0 as Controls +import Utils 1.0 + +ComboBox { + id: control + + leftPadding: 16 + rightPadding: 16 + + delegate: ItemDelegate { + width: control.width + leftPadding: control.leftPadding + clip: true + + contentItem: Text { + text: modelData + color: pressed ? Palette.selectedTextColor : Palette.textColor + font: control.font + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + color: control.currentIndex === index ? + Palette.selectedBackgroundColor : + (highlighted ? Palette.hoveredBackgroundColor : Palette.backgroundColor) + } + + highlighted: control.highlightedIndex === index + } + + indicator: Canvas { + id: canvas + x: control.width - width - control.rightPadding + y: control.topPadding + (control.availableHeight - height) / 2 + width: 8 + height: 5 + contextType: "2d" + + Connections { + target: control + onDownChanged: canvas.requestPaint() + } + + onPaint: { + context.reset(); + + if (control.down) { + context.moveTo(0, height); + context.lineTo(width, height); + context.lineTo(width / 2, 0); + } else { + context.moveTo(0, 0); + context.lineTo(width, 0); + context.lineTo(width / 2, height); + } + + context.closePath(); + context.fillStyle = control.down ? Palette.selectedTextColor : Palette.textColor; + context.fill(); + } + } + + contentItem: Text { + rightPadding: control.indicator.width + 8 + + text: control.displayText + font: control.font + color: control.down ? Palette.selectedTextColor : Palette.textColor + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + implicitWidth: 120 + implicitHeight: 46 + color: control.down ? Palette.selectedBackgroundColor : Palette.backgroundColor + border.color: Palette.borderColor + border.width: 1 + radius: 5 + } + + popup: Popup { + y: control.height + 2 + width: control.width + implicitHeight: contentItem.implicitHeight + padding: 1 + + contentItem: ListView { + clip: true + implicitHeight: contentHeight + model: control.popup.visible ? control.delegateModel : null + currentIndex: control.highlightedIndex + + ScrollBar.vertical: Controls.ScrollBar {} + } + + background: Rectangle { + color: Palette.backgroundColor + border.color: Palette.borderColor + border.width: 1 + radius: 5 + } + } +} diff --git a/qml/Controls/ContentLabel.qml b/qml/Controls/ContentLabel.qml new file mode 100644 index 0000000..c632db5 --- /dev/null +++ b/qml/Controls/ContentLabel.qml @@ -0,0 +1,10 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +import Utils 1.0 + +Label { + color: Palette.contentTextColor + font.pixelSize: 18 + font.weight: Font.Medium +} diff --git a/qml/Controls/DotSeparator.qml b/qml/Controls/DotSeparator.qml new file mode 100644 index 0000000..598c6c9 --- /dev/null +++ b/qml/Controls/DotSeparator.qml @@ -0,0 +1,34 @@ +import QtQuick 2.12 +import QtQuick.Shapes 1.12 + +import Utils 1.0 + +Shape { + id: shape + implicitHeight: 1 + + ShapePath { + strokeColor: Palette.contentTextColor + strokeWidth: 1 + strokeStyle: ShapePath.DashLine + dashPattern: [1, 3] + startX: 0 + startY: 0 + PathLine { x: shape.width; y: 0 } + } +} + +//Canvas { +// id: canvas +// contextType: "2d" +// implicitHeight: 1 + +// onPaint: { +// var ctx = getContext("2d"); +// ctx.setLineDash([2, 2]); +// ctx.beginPath(); +// ctx.moveTo(0, 0); +// ctx.lineTo(width, 0); +// ctx.stroke(); +// } +//} diff --git a/qml/Controls/Frame.qml b/qml/Controls/Frame.qml new file mode 100644 index 0000000..a686259 --- /dev/null +++ b/qml/Controls/Frame.qml @@ -0,0 +1,13 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +import Utils 1.0 + +Frame { + background: Rectangle { + color: Palette.backgroundColor + border.color: Palette.borderColor + border.width: 1 + radius: 8 + } +} diff --git a/qml/Controls/Label.qml b/qml/Controls/Label.qml new file mode 100644 index 0000000..9c36e13 --- /dev/null +++ b/qml/Controls/Label.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/qml/Controls/PaneItem.qml b/qml/Controls/PaneItem.qml new file mode 100644 index 0000000..9c36e13 --- /dev/null +++ b/qml/Controls/PaneItem.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/qml/Controls/ScrollBar.qml b/qml/Controls/ScrollBar.qml new file mode 100644 index 0000000..030990f --- /dev/null +++ b/qml/Controls/ScrollBar.qml @@ -0,0 +1,6 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +ScrollBar { + +} diff --git a/qml/Controls/SubtitleLabel.qml b/qml/Controls/SubtitleLabel.qml new file mode 100644 index 0000000..2bae39e --- /dev/null +++ b/qml/Controls/SubtitleLabel.qml @@ -0,0 +1,10 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +import Utils 1.0 + +Label { + color: Palette.contentTextColor + font.pixelSize: 18 + font.weight: Font.ExtraBold +} diff --git a/qml/Controls/TextField.qml b/qml/Controls/TextField.qml new file mode 100644 index 0000000..274b236 --- /dev/null +++ b/qml/Controls/TextField.qml @@ -0,0 +1,6 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +TextField { + selectByMouse: true +} diff --git a/qml/Controls/TitleLabel.qml b/qml/Controls/TitleLabel.qml new file mode 100644 index 0000000..6fdc5a4 --- /dev/null +++ b/qml/Controls/TitleLabel.qml @@ -0,0 +1,10 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +import Utils 1.0 + +Label { + color: Palette.selectedTextColor + font.pixelSize: 28 + font.weight: Font.ExtraBold +} diff --git a/qml/Controls/qmldir b/qml/Controls/qmldir new file mode 100644 index 0000000..ba36b57 --- /dev/null +++ b/qml/Controls/qmldir @@ -0,0 +1,13 @@ +module Controls +Label 1.0 Label.qml +ComboBox 1.0 ComboBox.qml +PaneItem 1.0 PaneItem.qml +ScrollBar 1.0 ScrollBar.qml +Button 1.0 Button.qml +AlternativeButton 1.0 AlternativeButton.qml +TextField 1.0 TextField.qml +Frame 1.0 Frame.qml +TitleLabel 1.0 TitleLabel.qml +SubtitleLabel 1.0 SubtitleLabel.qml +ContentLabel 1.0 ContentLabel.qml +DotSeparator 1.0 DotSeparator.qml diff --git a/qml/Icons/akb-monitor.svg b/qml/Icons/akb-monitor.svg new file mode 100644 index 0000000..9dd4412 --- /dev/null +++ b/qml/Icons/akb-monitor.svg @@ -0,0 +1,4 @@ + + + + diff --git a/qml/Icons/bms-configuration.svg b/qml/Icons/bms-configuration.svg new file mode 100644 index 0000000..dc27898 --- /dev/null +++ b/qml/Icons/bms-configuration.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/qml/Icons/bms-service.svg b/qml/Icons/bms-service.svg new file mode 100644 index 0000000..cb3ae4c --- /dev/null +++ b/qml/Icons/bms-service.svg @@ -0,0 +1,4 @@ + + + + diff --git a/qml/Icons/cell-monitor.svg b/qml/Icons/cell-monitor.svg new file mode 100644 index 0000000..a179990 --- /dev/null +++ b/qml/Icons/cell-monitor.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/qml/Icons/cubo-logo.svg b/qml/Icons/cubo-logo.svg new file mode 100644 index 0000000..85bcf5c --- /dev/null +++ b/qml/Icons/cubo-logo.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/qml/Icons/exit.svg b/qml/Icons/exit.svg new file mode 100644 index 0000000..a6a9d56 --- /dev/null +++ b/qml/Icons/exit.svg @@ -0,0 +1,4 @@ + + + + diff --git a/qml/Icons/hide-menu.svg b/qml/Icons/hide-menu.svg new file mode 100644 index 0000000..f91f900 --- /dev/null +++ b/qml/Icons/hide-menu.svg @@ -0,0 +1,4 @@ + + + + diff --git a/qml/Icons/history.svg b/qml/Icons/history.svg new file mode 100644 index 0000000..1eefc06 --- /dev/null +++ b/qml/Icons/history.svg @@ -0,0 +1,3 @@ + + + diff --git a/qml/Icons/visualization.svg b/qml/Icons/visualization.svg new file mode 100644 index 0000000..4d1ed70 --- /dev/null +++ b/qml/Icons/visualization.svg @@ -0,0 +1,4 @@ + + + + diff --git a/qml/MainWindow.qml b/qml/MainWindow.qml new file mode 100644 index 0000000..95bc64c --- /dev/null +++ b/qml/MainWindow.qml @@ -0,0 +1,220 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 + +import Controls 1.0 as Controls +import Screens 1.0 as Screens +import Utils 1.0 + +ApplicationWindow { + id: window + title: qsTr("Cubo Verde BMS Tool") + width: 1366 + height: 768 + visible: true + + RowLayout { + anchors.fill: parent + spacing: 0 + + Rectangle { + id: pane + color: Palette.alternativeBackgroundColor + implicitWidth: 300 + + property bool minimized: false + + ColumnLayout { + anchors.fill: parent + spacing: 0 + + Item { + Layout.preferredHeight: 40 + } + + Image { + source: "qrc:/Icons/cubo-logo.svg" + sourceSize.width: pane.minimized ? 80 : 115 + sourceSize.height: pane.minimized ? 80 : 115 + fillMode: Image.PreserveAspectFit + Layout.alignment: Qt.AlignCenter + } + + Item { + Layout.preferredHeight: pane.minimized ? 75 : 40 + } + + ItemDelegate { + leftPadding: pane.minimized ? 0 : 40 + + contentItem: RowLayout { + height: 50 + spacing: 25 + + Item { + visible: pane.minimized + Layout.fillWidth: true + } + + Image { + source: "qrc:/Icons/hide-menu.svg" + fillMode: Image.PreserveAspectFit + mirror: pane.minimized + Layout.alignment: Qt.AlignCenter + } + + Label { + text: qsTr("Hide menu") + color: Palette.alternativeTextColor + visible: !pane.minimized + } + + Item { + Layout.fillWidth: true + } + } + + background: Rectangle { + color: "transparent" + } + + onClicked: if (pane.implicitWidth === 300) { + animation.from = 300 + animation.to = 100 + animation.running = true + pane.minimized = true + } else { + animation.from = 100 + animation.to = 300 + animation.running = true + pane.minimized = false + } + + Layout.preferredHeight: 52 + Layout.fillWidth: true + } + + Item { + Layout.preferredHeight: 70 + } + + ListView { + id: menuView + model: [ + {"text": qsTr("AKB monitor"), "icon": "qrc:/Icons/akb-monitor.svg"}, + {"text": qsTr("Cell monitor"), "icon": "qrc:/Icons/cell-monitor.svg"}, + {"text": qsTr("Configuration"), "icon": "qrc:/Icons/bms-configuration.svg"}, + {"text": qsTr("Visualization"), "icon": "qrc:/Icons/visualization.svg"}, + {"text": qsTr("History"), "icon": "qrc:/Icons/history.svg"}, + {"text": qsTr("BMS service"), "icon": "qrc:/Icons/bms-service.svg"}, + {"text": qsTr("Exit"), "icon": "qrc:/Icons/exit.svg"}, + ] + + delegate: ItemDelegate { + id: menuDelegate + width: ListView.view.width + height: 52 + leftPadding: pane.minimized ? 0 : 40 + highlighted: ListView.isCurrentItem + onClicked: menuView.currentIndex = index + + contentItem: RowLayout { + spacing: pane.minimized ? 0 : 25 + height: 50 + + Item { + visible: pane.minimized + Layout.fillWidth: true + } + + Image { + source: modelData.icon + fillMode: Image.PreserveAspectFit + Layout.alignment: Qt.AlignCenter + } + + Label { + text: modelData.text + font.weight: Font.ExtraBold + color: Palette.alternativeTextColor + visible: !pane.minimized + } + + Item { + Layout.fillWidth: true + } + } + + background: Rectangle { + color: menuDelegate.highlighted ? Palette.pressedButtonColor : Palette.alternativeButtonColor + } + } + + Layout.fillHeight: true + Layout.fillWidth: true + } + } + + PropertyAnimation { + id: animation + target: pane + property: "implicitWidth" + duration: 200 + easing.type: Easing.InQuad + } + + Layout.preferredWidth: implicitWidth + Layout.fillHeight: true + } + + ColumnLayout { + RowLayout { + id: topBar + + property var labels: [ + qsTr("AKB Monitor"), + qsTr("Cell Monitor"), + ] + + Label { + text: topBar.labels[stack.currentIndex] + font.pixelSize: 38 + font.weight: Font.ExtraBold + } + + Item { + Layout.fillWidth: true + } + + Layout.leftMargin: 45 + Layout.rightMargin: 45 + } + + StackLayout { + id: stack + currentIndex: menuView.currentIndex + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.leftMargin: 45 + Layout.rightMargin: 45 + + Screens.AkbMonitorScreen { + } + + Screens.CellMonitorScreen { + } + } + } + } + + Screens.ConnectionScreen { + id: connectionScreen + } + + background: Rectangle { + color: Palette.screenBackgroundColor + } + + Component.onCompleted: connectionScreen.open() +} diff --git a/qml/Screens/AkbMonitorScreen.qml b/qml/Screens/AkbMonitorScreen.qml new file mode 100644 index 0000000..8491192 --- /dev/null +++ b/qml/Screens/AkbMonitorScreen.qml @@ -0,0 +1,105 @@ +import QtQuick 2.12 +import QtQuick.Layouts 1.12 + +import Controls 1.0 as Controls + +Item { + ColumnLayout { + anchors.fill: parent + + Controls.Frame { + Layout.fillWidth: true + + RowLayout { + anchors.fill: parent + + Controls.TitleLabel { + text: qsTr("Serial number") + Layout.fillWidth: true + } + + Controls.TextField { + text: "AABBCCDD" + Layout.fillWidth: true + } + } + } + + Controls.Frame { + Layout.fillWidth: true + + GridLayout { + columns: 2 + anchors.fill: parent + + RowLayout { + Controls.ContentLabel { + text: qsTr("Battery charge level, V") + } + + Controls.DotSeparator { + Layout.fillWidth: true + } + + Controls.SubtitleLabel { + text: "-" + } + + Layout.fillWidth: true + } + + RowLayout { + Controls.ContentLabel { + text: qsTr("Number of modules") + } + + Controls.DotSeparator { + Layout.fillWidth: true + } + + Controls.SubtitleLabel { + text: "-" + } + + Layout.fillWidth: true + } + + RowLayout { + Controls.ContentLabel { + text: qsTr("Battery voltage, V") + } + + Controls.DotSeparator { + Layout.fillWidth: true + } + + Controls.SubtitleLabel { + text: "-" + } + + Layout.fillWidth: true + } + + RowLayout { + Controls.ContentLabel { + text: qsTr("Number of cells") + } + + Controls.DotSeparator { + Layout.fillWidth: true + } + + Controls.SubtitleLabel { + text: "-" + } + + Layout.fillWidth: true + } + } + } + + Item { + Layout.fillHeight: true + } + } +} diff --git a/qml/Screens/CellMonitorScreen.qml b/qml/Screens/CellMonitorScreen.qml new file mode 100644 index 0000000..9c36e13 --- /dev/null +++ b/qml/Screens/CellMonitorScreen.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/qml/Screens/ConnectionScreen.qml b/qml/Screens/ConnectionScreen.qml new file mode 100644 index 0000000..df2ed6b --- /dev/null +++ b/qml/Screens/ConnectionScreen.qml @@ -0,0 +1,49 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Dialogs 1.2 +import QtQuick.Layouts 1.12 + +import Controls 1.0 as Controls +import Cubo 1.0 +import Utils 1.0 + +Dialog { + id: root + title: qsTr("Connection Screen") + width: 300 + height: 300 + standardButtons: Dialog.NoButton + + contentItem: Rectangle { + color: Palette.screenBackgroundColor + + ColumnLayout { + anchors.fill: parent + anchors.margins: 45 + + Label { + text: qsTr("Select serial port") + Layout.fillWidth: true + Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom + } + + Controls.ComboBox { + id: serialBox + model: BmsInterface.serialPortNames() + Layout.fillWidth: true + Layout.alignment: Qt.AlignCenter + } + + Controls.AlternativeButton { + text: qsTr("Connect") + Layout.fillWidth: true + Layout.alignment: Qt.AlignHCenter | Qt.AlignTop + onClicked: { + var currentPort = BmsInterface.serialPortNames()[serialBox.currentIndex] + if (BmsInterface.connectSerial(currentPort)) + root.close() + } + } + } + } +} diff --git a/qml/Screens/qmldir b/qml/Screens/qmldir new file mode 100644 index 0000000..4a978c8 --- /dev/null +++ b/qml/Screens/qmldir @@ -0,0 +1,4 @@ +module Screens +ConnectionScreen 1.0 ConnectionScreen.qml +AkbMonitorScreen 1.0 AkbMonitorScreen.qml +CellMonitorScreen 1.0 CellMonitorScreen.qml diff --git a/qml/Utils/Palette.qml b/qml/Utils/Palette.qml new file mode 100644 index 0000000..9b9ac0f --- /dev/null +++ b/qml/Utils/Palette.qml @@ -0,0 +1,22 @@ +pragma Singleton +import QtQuick 2.12 + +QtObject { + property color textColor: "#000000" + property color selectedTextColor: "#009352" + property color contentTextColor: "#869098" + property color alternativeTextColor: "#FFFFFF" + + property color backgroundColor: "#FFFFFF" + property color hoveredBackgroundColor: "#F0F1F4" + property color selectedBackgroundColor: "#CCE9DC" + property color alternativeBackgroundColor: "#009352" + property color screenBackgroundColor: "#F7F8FC" + + property color borderColor: "#DFE0EB" + + property color buttonColor: "#F7F8FC" + property color alternativeButtonColor: "#009352" + property color hoveredButtonColor: "#03AC61" + property color pressedButtonColor: "#057845" +} diff --git a/qml/Utils/qmldir b/qml/Utils/qmldir new file mode 100644 index 0000000..df3af39 --- /dev/null +++ b/qml/Utils/qmldir @@ -0,0 +1,2 @@ +module utils +singleton Palette 1.0 Palette.qml diff --git a/qml/qml_icons.qrc b/qml/qml_icons.qrc new file mode 100644 index 0000000..747a353 --- /dev/null +++ b/qml/qml_icons.qrc @@ -0,0 +1,13 @@ + + + Icons/akb-monitor.svg + Icons/bms-configuration.svg + Icons/bms-service.svg + Icons/cell-monitor.svg + Icons/cubo-logo.svg + Icons/exit.svg + Icons/hide-menu.svg + Icons/history.svg + Icons/visualization.svg + + diff --git a/qml/qml_items.qrc b/qml/qml_items.qrc new file mode 100644 index 0000000..6fd0e79 --- /dev/null +++ b/qml/qml_items.qrc @@ -0,0 +1,24 @@ + + + MainWindow.qml + Screens/ConnectionScreen.qml + Screens/AkbMonitorScreen.qml + Screens/CellMonitorScreen.qml + Controls/ComboBox.qml + Controls/PaneItem.qml + Controls/Label.qml + Utils/Palette.qml + Controls/qmldir + Screens/qmldir + Utils/qmldir + Controls/ScrollBar.qml + Controls/Button.qml + Controls/AlternativeButton.qml + Controls/TextField.qml + Controls/Frame.qml + Controls/TitleLabel.qml + Controls/SubtitleLabel.qml + Controls/ContentLabel.qml + Controls/DotSeparator.qml + +