From 66b40cb1981164d0f42350e420a7dcd3225f8233 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Sat, 30 Sep 2023 08:52:34 +0200 Subject: [PATCH] subwindows: Allow fading out Resolves #10 --- skins/fluent2/QskFluent2Skin.cpp | 2 ++ skins/material3/QskMaterial3Skin.cpp | 2 ++ src/controls/QskPopup.cpp | 31 ++++++++++++++++------------ src/controls/QskSubWindow.cpp | 15 ++++++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/skins/fluent2/QskFluent2Skin.cpp b/skins/fluent2/QskFluent2Skin.cpp index 7b56147c..fef335f7 100644 --- a/skins/fluent2/QskFluent2Skin.cpp +++ b/skins/fluent2/QskFluent2Skin.cpp @@ -1877,6 +1877,8 @@ void Editor::setupSubWindow( const QskFluent2Theme& theme ) using Q = QskSubWindow; const auto& pal = theme.palette; + setAnimation( Q::Panel | QskAspect::Position, 150 ); + setPadding( Q::Panel, { 0, 31, 0, 0 } ); setBoxShape( Q::Panel, 7 ); setBoxBorderMetrics( Q::Panel, 1 ); diff --git a/skins/material3/QskMaterial3Skin.cpp b/skins/material3/QskMaterial3Skin.cpp index 6653e202..7c698ea2 100644 --- a/skins/material3/QskMaterial3Skin.cpp +++ b/skins/material3/QskMaterial3Skin.cpp @@ -1236,6 +1236,8 @@ void Editor::setupSubWindow() using A = QskAspect; using Q = QskSubWindow; + setAnimation( Q::Panel | QskAspect::Position, 150 ); + // Panel setPadding( Q::Panel, { 24_dp, 0, 24_dp, 24_dp } ); diff --git a/src/controls/QskPopup.cpp b/src/controls/QskPopup.cpp index c3292083..0b9fbe11 100644 --- a/src/controls/QskPopup.cpp +++ b/src/controls/QskPopup.cpp @@ -4,6 +4,7 @@ *****************************************************************************/ #include "QskPopup.h" +#include "QskAnimationHint.h" #include "QskAspect.h" #include "QskInputGrabber.h" #include "QskQuick.h" @@ -638,8 +639,23 @@ int QskPopup::execPopup() */ connect( popup, &QObject::destroyed, this, &EventLoop::reject ); - connect( popup, &QskPopup::fadingChanged, this, &EventLoop::maybeQuit ); - connect( popup, &QskPopup::openChanged, this, &EventLoop::maybeQuit ); + + connect( popup, &QskPopup::fadingChanged, this, [this, popup]() + { + if ( !popup->isOpen() && !popup->isFading() ) + { + QEventLoop::exit( 0 ); + } + }); + + connect( popup, &QskPopup::openChanged, this, [this, popup]() + { + if( popup->faderAspect().value() == 0 + || popup->animationHint( popup->faderAspect().subControl() | QskAspect::Position ).duration <= 0 ) + { + QEventLoop::exit( 0 ); + } // otherwise wait for the fading to finish + }); } private: @@ -648,17 +664,6 @@ int QskPopup::execPopup() setParent( nullptr ); QEventLoop::exit( 1 ); } - - void maybeQuit() - { - if ( auto popup = qobject_cast< const QskPopup* >( parent() ) ) - { - if ( popup->isOpen() || popup->isFading() ) - return; - } - - QEventLoop::exit( 0 ); - } }; if ( isOpen() || isFading() ) diff --git a/src/controls/QskSubWindow.cpp b/src/controls/QskSubWindow.cpp index c278a889..464f5e6c 100644 --- a/src/controls/QskSubWindow.cpp +++ b/src/controls/QskSubWindow.cpp @@ -4,6 +4,7 @@ *****************************************************************************/ #include "QskSubWindow.h" +#include "QskAnimationHint.h" #include "QskAspect.h" #include "QskPlatform.h" #include "QskGraphic.h" @@ -49,7 +50,15 @@ QskSubWindow::QskSubWindow( QQuickItem* parent ) setMargins( 0 ); initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::MinimumExpanding ); + setFaderAspect( Panel | QskAspect::Metric ); + setAutoLayoutChildren( true ); + + connect(this, &QskSubWindow::closed, this, [this]() { + startTransition( Panel | QskAspect::Metric, + animationHint( Panel | QskAspect::Position ), + 0.0, 1.0 ); + }); } QskSubWindow::~QskSubWindow() @@ -189,6 +198,12 @@ bool QskSubWindow::event( QEvent* event ) void QskSubWindow::updateLayout() { + if( isFading() ) + { + const auto opacity = 1 - metric( faderAspect() ); + setOpacity( opacity ); + } + if ( m_data->isWindowIconSourceDirty ) { if ( !m_data->windowIconSource.isEmpty() )