commit 3b5ce8593ff8da789476192fb4d4d3e33aaf93b5 Author: wangguixi Date: Sat Oct 8 11:25:29 2022 +0800 init diff --git a/Time.qml b/Time.qml new file mode 100644 index 0000000..9c941cd --- /dev/null +++ b/Time.qml @@ -0,0 +1,270 @@ +import QtQuick 2.0 +import QtQml 2.12 +import QtQuick.Layouts 1.12 +import org.ukui.appwidget 1.0 +//import QtQuick.Controls 2.0 +AppWidget { + id:appwidget + appname: "time" + visible: true + width: 448 + height: 162 +// color: "gray" +// color: "transparent" +// border.color: "red" +// radius: 15 + property string timeformat: "12"; + property string dateformat: "cn" + property string hour; + property string minute; + property int hournumber; + property string week; + property string amorpm; + property bool v: false + property string themename; + + Timer { + id: gettime; + interval: 100; + running: true; + repeat: true; + triggeredOnStart: true + onTriggered: { + appwidget.hour = Qt.formatTime(new Date(),"hh"); + appwidget.minute = Qt.formatTime(new Date(),"mm"); + if(appwidget.timeformat === "12") { + appwidget.hournumber = Number(appwidget.hour); + if(appwidget.hournumber > 12) { + if(appwidget.dateformat == "cn") { + ampm.text = "下午" + } + else if(appwidget.dateformat == "en") { + ampm.text = "PM" + } + appwidget.hournumber -= 12; + } + else { + if(appwidget.dateformat == "cn") { + ampm.text = "上午" + } + else if(appwidget.dateformat == "en") { + ampm.text = "AM" + } + } + + if(appwidget.hournumber < 10) { + time1rec.width = 244 + time1.width = 244 +// console.log("=12制 宽度=",time1rec.width); + }else { + time1rec.width = 294 + time1.width = 294 +// console.log("=12制 宽度=",time1rec.width); + } + + appwidget.hour = appwidget.hournumber.toString(); + time1.text = appwidget.hour + ":" + appwidget.minute +// console.log("=12制=",time1.text); + } + else { + time2.text = appwidget.hour + ":" + appwidget.minute +// console.log("=24制=",time2.text); + } + week1.text = Qt.formatDate(new Date(),"ddd") + week2.text = Qt.formatDate(new Date(),"ddd") + + if(dateformat == "cn") { + date1.text = Qt.formatDate(new Date(),"MM/dd"); + date2.text = Qt.formatDate(new Date(),"MM/dd"); + } + if(dateformat == "en") { + date1.text = Qt.formatDate(new Date(),"MM-dd"); + date2.text = Qt.formatDate(new Date(),"MM-dd"); + } + } + } + + + Rectangle { + id :twelverec + color: "transparent" +// radius: 15 + anchors.fill: parent + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + visible: !v + Rectangle { + id :time1rec + color: "transparent" +// border.color: "green" + anchors.verticalCenter: parent.verticalCenter + width: 244 + height: 112 + Text { + id: time1 + anchors.fill:parent + verticalAlignment: TextInput.AlignVCenter + color: "#FAFAFA" + font.pixelSize:112 + font.letterSpacing: 0 + font.family: "STxihei" + } + } + Rectangle { + //间隔 + id :spacing1 + width: 16 + height: 112 + anchors.left: time1rec.right + anchors.verticalCenter: parent.verticalCenter + color: "transparent" + } + Rectangle { + id :daterec + color: "transparent" +// border.color: "pink" + width: 137 + height: 96 + anchors.verticalCenter: parent.verticalCenter + Layout.fillWidth: true + anchors.left: spacing1.right + + ColumnLayout{ + width: 137 + height: 96 + anchors.centerIn: parent + Text { + id: ampm + color: "#FAFAFA"; + font.pixelSize:40; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + RowLayout { + Text { + id: week1 + color: "#FAFAFA"; + font.pixelSize: 28; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + Text { + id: date1 + color: "#FAFAFA"; + font.pixelSize: 28; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + } + } + } + } + + + Rectangle{ + id :twentyfoursystem + color: "transparent" +// radius: 15 + anchors.fill: parent + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + visible: v + Rectangle { + id :time2rec + color: "transparent" +// border.color: "pink" + anchors.verticalCenter: parent.verticalCenter + width: 294 + height: 112 + Text { + id: time2 + anchors.fill:parent + verticalAlignment: TextInput.AlignVCenter + color: "#FAFAFA" + font.pixelSize:112 + font.letterSpacing:0 + font.family: "STxihei" + } + } + Rectangle { + //间隔 + id :spacing2 + width: 16 + height: 112 + anchors.left: time2rec.right + anchors.verticalCenter: parent.verticalCenter + color: "transparent" + } + Rectangle { + color: "transparent" + width: 87 + height: 112 + Layout.fillWidth: true + anchors.verticalCenter: parent.verticalCenter + anchors.left: spacing2.right + + ColumnLayout{ + width: 87 + height: 112 + anchors.centerIn: parent + Layout.fillWidth: true + Text { + id: week2 + color: "#FAFAFA"; + font.pixelSize:40; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + Text { + id: date2 + color: "#FAFAFA"; + font.pixelSize:40; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + } + } + } + + Component.onCompleted: { + + gettime.start(); +// appwidget.update.connect(appwidget.onupdate); + console.log("qml 接收到数据更新信号"); + + appwidget.creatGsetting("org.ukui.control-center.panel.plugins"); + appwidget.gsettingUpdate.connect(appwidget.onGsettingUpdate); + timeformat = appwidget.getGsettingValue("org.ukui.control-center.panel.plugins","hoursystem"); + dateformat = appwidget.getGsettingValue("org.ukui.control-center.panel.plugins","date"); + if(timeformat == "24") { + v = true + }else { + v = false + } + console.log("当前gsetting为", timeformat, dateformat); + } + function onGsettingUpdate(key, value) + { + if(key === "hoursystem") + { + timeformat = value + if(timeformat == "24") { + v = true + }else { + v = false + } + } + if(key === "date") + { + dateformat = value + } + } +} + + + diff --git a/data/time/time.conf b/data/time/time.conf new file mode 100644 index 0000000..db6a6d2 --- /dev/null +++ b/data/time/time.conf @@ -0,0 +1,14 @@ +[AppWidget] +name = time +providerName = clock +previewPath = /usr/share/appwidgetdemo/clock/time.png +qmlFile = /usr/share/appwidget/qml/time.qml +zoom = false +rightButton = false +repeatPlacement = false +minWidget = 448 +minHeight = 162 +targetCellWidth = 2 +targetCellHeight = 1 +updatePeriodMillis = 0 +describe = this is a datetime diff --git a/data/time/time.png b/data/time/time.png new file mode 100644 index 0000000..8f37bd4 Binary files /dev/null and b/data/time/time.png differ diff --git a/data/time/time.qml b/data/time/time.qml new file mode 100644 index 0000000..9c941cd --- /dev/null +++ b/data/time/time.qml @@ -0,0 +1,270 @@ +import QtQuick 2.0 +import QtQml 2.12 +import QtQuick.Layouts 1.12 +import org.ukui.appwidget 1.0 +//import QtQuick.Controls 2.0 +AppWidget { + id:appwidget + appname: "time" + visible: true + width: 448 + height: 162 +// color: "gray" +// color: "transparent" +// border.color: "red" +// radius: 15 + property string timeformat: "12"; + property string dateformat: "cn" + property string hour; + property string minute; + property int hournumber; + property string week; + property string amorpm; + property bool v: false + property string themename; + + Timer { + id: gettime; + interval: 100; + running: true; + repeat: true; + triggeredOnStart: true + onTriggered: { + appwidget.hour = Qt.formatTime(new Date(),"hh"); + appwidget.minute = Qt.formatTime(new Date(),"mm"); + if(appwidget.timeformat === "12") { + appwidget.hournumber = Number(appwidget.hour); + if(appwidget.hournumber > 12) { + if(appwidget.dateformat == "cn") { + ampm.text = "下午" + } + else if(appwidget.dateformat == "en") { + ampm.text = "PM" + } + appwidget.hournumber -= 12; + } + else { + if(appwidget.dateformat == "cn") { + ampm.text = "上午" + } + else if(appwidget.dateformat == "en") { + ampm.text = "AM" + } + } + + if(appwidget.hournumber < 10) { + time1rec.width = 244 + time1.width = 244 +// console.log("=12制 宽度=",time1rec.width); + }else { + time1rec.width = 294 + time1.width = 294 +// console.log("=12制 宽度=",time1rec.width); + } + + appwidget.hour = appwidget.hournumber.toString(); + time1.text = appwidget.hour + ":" + appwidget.minute +// console.log("=12制=",time1.text); + } + else { + time2.text = appwidget.hour + ":" + appwidget.minute +// console.log("=24制=",time2.text); + } + week1.text = Qt.formatDate(new Date(),"ddd") + week2.text = Qt.formatDate(new Date(),"ddd") + + if(dateformat == "cn") { + date1.text = Qt.formatDate(new Date(),"MM/dd"); + date2.text = Qt.formatDate(new Date(),"MM/dd"); + } + if(dateformat == "en") { + date1.text = Qt.formatDate(new Date(),"MM-dd"); + date2.text = Qt.formatDate(new Date(),"MM-dd"); + } + } + } + + + Rectangle { + id :twelverec + color: "transparent" +// radius: 15 + anchors.fill: parent + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + visible: !v + Rectangle { + id :time1rec + color: "transparent" +// border.color: "green" + anchors.verticalCenter: parent.verticalCenter + width: 244 + height: 112 + Text { + id: time1 + anchors.fill:parent + verticalAlignment: TextInput.AlignVCenter + color: "#FAFAFA" + font.pixelSize:112 + font.letterSpacing: 0 + font.family: "STxihei" + } + } + Rectangle { + //间隔 + id :spacing1 + width: 16 + height: 112 + anchors.left: time1rec.right + anchors.verticalCenter: parent.verticalCenter + color: "transparent" + } + Rectangle { + id :daterec + color: "transparent" +// border.color: "pink" + width: 137 + height: 96 + anchors.verticalCenter: parent.verticalCenter + Layout.fillWidth: true + anchors.left: spacing1.right + + ColumnLayout{ + width: 137 + height: 96 + anchors.centerIn: parent + Text { + id: ampm + color: "#FAFAFA"; + font.pixelSize:40; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + RowLayout { + Text { + id: week1 + color: "#FAFAFA"; + font.pixelSize: 28; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + Text { + id: date1 + color: "#FAFAFA"; + font.pixelSize: 28; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + } + } + } + } + + + Rectangle{ + id :twentyfoursystem + color: "transparent" +// radius: 15 + anchors.fill: parent + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + visible: v + Rectangle { + id :time2rec + color: "transparent" +// border.color: "pink" + anchors.verticalCenter: parent.verticalCenter + width: 294 + height: 112 + Text { + id: time2 + anchors.fill:parent + verticalAlignment: TextInput.AlignVCenter + color: "#FAFAFA" + font.pixelSize:112 + font.letterSpacing:0 + font.family: "STxihei" + } + } + Rectangle { + //间隔 + id :spacing2 + width: 16 + height: 112 + anchors.left: time2rec.right + anchors.verticalCenter: parent.verticalCenter + color: "transparent" + } + Rectangle { + color: "transparent" + width: 87 + height: 112 + Layout.fillWidth: true + anchors.verticalCenter: parent.verticalCenter + anchors.left: spacing2.right + + ColumnLayout{ + width: 87 + height: 112 + anchors.centerIn: parent + Layout.fillWidth: true + Text { + id: week2 + color: "#FAFAFA"; + font.pixelSize:40; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + Text { + id: date2 + color: "#FAFAFA"; + font.pixelSize:40; + font.letterSpacing: 0 + font.family: "STxihei" + verticalAlignment: TextInput.AlignVCenter + } + } + } + } + + Component.onCompleted: { + + gettime.start(); +// appwidget.update.connect(appwidget.onupdate); + console.log("qml 接收到数据更新信号"); + + appwidget.creatGsetting("org.ukui.control-center.panel.plugins"); + appwidget.gsettingUpdate.connect(appwidget.onGsettingUpdate); + timeformat = appwidget.getGsettingValue("org.ukui.control-center.panel.plugins","hoursystem"); + dateformat = appwidget.getGsettingValue("org.ukui.control-center.panel.plugins","date"); + if(timeformat == "24") { + v = true + }else { + v = false + } + console.log("当前gsetting为", timeformat, dateformat); + } + function onGsettingUpdate(key, value) + { + if(key === "hoursystem") + { + timeformat = value + if(timeformat == "24") { + v = true + }else { + v = false + } + } + if(key === "date") + { + dateformat = value + } + } +} + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..db8d3b8 --- /dev/null +++ b/main.cpp @@ -0,0 +1,20 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + const QUrl url(QStringLiteral("qrc:/main.qml")); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} diff --git a/main.qml b/main.qml new file mode 100644 index 0000000..afd1e26 --- /dev/null +++ b/main.qml @@ -0,0 +1,15 @@ +import QtQuick 2.12 +import QtQuick.Window 2.12 + +Window { + visible: true + width: 640 + height: 480 + color: "black" + title: qsTr("Hello World") + + + Time{ + + } +} diff --git a/qml.qrc b/qml.qrc new file mode 100644 index 0000000..8c114e5 --- /dev/null +++ b/qml.qrc @@ -0,0 +1,9 @@ + + + main.qml + data/time/time.conf + data/time/time.png + data/time/time.qml + Time.qml + + diff --git a/ukui-system-appwidget.pro b/ukui-system-appwidget.pro new file mode 100644 index 0000000..467c0b0 --- /dev/null +++ b/ukui-system-appwidget.pro @@ -0,0 +1,36 @@ +QT += quick + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Refer to the documentation for the +# deprecated API to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# Default rules for deployment. +target.path = /usr/bin +timeqml.files += data/time/time.qml +timeqml.path = /usr/share/appwidget/qml/ +timecong.files += data/time/time.conf +timecong.path = /usr/share/appwidget/config/ +timepreview.files += data/time/time.png +timepreview.path = /usr/share/appwidgetdemo/clock/ + +INSTALLS += target timeqml timepreview timecong