KDE Plasma 任务栏时间

2 篇文章 0 订阅
1 篇文章 0 订阅

自定义plasma目录:~/.local/share/plasma/plasmoids/

调试:plasmawindowed org.hty.datetime

metadata.json

{
    "KPlugin": {
	    "Id": "org.hty.datetime",
        "Authors": [
            {
                "Email": "sonichy@163.com",
                "Name": "sonichy"
            }
        ],
        "Icon": "preferences-system-time",
        "Category": "Date and Time",
        "Name": "HTY Calendar",
        "Name[zh_CN]": "海天鹰日期时间",
        "Description": "Hai Tian Ying datetime",
        "Description[zh_CN]": "显示时间,日期,日历",
        "ServiceTypes": [
            "Plasma/Applet"
        ],
        "Version": "1.0",
        "Website": "https://github.com/sonichy/datetime_plasma",
        "License": "GPL-2.0+"
    },
    "X-Plasma-API": "declarativeappletscript",
    "X-Plasma-MainScript": "ui/main.qml"
}

contents/ui/main.qml

import QtQuick 2.0
import QtQuick.Layouts 1.1

import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.calendar 2.0 as PlasmaCalendar

Item {
    id: root

    readonly property date currentDateTime: dataSource.data.Local ? dataSource.data.Local.DateTime : new Date()

    width: PlasmaCore.Units.gridUnit * 10
    height: PlasmaCore.Units.gridUnit * 4

    Plasmoid.toolTipMainText: Qt.formatTime(currentDateTime, "hh:mm")
    Plasmoid.toolTipSubText: Qt.formatDate(currentDateTime, Qt.locale().dateFormat(Locale.LongFormat))

    PlasmaCore.DataSource {
        id: dataSource
        engine: "time"
        connectedSources: ["Local"]
        interval: 60000
        intervalAlignment: PlasmaCore.Types.AlignToMinute
    }

	Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
    Plasmoid.compactRepresentation: CompactRepresentation { }

    Plasmoid.fullRepresentation: PlasmaCalendar.MonthView {
        Layout.minimumWidth: PlasmaCore.Units.gridUnit * 20
        Layout.minimumHeight: PlasmaCore.Units.gridUnit * 20
        today: currentDateTime
    }
}

contents/ui/CompactRepresentation.qml 

import QtQuick 2.5
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
 
Item {
	anchors.fill: parent
	Layout.preferredWidth: textMetrics.width
	
	property var fontSize: 20
	property var fontFamily: "serif"
	property bool showSeconds: plasmoid.configuration.showSeconds
	
	TextMetrics {
        id: textMetrics
        font {
            //family: fontFamily
            pixelSize: fontSize
        }
        text: "00:00:00"
	}

	ColumnLayout {
		spacing: -6
		
		Text {
			id: time
			width: parent.width
		    color: theme.textColor
		    font.pixelSize: fontSize
			Layout.alignment: Qt.AlignCenter
		}
		
		Text {
			id: tdate
			width: parent.width
		    color: theme.textColor
		    font.pixelSize: fontSize - 5
			Layout.alignment: Qt.AlignCenter
		}
    }
    
    Timer {
        //interval: 1000  //定时器时间间隔,默认1000ms
        running: true  //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
        repeat: true   //是否重复定时,默认为false
        onTriggered: { //定时触发槽,定时完成一次就进入一次
        	var date = new Date()
        	if (showSeconds) {
        	    time.text = date.toLocaleString(Qt.locale(), "HH:mm:ss")
        	    tdate.text = date.toLocaleString(Qt.locale(), "M/d ddd")
        	} else {
        	    time.text = date.toLocaleString(Qt.locale(), "HH:mm")
          	    tdate.text = date.toLocaleString(Qt.locale(), "M/d ddd")
        	}
        }
    }
    
    MouseArea {
        anchors.fill: parent
        onClicked: plasmoid.expanded = !plasmoid.expanded
    }
    
}

入门踩坑

1.id(metadata.json) 和目录名必须一样,否则部件无法添加!

2.添加部件前必须重启 plasma 来重载部件:plasmashell --replace

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值