From adca1b382b12006ec872f7b9f4b6aa0b4a7cf741 Mon Sep 17 00:00:00 2001 From: cutefishd Date: Fri, 2 Apr 2021 19:26:06 +0800 Subject: [PATCH] Perfect about page --- debian/control | 2 ++ src/about.cpp | 38 ++++++++++++++++++++++++++++ src/about.h | 23 +++++++++-------- src/qml/AboutPage.qml | 17 ++++++++++++- src/qml/SideBar.qml | 12 ++++----- src/qml/Wallpaper/BackgroundPage.qml | 30 +++++++++++++++------- translations/zh_CN.ts | 22 +++++++++++++--- 7 files changed, 113 insertions(+), 31 deletions(-) diff --git a/debian/control b/debian/control index f1899fa..f84dc23 100644 --- a/debian/control +++ b/debian/control @@ -29,6 +29,8 @@ Depends: qml-module-qtquick-controls2, qml-module-qtqml, qml-module-qtquick-window2, qml-module-qtquick-shapes, + qml-module-qtquick-dialogs, + qml-module-qtquick-particles2, ${misc:Depends}, ${shlibs:Depends} Description: CutefishOS Settings diff --git a/src/about.cpp b/src/about.cpp index 243442f..04532ff 100644 --- a/src/about.cpp +++ b/src/about.cpp @@ -1,6 +1,8 @@ #include "about.h" #include +#include +#include #ifdef Q_OS_LINUX #include @@ -19,6 +21,11 @@ QString About::osName() return QSysInfo::prettyProductName(); } +QString About::architecture() +{ + return QSysInfo::currentCpuArchitecture(); +} + QString About::kernelType() { return QSysInfo::kernelType(); @@ -60,6 +67,37 @@ QString About::prettyProductName() return QSysInfo::prettyProductName(); } +QString About::internalStorage() +{ + QStorageInfo storage = QStorageInfo::root(); + return QString("%1 / %2") + .arg(KFormat().formatByteSize(storage.bytesTotal() - storage.bytesAvailable())) + .arg(KFormat().formatByteSize(storage.bytesTotal(), 0)); +} + +QString About::cpuInfo() +{ + QFile file("/proc/cpuinfo"); + + if (file.open(QIODevice::ReadOnly)) { + QString buffer = file.readAll(); + QStringList modelLine = buffer.split('\n').filter(QRegularExpression("^model name")); + QStringList lines = buffer.split('\n'); + + int count = lines.filter(QRegularExpression("^processor")).count(); + + QString result; + result.append(modelLine.first().split(':').at(1)); + + if (count > 0) + result.append(QString(" x %1").arg(count)); + + return result; + } + + return QString(); +} + qlonglong About::calculateTotalRam() const { qlonglong ret = -1; diff --git a/src/about.h b/src/about.h index c027f50..c8f1e55 100644 --- a/src/about.h +++ b/src/about.h @@ -9,32 +9,33 @@ class About : public QObject { Q_OBJECT - Q_PROPERTY(QString osName READ osName NOTIFY stub) - Q_PROPERTY(QString kernelVersion READ kernelVersion NOTIFY stub) - Q_PROPERTY(QString hostname READ hostname NOTIFY stub) - Q_PROPERTY(QString userName READ userName NOTIFY stub) - Q_PROPERTY(QString memorySize READ memorySize NOTIFY stub) - Q_PROPERTY(QString prettyProductName READ prettyProductName NOTIFY stub) + Q_PROPERTY(QString osName READ osName CONSTANT) + Q_PROPERTY(QString architecture READ architecture CONSTANT) + Q_PROPERTY(QString kernelVersion READ kernelVersion CONSTANT) + Q_PROPERTY(QString hostname READ hostname CONSTANT) + Q_PROPERTY(QString userName READ userName CONSTANT) + Q_PROPERTY(QString memorySize READ memorySize CONSTANT) + Q_PROPERTY(QString prettyProductName READ prettyProductName CONSTANT) + Q_PROPERTY(QString internalStorage READ internalStorage CONSTANT) + Q_PROPERTY(QString cpuInfo READ cpuInfo CONSTANT) public: explicit About(QObject *parent = nullptr); QString osName(); + QString architecture(); QString kernelType(); QString kernelVersion(); QString hostname(); QString userName(); QString settingsVersion(); QString memorySize(); - QString prettyProductName(); + QString internalStorage(); + QString cpuInfo(); private: qlonglong calculateTotalRam() const; - -// Only here so that QML doesn't whine about non-NOTIFYable properties. -signals: - void stub(); }; #endif // ABOUT_H diff --git a/src/qml/AboutPage.qml b/src/qml/AboutPage.qml index 137c90b..a7f2aea 100644 --- a/src/qml/AboutPage.qml +++ b/src/qml/AboutPage.qml @@ -45,7 +45,12 @@ ItemPage { StandardItem { key: qsTr("System Version") - value: "0.1" + value: "0.2" + } + + StandardItem { + key: qsTr("System Type") + value: about.architecture } StandardItem { @@ -53,10 +58,20 @@ ItemPage { value: about.kernelVersion } + StandardItem { + key: qsTr("Processor") + value: about.cpuInfo + } + StandardItem { key: qsTr("RAM") value: about.memorySize } + + StandardItem { + key: qsTr("Internal Storage") + value: about.internalStorage + } } } } diff --git a/src/qml/SideBar.qml b/src/qml/SideBar.qml index 3a444f7..3e40875 100644 --- a/src/qml/SideBar.qml +++ b/src/qml/SideBar.qml @@ -49,12 +49,12 @@ Item { iconSource: "qrc:/images/sidebar/network.svg" } - ListElement { - title: qsTr("Bluetooth") - name: "bluetooth" - page: "qrc:/qml/BluetoothPage.qml" - iconSource: "qrc:/images/sidebar/bluetooth.svg" - } +// ListElement { +// title: qsTr("Bluetooth") +// name: "bluetooth" +// page: "qrc:/qml/BluetoothPage.qml" +// iconSource: "qrc:/images/sidebar/bluetooth.svg" +// } ListElement { title: qsTr("Appearance") diff --git a/src/qml/Wallpaper/BackgroundPage.qml b/src/qml/Wallpaper/BackgroundPage.qml index 536b0d6..4af3b7e 100644 --- a/src/qml/Wallpaper/BackgroundPage.qml +++ b/src/qml/Wallpaper/BackgroundPage.qml @@ -24,11 +24,11 @@ ItemPage { anchors.topMargin: Meui.Units.smallSpacing spacing: Meui.Units.largeSpacing -// DesktopPreview { -// Layout.alignment: Qt.AlignHCenter -// width: 500 -// height: 300 -// } + // DesktopPreview { + // Layout.alignment: Qt.AlignHCenter + // width: 500 + // height: 300 + // } RowLayout { spacing: Meui.Units.largeSpacing * 2 @@ -73,16 +73,17 @@ ItemPage { // spacing: Meui.Units.smallSpacing // orientation: Qt.Horizontal - height: count * itemSize + height: count * itemHeight clip: true model: background.backgrounds currentIndex: -1 - cellHeight: itemSize - cellWidth: itemSize + cellHeight: calcExtraSpacing(itemHeight, _view.height) + itemHeight + cellWidth: calcExtraSpacing(itemWidth, _view.width) + itemWidth - property int itemSize: 200 + property int itemWidth: 250 + property int itemHeight: 150 delegate: Item { id: item @@ -161,6 +162,17 @@ ItemPage { } } } + + function calcExtraSpacing(cellSize, containerSize) { + var availableColumns = Math.floor(containerSize / cellSize) + var extraSpacing = 0 + if (availableColumns > 0) { + var allColumnSize = availableColumns * cellSize + var extraSpace = Math.max(containerSize - allColumnSize, Meui.Units.largeSpacing) + extraSpacing = extraSpace / availableColumns + } + return Math.floor(extraSpacing) + } } } diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index aff889b..6a28f19 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -18,17 +18,32 @@ System Version 系统版本 + + + System Type + 系统类型 + + + + Internal Storage + 内部存储 + Software Version 软件版本 - + Kernel Version 内核版本 - + + Processor + 处理器 + + + RAM 内存大小 @@ -418,9 +433,8 @@ 用户 - Bluetooth - 蓝牙 + 蓝牙