优化切换全屏动画,可以跟随任务栏位置改变

This commit is contained in:
qiqi 2023-04-03 17:15:32 +08:00 committed by hewenfei
parent 38f3673a7d
commit e74de65c27
3 changed files with 142 additions and 61 deletions

View File

@ -26,7 +26,6 @@ Item {
clip: true
property int animationDuration: menuSetting.get("animationDuration")
property var normalGeometry: mainWindow.normalScreenSize()
property double transparency: mainWindow.transparency
property bool onComlpeted: false
@ -41,7 +40,7 @@ Item {
if (mainWindow.isFullScreen) {
normalHide.start();
fullShow.start();
backgroundMask.state = "fullScreen";
enterFullScreenAnimation.start();
if (root.transparency <= 0.6) {
maskHide.start();
}
@ -51,7 +50,7 @@ Item {
function exitFullScreen() {
normalShow.start();
fullHide.start();
backgroundMask.state = "normalScreen";
exitFullScreenAnimation.start();
if (root.transparency <= 0.6) {
maskShow.start();
}
@ -69,16 +68,67 @@ Item {
}
}
QtObject {
id: normalScreenGeometry
property var normalGeometry: mainWindow.normalScreenSize()
property int normalScreenX: normalScreenMargin
property int normalScreenY: root.height - normalGeometry.height - normalScreenMargin
property int normalScreenMargin: 8
property bool isFullScreen: mainWindow.isFullScreen
onIsFullScreenChanged: {
switch (mainWindow.panelPos) {
case 0 :
normalScreenX = normalScreenMargin;
normalScreenY = root.height - normalGeometry.height - normalScreenMargin;
break;
case 1 :
normalScreenX = normalScreenMargin;
normalScreenY = normalScreenMargin;
break;
case 2 :
normalScreenX = normalScreenMargin;
normalScreenY = normalScreenMargin;
break;
case 3 :
normalScreenX = root.width - normalGeometry.width - normalScreenMargin;
normalScreenY = normalScreenMargin;
break;
default :
normalScreenX = normalScreenMargin;
normalScreenY = root.height - normalGeometry.height - normalScreenMargin;
break;
}
}
}
AppControls2.StyleBackground {
id: backgroundMask
anchors.left: parent.left
anchors.bottom: parent.bottom
// normalScreen
x: 0; y: 0
height: normalScreenGeometry.normalGeometry.height
width: normalScreenGeometry.normalGeometry.width
radius: 12
state: mainWindow.isFullScreen ? "fullScreen" : "normalScreen"
onHeightChanged: {
onHeightChanged: {
if (root.transparency <= 0.6 && root.onComlpeted) {
mainWindow.changeWindowBlurRegion(0, root.height - height, width, height)
switch (mainWindow.panelPos) {
case 0 :
mainWindow.changeWindowBlurRegion(0, root.height - height, width, height);
break;
case 1 :
mainWindow.changeWindowBlurRegion(0, 0, width, height);
break;
case 2:
mainWindow.changeWindowBlurRegion(0, 0, width, height);
break;
case 3 :
mainWindow.changeWindowBlurRegion(root.width - width, 0, width, height);
break;
default :
mainWindow.changeWindowBlurRegion(0, root.height - height, width, height);
break;
}
}
}
@ -96,66 +146,82 @@ Item {
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 }
ParallelAnimation {
id: enterFullScreenAnimation
PropertyAnimation {
target: backgroundMask; property: "x"
from: normalScreenGeometry.normalScreenX; to: 0
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "y"
from: normalScreenGeometry.normalScreenY; to: 0
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "height"
from: normalScreenGeometry.normalGeometry.height; to: root.height
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "width"
from: normalScreenGeometry.normalGeometry.width; to: root.width
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
]
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;
}
}
}
onStarted: {
fullScreenLoader.active = true;
normalScreenLoader.x = normalScreenGeometry.normalScreenX;
normalScreenLoader.y = normalScreenGeometry.normalScreenY;
}
]
onFinished: {
normalScreenLoader.active = false;
mainWindow.enableWindowBlur(true);
}
}
ParallelAnimation {
id: exitFullScreenAnimation
PropertyAnimation {
target: backgroundMask; property: "x"
from: 0; to: normalScreenGeometry.normalScreenX
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "y"
from: 0; to: normalScreenGeometry.normalScreenY
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "height"
from: root.height; to: normalScreenGeometry.normalGeometry.height
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
PropertyAnimation {
target: backgroundMask; property: "width"
from: root.width; to: normalScreenGeometry.normalGeometry.width
duration: root.animationDuration; easing.type: Easing.InOutQuad
}
onStarted: {
normalScreenLoader.active = true;
mainWindow.enableWindowBlur(false);
}
onFinished: {
normalScreenLoader.x = 0;
normalScreenLoader.y = 0;
backgroundMask.x = 0;
backgroundMask.y = 0;
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
height: normalScreenGeometry.normalGeometry.height; width: normalScreenGeometry.normalGeometry.width
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 }

View File

@ -364,6 +364,11 @@ const QRect &WindowGeometryHelper::normalGeometry()
return m_normalGeometry;
}
const int WindowGeometryHelper::getPanelPos()
{
return m_panelPos;
}
//======MenuWindow======//
MenuWindow::MenuWindow(QWindow *parent) : QQuickView(parent), m_geometryHelper(new WindowGeometryHelper(this))
{
@ -394,6 +399,7 @@ void MenuWindow::init()
connect(m_geometryHelper, &WindowGeometryHelper::geometryChanged, this, [this] {
QEvent event(QEvent::Move);
QCoreApplication::sendEvent(this, &event);
Q_EMIT panelPosChanged();
});
connect(GlobalSetting::instance(), &GlobalSetting::styleChanged, this , [this] (const GlobalSetting::Key& key) {
@ -510,4 +516,9 @@ double MenuWindow::transparency() const
return GlobalSetting::instance()->get(GlobalSetting::Transparency).toDouble();
}
int MenuWindow::panelPos() const
{
return m_geometryHelper->getPanelPos();
}
} // UkuiMenu

View File

@ -50,6 +50,7 @@ public:
const QRect &normalGeometry();
const QRect &fullScreenGeometry();
const int getPanelPos();
Q_SIGNALS:
void geometryChanged();
@ -107,6 +108,7 @@ class MenuWindow : public QQuickView
Q_PROPERTY(bool isFullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
Q_PROPERTY(bool effectEnabled READ effectEnabled NOTIFY effectEnabledChanged)
Q_PROPERTY(double transparency READ transparency NOTIFY transparencyChanged)
Q_PROPERTY(int panelPos READ panelPos NOTIFY panelPosChanged)
public:
explicit MenuWindow(QWindow *parent = nullptr);
@ -116,6 +118,7 @@ public:
bool isFullScreen() const;
double transparency() const;
void setFullScreen(bool isFullScreen);
int panelPos() const;
Q_INVOKABLE void changeWindowBlurRegion(int x, int y, int width, int height);
Q_INVOKABLE QRect normalScreenSize();
@ -128,6 +131,7 @@ Q_SIGNALS:
void fullScreenChanged();
void beforeFullScreenChanged();
void beforeFullScreenExited();
void panelPosChanged();
private Q_SLOTS:
void onActiveFocusItemChanged();