dock/qml/ControlCenterItem.qml

94 lines
3.5 KiB
QML
Raw Normal View History

2021-03-15 20:17:11 -07:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.0
2021-03-16 03:20:04 -07:00
import Cutefish.Dock 1.0
2021-03-15 20:17:11 -07:00
import MeuiKit 1.0 as Meui
StandardItem {
id: controlItem
2021-03-20 02:17:41 -07:00
Layout.preferredWidth: isHorizontal ? controlLayout.implicitWidth + root.largeSpacing * 2 : mainLayout.width * 0.7
Layout.preferredHeight: isHorizontal ? mainLayout.height * 0.7 : controlLayout.implicitHeight + root.largeSpacing * 2
Layout.rightMargin: isHorizontal ? root.windowRadius ? root.windowRadius / 2 : root.largeSpacing : 0
Layout.bottomMargin: isHorizontal ? 0 : root.windowRadius ? root.windowRadius / 2 : root.largeSpacing
2021-03-15 20:17:11 -07:00
Layout.alignment: Qt.AlignCenter
onClicked: {
if (controlCenter.visible)
controlCenter.visible = false
else {
// 先初始化用户可能会通过Alt鼠标左键移动位置
controlCenter.position = Qt.point(0, 0)
controlCenter.visible = true
controlCenter.position = Qt.point(mapToGlobal(0, 0).x, mapToGlobal(0, 0).y)
}
}
GridLayout {
id: controlLayout
anchors.fill: parent
2021-03-20 02:17:41 -07:00
anchors.leftMargin: isHorizontal ? root.smallSpacing : 0
anchors.rightMargin: isHorizontal ? root.smallSpacing : 0
anchors.topMargin: isHorizontal ? root.smallSpacing : 0
anchors.bottomMargin: isHorizontal ? root.smallSpacing : 0
columnSpacing: isHorizontal ? root.largeSpacing + root.smallSpacing : 0
rowSpacing: isHorizontal ? 0 : root.largeSpacing + root.smallSpacing
2021-03-15 20:17:11 -07:00
flow: isHorizontal ? Grid.LeftToRight : Grid.TopToBottom
2021-03-23 00:36:06 -07:00
Image {
id: volumeIcon
visible: volume.isValid && status === Image.Ready
source: "qrc:/svg/" + (Meui.Theme.darkMode ? "dark/" : "light/") + volume.iconName + ".svg"
width: root.trayItemSize
height: width
sourceSize: Qt.size(width, height)
asynchronous: true
Layout.alignment: Qt.AlignCenter
}
2021-03-15 20:17:11 -07:00
Image {
id: wirelessIcon
width: root.trayItemSize
height: width
sourceSize: Qt.size(width, height)
source: network.wirelessIconName ? "qrc:/svg/" + (Meui.Theme.darkMode ? "dark/" : "light/") + network.wirelessIconName + ".svg" : ""
asynchronous: true
Layout.alignment: Qt.AlignCenter
visible: network.enabled &&
network.wirelessEnabled &&
network.wirelessConnectionName !== "" &&
wirelessIcon.status === Image.Ready
}
Image {
id: batteryIcon
visible: battery.available && status === Image.Ready
height: root.trayItemSize
width: height + 6
sourceSize: Qt.size(width, height)
source: "qrc:/svg/" + (Meui.Theme.darkMode ? "dark/" : "light/") + battery.iconSource
asynchronous: true
Layout.alignment: Qt.AlignCenter
}
Label {
id: timeLabel
Layout.alignment: Qt.AlignCenter
font.pixelSize: isHorizontal ? controlLayout.height / 3 : controlLayout.width / 5
Timer {
interval: 1000
repeat: true
running: true
triggeredOnStart: true
onTriggered: {
timeLabel.text = new Date().toLocaleTimeString(Qt.locale(), Locale.ShortFormat)
}
}
}
}
}