From 2f8eed392da5bce39838a092ab1b183b4f56a13f Mon Sep 17 00:00:00 2001 From: houchengqiu Date: Fri, 2 Aug 2024 10:04:51 +0800 Subject: [PATCH] feat: Add switch types to set animation switching effects Add switch types to set animation switching effects Log: Add switch types to set animation switching effects Bug: https://pms.uniontech.com/bug-view-168549.html --- src/qml/AlbumTitle.qml | 14 +++++++++++- .../Control/Animation/SwitchViewAnimation.qml | 22 +++++++++++++++++-- src/qml/StatusBar.qml | 2 +- .../CollecttionView/CollecttionView.qml | 10 ++++----- src/qml/ThumbnailImageView/ThumbnailImage.qml | 11 ++++------ src/src/globalstatus.cpp | 13 +++++++++++ src/src/globalstatus.h | 7 ++++++ src/src/types.h | 12 ++++++++++ 8 files changed, 75 insertions(+), 16 deletions(-) diff --git a/src/qml/AlbumTitle.qml b/src/qml/AlbumTitle.qml index 23e37ff4..30ab4a6e 100644 --- a/src/qml/AlbumTitle.qml +++ b/src/qml/AlbumTitle.qml @@ -318,6 +318,7 @@ TitleBar { visible: GStatus.currentViewType === Album.Types.ViewCollecttion && albumControl.getYears(refreshVisible).length !== 0 && window.width <= showCollComboWidth property bool refreshVisible: false + property bool blocksignal: false model: ListModel { ListElement { text: qsTr("Y"); icon: "" } @@ -330,10 +331,21 @@ TitleBar { collectionCombo.currentIndex = index } + function updateIndex() { + blocksignal = true + collectionCombo.currentIndex = GStatus.currentCollecttionViewIndex + blocksignal = false + } + onCurrentIndexChanged: { - collectionBtnClicked(currentIndex) + if (!blocksignal) + collectionBtnClicked(currentIndex) collectionBtnBox.setChecked(currentIndex) } + + Component.onCompleted: { + GStatus.currentCollecttionViewIndexChanged.connect(updateIndex) + } } } diff --git a/src/qml/Control/Animation/SwitchViewAnimation.qml b/src/qml/Control/Animation/SwitchViewAnimation.qml index cf26216d..1b56fd0a 100644 --- a/src/qml/Control/Animation/SwitchViewAnimation.qml +++ b/src/qml/Control/Animation/SwitchViewAnimation.qml @@ -5,6 +5,8 @@ import QtQuick 2.11 import QtQuick.Controls 2.4 +import org.deepin.album 1.0 as Album + Item { id: switchViewAnimation @@ -15,6 +17,19 @@ Item { property real hideOpacity: 0 property real hideX: -width - 20 + property int switchType: GStatus.currentSwitchType + property string switchPropertys: "x,opacity" + + onSwitchTypeChanged: { + if (switchType === Album.Types.FlipScroll) { + x = width + 20 + switchPropertys = "x,opacity" + } else if (switchType === Album.Types.FadeInOut) { + x = 0 + switchPropertys = "opacity" + } + } + state: "hide" states: [ State { @@ -37,7 +52,10 @@ Item { } ] - transitions: Transition { - NumberAnimation{properties: "x,opacity"; easing.type: Easing.OutExpo; duration: 400} + transitions: + Transition { + enabled: switchType !== Album.Types.HardCut + NumberAnimation{properties: switchPropertys; easing.type: Easing.OutExpo; duration: 400 + } } } diff --git a/src/qml/StatusBar.qml b/src/qml/StatusBar.qml index fb86bf4c..71fc08b4 100644 --- a/src/qml/StatusBar.qml +++ b/src/qml/StatusBar.qml @@ -40,7 +40,7 @@ Item { right: parent.right rightMargin: 20 } - visible: !(GStatus.currentViewType === Album.Types.ViewCollecttion && thumbnailImage.m_CollecttionCurrentViewIndex < 2) + visible: !(GStatus.currentViewType === Album.Types.ViewCollecttion && GStatus.currentCollecttionViewIndex < 2) from: 0 value: 0 stepSize: 1 diff --git a/src/qml/ThumbnailImageView/CollecttionView/CollecttionView.qml b/src/qml/ThumbnailImageView/CollecttionView/CollecttionView.qml index f3f90d33..a24284c3 100644 --- a/src/qml/ThumbnailImageView/CollecttionView/CollecttionView.qml +++ b/src/qml/ThumbnailImageView/CollecttionView/CollecttionView.qml @@ -36,10 +36,9 @@ BaseView { dayCollection.flushModel() if (dayCollection.x < 0) dayCollection.x = rollingWidth - if (dayCollection.x !== 0) { + if (!dayCollection.visible) { dayCollection.visible = true } - GStatus.selectedPaths = [] flushDayViewStatusText() } else if (index === 3) { @@ -83,7 +82,6 @@ BaseView { YearCollection { id: yearCollection - x: rollingWidth width: collecttView.width height: collecttView.height show: currentViewIndex === 0 @@ -91,7 +89,6 @@ BaseView { MonthCollection { id: monthCollection - x: rollingWidth width: collecttView.width height: collecttView.height show: currentViewIndex === 1 @@ -100,7 +97,6 @@ BaseView { DayCollection { id: dayCollection visible: false - x: rollingWidth width: collecttView.width height: collecttView.height show: currentViewIndex === 2 @@ -127,11 +123,15 @@ BaseView { } function onYearClicked(year) { + // 点击在图片上,动画切换类型为渐显渐隐 + GStatus.currentSwitchType = Album.Types.FadeInOut setIndex(1) monthCollection.scrollToYear(year) } function onMonthClicked(year, month) { + // 点击在图片上,动画切换类型为渐显渐隐 + GStatus.currentSwitchType = Album.Types.FadeInOut setIndex(2) dayCollection.scrollToMonth(year, month) } diff --git a/src/qml/ThumbnailImageView/ThumbnailImage.qml b/src/qml/ThumbnailImageView/ThumbnailImage.qml index d0d82124..ffbfdb37 100644 --- a/src/qml/ThumbnailImageView/ThumbnailImage.qml +++ b/src/qml/ThumbnailImageView/ThumbnailImage.qml @@ -23,13 +23,8 @@ import "./../" Item { - property int m_CollecttionCurrentViewIndex: collecttionView.currentViewIndex signal escKeyPressed() - function setCollecttionViewIndex(index) { - collecttionView.setIndex(index) - } - CollecttionView{ id: collecttionView visible: GStatus.currentViewType === Album.Types.ViewCollecttion @@ -74,8 +69,10 @@ Item { Connections { target: titleAlubmRect - onCollectionBtnClicked: { - setCollecttionViewIndex(nIndex) + function onCollectionBtnClicked(index) { + // 点击按钮,动画切换类型设定为翻页滚动 + GStatus.currentSwitchType = Album.Types.FlipScroll + collecttionView.setIndex(index) } } diff --git a/src/src/globalstatus.cpp b/src/src/globalstatus.cpp index c272b5a0..0f14038f 100644 --- a/src/src/globalstatus.cpp +++ b/src/src/globalstatus.cpp @@ -445,6 +445,19 @@ void GlobalStatus::setCurrentCollecttionViewIndex(const int &value) } } +Types::SwitchType GlobalStatus::currentSwitchType() const +{ + return m_currentSwitchType; +} + +void GlobalStatus::setCurrentSwitchType(const int &value) +{ + if (m_currentSwitchType != value) { + m_currentSwitchType = static_cast(value); + Q_EMIT currentSwitchTypeChanged(); + } +} + int GlobalStatus::currentCustomAlbumUId() const { return m_currentCustomAlbumUId; diff --git a/src/src/globalstatus.h b/src/src/globalstatus.h index cddb89d3..1ba6e559 100644 --- a/src/src/globalstatus.h +++ b/src/src/globalstatus.h @@ -145,6 +145,12 @@ class GlobalStatus : public QObject void setCurrentCollecttionViewIndex(const int& value); Q_SIGNAL void currentCollecttionViewIndexChanged(); + // 合集当前动画切换类型 + Q_PROPERTY(Types::SwitchType currentSwitchType READ currentSwitchType WRITE setCurrentSwitchType NOTIFY currentSwitchTypeChanged) + Types::SwitchType currentSwitchType() const; + void setCurrentSwitchType(const int& value); + Q_SIGNAL void currentSwitchTypeChanged(); + // 当前自定义相册Id Q_PROPERTY(int currentCustomAlbumUId READ currentCustomAlbumUId WRITE setCurrentCustomAlbumUId NOTIFY currentCustomAlbumUIdChanged) int currentCustomAlbumUId() const; @@ -294,6 +300,7 @@ class GlobalStatus : public QObject bool m_bRefreshRangeBtnState = false; // 刷新显示比例图标激活状态标记,翻转一次,前端图标就刷新一次 Types::ThumbnailViewType m_currentViewType = Types::ViewImport; // 当前显示的视图类型 int m_currentCollecttionViewIndex = 3; // 合集当前索引 0:年 1:月 2:日 3:所有图片 + Types::SwitchType m_currentSwitchType = Types::UnknownSwitchType; int m_currentCustomAlbumUId = -1; // 当前自定义相册所在UId,-1:照片库(非我的收藏) 0:我的收藏 1:截图录屏 2:相机 3:画板 其他:自定义相册 int m_stackControlCurrent = 0; // 0:相册界面 1:看图界面 2:幻灯片 int m_stackControlLastCurrent = -1; // 记录上一次显示的主界面索引 0:相册界面 1:看图界面 2:幻灯片 diff --git a/src/src/types.h b/src/src/types.h index 71da5427..5c10df6d 100644 --- a/src/src/types.h +++ b/src/src/types.h @@ -22,6 +22,8 @@ class Types : public QObject Q_ENUMS(ItemRole) Q_ENUMS(ImageType) Q_ENUMS(StackPage) + + Q_ENUMS(SwitchType) public: explicit Types(QObject *parent = nullptr); ~Types() override; @@ -110,6 +112,16 @@ class Types : public QObject ImageViewPage, ///< 图片展示界面(含缩略图栏) SliderShowPage, ///< 图片动画展示界面 }; + + /** + @brief 年月日动画切换类型 + */ + enum SwitchType { + UnknownSwitchType = -1, + HardCut, ///< 硬切 + FlipScroll, ///< 滚动翻页 + FadeInOut, ///< 渐显渐隐 + }; }; #endif // TYPES_H