From 6039e6c66cb2bfa7e6ebcf491cff45ff8a90b824 Mon Sep 17 00:00:00 2001 From: qiqi Date: Wed, 6 Dec 2023 10:54:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(powerButton):=E7=94=B5=E6=BA=90=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E8=8F=9C=E5=8D=95=E6=B7=BB=E5=8A=A0tooltips=EF=BC=88i?= =?UTF-8?q?ssues:I7H1AF;I8J75H)=20=E4=BF=AE=E5=A4=8D=E7=94=B5=E6=BA=90?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95=E4=BD=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=E9=97=AE=E9=A2=98=EF=BC=88issues:I8J74R)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppUI/Sidebar.qml | 5 +++-- src/utils/power-button.cpp | 39 +++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/qml/AppUI/Sidebar.qml b/qml/AppUI/Sidebar.qml index 2d1ed21..bdffa73 100644 --- a/qml/AppUI/Sidebar.qml +++ b/qml/AppUI/Sidebar.qml @@ -202,7 +202,7 @@ Item { ToolTip.visible: containsMouse ToolTip.text: powerButtonBase.toolTip acceptedButtons: Qt.LeftButton | Qt.RightButton - property int spacingFromMenu: 16 + property int spacingFromMenu: 4 activeFocusOnTab: true Keys.onPressed: { @@ -213,7 +213,8 @@ Item { onClicked: { var buttonPosition = powerButtonArea.mapToGlobal(width, height); - powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen); + powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + sidebarBottomBar.Layout.rightMargin + 4, + buttonPosition.y + sidebarBottomBar.Layout.bottomMargin, mainWindow.isFullScreen); } } } diff --git a/src/utils/power-button.cpp b/src/utils/power-button.cpp index dbde67a..dd4e35d 100644 --- a/src/utils/power-button.cpp +++ b/src/utils/power-button.cpp @@ -68,50 +68,75 @@ void PowerButton::openMenu(int menuX, int menuY, bool isFullScreen) "org.gnome.SessionManager", QDBusConnection::sessionBus()); if (canSwitch() && hasMultipleUsers()) { - connect(powerMenu.addAction(tr("Switch user")), &QAction::triggered, &powerMenu, [] { + QAction *action = new QAction(tr("Switch user"), &powerMenu); + connect(action, &QAction::triggered, &powerMenu, [] { AppManager::instance()->launchBinaryApp("ukui-session-tools", "--switchuser"); }); + powerMenu.addAction(action); } reply = qDBusInterface.call("canHibernate"); if (reply.isValid() && reply.value()) { - connect(powerMenu.addAction(tr("Hibernate")), &QAction::triggered, &powerMenu, [] { + QAction *action = new QAction(tr("Hibernate"), &powerMenu); + action->setToolTip(tr("

Turn off the computer, but the applications " + "will remain open. When you turn on the computer again, " + "you can return to the state you were in before

")); + connect(action, &QAction::triggered, &powerMenu, [] { AppManager::instance()->launchBinaryApp("ukui-session-tools", "--hibernate"); }); + powerMenu.addAction(action); } reply = qDBusInterface.call("canSuspend"); if (reply.isValid() && reply.value()) { - connect(powerMenu.addAction(tr("Suspend")), &QAction::triggered, &powerMenu, [] { + QAction *action = new QAction(tr("Suspend"), &powerMenu); + action->setToolTip(tr("

The computer remains on but consumes less power, " + "and the applications will remain open. You can quickly wake " + "up the computer and return to the state you left

")); + connect(action, &QAction::triggered, &powerMenu, [] { AppManager::instance()->launchBinaryApp("ukui-session-tools", "--suspend"); }); + powerMenu.addAction(action); } - connect(powerMenu.addAction(tr("Lock Screen")), &QAction::triggered, &powerMenu, [] { + QAction *lockAction = new QAction(tr("Lock Screen"), &powerMenu); + connect(lockAction, &QAction::triggered, &powerMenu, [] { AppManager::instance()->launchBinaryApp("ukui-screensaver-command", "-l"); }); + powerMenu.addAction(lockAction); reply = qDBusInterface.call("canLogout"); if (reply.isValid() && reply.value()) { - connect(powerMenu.addAction(tr("Log Out")), &QAction::triggered, &powerMenu, [] { + QAction *action = new QAction(tr("Log Out"), &powerMenu); + action->setToolTip(tr("

The current user logs out of the system, ending " + "their session and returning to the login screen

")); + connect(action, &QAction::triggered, &powerMenu, [] { AppManager::instance()->launchBinaryApp("ukui-session-tools", "--logout"); }); + powerMenu.addAction(action); } reply = qDBusInterface.call("canReboot"); if (reply.isValid() && reply.value()) { - connect(powerMenu.addAction(tr("Reboot")), &QAction::triggered, &powerMenu, [] { + QAction *action = new QAction(tr("Reboot"), &powerMenu); + action->setToolTip(tr("

Close all applications, turn off the computer, and then turn it back on

")); + connect(action, &QAction::triggered, &powerMenu, [] { AppManager::instance()->launchBinaryApp("ukui-session-tools", "--reboot"); }); + powerMenu.addAction(action); } reply = qDBusInterface.call("canPowerOff"); if (reply.isValid() && reply.value()) { - connect(powerMenu.addAction(tr("Power Off")), &QAction::triggered, &powerMenu, [] { + QAction *action = new QAction(tr("Power Off"), &powerMenu); + action->setToolTip(tr("

Close all applications, and then turn off the computer

")); + connect(action, &QAction::triggered, &powerMenu, [] { AppManager::instance()->launchBinaryApp("ukui-session-tools", "--shutdown"); }); + powerMenu.addAction(action); } + powerMenu.setToolTipsVisible(true); powerMenu.setAttribute(Qt::WA_DeleteOnClose); if (isFullScreen) {