forked from openkylin/ukui-system-appwidget
Fix: Optimize code structure
This commit is contained in:
parent
29f675451e
commit
e373f7e0fe
|
@ -4,35 +4,3 @@ TimeProvider::TimeProvider(QString providername, QObject *parent)
|
|||
: KAppWidgetProvider(providername, parent)
|
||||
{
|
||||
}
|
||||
TimeProvider::~TimeProvider()
|
||||
{
|
||||
}
|
||||
void TimeProvider::appWidgetRecevie(const QString &eventname,
|
||||
const QString &widgetname,
|
||||
const QDBusVariant &value)
|
||||
{
|
||||
Q_UNUSED(eventname);
|
||||
Q_UNUSED(widgetname);
|
||||
Q_UNUSED(value);
|
||||
}
|
||||
void TimeProvider::appWidgetUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
void TimeProvider::appWidgetDisable()
|
||||
{
|
||||
|
||||
}
|
||||
void TimeProvider::appWidgetDeleted()
|
||||
{
|
||||
|
||||
}
|
||||
void TimeProvider::appWidgetEnable()
|
||||
{
|
||||
|
||||
}
|
||||
void TimeProvider::appWidgetClicked(const QString &widgetname, const QDBusVariant &value)
|
||||
{
|
||||
Q_UNUSED(widgetname);
|
||||
Q_UNUSED(value);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef TIMEPROVIDER_H
|
||||
#define TIMEPROVIDER_H
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <ukui/kappwidgetprovider.h>
|
||||
namespace AppWidget {
|
||||
class KAppWidgetManager;
|
||||
|
@ -9,13 +8,7 @@ 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);
|
||||
~TimeProvider() override = default;
|
||||
};
|
||||
|
||||
#endif // TIMEPROVIDER_H
|
||||
|
|
|
@ -16,16 +16,12 @@ AppWidget {
|
|||
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
|
||||
property bool qmlenable: true
|
||||
property var timeStr: ""
|
||||
property var dateInfo: ""
|
||||
property var timeInfo: ""
|
||||
|
||||
Timer {
|
||||
id: gettime;
|
||||
|
@ -307,40 +303,47 @@ AppWidget {
|
|||
}
|
||||
function updateTimeInfo()
|
||||
{
|
||||
appwidget.timeInfo = (appwidget.timeformat === "12") ? "hh mm AP" : "hh mm";
|
||||
appwidget.timeStr = Qt.formatTime(new Date(), appwidget.timeInfo).trim().split(/\s+/);
|
||||
appwidget.hour = appwidget.timeStr[0];
|
||||
appwidget.minute = appwidget.timeStr[1];
|
||||
if (appwidget.timeInfo === "hh mm AP") {
|
||||
appwidget.hournumber = Number(appwidget.hour);
|
||||
if(appwidget.hournumber < 10) {
|
||||
time1rec.width = 244*appwidget.scalefactor
|
||||
}
|
||||
else {
|
||||
time1rec.width = 294*appwidget.scalefactor;
|
||||
}
|
||||
appwidget.hour = appwidget.hournumber.toString();
|
||||
var timeInfo = "";
|
||||
timeInfo = (appwidget.timeformat === "12") ? "hh mm AP" : "hh mm";
|
||||
updateSystemTime(timeInfo);
|
||||
if (timeInfo === "hh mm AP") {
|
||||
updateTimeRecWidth(appwidget.hour);
|
||||
ampm.text = Qt.formatTime(new Date(), "AP");
|
||||
}
|
||||
|
||||
time1.text = appwidget.hour + ":" + appwidget.minute;
|
||||
time2.text = appwidget.hour + ":" + appwidget.minute
|
||||
}
|
||||
function updateSystemTime(timeString)
|
||||
{
|
||||
var timeStr = "";
|
||||
timeStr = Qt.formatTime(new Date(), timeString).trim().split(/\s+/);
|
||||
appwidget.hour = timeStr[0];
|
||||
appwidget.minute = timeStr[1];
|
||||
}
|
||||
function updateTimeRecWidth(hh)
|
||||
{
|
||||
var hournumber = 0;
|
||||
hournumber = Number(hh);
|
||||
appwidget.hour = hournumber.toString();
|
||||
time1rec.width = hournumber < 10 ? 244*appwidget.scalefactor
|
||||
: 294*appwidget.scalefactor
|
||||
}
|
||||
function updateWeakInfo()
|
||||
{
|
||||
week1.text = Qt.formatDate(new Date(),"ddd")
|
||||
week2.text = Qt.formatDate(new Date(),"ddd")
|
||||
week1.text = Qt.formatDate(new Date(), "ddd")
|
||||
week2.text = Qt.formatDate(new Date(), "ddd")
|
||||
}
|
||||
function updateDateInfo()
|
||||
{
|
||||
var dateInfo = "";
|
||||
if(dateformat == "cn") {
|
||||
appwidget.dateInfo = "MM/dd";
|
||||
dateInfo = "MM/dd";
|
||||
}
|
||||
if(dateformat == "en") {
|
||||
appwidget.dateInfo = "MM-dd";
|
||||
dateInfo = "MM-dd";
|
||||
}
|
||||
date1.text = Qt.formatDate(new Date(),appwidget.dateInfo);
|
||||
date2.text = Qt.formatDate(new Date(),appwidget.dateInfo);
|
||||
date1.text = Qt.formatDate(new Date(), dateInfo);
|
||||
date2.text = Qt.formatDate(new Date(), dateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue