From 80404223954d1d9b7d3744d7481339f92d50887c Mon Sep 17 00:00:00 2001 From: chatlanin Date: Sat, 14 Nov 2026 08:45:30 +0300 Subject: [PATCH] add utils and impl title version --- CMakeLists.txt | 11 ++++++++--- Main.qml | 4 +++- cpp/utils/utils.cpp | 18 ++++++++++++++++++ cpp/utils/utils.hpp | 17 +++++++++++++++++ main.cpp | 1 + qml/components/Title.qml | 14 +++++++++----- qml/style/Theme.qml | 6 +++++- 7 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 cpp/utils/utils.cpp create mode 100644 cpp/utils/utils.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e92ca6a..fb86b65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ qt_add_executable(apparchpack main.cpp ) +target_compile_definitions(apparchpack PRIVATE APP_VERSION="${PROJECT_VERSION}") + set_source_files_properties(qml/style/Theme.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE ) @@ -23,11 +25,14 @@ qt_add_qml_module(apparchpack qml/style/Theme.qml qml/components/Title.qml qml/buttons/Settings.qml + SOURCES + cpp/utils/utils.hpp + cpp/utils/utils.cpp ) -target_link_libraries(apparchpack - PRIVATE Qt6::Quick -) +target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/utils) + +target_link_libraries(apparchpack PRIVATE Qt6::Quick) install(TARGETS apparchpack BUNDLE DESTINATION . diff --git a/Main.qml b/Main.qml index 210a091..098bd1c 100644 --- a/Main.qml +++ b/Main.qml @@ -10,12 +10,14 @@ ApplicationWindow { id: root title: "Arch Linux Updater" + width: 740 + height: 960 minimumWidth: 740 minimumHeight: 560 maximumWidth: 1080 maximumHeight: 1460 visible: true - color: Theme.base + color: Theme.color1 ColumnLayout { id: mainLayout diff --git a/cpp/utils/utils.cpp b/cpp/utils/utils.cpp new file mode 100644 index 0000000..8ddc3ab --- /dev/null +++ b/cpp/utils/utils.cpp @@ -0,0 +1,18 @@ +#include "utils.hpp" + +Utils::Utils(QObject* parent) : QObject{parent} { } + +QString Utils::declensionLabel(int count) +{ + const int n = qAbs(count) % 100; + + QString suffix; + if (n >= 11 && n <= 14) suffix = QStringLiteral("пакетов"); + else if (n % 10 == 1) suffix = QStringLiteral("пакет"); + else if (n % 10 >= 2 && n % 10 <= 4) suffix = QStringLiteral("пакета"); + else suffix = QStringLiteral("пакетов"); + + + return QString::number(count) + " " + suffix; +} + diff --git a/cpp/utils/utils.hpp b/cpp/utils/utils.hpp new file mode 100644 index 0000000..4a4db12 --- /dev/null +++ b/cpp/utils/utils.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include + +class Utils : public QObject +{ + Q_OBJECT + QML_SINGLETON + + public: + explicit Utils(QObject *parent = nullptr); + + Q_INVOKABLE static QString declensionLabel(int count); +}; + diff --git a/main.cpp b/main.cpp index 31588fb..e6834bc 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); + QGuiApplication::setApplicationVersion(APP_VERSION); QQmlApplicationEngine engine; QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); diff --git a/qml/components/Title.qml b/qml/components/Title.qml index 9dcbd94..ba4d11f 100644 --- a/qml/components/Title.qml +++ b/qml/components/Title.qml @@ -6,6 +6,9 @@ ColumnLayout { Layout.fillWidth: true spacing: 4 + property bool isChecking: true + property int packageCount: 0 + RowLayout { spacing: 5 @@ -13,7 +16,7 @@ ColumnLayout { text: "Arch Linux Updater" font.pixelSize: 20 font.bold: true - color: "#cdd6f4" + color: Theme.color2 Layout.alignment: Qt.AlignBaseline } @@ -21,17 +24,18 @@ ColumnLayout { text: "v. " + Qt.application.version font.pixelSize: 12 font.italic: true - color: "#6c7086" + color: Theme.color3 Layout.alignment: Qt.AlignBaseline } } Text { - text: "Можно обновить: " + text: "Можно обновить: " + Utils.packageLabel(root.packageCount) Layout.fillWidth: true wrapMode: Text.WordWrap - font.pixelSize: 12 - color: "#6c7086" + font.pixelSize: Theme.fontSize + color: Theme.color3 + visible: !root.isChecking && root.packageCount > 0 } } diff --git a/qml/style/Theme.qml b/qml/style/Theme.qml index 0d3f06d..7eea281 100644 --- a/qml/style/Theme.qml +++ b/qml/style/Theme.qml @@ -3,5 +3,9 @@ pragma Singleton import QtQuick 2.15 QtObject { - readonly property color base: "#303446" + readonly property color color1: "#303446" + readonly property color color2: "#cdd6f4" + readonly property color color3: "#6c7086" + + readonly property int fontSize: 12 }