From 25461aaaf63db61e5c690083a99a805bd72ee30e Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 18 Oct 2023 15:05:17 +0200 Subject: [PATCH 1/3] QskDrawer improvements --- src/controls/QskDrawer.cpp | 146 ++++++++++++++++++++++++++++++++----- src/controls/QskDrawer.h | 7 ++ 2 files changed, 136 insertions(+), 17 deletions(-) diff --git a/src/controls/QskDrawer.cpp b/src/controls/QskDrawer.cpp index c24a4d2d..55a8d33f 100644 --- a/src/controls/QskDrawer.cpp +++ b/src/controls/QskDrawer.cpp @@ -241,6 +241,15 @@ namespace class QskDrawer::PrivateData { public: + inline void resetListener( QskDrawer* drawer ) + { + delete listener; + listener = nullptr; + + if ( drawer->parentItem() && drawer->isVisible() ) + listener = new GeometryListener( drawer->parentItem(), drawer ); + } + Qt::Edge edge = Qt::LeftEdge; GestureRecognizer* gestureRecognizer = nullptr; GeometryListener* listener = nullptr; @@ -268,18 +277,10 @@ QskDrawer::QskDrawer( QQuickItem* parentItem ) the layout updates manually. */ setPlacementPolicy( QskPlacementPolicy::Ignore ); - if ( parentItem ) - m_data->listener = new GeometryListener( parentItem, this ); + m_data->resetListener( this ); connect( this, &QskPopup::openChanged, this, &QskDrawer::setFading ); - - /* - When the content of the parentItem does not fit we will have - a difference between fading and normal state. To overcome this problem - we need to expand the rectangle of the QQuickDefaultClipNode manually to - the window borders: TODO ... - */ - connect( this, &QskPopup::fadingChanged, parentItem, &QQuickItem::setClip ); + connect( this, &QskPopup::fadingChanged, this, &QskDrawer::setIntermediate ); } QskDrawer::~QskDrawer() @@ -349,6 +350,64 @@ qreal QskDrawer::dragMargin() const return m_data->dragMargin; } +void QskDrawer::keyPressEvent( QKeyEvent* event ) +{ + if ( isOpen() ) + { + bool doClose = false; + + const auto key = event->key(); + + switch( key ) + { + case Qt::Key_Escape: + case Qt::Key_Cancel: + { + doClose = true; + break; + } + +#if 0 + /* + Do we want to have this - and what about opening with + the same keys ??? + */ + case Qt::Key_Up: + case Qt::Key_Down: + case Qt::Key_Left: + case Qt::Key_Right: + { + switch( m_data->edge ) + { + case Qt::TopEdge: + doClose = ( key == Qt::Key_Up ); + break; + case Qt::BottomEdge: + doClose = ( key == Qt::Key_Down ); + break; + case Qt::LeftEdge: + doClose = ( key == Qt::Key_Left ); + break; + case Qt::RightEdge: + doClose = ( key == Qt::Key_Right ); + break; + } + + break; + } +#endif + } + + if ( doClose ) + { + close(); + return; + } + } + + Inherited::keyPressEvent( event ); +} + void QskDrawer::gestureEvent( QskGestureEvent* event ) { if ( event->gesture()->type() == QskGesture::Pan ) @@ -395,16 +454,12 @@ void QskDrawer::itemChange( QQuickItem::ItemChange change, if ( parentItem() && isInteractive() ) qskCatchMouseEvents( parentItem() ); - Q_FALLTHROUGH(); + m_data->resetListener( this ); + break; } case QQuickItem::ItemVisibleHasChanged: { - delete m_data->listener; - m_data->listener = nullptr; - - if ( parentItem() && isVisible() ) - m_data->listener = new GeometryListener( parentItem(), this ); - + m_data->resetListener( this ); break; } } @@ -423,4 +478,61 @@ void QskDrawer::setFading( bool on ) startTransition( aspect, hint, from, to ); } +QRectF QskDrawer::clipRect() const +{ + if ( !isFading() ) + return Inherited::clipRect(); + + /* + When fading we want to clip against the edge, where the drawer + slides in/out. However the size of the drawer is often smaller than the + one of the parent and we would clip the overlay node + and all content, that is located outside the drawer geometry. + + So we expand the clip rectangle to "unbounded" at the other edges. + + Note, that clipping against "rounded" rectangles can't be done + properly by overloading clipRect. We would have to manipulate the clip node + manually - like it is done in QskScrollArea. TODO .. + */ + constexpr qreal d = std::numeric_limits< short >::max(); + + QRectF r( -d, -d, 2.0 * d, 2.0 * d ); + + switch( m_data->edge ) + { + case Qt::LeftEdge: + r.setLeft( 0.0 ); + break; + + case Qt::RightEdge: + r.setRight( width() ); + break; + + case Qt::TopEdge: + r.setTop( 0.0 ); + break; + + case Qt::BottomEdge: + r.setBottom( height() ); + break; + } + + return r; +} + +void QskDrawer::setIntermediate( bool on ) +{ + setClip( on ); + Q_EMIT focusIndicatorRectChanged(); +} + +QRectF QskDrawer::focusIndicatorRect() const +{ + if ( isFading() ) + return QRectF(); + + return Inherited::focusIndicatorRect(); +} + #include "moc_QskDrawer.cpp" diff --git a/src/controls/QskDrawer.h b/src/controls/QskDrawer.h index 6627b9fc..d7e66d0c 100644 --- a/src/controls/QskDrawer.h +++ b/src/controls/QskDrawer.h @@ -41,6 +41,9 @@ class QSK_EXPORT QskDrawer : public QskPopup QRectF layoutRectForSize( const QSizeF& ) const override; + QRectF clipRect() const override; + QRectF focusIndicatorRect() const override; + Q_SIGNALS: void edgeChanged( Qt::Edge ); void dragMarginChanged( qreal ); @@ -49,9 +52,13 @@ class QSK_EXPORT QskDrawer : public QskPopup protected: void itemChange( ItemChange, const ItemChangeData& ) override; void gestureEvent( QskGestureEvent* ) override; + void keyPressEvent( QKeyEvent* ) override; private: void setFading( bool ); + void setFadingClip( bool ); + + void setIntermediate( bool ); class PrivateData; std::unique_ptr< PrivateData > m_data; From e56360480fed61dbf3419ef122c9b8235f81ed45 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 18 Oct 2023 15:07:29 +0200 Subject: [PATCH 2/3] using 0/1 for closed/open ( instead of 1/0 ) --- skins/fluent2/QskFluent2Skin.cpp | 4 ++-- skins/material3/QskMaterial3Skin.cpp | 4 ++-- skins/squiek/QskSquiekSkin.cpp | 4 ++-- src/controls/QskDrawer.cpp | 8 +++++--- src/nodes/QskSlideInNode.cpp | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/skins/fluent2/QskFluent2Skin.cpp b/skins/fluent2/QskFluent2Skin.cpp index 30829413..963e22a3 100644 --- a/skins/fluent2/QskFluent2Skin.cpp +++ b/skins/fluent2/QskFluent2Skin.cpp @@ -745,8 +745,8 @@ void Editor::setupMenuMetrics() setPadding( Q::Icon, { 8, 8, 0, 8 } ); #if 1 - setPosition( Q::Panel, 0 ); - setPosition( Q::Panel | QskPopup::Closed, 1 ); + setPosition( Q::Panel, 1 ); + setPosition( Q::Panel | QskPopup::Closed, 0 ); // copied from Mat3 - what are the correct values for Fluent2 ??? setAnimation( Q::Panel | A::Metric, 150 ); diff --git a/skins/material3/QskMaterial3Skin.cpp b/skins/material3/QskMaterial3Skin.cpp index 9ea1c054..f5780f04 100644 --- a/skins/material3/QskMaterial3Skin.cpp +++ b/skins/material3/QskMaterial3Skin.cpp @@ -378,8 +378,8 @@ void Editor::setupMenu() setColor( Q::Text, m_pal.onSurface ); setFontRole( Q::Text, QskMaterial3Skin::M3BodyMedium ); - setPosition( Q::Panel, 0 ); - setPosition( Q::Panel | QskPopup::Closed, 1 ); + setPosition( Q::Panel, 1 ); + setPosition( Q::Panel | QskPopup::Closed, 0 ); setAnimation( Q::Panel | A::Metric, 150 ); setAnimation( Q::Cursor | A::Position | A::Metric, 75, QEasingCurve::OutCubic ); diff --git a/skins/squiek/QskSquiekSkin.cpp b/skins/squiek/QskSquiekSkin.cpp index c5ea53ab..f92ba16a 100644 --- a/skins/squiek/QskSquiekSkin.cpp +++ b/skins/squiek/QskSquiekSkin.cpp @@ -446,8 +446,8 @@ void Editor::setupMenu() setGraphicRole( Q::Icon | Q::Disabled, DisabledSymbol ); setGraphicRole( Q::Icon | Q::Selected, CursorSymbol ); - setPosition( Q::Panel, 0 ); - setPosition( Q::Panel | QskPopup::Closed, 1 ); + setPosition( Q::Panel, 1 ); + setPosition( Q::Panel | QskPopup::Closed, 0 ); setAnimation( Q::Panel | A::Metric, 150 ); setAnimation( Q::Cursor | A::Position | A::Metric, 75, QEasingCurve::OutCubic ); diff --git a/src/controls/QskDrawer.cpp b/src/controls/QskDrawer.cpp index 55a8d33f..717a30e5 100644 --- a/src/controls/QskDrawer.cpp +++ b/src/controls/QskDrawer.cpp @@ -108,6 +108,8 @@ static inline QRectF qskSlidingRect( auto x = 0.0; auto y = 0.0; + ratio = 1.0 - ratio; + switch( edge ) { case Qt::LeftEdge: @@ -437,7 +439,7 @@ QRectF QskDrawer::layoutRectForSize( const QSizeF& size ) const if ( isFading() ) ratio = metric( faderAspect() ); else - ratio = isOpen() ? 0.0 : 1.0; + ratio = isOpen() ? 1.0 : 0.0; return qskSlidingRect( size, m_data->edge, ratio ); } @@ -467,8 +469,8 @@ void QskDrawer::itemChange( QQuickItem::ItemChange change, void QskDrawer::setFading( bool on ) { - const qreal from = on ? 1.0 : 0.0; - const qreal to = on ? 0.0 : 1.0; + const qreal from = on ? 0.0 : 1.0; + const qreal to = on ? 1.0 : 0.0; const auto aspect = faderAspect(); diff --git a/src/nodes/QskSlideInNode.cpp b/src/nodes/QskSlideInNode.cpp index 6c77b366..24590845 100644 --- a/src/nodes/QskSlideInNode.cpp +++ b/src/nodes/QskSlideInNode.cpp @@ -59,7 +59,7 @@ void QskSlideInNode::updateTranslation( const QRectF& rect, { // clipping - if ( progress > 0.0 && progress <= 1.0 ) + if ( progress >= 0.0 && progress < 1.0 ) { if ( d->clipNode == nullptr ) { @@ -85,7 +85,7 @@ void QskSlideInNode::updateTranslation( const QRectF& rect, // translation qreal dx = 0.0; - qreal dy = -progress* rect.height(); + qreal dy = ( progress - 1.0 ) * rect.height(); if ( dx != 0.0 || dy != 0.0 ) { From 4cbd0d62a5c079a791da3102a7c545d75618c9d8 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 18 Oct 2023 15:10:55 +0200 Subject: [PATCH 3/3] respect QskPopup::hasFaderEffect --- src/controls/QskDrawer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/controls/QskDrawer.cpp b/src/controls/QskDrawer.cpp index 717a30e5..614271d2 100644 --- a/src/controls/QskDrawer.cpp +++ b/src/controls/QskDrawer.cpp @@ -469,6 +469,9 @@ void QskDrawer::itemChange( QQuickItem::ItemChange change, void QskDrawer::setFading( bool on ) { + if ( !hasFaderEffect() ) + return; + const qreal from = on ? 0.0 : 1.0; const qreal to = on ? 1.0 : 0.0;