forked from openkylin/ukui-system-appwidget
fix:148558中等一般未确认【UKUI需求 17140】【小插件】【日历】控制面板时间设置为12小时制,日历小插件的上下午信息未汉化
This commit is contained in:
parent
b28a3cf615
commit
20b84a533d
340
Time.qml
340
Time.qml
|
@ -1,340 +0,0 @@
|
||||||
import QtQuick 2.0
|
|
||||||
import QtQml 2.12
|
|
||||||
import QtQuick.Layouts 1.12
|
|
||||||
import org.ukui.appwidget 1.0
|
|
||||||
import QtGraphicalEffects 1.0
|
|
||||||
//import QtQuick.Controls 2.0
|
|
||||||
AppWidget {
|
|
||||||
id:appwidget
|
|
||||||
appname: "time"
|
|
||||||
visible: true
|
|
||||||
width: 448*scalefactor
|
|
||||||
height: 162*scalefactor
|
|
||||||
anchors.centerIn: parent
|
|
||||||
property double scalefactor: 1.00
|
|
||||||
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;
|
|
||||||
property bool qmleffect: false
|
|
||||||
|
|
||||||
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*appwidget.scalefactor
|
|
||||||
height: 112*appwidget.scalefactor
|
|
||||||
Text {
|
|
||||||
id: time1
|
|
||||||
anchors.fill:parent
|
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
|
||||||
color: "#FAFAFA"
|
|
||||||
font.pixelSize:112*appwidget.scalefactor
|
|
||||||
font.letterSpacing: 0
|
|
||||||
font.family: "STxihei"
|
|
||||||
|
|
||||||
layer.enabled: appwidget.qmleffect
|
|
||||||
layer.effect: DropShadow {
|
|
||||||
verticalOffset: 1
|
|
||||||
color: "#40262626"
|
|
||||||
samples: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rectangle {
|
|
||||||
//间隔
|
|
||||||
id :spacing1
|
|
||||||
width: 16*appwidget.scalefactor
|
|
||||||
height: 112*appwidget.scalefactor
|
|
||||||
anchors.left: time1rec.right
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
color: "transparent"
|
|
||||||
}
|
|
||||||
Rectangle {
|
|
||||||
id :daterec
|
|
||||||
color: "transparent"
|
|
||||||
// border.color: "pink"
|
|
||||||
width: 137*appwidget.scalefactor
|
|
||||||
height: 96*appwidget.scalefactor
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
Layout.fillWidth: true
|
|
||||||
anchors.left: spacing1.right
|
|
||||||
|
|
||||||
ColumnLayout{
|
|
||||||
width: 137*appwidget.scalefactor
|
|
||||||
height: 96*appwidget.scalefactor
|
|
||||||
anchors.centerIn: parent
|
|
||||||
Text {
|
|
||||||
id: ampm
|
|
||||||
color: "#FAFAFA";
|
|
||||||
font.pixelSize:40*appwidget.scalefactor;
|
|
||||||
font.letterSpacing: 0
|
|
||||||
font.family: "STxihei"
|
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
|
||||||
|
|
||||||
layer.enabled: appwidget.qmleffect
|
|
||||||
layer.effect: DropShadow {
|
|
||||||
verticalOffset: 1
|
|
||||||
color: "#40262626"
|
|
||||||
samples: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RowLayout {
|
|
||||||
Text {
|
|
||||||
id: week1
|
|
||||||
color: "#FAFAFA";
|
|
||||||
font.pixelSize: 28*appwidget.scalefactor;
|
|
||||||
font.letterSpacing: 0
|
|
||||||
font.family: "STxihei"
|
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
|
||||||
|
|
||||||
layer.enabled: appwidget.qmleffect
|
|
||||||
layer.effect: DropShadow {
|
|
||||||
verticalOffset: 1
|
|
||||||
color: "#40262626"
|
|
||||||
samples: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
id: date1
|
|
||||||
color: "#FAFAFA";
|
|
||||||
font.pixelSize: 28*appwidget.scalefactor;
|
|
||||||
font.letterSpacing: 0
|
|
||||||
font.family: "STxihei"
|
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
|
||||||
|
|
||||||
layer.enabled: appwidget.qmleffect
|
|
||||||
layer.effect: DropShadow {
|
|
||||||
verticalOffset: 1
|
|
||||||
color: "#40262626"
|
|
||||||
samples: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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*appwidget.scalefactor
|
|
||||||
height: 112*appwidget.scalefactor
|
|
||||||
Text {
|
|
||||||
id: time2
|
|
||||||
anchors.fill:parent
|
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
|
||||||
color: "#FAFAFA"
|
|
||||||
font.pixelSize:112*appwidget.scalefactor
|
|
||||||
font.letterSpacing:0
|
|
||||||
font.family: "STxihei"
|
|
||||||
|
|
||||||
layer.enabled: appwidget.qmleffect
|
|
||||||
layer.effect: DropShadow {
|
|
||||||
verticalOffset: 1
|
|
||||||
color: "#40262626"
|
|
||||||
samples: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rectangle {
|
|
||||||
//间隔
|
|
||||||
id :spacing2
|
|
||||||
width: 16*appwidget.scalefactor
|
|
||||||
height: 112*appwidget.scalefactor
|
|
||||||
anchors.left: time2rec.right
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
color: "transparent"
|
|
||||||
}
|
|
||||||
Rectangle {
|
|
||||||
color: "transparent"
|
|
||||||
width: 87*appwidget.scalefactor
|
|
||||||
height: 112*appwidget.scalefactor
|
|
||||||
Layout.fillWidth: true
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.left: spacing2.right
|
|
||||||
|
|
||||||
ColumnLayout{
|
|
||||||
width: 87*appwidget.scalefactor
|
|
||||||
height: 112*appwidget.scalefactor
|
|
||||||
anchors.centerIn: parent
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Text {
|
|
||||||
id: week2
|
|
||||||
color: "#FAFAFA";
|
|
||||||
font.pixelSize:40*appwidget.scalefactor;
|
|
||||||
font.letterSpacing: 0
|
|
||||||
font.family: "STxihei"
|
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
|
||||||
|
|
||||||
layer.enabled: appwidget.qmleffect
|
|
||||||
layer.effect: DropShadow {
|
|
||||||
verticalOffset: 1
|
|
||||||
color: "#40262626"
|
|
||||||
samples: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
id: date2
|
|
||||||
color: "#FAFAFA";
|
|
||||||
font.pixelSize:40*appwidget.scalefactor;
|
|
||||||
font.letterSpacing: 0
|
|
||||||
font.family: "STxihei"
|
|
||||||
verticalAlignment: TextInput.AlignVCenter
|
|
||||||
|
|
||||||
layer.enabled: appwidget.qmleffect
|
|
||||||
layer.effect: DropShadow {
|
|
||||||
verticalOffset: 1
|
|
||||||
color: "#40262626"
|
|
||||||
samples: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
|
|
||||||
initScalefactor()
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function initScalefactor()
|
|
||||||
{
|
|
||||||
//按宽计算缩放比例,计算在这个比例系数下的小插件宽高,如果高超出父类的高,则更换比例系数的计算方式
|
|
||||||
//按高计算缩放比例
|
|
||||||
//console.log("父类窗口大小", appwidget.parent.width,appwidget.parent.height);
|
|
||||||
if(appwidget.parent.width == 0 || appwidget.parent.height == 0) {
|
|
||||||
appwidget.scalefactor = 1.0
|
|
||||||
console.log("父类窗口大小为 0 默认缩放比为1.0")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
appwidget.scalefactor = appwidget.parent.width/448
|
|
||||||
//console.log("当前比例系数", appwidget.scalefactor);
|
|
||||||
var tw = appwidget.scalefactor *448
|
|
||||||
var th = appwidget.scalefactor *162
|
|
||||||
//console.log("大小:", tw,th ,appwidget.height);
|
|
||||||
if(th > appwidget.parent.height) {
|
|
||||||
appwidget.scalefactor = appwidget.parent.height/162
|
|
||||||
//console.log("以宽度计算比例系数", appwidget.scalefactor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
9
qml.qrc
9
qml.qrc
|
@ -1,9 +0,0 @@
|
||||||
<RCC>
|
|
||||||
<qresource prefix="/">
|
|
||||||
<file>main.qml</file>
|
|
||||||
<file>data/time/time.conf</file>
|
|
||||||
<file>data/time/time.png</file>
|
|
||||||
<file>data/time/time.qml</file>
|
|
||||||
<file>Time.qml</file>
|
|
||||||
</qresource>
|
|
||||||
</RCC>
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
TEMPLATE = subdirs
|
||||||
|
|
||||||
|
SUBDIRS += \
|
||||||
|
ukui-appwidget-time \
|
||||||
|
ukui-appwidget-time-service
|
|
@ -0,0 +1,3 @@
|
||||||
|
[D-BUS Service]
|
||||||
|
Name=org.ukui.appwidget.provider.time
|
||||||
|
Exec=/usr/bin/ukui-appwidget-time-service
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <timeprovider.h>
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
TimeProvider time;
|
||||||
|
return a.exec();
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>data/org.ukui.appwidget.provider.time.service</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
|
@ -0,0 +1,65 @@
|
||||||
|
#include "timeprovider.h"
|
||||||
|
#include <ukui/kappwidgetmanager.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#define UKUI_CONTROL_CENTER_SERVER "org.freedesktop.Accounts"
|
||||||
|
//#define UKUI_CONTROL_CENTER_PATH "/org/freedesktop/Accounts/User1000"
|
||||||
|
#define UKUI_CONTROL_CENTER_INTERFACE "org.freedesktop.Accounts.User"
|
||||||
|
#define PROPERTIES_NAME "FormatsLocale"
|
||||||
|
TimeProvider::TimeProvider(QString providername, QObject *parent)
|
||||||
|
: KAppWidgetProvider(providername, parent)
|
||||||
|
{
|
||||||
|
QString UKUI_CONTROL_CENTER_PATH = "/org/freedesktop/Accounts/User" + QString("%1").arg(QString::number(getuid()));
|
||||||
|
m_interface = new QDBusInterface(UKUI_CONTROL_CENTER_SERVER,
|
||||||
|
UKUI_CONTROL_CENTER_PATH,
|
||||||
|
UKUI_CONTROL_CENTER_INTERFACE,
|
||||||
|
QDBusConnection::systemBus());
|
||||||
|
m_local = m_interface->property(PROPERTIES_NAME);
|
||||||
|
qDebug() << "当前FormatsLocale为:" << m_local;
|
||||||
|
|
||||||
|
}
|
||||||
|
TimeProvider::~TimeProvider()
|
||||||
|
{
|
||||||
|
delete m_manager;
|
||||||
|
}
|
||||||
|
void TimeProvider::appWidgetRecevie(const QString &eventname,
|
||||||
|
const QString &widgetname,
|
||||||
|
const QDBusVariant &value)
|
||||||
|
{
|
||||||
|
Q_UNUSED(eventname);
|
||||||
|
Q_UNUSED(widgetname);
|
||||||
|
Q_UNUSED(value);
|
||||||
|
}
|
||||||
|
void TimeProvider::appWidgetUpdate()
|
||||||
|
{
|
||||||
|
QVariantMap m;
|
||||||
|
m.insert("FormatsLocale", m_local);
|
||||||
|
if(m_manager) {
|
||||||
|
m_manager->updateAppWidget("time", m);
|
||||||
|
qDebug() <<"更新时间小插件";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TimeProvider::appWidgetDisable()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void TimeProvider::appWidgetDeleted()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void TimeProvider::appWidgetEnable()
|
||||||
|
{
|
||||||
|
if(!m_manager) {
|
||||||
|
m_manager = new AppWidget::KAppWidgetManager(this);
|
||||||
|
}
|
||||||
|
QVariantMap m;
|
||||||
|
m.insert("FormatsLocale" , m_local);
|
||||||
|
if(m_manager) {
|
||||||
|
m_manager->updateAppWidget("time", m);
|
||||||
|
qDebug() <<"更新时间小插件";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TimeProvider::appWidgetClicked(const QString &widgetname, const QDBusVariant &value)
|
||||||
|
{
|
||||||
|
Q_UNUSED(widgetname);
|
||||||
|
Q_UNUSED(value);
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef TIMEPROVIDER_H
|
||||||
|
#define TIMEPROVIDER_H
|
||||||
|
#include <QtDBus/QtDBus>
|
||||||
|
#include <ukui/kappwidgetprovider.h>
|
||||||
|
namespace AppWidget {
|
||||||
|
class KAppWidgetManager;
|
||||||
|
}
|
||||||
|
class TimeProvider:public AppWidget::KAppWidgetProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TimeProvider(QString providername = "time",QObject *parent = nullptr);
|
||||||
|
~TimeProvider();
|
||||||
|
void appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value);
|
||||||
|
void appWidgetUpdate();
|
||||||
|
void appWidgetDisable();
|
||||||
|
void appWidgetDeleted();
|
||||||
|
void appWidgetEnable();
|
||||||
|
void appWidgetClicked(const QString &widgetname, const QDBusVariant &value);
|
||||||
|
private:
|
||||||
|
AppWidget::KAppWidgetManager * m_manager = nullptr;
|
||||||
|
QDBusInterface *m_interface = nullptr;
|
||||||
|
QVariant m_local;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TIMEPROVIDER_H
|
|
@ -0,0 +1,34 @@
|
||||||
|
QT -= gui
|
||||||
|
QT += dbus
|
||||||
|
|
||||||
|
CONFIG += c++11 console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
# 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). Please consult the documentation of the
|
||||||
|
# deprecated API in order 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
|
||||||
|
LIBS += -lukui-appwidget-manager -lukui-appwidget-provider
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
main.cpp \
|
||||||
|
timeprovider.cpp
|
||||||
|
|
||||||
|
# Default rules for deployment.
|
||||||
|
qnx: target.path = /usr/bin/
|
||||||
|
else: unix:!android: target.path = /usr/bin/
|
||||||
|
timeservice.files += data/org.ukui.appwidget.provider.time.service
|
||||||
|
timeservice.path += /usr/share/dbus-1/services/
|
||||||
|
INSTALLS += target timeservice
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
timeprovider.h
|
||||||
|
|
||||||
|
RESOURCES += \
|
||||||
|
src.qrc
|
|
@ -1,7 +1,7 @@
|
||||||
[AppWidget]
|
[AppWidget]
|
||||||
name = time
|
name = time
|
||||||
providerName = clock
|
providerName = time
|
||||||
previewPath = /usr/share/appwidgetdemo/clock/time.png
|
previewPath = /usr/share/appwidgetdemo/time/time.png
|
||||||
qmlFile = /usr/share/appwidget/qml/time.qml
|
qmlFile = /usr/share/appwidget/qml/time.qml
|
||||||
zoom = false
|
zoom = false
|
||||||
rightButton = false
|
rightButton = false
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
@ -13,7 +13,8 @@ AppWidget {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
property double scalefactor: 1.00
|
property double scalefactor: 1.00
|
||||||
property string timeformat: "12";
|
property string timeformat: "12";
|
||||||
property string dateformat: "cn"
|
property string dateformat: "cn";
|
||||||
|
property string locale: "zh_CN.UTF-8"
|
||||||
property string hour;
|
property string hour;
|
||||||
property string minute;
|
property string minute;
|
||||||
property int hournumber;
|
property int hournumber;
|
||||||
|
@ -22,6 +23,8 @@ AppWidget {
|
||||||
property bool v: false
|
property bool v: false
|
||||||
property string themename;
|
property string themename;
|
||||||
property bool qmleffect: false
|
property bool qmleffect: false
|
||||||
|
property bool qmlenable: true
|
||||||
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: gettime;
|
id: gettime;
|
||||||
|
@ -35,19 +38,19 @@ AppWidget {
|
||||||
if(appwidget.timeformat === "12") {
|
if(appwidget.timeformat === "12") {
|
||||||
appwidget.hournumber = Number(appwidget.hour);
|
appwidget.hournumber = Number(appwidget.hour);
|
||||||
if(appwidget.hournumber > 12) {
|
if(appwidget.hournumber > 12) {
|
||||||
if(appwidget.dateformat == "cn") {
|
if(appwidget.locale == "zh_CN.UTF-8") {
|
||||||
ampm.text = "下午"
|
ampm.text = "下午"
|
||||||
}
|
}
|
||||||
else if(appwidget.dateformat == "en") {
|
else if(appwidget.locale == "en_US.UTF-8") {
|
||||||
ampm.text = "PM"
|
ampm.text = "PM"
|
||||||
}
|
}
|
||||||
appwidget.hournumber -= 12;
|
appwidget.hournumber -= 12;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(appwidget.dateformat == "cn") {
|
if(appwidget.locale == "zh_CN.UTF-8") {
|
||||||
ampm.text = "上午"
|
ampm.text = "上午"
|
||||||
}
|
}
|
||||||
else if(appwidget.dateformat == "en") {
|
else if(appwidget.locale == "en_US.UTF-8") {
|
||||||
ampm.text = "AM"
|
ampm.text = "AM"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +96,11 @@ AppWidget {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
visible: !v
|
visible: !v
|
||||||
|
Component.onCompleted:{
|
||||||
|
console.log("===aaaa=======",twelverec.width,twelverec.height)
|
||||||
|
console.log("=====",appwidget.scalefactor)
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id :time1rec
|
id :time1rec
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
@ -241,6 +249,7 @@ AppWidget {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.left: spacing2.right
|
anchors.left: spacing2.right
|
||||||
|
|
||||||
|
|
||||||
ColumnLayout{
|
ColumnLayout{
|
||||||
width: 87*appwidget.scalefactor
|
width: 87*appwidget.scalefactor
|
||||||
height: 112*appwidget.scalefactor
|
height: 112*appwidget.scalefactor
|
||||||
|
@ -284,7 +293,9 @@ AppWidget {
|
||||||
|
|
||||||
initScalefactor()
|
initScalefactor()
|
||||||
gettime.start();
|
gettime.start();
|
||||||
// appwidget.update.connect(appwidget.onupdate);
|
|
||||||
|
appwidget.update.connect(appwidget.onupdate);
|
||||||
|
userStatusChangedSignal.connect(onUserStatusChanged)
|
||||||
console.log("qml 接收到数据更新信号");
|
console.log("qml 接收到数据更新信号");
|
||||||
|
|
||||||
appwidget.creatGsetting("org.ukui.control-center.panel.plugins");
|
appwidget.creatGsetting("org.ukui.control-center.panel.plugins");
|
||||||
|
@ -298,6 +309,17 @@ AppWidget {
|
||||||
}
|
}
|
||||||
console.log("当前gsetting为", timeformat, dateformat);
|
console.log("当前gsetting为", timeformat, dateformat);
|
||||||
}
|
}
|
||||||
|
function onupdate()
|
||||||
|
{
|
||||||
|
for (var i in appwidget.datavalue)
|
||||||
|
{
|
||||||
|
var info = appwidget.datavalue[i];
|
||||||
|
if( i === "FormatsLocale") {
|
||||||
|
console.log("date", info);
|
||||||
|
appwidget.locale = info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
function onGsettingUpdate(key, value)
|
function onGsettingUpdate(key, value)
|
||||||
{
|
{
|
||||||
if(key === "hoursystem")
|
if(key === "hoursystem")
|
||||||
|
@ -318,7 +340,7 @@ AppWidget {
|
||||||
{
|
{
|
||||||
//按宽计算缩放比例,计算在这个比例系数下的小插件宽高,如果高超出父类的高,则更换比例系数的计算方式
|
//按宽计算缩放比例,计算在这个比例系数下的小插件宽高,如果高超出父类的高,则更换比例系数的计算方式
|
||||||
//按高计算缩放比例
|
//按高计算缩放比例
|
||||||
//console.log("父类窗口大小", appwidget.parent.width,appwidget.parent.height);
|
console.log("父类窗口大小", appwidget.parent.width,appwidget.parent.height);
|
||||||
if(appwidget.parent.width == 0 || appwidget.parent.height == 0) {
|
if(appwidget.parent.width == 0 || appwidget.parent.height == 0) {
|
||||||
appwidget.scalefactor = 1.0
|
appwidget.scalefactor = 1.0
|
||||||
console.log("父类窗口大小为 0 默认缩放比为1.0")
|
console.log("父类窗口大小为 0 默认缩放比为1.0")
|
||||||
|
@ -334,6 +356,16 @@ AppWidget {
|
||||||
//console.log("以宽度计算比例系数", appwidget.scalefactor);
|
//console.log("以宽度计算比例系数", appwidget.scalefactor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function onUserStatusChanged(status)
|
||||||
|
{
|
||||||
|
console.log("qml Appwidget demosearch user status changed ", status);
|
||||||
|
if(status === "Normal") {
|
||||||
|
appwidget.qmlenable = true;
|
||||||
|
}else if(status === "Editable") {
|
||||||
|
appwidget.qmlenable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import QtQuick.Window 2.12
|
import QtQuick.Window 2.12
|
||||||
|
//import QtQuick.Controls 2.12
|
||||||
Window {
|
Window {
|
||||||
visible: true
|
visible: true
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
color: "transparent"
|
|
||||||
title: qsTr("Hello World")
|
title: qsTr("Hello World")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Rectangle{
|
Rectangle{
|
||||||
|
|
||||||
width: 300
|
id:rec
|
||||||
height: 200
|
anchors.centerIn: parent
|
||||||
// color: "transparent"
|
width: 448
|
||||||
|
height:162
|
||||||
|
color: "transparent"
|
||||||
border.color: "green"
|
border.color: "green"
|
||||||
Time{
|
Loader{
|
||||||
|
source: "/data/time.qml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>main.qml</file>
|
||||||
|
<file>data/time.qml</file>
|
||||||
|
<file>data/time.png</file>
|
||||||
|
<file>data/time.conf</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
|
@ -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.qml
|
||||||
|
timeqml.path = /usr/share/appwidget/qml/
|
||||||
|
timeconf.files += data/time.conf
|
||||||
|
timeconf.path = /usr/share/appwidget/config/
|
||||||
|
timepreview.files += data/time.png
|
||||||
|
timepreview.path = /usr/share/appwidgetdemo/time/
|
||||||
|
|
||||||
|
INSTALLS += target timeqml timepreview timeconf
|
|
@ -1,36 +1,4 @@
|
||||||
QT += quick
|
TEMPLATE = subdirs
|
||||||
|
|
||||||
CONFIG += c++11
|
SUBDIRS += \
|
||||||
|
time
|
||||||
# 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
|
|
||||||
|
|
Loading…
Reference in New Issue