185 lines
5.1 KiB
QML
185 lines
5.1 KiB
QML
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
|
|
//
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
import QtQuick 2.15
|
|
import QtQuick.Controls 2.15
|
|
import QtQuick.Layouts 1.15
|
|
import org.deepin.ds 1.0
|
|
import org.deepin.ds.dock 1.0
|
|
|
|
AppletItem {
|
|
id: root
|
|
objectName: "graphics driver applet"
|
|
|
|
property bool useColumnLayout: Panel.position % 2
|
|
property int dockOrder: 20
|
|
property int dockSize: Panel.rootObject.dockSize || 48
|
|
|
|
implicitWidth: useColumnLayout ? dockSize : 80
|
|
implicitHeight: dockSize
|
|
|
|
property var applet: Applet
|
|
|
|
PanelToolTip {
|
|
id: toolTip
|
|
text: qsTr("Graphics Driver Manager")
|
|
toolTipX: DockPanelPositioner.x
|
|
toolTipY: DockPanelPositioner.y
|
|
}
|
|
|
|
HoverHandler {
|
|
onHoveredChanged: {
|
|
if (hovered && !driverPopup.popupVisible) {
|
|
const point = root.mapToItem(null, root.width / 2, root.height / 2)
|
|
toolTip.DockPanelPositioner.bounding = Qt.rect(point.x, point.y, toolTip.width, toolTip.height)
|
|
toolTip.open()
|
|
} else {
|
|
toolTip.close()
|
|
}
|
|
}
|
|
}
|
|
|
|
PanelPopup {
|
|
id: driverPopup
|
|
width: 300
|
|
height: 360
|
|
popupX: DockPanelPositioner.x
|
|
popupY: DockPanelPositioner.y
|
|
|
|
onPopupVisibleChanged: {
|
|
if (popupVisible) {
|
|
toolTip.close()
|
|
}
|
|
}
|
|
|
|
ColumnLayout {
|
|
anchors.fill: parent
|
|
anchors.margins: 16
|
|
spacing: 12
|
|
|
|
Text {
|
|
text: qsTr("Graphics Driver Manager")
|
|
font.pixelSize: 16
|
|
font.bold: true
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Rectangle {
|
|
Layout.fillWidth: true
|
|
Layout.preferredHeight: 1
|
|
color: "#ccc"
|
|
}
|
|
|
|
GroupBox {
|
|
Layout.fillWidth: true
|
|
title: qsTr("Device Information")
|
|
|
|
ColumnLayout {
|
|
anchors.fill: parent
|
|
spacing: 8
|
|
|
|
Text {
|
|
text: "Current Driver: " + (root.applet ? root.applet.currentDriver || "Unknown" : "Unknown")
|
|
font.pixelSize: 12
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Text {
|
|
text: "Device Info: " + (root.applet ? root.applet.deviceInfo || "Unknown" : "Unknown")
|
|
font.pixelSize: 12
|
|
wrapMode: Text.WordWrap
|
|
Layout.fillWidth: true
|
|
}
|
|
}
|
|
}
|
|
|
|
Button {
|
|
text: qsTr("Refresh")
|
|
Layout.fillWidth: true
|
|
onClicked: {
|
|
if (root.applet) {
|
|
root.applet.refreshDeviceInfo()
|
|
}
|
|
}
|
|
}
|
|
|
|
Button {
|
|
text: qsTr("Test Install")
|
|
Layout.fillWidth: true
|
|
enabled: root.applet && !root.applet.isInstalling
|
|
onClicked: {
|
|
if (root.applet) {
|
|
root.applet.testInstall()
|
|
}
|
|
}
|
|
}
|
|
|
|
ColumnLayout {
|
|
visible: root.applet && root.applet.isInstalling
|
|
Layout.fillWidth: true
|
|
spacing: 8
|
|
|
|
Text {
|
|
text: qsTr("Installing... ") + (root.applet ? root.applet.installProgress + "%" : "0%")
|
|
font.pixelSize: 12
|
|
}
|
|
|
|
ProgressBar {
|
|
Layout.fillWidth: true
|
|
value: root.applet ? root.applet.installProgress / 100 : 0
|
|
}
|
|
|
|
Button {
|
|
text: qsTr("Cancel")
|
|
Layout.fillWidth: true
|
|
onClicked: {
|
|
if (root.applet) {
|
|
root.applet.cancelInstall()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Item {
|
|
Layout.fillHeight: true
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
DockPanelPositioner.bounding = Qt.binding(function () {
|
|
const point = root.mapToItem(null, root.width / 2, root.height / 2)
|
|
return Qt.rect(point.x, point.y, driverPopup.width, driverPopup.height)
|
|
})
|
|
}
|
|
}
|
|
|
|
TapHandler {
|
|
acceptedButtons: Qt.LeftButton
|
|
gesturePolicy: TapHandler.ReleaseWithinBounds
|
|
|
|
onTapped: {
|
|
if (driverPopup.popupVisible) {
|
|
driverPopup.close()
|
|
} else {
|
|
Panel.requestClosePopup()
|
|
driverPopup.open()
|
|
}
|
|
toolTip.close()
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: root.applet
|
|
function onInstallSuccess() {
|
|
console.log("Install succeeded")
|
|
}
|
|
function onInstallFailed(error) {
|
|
console.log("Install failed:", error)
|
|
}
|
|
function onRequestReboot() {
|
|
console.log("Reboot requested")
|
|
}
|
|
}
|
|
}
|