You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
statusbar/qml/main.qml

251 lines
8.0 KiB
QML

5 years ago
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import QtQuick.Window 2.12
5 years ago
import Cutefish.StatusBar 1.0
5 years ago
import Cutefish.NetworkManagement 1.0 as NM
5 years ago
import FishUI 1.0 as FishUI
5 years ago
Item {
id: rootItem
property int iconSize: 16 * Screen.devicePixelRatio
5 years ago
5 years ago
Rectangle {
id: background
anchors.fill: parent
5 years ago
color: FishUI.Theme.backgroundColor
opacity: 0.6
5 years ago
Behavior on color {
ColorAnimation {
duration: 200
easing.type: Easing.Linear
}
}
5 years ago
}
5 years ago
FishUI.PopupTips {
5 years ago
id: popupTips
5 years ago
backgroundColor: FishUI.Theme.backgroundColor
backgroundOpacity: FishUI.Theme.darkMode ? 0.3 : 0.4
5 years ago
}
5 years ago
FishUI.DesktopMenu {
id: acticityMenu
MenuItem {
text: qsTr("Close")
onTriggered: acticity.close()
}
}
5 years ago
RowLayout {
anchors.fill: parent
5 years ago
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
spacing: FishUI.Units.smallSpacing
5 years ago
StandardItem {
id: acticityItem
Layout.fillHeight: true
Layout.preferredWidth: acticityLayout.implicitWidth ? Math.min(acticityLayout.implicitWidth + FishUI.Units.largeSpacing,
rootItem.width / 2)
: 0
onClicked: acticityMenu.open()
RowLayout {
id: acticityLayout
anchors.fill: parent
5 years ago
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
5 years ago
spacing: FishUI.Units.smallSpacing * 1.5
Image {
id: acticityIcon
5 years ago
width: rootItem.iconSize
height: rootItem.iconSize
5 years ago
sourceSize: Qt.size(rootItem.iconSize,
rootItem.iconSize)
source: acticity.icon ? "image://icontheme/" + acticity.icon : ""
visible: status === Image.Ready
}
Label {
id: acticityLabel
text: acticity.title
Layout.fillWidth: true
elide: Qt.ElideRight
color: FishUI.Theme.darkMode ? 'white' : 'black'
visible: text
5 years ago
Layout.alignment: Qt.AlignVCenter
font.pointSize: parent.height ? parent.height / 3 : 1
}
}
}
5 years ago
Item {
Layout.fillWidth: true
}
ListView {
id: trayView
orientation: Qt.Horizontal
layoutDirection: Qt.RightToLeft
interactive: false
clip: true
spacing: FishUI.Units.smallSpacing
5 years ago
property var itemSize: rootItem.height * 0.8
5 years ago
property var itemWidth: itemSize + FishUI.Units.smallSpacing
5 years ago
Layout.fillHeight: true
Layout.preferredWidth: (itemWidth + (count - 1) * FishUI.Units.smallSpacing) * count
5 years ago
model: SystemTrayModel {
id: trayModel
}
delegate: StandardItem {
width: trayView.itemWidth
height: ListView.view.height
5 years ago
property bool darkMode: FishUI.Theme.darkMode
5 years ago
onDarkModeChanged: updateTimer.restart()
Timer {
id: updateTimer
interval: 10
onTriggered: iconItem.updateIcon()
}
5 years ago
FishUI.IconItem {
5 years ago
id: iconItem
5 years ago
anchors.centerIn: parent
5 years ago
width: rootItem.iconSize
5 years ago
height: width
source: model.iconName ? model.iconName : model.icon
5 years ago
}
onClicked: trayModel.leftButtonClick(model.id)
onRightClicked: trayModel.rightButtonClick(model.id)
popupText: model.toolTip ? model.toolTip : model.title
}
}
StandardItem {
id: controler
Layout.fillHeight: true
5 years ago
Layout.preferredWidth: _controlerLayout.implicitWidth + FishUI.Units.largeSpacing
5 years ago
onClicked: {
if (controlDialog.visible)
controlDialog.visible = false
else {
// 先初始化用户可能会通过Alt鼠标左键移动位置
controlDialog.position = Qt.point(0, 0)
controlDialog.visible = true
controlDialog.position = Qt.point(mapToGlobal(0, 0).x, mapToGlobal(0, 0).y)
}
}
RowLayout {
id: _controlerLayout
anchors.fill: parent
5 years ago
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
5 years ago
5 years ago
spacing: FishUI.Units.largeSpacing
5 years ago
Image {
id: volumeIcon
visible: volume.isValid && status === Image.Ready
5 years ago
source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark/" : "light/") + volume.iconName + ".svg"
5 years ago
width: rootItem.iconSize
5 years ago
height: width
sourceSize: Qt.size(width, height)
asynchronous: true
Layout.alignment: Qt.AlignCenter
}
Image {
id: wirelessIcon
5 years ago
width: rootItem.iconSize
5 years ago
height: width
sourceSize: Qt.size(width, height)
5 years ago
source: network.wirelessIconName ? "qrc:/images/" + (FishUI.Theme.darkMode ? "dark/" : "light/") + network.wirelessIconName + ".svg" : ""
5 years ago
asynchronous: true
Layout.alignment: Qt.AlignCenter
visible: network.enabled &&
network.wirelessEnabled &&
network.wirelessConnectionName !== "" &&
wirelessIcon.status === Image.Ready
}
// Battery Item
RowLayout {
5 years ago
visible: battery.available
Image {
id: batteryIcon
height: rootItem.iconSize
5 years ago
width: height + (6 * Screen.devicePixelRatio)
sourceSize: Qt.size(width, height)
5 years ago
source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark/" : "light/") + battery.iconSource
Layout.alignment: Qt.AlignCenter
}
5 years ago
Label {
text: battery.chargePercent + "%"
5 years ago
font.pointSize: parent.height ? parent.height / 2 : 1
color: FishUI.Theme.darkMode ? 'white' : 'black'
visible: battery.showPercentage
}
}
5 years ago
Label {
id: timeLabel
Layout.alignment: Qt.AlignCenter
5 years ago
font.pointSize: parent.height ? parent.height / 3 : 1
color: FishUI.Theme.darkMode ? 'white' : 'black'
5 years ago
Timer {
interval: 1000
repeat: true
running: true
triggeredOnStart: true
onTriggered: {
timeLabel.text = new Date().toLocaleTimeString(Qt.locale(), Locale.ShortFormat)
}
}
}
}
}
}
// Components
ControlDialog {
id: controlDialog
}
Volume {
id: volume
}
Battery {
id: battery
}
NM.ConnectionIcon {
id: connectionIconProvider
}
NM.Network {
id: network
}
}