forked from openkylin/ukui-system-appwidget
update:添加时间小插件在不同缩放比的情况在在桌面的适应,根据使用端提供的窗口进行缩放小插件
This commit is contained in:
parent
a7d37e0b99
commit
a8bf5cfa43
72
Time.qml
72
Time.qml
|
@ -8,12 +8,10 @@ AppWidget {
|
|||
id:appwidget
|
||||
appname: "time"
|
||||
visible: true
|
||||
width: 448
|
||||
height: 162
|
||||
// color: "gray"
|
||||
// color: "transparent"
|
||||
// border.color: "red"
|
||||
// radius: 15
|
||||
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;
|
||||
|
@ -99,14 +97,14 @@ AppWidget {
|
|||
color: "transparent"
|
||||
// border.color: "green"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 244
|
||||
height: 112
|
||||
width: 244*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
Text {
|
||||
id: time1
|
||||
anchors.fill:parent
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: "#FAFAFA"
|
||||
font.pixelSize:112
|
||||
font.pixelSize:112*appwidget.scalefactor
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
|
||||
|
@ -121,8 +119,8 @@ AppWidget {
|
|||
Rectangle {
|
||||
//间隔
|
||||
id :spacing1
|
||||
width: 16
|
||||
height: 112
|
||||
width: 16*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
anchors.left: time1rec.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: "transparent"
|
||||
|
@ -131,20 +129,20 @@ AppWidget {
|
|||
id :daterec
|
||||
color: "transparent"
|
||||
// border.color: "pink"
|
||||
width: 137
|
||||
height: 96
|
||||
width: 137*appwidget.scalefactor
|
||||
height: 96*appwidget.scalefactor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
Layout.fillWidth: true
|
||||
anchors.left: spacing1.right
|
||||
|
||||
ColumnLayout{
|
||||
width: 137
|
||||
height: 96
|
||||
width: 137*appwidget.scalefactor
|
||||
height: 96*appwidget.scalefactor
|
||||
anchors.centerIn: parent
|
||||
Text {
|
||||
id: ampm
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize:40;
|
||||
font.pixelSize:40*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -160,7 +158,7 @@ AppWidget {
|
|||
Text {
|
||||
id: week1
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize: 28;
|
||||
font.pixelSize: 28*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -175,7 +173,7 @@ AppWidget {
|
|||
Text {
|
||||
id: date1
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize: 28;
|
||||
font.pixelSize: 28*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -206,14 +204,14 @@ AppWidget {
|
|||
color: "transparent"
|
||||
// border.color: "pink"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 294
|
||||
height: 112
|
||||
width: 294*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
Text {
|
||||
id: time2
|
||||
anchors.fill:parent
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: "#FAFAFA"
|
||||
font.pixelSize:112
|
||||
font.pixelSize:112*appwidget.scalefactor
|
||||
font.letterSpacing:0
|
||||
font.family: "STxihei"
|
||||
|
||||
|
@ -228,29 +226,29 @@ AppWidget {
|
|||
Rectangle {
|
||||
//间隔
|
||||
id :spacing2
|
||||
width: 16
|
||||
height: 112
|
||||
width: 16*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
anchors.left: time2rec.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: "transparent"
|
||||
}
|
||||
Rectangle {
|
||||
color: "transparent"
|
||||
width: 87
|
||||
height: 112
|
||||
width: 87*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
Layout.fillWidth: true
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: spacing2.right
|
||||
|
||||
ColumnLayout{
|
||||
width: 87
|
||||
height: 112
|
||||
width: 87*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
anchors.centerIn: parent
|
||||
Layout.fillWidth: true
|
||||
Text {
|
||||
id: week2
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize:40;
|
||||
font.pixelSize:40*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -265,7 +263,7 @@ AppWidget {
|
|||
Text {
|
||||
id: date2
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize:40;
|
||||
font.pixelSize:40*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -283,6 +281,7 @@ AppWidget {
|
|||
|
||||
Component.onCompleted: {
|
||||
|
||||
initScalefactor()
|
||||
gettime.start();
|
||||
// appwidget.update.connect(appwidget.onupdate);
|
||||
console.log("qml 接收到数据更新信号");
|
||||
|
@ -314,6 +313,21 @@ AppWidget {
|
|||
dateformat = value
|
||||
}
|
||||
}
|
||||
function initScalefactor()
|
||||
{
|
||||
//按宽计算缩放比例,计算在这个比例系数下的小插件宽高,如果高超出父类的高,则更换比例系数的计算方式
|
||||
//按高计算缩放比例,
|
||||
//console.log("父类窗口大小", appwidget.parent.width,appwidget.parent.height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,12 +8,10 @@ AppWidget {
|
|||
id:appwidget
|
||||
appname: "time"
|
||||
visible: true
|
||||
width: 448
|
||||
height: 162
|
||||
// color: "gray"
|
||||
// color: "transparent"
|
||||
// border.color: "red"
|
||||
// radius: 15
|
||||
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;
|
||||
|
@ -99,14 +97,14 @@ AppWidget {
|
|||
color: "transparent"
|
||||
// border.color: "green"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 244
|
||||
height: 112
|
||||
width: 244*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
Text {
|
||||
id: time1
|
||||
anchors.fill:parent
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: "#FAFAFA"
|
||||
font.pixelSize:112
|
||||
font.pixelSize:112*appwidget.scalefactor
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
|
||||
|
@ -121,8 +119,8 @@ AppWidget {
|
|||
Rectangle {
|
||||
//间隔
|
||||
id :spacing1
|
||||
width: 16
|
||||
height: 112
|
||||
width: 16*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
anchors.left: time1rec.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: "transparent"
|
||||
|
@ -131,20 +129,20 @@ AppWidget {
|
|||
id :daterec
|
||||
color: "transparent"
|
||||
// border.color: "pink"
|
||||
width: 137
|
||||
height: 96
|
||||
width: 137*appwidget.scalefactor
|
||||
height: 96*appwidget.scalefactor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
Layout.fillWidth: true
|
||||
anchors.left: spacing1.right
|
||||
|
||||
ColumnLayout{
|
||||
width: 137
|
||||
height: 96
|
||||
width: 137*appwidget.scalefactor
|
||||
height: 96*appwidget.scalefactor
|
||||
anchors.centerIn: parent
|
||||
Text {
|
||||
id: ampm
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize:40;
|
||||
font.pixelSize:40*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -160,7 +158,7 @@ AppWidget {
|
|||
Text {
|
||||
id: week1
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize: 28;
|
||||
font.pixelSize: 28*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -175,7 +173,7 @@ AppWidget {
|
|||
Text {
|
||||
id: date1
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize: 28;
|
||||
font.pixelSize: 28*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -206,14 +204,14 @@ AppWidget {
|
|||
color: "transparent"
|
||||
// border.color: "pink"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 294
|
||||
height: 112
|
||||
width: 294*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
Text {
|
||||
id: time2
|
||||
anchors.fill:parent
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: "#FAFAFA"
|
||||
font.pixelSize:112
|
||||
font.pixelSize:112*appwidget.scalefactor
|
||||
font.letterSpacing:0
|
||||
font.family: "STxihei"
|
||||
|
||||
|
@ -228,29 +226,29 @@ AppWidget {
|
|||
Rectangle {
|
||||
//间隔
|
||||
id :spacing2
|
||||
width: 16
|
||||
height: 112
|
||||
width: 16*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
anchors.left: time2rec.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: "transparent"
|
||||
}
|
||||
Rectangle {
|
||||
color: "transparent"
|
||||
width: 87
|
||||
height: 112
|
||||
width: 87*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
Layout.fillWidth: true
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: spacing2.right
|
||||
|
||||
ColumnLayout{
|
||||
width: 87
|
||||
height: 112
|
||||
width: 87*appwidget.scalefactor
|
||||
height: 112*appwidget.scalefactor
|
||||
anchors.centerIn: parent
|
||||
Layout.fillWidth: true
|
||||
Text {
|
||||
id: week2
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize:40;
|
||||
font.pixelSize:40*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -265,7 +263,7 @@ AppWidget {
|
|||
Text {
|
||||
id: date2
|
||||
color: "#FAFAFA";
|
||||
font.pixelSize:40;
|
||||
font.pixelSize:40*appwidget.scalefactor;
|
||||
font.letterSpacing: 0
|
||||
font.family: "STxihei"
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
|
@ -283,6 +281,7 @@ AppWidget {
|
|||
|
||||
Component.onCompleted: {
|
||||
|
||||
initScalefactor()
|
||||
gettime.start();
|
||||
// appwidget.update.connect(appwidget.onupdate);
|
||||
console.log("qml 接收到数据更新信号");
|
||||
|
@ -314,6 +313,21 @@ AppWidget {
|
|||
dateformat = value
|
||||
}
|
||||
}
|
||||
function initScalefactor()
|
||||
{
|
||||
//按宽计算缩放比例,计算在这个比例系数下的小插件宽高,如果高超出父类的高,则更换比例系数的计算方式
|
||||
//按高计算缩放比例
|
||||
//console.log("父类窗口大小", appwidget.parent.width,appwidget.parent.height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue