ukui-menu/qml/main.qml

189 lines
7.0 KiB
QML
Raw Normal View History

2023-03-17 17:25:50 +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/>.
*
*/
2022-12-02 15:58:09 +08:00
import QtQuick 2.12
2022-12-23 11:32:21 +08:00
import AppUI 1.0 as AppUI
2023-03-17 17:25:50 +08:00
import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
Item {
2023-03-17 17:25:50 +08:00
id: root
clip: true
2023-03-20 15:33:32 +08:00
property int animationDuration: menuSetting.get("animationDuration")
property var normalGeometry: mainWindow.normalRect
2023-03-17 17:25:50 +08:00
Component.onCompleted: {
2023-03-20 15:33:32 +08:00
mainWindow.fullScreenChanged.connect(enterFullScreen);
mainWindow.beforeFullScreenExited.connect(exitFullScreen);
menuSetting.changed.connect(updateAnimationDuration);
2023-03-17 17:25:50 +08:00
}
2023-03-20 15:33:32 +08:00
function enterFullScreen() {
if (mainWindow.isFullScreen) {
normalHide.start();
fullShow.start();
enterFullScreenAnimation.start();
2023-03-20 15:33:32 +08:00
}
2023-03-17 17:25:50 +08:00
}
2023-03-20 15:33:32 +08:00
function exitFullScreen() {
normalShow.start();
fullHide.start();
exitFullScreenAnimation.start();
2023-03-17 17:25:50 +08:00
}
2023-03-20 15:33:32 +08:00
function updateAnimationDuration(key) {
if (key === "animationDuration") {
root.animationDuration = menuSetting.get("animationDuration");
}
}
2023-03-17 17:25:50 +08:00
UkuiItems.StyleBackground {
2023-03-17 17:25:50 +08:00
id: backgroundMask
// 初始状态默认为normalScreen
x: mainWindow.isFullScreen ? 0 : normalGeometry.x
y: mainWindow.isFullScreen ? 0 : normalGeometry.y
height: mainWindow.isFullScreen ? root.height : normalGeometry.height
width: mainWindow.isFullScreen ? root.width : normalGeometry.width
radius: mainWindow.isFullScreen ? 0 : Platform.Theme.windowRadius
2023-03-17 17:25:50 +08:00
border.width: mainWindow.isFullScreen ? 0 : 1
borderColor: Platform.Theme.Text
borderAlpha: 0.15
2023-03-20 15:33:32 +08:00
Component.onCompleted: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
onRadiusChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
onWidthChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
onHeightChanged: mainWindow.changeWindowBlurRegion(x, y, width, height, radius)
2023-03-17 17:25:50 +08:00
ParallelAnimation {
id: enterFullScreenAnimation
PropertyAnimation {
target: backgroundMask; property: "x"
from: normalGeometry.x; to: 0
duration: root.animationDuration; easing.type: Easing.InOutQuad
2023-03-17 17:25:50 +08:00
}
PropertyAnimation {
target: backgroundMask; property: "y"
from: normalGeometry.y; to: 0
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "height"
from: normalGeometry.height; to: root.height
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "width"
from: normalGeometry.width; to: root.width
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
onStarted: {
fullScreenLoader.active = true;
2023-03-17 17:25:50 +08:00
}
onFinished: {
normalScreenLoader.active = false;
}
}
ParallelAnimation {
id: exitFullScreenAnimation
PropertyAnimation {
target: backgroundMask; property: "x"
from: 0; to: normalGeometry.x
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "y"
from: 0; to: normalGeometry.y
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "height"
from: root.height; to: normalGeometry.height
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "width"
from: root.width; to: normalGeometry.width
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
onStarted: {
normalScreenLoader.active = true;
}
onFinished: {
fullScreenLoader.active = false;
mainWindow.isFullScreen = false;
}
}
2023-03-20 15:33:32 +08:00
}
Loader {
id: normalScreenLoader
focus: !mainWindow.isFullScreen
active: false
x: normalGeometry.x
y: normalGeometry.y
height: normalGeometry.height
width: normalGeometry.width
2023-03-20 15:33:32 +08:00
sourceComponent: normalComponent
NumberAnimation { id: normalShow; target: normalScreenLoader; properties: "opacity"; from: 0; to: 1; duration: root.animationDuration; easing.type: Easing.InQuint }
NumberAnimation { id: normalHide; target: normalScreenLoader; properties: "opacity"; from: 1; to: 0; duration: root.animationDuration; easing.type: Easing.OutQuint }
Component.onCompleted: {
active = mainWindow.isFullScreen ? false : true;
opacity = mainWindow.isFullScreen ? 0 : 1;
}
Keys.onPressed: {
item.keyPressed(event);
}
2023-03-20 15:33:32 +08:00
}
Loader {
id: fullScreenLoader
x: 0; y: 0
width: parent.width; height: parent.height
focus: mainWindow.isFullScreen
2023-03-20 15:33:32 +08:00
sourceComponent: fullSceenComponent
ParallelAnimation {
id: fullShow
NumberAnimation { target: fullScreenLoader; properties: "opacity"; from: 0; to: 1; duration: root.animationDuration; easing.type: Easing.InQuint }
NumberAnimation { target: fullScreenLoader; properties: "y"; from: -100; to: 0; duration: root.animationDuration; easing.type: Easing.InOutQuad }
}
2023-03-20 15:33:32 +08:00
NumberAnimation { id: fullHide; target: fullScreenLoader; properties: "opacity"; from: 1; to: 0; duration: root.animationDuration; easing.type: Easing.OutQuint }
Component.onCompleted: {
active = mainWindow.isFullScreen ? true : false;
opacity = mainWindow.isFullScreen ? 1 : 0;
}
2023-03-17 17:25:50 +08:00
}
Component {
id: fullSceenComponent
AppUI.FullScreenUI {}
}
Component {
id: normalComponent
AppUI.NormalUI { }
2022-12-02 15:58:09 +08:00
}
}