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

488 lines
15 KiB
QML

/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <aj@cutefishos.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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.System 1.0 as System
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
5 years ago
property int iconSize: 16
5 years ago
LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
LayoutMirroring.childrenInherit: true
property bool darkMode: false
property color textColor: rootItem.darkMode ? "#FFFFFF" : "#000000";
property var fontSize: rootItem.height ? rootItem.height / 3 : 1
property var timeFormat: StatusBar.twentyFourTime ? "HH:mm" : "h:mm ap"
onTimeFormatChanged: {
timeTimer.restart()
}
System.Wallpaper {
id: sysWallpaper
function reload() {
if (sysWallpaper.type === 0)
bgHelper.setBackgound(sysWallpaper.path)
else
bgHelper.setColor(sysWallpaper.color)
}
Component.onCompleted: sysWallpaper.reload()
onTypeChanged: sysWallpaper.reload()
onColorChanged: sysWallpaper.reload()
onPathChanged: sysWallpaper.reload()
}
BackgroundHelper {
id: bgHelper
onNewColor: {
background.color = color
4 years ago
rootItem.darkMode = darkMode
}
}
5 years ago
Rectangle {
id: background
anchors.fill: parent
opacity: 0.3
// color: FishUI.Theme.darkMode ? "#4D4D4D" : "#FFFFFF"
// opacity: windowHelper.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.7 : 1.0
5 years ago
// Behavior on color {
// ColorAnimation {
// duration: 100
// easing.type: Easing.Linear
// }
// }
5 years ago
}
FishUI.WindowHelper {
id: windowHelper
}
5 years ago
FishUI.PopupTips {
5 years ago
id: popupTips
}
5 years ago
FishUI.DesktopMenu {
id: acticityMenu
MenuItem {
text: qsTr("Close")
onTriggered: acticity.close()
}
}
// Main layout
5 years ago
RowLayout {
anchors.fill: parent
5 years ago
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
spacing: FishUI.Units.smallSpacing / 2
5 years ago
// App name
StandardItem {
id: acticityItem
animationEnabled: true
Layout.fillHeight: true
Layout.preferredWidth: Math.min(rootItem.width / 3,
acticityLayout.implicitWidth + FishUI.Units.largeSpacing)
onClicked: {
if (mouse.button === Qt.RightButton)
acticityMenu.open()
}
RowLayout {
id: acticityLayout
anchors.fill: parent
5 years ago
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
spacing: FishUI.Units.smallSpacing
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
5 years ago
antialiasing: true
smooth: false
}
Label {
id: acticityLabel
text: acticity.title
Layout.fillWidth: true
elide: Qt.ElideRight
color: rootItem.textColor
visible: text
5 years ago
Layout.alignment: Qt.AlignVCenter
font.pointSize: rootItem.fontSize
}
}
}
// App menu
5 years ago
Item {
id: appMenuItem
Layout.fillHeight: true
5 years ago
Layout.fillWidth: true
ListView {
id: appMenuView
anchors.fill: parent
orientation: Qt.Horizontal
spacing: FishUI.Units.smallSpacing
visible: appMenuModel.visible
interactive: false
clip: true
model: appMenuModel
// Initialize the current index
onVisibleChanged: {
if (!visible)
appMenuView.currentIndex = -1
}
delegate: StandardItem {
id: _menuItem
width: _actionText.width + FishUI.Units.largeSpacing
height: ListView.view.height
checked: appMenuApplet.currentIndex === index
onClicked: {
appMenuApplet.trigger(_menuItem, index)
checked = Qt.binding(function() {
return appMenuApplet.currentIndex === index
})
}
Text {
id: _actionText
anchors.centerIn: parent
color: rootItem.textColor
font.pointSize: rootItem.fontSize
text: {
var text = activeMenu
text = text.replace(/([^&]*)&(.)([^&]*)/g, function (match, p1, p2, p3) {
return p1.concat(p2, p3)
})
return text
}
}
// QMenu opens on press, so we'll replicate that here
MouseArea {
anchors.fill: parent
hoverEnabled: appMenuApplet.currentIndex !== -1
onPressed: parent.clicked(null)
onEntered: parent.clicked(null)
}
}
AppMenuModel {
id: appMenuModel
onRequestActivateIndex: appMenuApplet.requestActivateIndex(appMenuView.currentIndex)
Component.onCompleted: {
appMenuView.model = appMenuModel
}
}
AppMenuApplet {
id: appMenuApplet
model: appMenuModel
}
Component.onCompleted: {
appMenuApplet.buttonGrid = appMenuView
// Handle left and right shortcut keys.
appMenuApplet.requestActivateIndex.connect(function (index) {
var idx = Math.max(0, Math.min(appMenuView.count - 1, index))
var button = appMenuView.itemAtIndex(index)
if (button) {
button.clicked(null)
}
});
// Handle mouse movement.
appMenuApplet.mousePosChanged.connect(function (x, y) {
var item = itemAt(x, y)
if (item)
item.clicked(null)
});
}
}
5 years ago
}
// System tray(Right)
SystemTray {}
5 years ago
StandardItem {
id: controler
checked: controlCenter.item.visible
animationEnabled: true
5 years ago
Layout.fillHeight: true
5 years ago
Layout.preferredWidth: _controlerLayout.implicitWidth + FishUI.Units.largeSpacing
5 years ago
onClicked: {
toggleDialog()
}
function toggleDialog() {
if (controlCenter.item.visible)
controlCenter.item.close()
5 years ago
else {
// 先初始化用户可能会通过Alt鼠标左键移动位置
controlCenter.item.position = Qt.point(0, 0)
controlCenter.item.position = mapToGlobal(0, 0)
controlCenter.item.open()
5 years ago
}
}
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: controlCenter.item.defaultSink
source: "qrc:/images/" + (rootItem.darkMode ? "dark/" : "light/") + controlCenter.item.volumeIconName + ".svg"
5 years ago
width: rootItem.iconSize
5 years ago
height: width
sourceSize: Qt.size(width, height)
asynchronous: true
Layout.alignment: Qt.AlignCenter
5 years ago
antialiasing: true
smooth: false
5 years ago
}
Image {
id: wirelessIcon
5 years ago
width: rootItem.iconSize
5 years ago
height: width
sourceSize: Qt.size(width, height)
source: activeConnection.wirelessIcon ? "qrc:/images/" + (rootItem.darkMode ? "dark/" : "light/") + activeConnection.wirelessIcon + ".svg" : ""
5 years ago
asynchronous: true
Layout.alignment: Qt.AlignCenter
visible: enabledConnections.wirelessHwEnabled &&
enabledConnections.wirelessEnabled &&
activeConnection.wirelessName &&
5 years ago
wirelessIcon.status === Image.Ready
5 years ago
antialiasing: true
smooth: false
5 years ago
}
// Battery Item
RowLayout {
5 years ago
visible: battery.available
Image {
id: batteryIcon
height: rootItem.iconSize
5 years ago
width: height + 6
sourceSize: Qt.size(width, height)
source: "qrc:/images/" + (rootItem.darkMode ? "dark/" : "light/") + battery.iconSource
Layout.alignment: Qt.AlignCenter
5 years ago
antialiasing: true
smooth: false
}
5 years ago
Label {
text: battery.chargePercent + "%"
font.pointSize: rootItem.fontSize
color: rootItem.textColor
visible: battery.showPercentage
}
}
}
}
StandardItem {
id: shutdownItem
animationEnabled: true
Layout.fillHeight: true
Layout.preferredWidth: shutdownIcon.implicitWidth + FishUI.Units.smallSpacing
checked: shutdownDialog.item.visible
onClicked: {
shutdownDialog.item.position = Qt.point(0, 0)
shutdownDialog.item.position = mapToGlobal(0, 0)
shutdownDialog.item.open()
}
Image {
id: shutdownIcon
anchors.centerIn: parent
width: rootItem.iconSize
height: width
sourceSize: Qt.size(width, height)
source: "qrc:/images/" + (rootItem.darkMode ? "dark/" : "light/") + "system-shutdown-symbolic.svg"
asynchronous: true
antialiasing: true
smooth: false
}
}
// Pop-up notification center and calendar
StandardItem {
id: datetimeItem
animationEnabled: true
Layout.fillHeight: true
Layout.preferredWidth: _dateTimeLayout.implicitWidth + FishUI.Units.smallSpacing
onClicked: {
process.startDetached("cutefish-notificationd", ["-s"])
}
RowLayout {
id: _dateTimeLayout
anchors.fill: parent
// Image {
// width: rootItem.iconSize
// height: width
// sourceSize: Qt.size(width, height)
// source: "qrc:/images/" + (rootItem.darkMode ? "dark/" : "light/") + "notification-symbolic.svg"
// asynchronous: true
// Layout.alignment: Qt.AlignCenter
// antialiasing: true
// smooth: false
// }
5 years ago
Label {
id: timeLabel
Layout.alignment: Qt.AlignCenter
font.pointSize: rootItem.fontSize
color: rootItem.textColor
5 years ago
Timer {
id: timeTimer
5 years ago
interval: 1000
repeat: true
running: true
triggeredOnStart: true
onTriggered: {
5 years ago
timeLabel.text = new Date().toLocaleTimeString(Qt.locale(), StatusBar.twentyFourTime ? rootItem.timeFormat
: Locale.ShortFormat)
5 years ago
}
}
}
}
}
5 years ago
}
MouseArea {
id: _sliding
anchors.fill: parent
z: -1
property int startY: -1
property bool activated: false
onActivatedChanged: {
// TODO
// if (activated)
// acticity.move()
}
onPressed: {
startY = mouse.y
}
onReleased: {
startY = -1
}
onDoubleClicked: {
acticity.toggleMaximize()
}
onMouseYChanged: {
if (startY === parseInt(mouse.y)) {
activated = false
return
}
// Up
if (startY > parseInt(mouse.y)) {
activated = false
return
}
if (mouse.y > rootItem.height)
activated = true
else
activated = false
}
}
5 years ago
// Components
Loader {
id: controlCenter
sourceComponent: ControlCenter {}
asynchronous: true
5 years ago
}
Loader {
id: shutdownDialog
sourceComponent: ShutdownDialog {}
asynchronous: true
}
NM.ActiveConnection {
id: activeConnection
5 years ago
}
NM.EnabledConnections {
id: enabledConnections
}
NM.Handler {
id: nmHandler
5 years ago
}
}