From c57f0adfb01884177de28ba124540970bba36e78 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 17 Oct 2023 17:03:06 +0200 Subject: [PATCH] QskDrawer::setInteractive added --- src/controls/QskDrawer.cpp | 49 +++++++++++++++++++++++++++++++------- src/controls/QskDrawer.h | 10 +++++++- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/controls/QskDrawer.cpp b/src/controls/QskDrawer.cpp index 5b62d1e1..c24a4d2d 100644 --- a/src/controls/QskDrawer.cpp +++ b/src/controls/QskDrawer.cpp @@ -26,6 +26,12 @@ QSK_QT_PRIVATE_END */ QSK_SUBCONTROL( QskDrawer, Panel ) +static inline qreal qskDefaultDragMargin() +{ + // a skin hint ??? + return QGuiApplication::styleHints()->startDragDistance(); +} + static void qskCatchMouseEvents( QQuickItem* item ) { #if 1 @@ -239,8 +245,7 @@ class QskDrawer::PrivateData GestureRecognizer* gestureRecognizer = nullptr; GeometryListener* listener = nullptr; - // a skin hint ??? - qreal dragMargin = QGuiApplication::styleHints()->startDragDistance(); + qreal dragMargin = qskDefaultDragMargin(); }; QskDrawer::QskDrawer( QQuickItem* parentItem ) @@ -252,6 +257,7 @@ QskDrawer::QskDrawer( QQuickItem* parentItem ) #endif setAutoLayoutChildren( true ); + setInteractive( true ); setPopupFlag( PopupFlag::CloseOnPressOutside, true ); setFaderAspect( Panel | QskAspect::Position | QskAspect::Metric ); @@ -263,13 +269,7 @@ QskDrawer::QskDrawer( QQuickItem* parentItem ) */ setPlacementPolicy( QskPlacementPolicy::Ignore ); if ( parentItem ) - { m_data->listener = new GeometryListener( parentItem, this ); - qskCatchMouseEvents( parentItem ); - } - - m_data->gestureRecognizer = new GestureRecognizer( this ); - connect( this, &QskPopup::openChanged, this, &QskDrawer::setFading ); @@ -302,6 +302,32 @@ void QskDrawer::setEdge( Qt::Edge edge ) edgeChanged( edge ); } +void QskDrawer::setInteractive( bool on ) +{ + if ( on == isInteractive() ) + return; + + if ( on ) + { + m_data->gestureRecognizer = new GestureRecognizer( this ); + if ( parentItem() ) + qskCatchMouseEvents( parentItem() ); + } + else + { + // how to revert qskCatchMouseEvents properly ??? + delete m_data->gestureRecognizer; + m_data->gestureRecognizer = nullptr; + } + + Q_EMIT interactiveChanged( on ); +} + +bool QskDrawer::isInteractive() const +{ + return m_data->gestureRecognizer != nullptr; +} + void QskDrawer::setDragMargin( qreal margin ) { margin = std::max( margin, 0.0 ); @@ -313,6 +339,11 @@ void QskDrawer::setDragMargin( qreal margin ) } } +void QskDrawer::resetDragMargin() +{ + setDragMargin( qskDefaultDragMargin() ); +} + qreal QskDrawer::dragMargin() const { return m_data->dragMargin; @@ -361,7 +392,7 @@ void QskDrawer::itemChange( QQuickItem::ItemChange change, { case QQuickItem::ItemParentHasChanged: { - if ( parentItem() ) + if ( parentItem() && isInteractive() ) qskCatchMouseEvents( parentItem() ); Q_FALLTHROUGH(); diff --git a/src/controls/QskDrawer.h b/src/controls/QskDrawer.h index a82e57b3..6627b9fc 100644 --- a/src/controls/QskDrawer.h +++ b/src/controls/QskDrawer.h @@ -18,7 +18,10 @@ class QSK_EXPORT QskDrawer : public QskPopup Q_PROPERTY( Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged ) Q_PROPERTY( qreal dragMargin READ dragMargin - WRITE setDragMargin NOTIFY dragMarginChanged ) + WRITE setDragMargin RESET resetDragMargin NOTIFY dragMarginChanged ) + + Q_PROPERTY( bool interactive READ isInteractive + WRITE setInteractive NOTIFY interactiveChanged ) public: QSK_SUBCONTROLS( Panel ) @@ -29,7 +32,11 @@ class QSK_EXPORT QskDrawer : public QskPopup void setEdge( Qt::Edge ); Qt::Edge edge() const; + void setInteractive( bool ); + bool isInteractive() const; + void setDragMargin( qreal ); + void resetDragMargin(); qreal dragMargin() const; QRectF layoutRectForSize( const QSizeF& ) const override; @@ -37,6 +44,7 @@ class QSK_EXPORT QskDrawer : public QskPopup Q_SIGNALS: void edgeChanged( Qt::Edge ); void dragMarginChanged( qreal ); + void interactiveChanged( bool ); protected: void itemChange( ItemChange, const ItemChangeData& ) override;