diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc3311d..fafbb8d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -92,6 +92,7 @@ set(SOURCE_FILES
src/extension/menu-extension.cpp src/extension/menu-extension.h
src/extension/extensions/folder-extension.cpp src/extension/extensions/folder-extension.h
src/extension/extensions/recent-file-extension.cpp src/extension/extensions/recent-file-extension.h
+ src/utils/power-button.cpp src/utils/power-button.h
)
# qrc文件
diff --git a/qml/AppUI/Sidebar.qml b/qml/AppUI/Sidebar.qml
index a9145dd..5ccb611 100644
--- a/qml/AppUI/Sidebar.qml
+++ b/qml/AppUI/Sidebar.qml
@@ -1,5 +1,9 @@
import QtQuick 2.0
import QtQuick.Layouts 1.12
+import org.ukui.menu.utils 1.0
+import QtQuick.Controls 2.5
+import AppControls2 1.0 as AppControls2
+import org.ukui.menu.core 1.0
Item {
ColumnLayout {
@@ -58,9 +62,42 @@ Item {
Layout.rightMargin: 12
layoutDirection: Qt.RightToLeft
- Item {
+ AppControls2.StyleBackground {
width: 32
height: 32
+ paletteRole: Palette.Base
+ useStyleTransparent: false
+ alpha: powerButtonArea.pressed ? 0.85 : powerButtonArea.hovered ? 0.65 : 0
+ radius: height / 2
+
+ PowerButton {
+ id: powerButtonBase
+ }
+
+ Image {
+ anchors.centerIn: parent
+ width: Math.floor(parent.width / 2)
+ height: width
+ source: powerButtonBase.icon
+ }
+
+ MouseArea {
+ id: powerButtonArea
+ property bool hovered: false
+ anchors.fill: parent
+ hoverEnabled: true
+ ToolTip.visible: hovered
+ ToolTip.text: powerButtonBase.toolTip
+ onClicked: {
+ powerButtonBase.clicked()
+ }
+ onEntered: {
+ hovered = true
+ }
+ onExited: {
+ hovered = false
+ }
+ }
}
}
}
diff --git a/res/icon/pad_mainpower.svg b/res/icon/pad_mainpower.svg
new file mode 100644
index 0000000..4fb7c20
--- /dev/null
+++ b/res/icon/pad_mainpower.svg
@@ -0,0 +1,7 @@
+
\ No newline at end of file
diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp
index f1cba61..d44c6a8 100644
--- a/src/ukui-menu-application.cpp
+++ b/src/ukui-menu-application.cpp
@@ -25,6 +25,7 @@
#include "app-icon-provider.h"
#include "menu-main-window.h"
#include "extension/menu-extension.h"
+#include "utils/power-button.h"
#include
#include
@@ -54,6 +55,7 @@ void UkuiMenuApplication::registerQmlTypes()
CommonsModule::defineModule(uri, versionMajor, versionMinor);
SettingModule::defineModule(uri, versionMajor, versionMinor);
WindowModule::defineModule(uri, versionMajor, versionMinor);
+ PowerButton::defineModule(uri, versionMajor, versionMinor);
ModelManager::registerMetaTypes();
diff --git a/src/utils/power-button.cpp b/src/utils/power-button.cpp
new file mode 100644
index 0000000..283b2d3
--- /dev/null
+++ b/src/utils/power-button.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2023, KylinSoft Co., Ltd.
+ *
+ * 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
+ * (at your option) 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 .
+ *
+ */
+
+#include
+#include
+
+#include "power-button.h"
+
+#define KYLIN_POWER_NORMAL_PATH_MAJOR "qrc:///res/icon/pad_mainpower.svg"
+
+using namespace UkuiMenu;
+
+PowerButton::PowerButton(QObject *parent) : QObject(nullptr)
+{
+
+}
+
+void PowerButton::defineModule(const char *uri, int versionMajor, int versionMinor)
+{
+ qmlRegisterType("org.ukui.menu.utils", versionMajor, versionMinor, "PowerButton");
+}
+
+PowerButton::~PowerButton()
+= default;
+
+QString PowerButton::getIcon()
+{
+ return {KYLIN_POWER_NORMAL_PATH_MAJOR};
+}
+
+QString PowerButton::getToolTip()
+{
+ return {tr("power")};
+}
+
+void PowerButton::clicked()
+{
+ QProcess::startDetached("ukui-session-tools");
+}
diff --git a/src/utils/power-button.h b/src/utils/power-button.h
new file mode 100644
index 0000000..1b1611a
--- /dev/null
+++ b/src/utils/power-button.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2023, KylinSoft Co., Ltd.
+ *
+ * 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
+ * (at your option) 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 .
+ *
+ */
+#ifndef POWERBUTTON_H
+#define POWERBUTTON_H
+
+#include
+
+namespace UkuiMenu {
+
+class PowerButton : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString icon READ getIcon NOTIFY iconChanged)
+ Q_PROPERTY(QString toolTip READ getToolTip NOTIFY toolTipChanged)
+public:
+ explicit PowerButton(QObject *parent = nullptr);
+ ~PowerButton() override;
+ static void defineModule(const char *uri, int versionMajor, int versionMinor);
+ QString getIcon();
+ QString getToolTip();
+
+public Q_SLOTS:
+ void clicked();
+
+Q_SIGNALS:
+ void iconChanged();
+ void toolTipChanged();
+};
+
+} // UkuiMenu
+
+#endif // POWERBUTTON_H