2023-03-24 17:47:17 +08:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-04-26 17:04:22 +08:00
|
|
|
import QtQuick 2.12
|
2023-03-24 17:47:17 +08:00
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
|
2024-01-04 11:13:41 +08:00
|
|
|
import org.ukui.quick.platform 1.0 as Platform
|
2023-12-11 16:13:53 +08:00
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
2023-03-24 17:47:17 +08:00
|
|
|
import org.ukui.menu.core 1.0
|
|
|
|
import org.ukui.menu.utils 1.0
|
|
|
|
|
|
|
|
Row {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 48
|
|
|
|
layoutDirection: Qt.RightToLeft
|
|
|
|
|
2023-12-11 16:13:53 +08:00
|
|
|
UkuiItems.StyleBackground {
|
2023-03-24 17:47:17 +08:00
|
|
|
width: 48; height: width
|
2023-12-11 16:13:53 +08:00
|
|
|
useStyleTransparency: false
|
2024-01-04 11:13:41 +08:00
|
|
|
paletteRole: Platform.Theme.Light
|
2023-03-24 17:47:17 +08:00
|
|
|
alpha: powerButtonArea.containsPress ? 0.25 : powerButtonArea.containsMouse ? 0.12 : 0
|
|
|
|
radius: height / 2
|
2024-01-04 11:13:41 +08:00
|
|
|
borderColor: Platform.Theme.Highlight
|
2023-04-26 17:04:22 +08:00
|
|
|
border.width: powerButtonArea.activeFocus ? 2 : 0
|
2023-03-17 17:25:50 +08:00
|
|
|
|
2023-03-24 17:47:17 +08:00
|
|
|
PowerButton {
|
|
|
|
id: powerButtonBase
|
|
|
|
}
|
|
|
|
|
2024-01-09 10:08:53 +08:00
|
|
|
UkuiItems.Icon {
|
2023-03-24 17:47:17 +08:00
|
|
|
anchors.centerIn: parent
|
|
|
|
width: Math.floor(parent.width / 2)
|
|
|
|
height: width
|
2024-01-09 10:08:53 +08:00
|
|
|
mode: UkuiItems.Icon.Highlight
|
2023-03-24 17:47:17 +08:00
|
|
|
source: powerButtonBase.icon
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: powerButtonArea
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
2023-06-06 09:22:29 +08:00
|
|
|
ToolTip.delay: 500
|
2023-03-24 17:47:17 +08:00
|
|
|
ToolTip.visible: containsMouse
|
|
|
|
ToolTip.text: powerButtonBase.toolTip
|
2023-03-29 10:17:33 +08:00
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
property int spacingFromMenu: 8
|
2023-04-26 17:04:22 +08:00
|
|
|
activeFocusOnTab: true
|
2023-03-29 10:17:33 +08:00
|
|
|
|
2023-03-24 17:47:17 +08:00
|
|
|
onClicked: {
|
2023-03-29 10:17:33 +08:00
|
|
|
var buttonPosition = powerButtonArea.mapToGlobal(width, height);
|
|
|
|
powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x - width - spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen);
|
2023-03-24 17:47:17 +08:00
|
|
|
}
|
2023-04-26 17:04:22 +08:00
|
|
|
Keys.onPressed: {
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
|
|
|
powerButtonBase.clicked(true, 0, 0, mainWindow.isFullScreen);
|
|
|
|
}
|
|
|
|
}
|
2023-03-24 17:47:17 +08:00
|
|
|
}
|
2023-03-17 17:25:50 +08:00
|
|
|
}
|
|
|
|
}
|