添加电源按钮

This commit is contained in:
gjq 2023-02-13 09:31:11 +08:00 committed by hewenfei
parent db3c8c7601
commit f83fd97ee8
6 changed files with 149 additions and 1 deletions

View File

@ -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

View File

@ -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
}
}
}
}
}

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22">
<g fill="none" fill-rule="evenodd" transform="translate(-1 -1)">
<rect width="24" height="24" fill="#000" fill-rule="nonzero" opacity="0"/>
<path stroke="#FD625E" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7.50170415,4.09248544 C2.82933979,6.55809125 1.05559575,12.3159964 3.53993595,16.9531265 C6.02427615,21.5902566 11.8259315,23.3506249 16.4982958,20.8850191 C21.1706602,18.4194132 22.9444042,12.6615081 20.4600641,8.02437799 C19.4943306,6.22179414 18.0273187,4.85391695 16.3202246,4"/>
<line x1="12" x2="12" y1="11" y2="2" stroke="#FD625E" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 723 B

View File

@ -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 <QCoreApplication>
#include <QCommandLineParser>
@ -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();

View File

@ -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 <https://www.gnu.org/licenses/>.
*
*/
#include <QProcess>
#include <QQmlEngine>
#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<PowerButton>("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");
}

47
src/utils/power-button.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*
*/
#ifndef POWERBUTTON_H
#define POWERBUTTON_H
#include <QObject>
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