ukui-menu/qml/main.qml

183 lines
6.4 KiB
QML

/*
* 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/>.
*
*/
import QtQuick 2.12
import AppUI 1.0 as AppUI
import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0
Item {
id: root
clip: true
property int animationDuration: menuSetting.get("animationDuration")
property var normalGeometry: mainWindow.normalScreenSize()
property double transparency: mainWindow.transparency
property bool onComlpeted: false
Component.onCompleted: {
mainWindow.fullScreenChanged.connect(enterFullScreen);
mainWindow.beforeFullScreenExited.connect(exitFullScreen);
menuSetting.changed.connect(updateAnimationDuration);
onComlpeted = true;
}
function enterFullScreen() {
if (mainWindow.isFullScreen) {
normalHide.start();
fullShow.start();
backgroundMask.state = "fullScreen";
if (root.transparency <= 0.6) {
maskHide.start();
}
}
}
function exitFullScreen() {
normalShow.start();
fullHide.start();
backgroundMask.state = "normalScreen";
if (root.transparency <= 0.6) {
maskShow.start();
}
}
function updateAnimationDuration(key) {
if (key === "animationDuration") {
root.animationDuration = menuSetting.get("animationDuration");
}
}
onTransparencyChanged: {
if (transparency > 0.6) {
backgroundMask.opacity = 1;
}
}
AppControls2.StyleBackground {
id: backgroundMask
anchors.left: parent.left
anchors.bottom: parent.bottom
radius: 12
state: "normalScreen"
onHeightChanged: {
if (root.transparency <= 0.6 && root.onComlpeted) {
mainWindow.changeWindowBlurRegion(0, root.height - height, width, height)
}
}
NumberAnimation {
id: maskHide
target: backgroundMask; property: "opacity"
from: 1.0; to: 0;
duration: root.animationDuration / 4; easing.type: Easing.InOutQuad
}
NumberAnimation {
id: maskShow
target: backgroundMask; property: "opacity"
from: 0; to: 1.0;
duration: root.animationDuration * 2; easing.type: Easing.InOutExpo
}
states: [
State {
name: "normalScreen"
PropertyChanges { target: backgroundMask; height: root.normalGeometry.height; width: root.normalGeometry.width }
},
State {
name: "fullScreen"
PropertyChanges { target: backgroundMask; height: root.height; width: root.width }
PropertyChanges { target: normalScreenLoader; anchors.margins: 8 }
AnchorChanges { target: normalScreenLoader; anchors.bottom: root.bottom; anchors.left: root.left }
}
]
transitions: [
Transition {
to: "fullScreen"
SequentialAnimation {
ScriptAction {
script: {
normalScreenLoader.anchors.left = root.left;
normalScreenLoader.anchors.bottom = root.bottom;
normalScreenLoader.anchors.margins = 8;
fullScreenLoader.active = true;
}
}
NumberAnimation { properties: "height,width"; duration: root.animationDuration; easing.type: Easing.InOutQuad }
ScriptAction {
script: {
normalScreenLoader.active = false;
mainWindow.enableWindowBlur(true);
}
}
}
},
Transition {
to: "normalScreen"
SequentialAnimation {
ScriptAction {
script: {
normalScreenLoader.active = true;
mainWindow.enableWindowBlur(false);
}
}
NumberAnimation { properties: "height,width"; duration: root.animationDuration; easing.type: Easing.InOutQuad }
ScriptAction {
script: {
fullScreenLoader.active = false;
mainWindow.isFullScreen = false;
}
}
}
}
]
}
Loader {
id: normalScreenLoader
height: root.normalGeometry.height; width: root.normalGeometry.width
anchors.bottom: root.bottom
anchors.left: root.left
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 }
}
Loader {
id: fullScreenLoader
anchors.fill: parent
sourceComponent: fullSceenComponent
opacity: 0
NumberAnimation { id: fullShow; target: fullScreenLoader; properties: "opacity"; from: 0; to: 1; duration: root.animationDuration; easing.type: Easing.InQuint }
NumberAnimation { id: fullHide; target: fullScreenLoader; properties: "opacity"; from: 1; to: 0; duration: root.animationDuration; easing.type: Easing.OutQuint }
}
Component {
id: fullSceenComponent
AppUI.FullScreenUI {}
}
Component {
id: normalComponent
AppUI.NormalUI {}
}
}