add utils and impl title version
This commit is contained in:
@@ -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 .
|
||||
|
||||
4
Main.qml
4
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
|
||||
|
||||
18
cpp/utils/utils.cpp
Normal file
18
cpp/utils/utils.cpp
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
17
cpp/utils/utils.hpp
Normal file
17
cpp/utils/utils.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QQmlEngine>
|
||||
|
||||
class Utils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_SINGLETON
|
||||
|
||||
public:
|
||||
explicit Utils(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE static QString declensionLabel(int count);
|
||||
};
|
||||
|
||||
1
main.cpp
1
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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user