From 2980fc91e3b4032eddc5cc9dd675df44dff68dd4 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 2 May 2023 18:51:09 +0200 Subject: [PATCH] minor updates for QskDrawer --- examples/gallery/main.cpp | 46 +++++---- src/CMakeLists.txt | 4 +- src/controls/QskDrawer.cpp | 135 ++++++++++++++++++++++++++ src/{layouts => controls}/QskDrawer.h | 14 +-- src/layouts/QskDrawer.cpp | 130 ------------------------- 5 files changed, 173 insertions(+), 156 deletions(-) create mode 100644 src/controls/QskDrawer.cpp rename src/{layouts => controls}/QskDrawer.h (96%) delete mode 100644 src/layouts/QskDrawer.cpp diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index c879c9c6..be93afa7 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -55,6 +55,30 @@ namespace } }; + class Drawer : public QskDrawer + { + public: + Drawer( QQuickItem* parent = nullptr ) + : QskDrawer( parent ) + { + auto box = new QskLinearBox( Qt::Vertical ); + box->setSection( QskAspect::Header ); + box->setPanel( true ); + box->setPaddingHint( QskBox::Panel, 20 ); + + new QskPushButton( "One", box ); + new QskPushButton( "Two", box ); + new QskPushButton( "Three", box ); + + box->addStretch( 1 ); + + auto btn = new QskPushButton( "Close", box ); + connect( btn, &QskPushButton::clicked, this, &QskDrawer::close ); + + setContent( box ); + } + }; + class TabView : public QskTabView { public: @@ -213,28 +237,14 @@ namespace } { - QskDrawer* drawer = new QskDrawer( this->parentItem() ); + auto drawer = new Drawer( parentItem() ); drawer->setEdge( Qt::RightEdge ); - auto o = new QskLinearBox( Qt::Vertical ); - - auto c = new QskLinearBox( Qt::Vertical, o ); - new QskPushButton( "One", c ); - new QskPushButton( "Two", c ); - new QskPushButton( "Three", c ); - - c->setExtraSpacingAt( Qt::BottomEdge ); - - auto close = new QskPushButton( "Close", o ); - connect( close, &QskPushButton::clicked, - drawer, &QskDrawer::close ); - - drawer->setContent( o ); - auto burger = new QskPushButton( "≡", this ); - burger->setEmphasis( QskPushButton::LowEmphasis ); + burger->setEmphasis( QskPushButton::LowEmphasis ); + connect( burger, &QskPushButton::clicked, - this, [drawer]() { drawer->open(); }); + drawer, &QskPopup::open ); } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4fc0a28a..8d8cf4e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -169,6 +169,7 @@ list(APPEND HEADERS controls/QskComboBox.h controls/QskComboBoxSkinlet.h controls/QskControl.h + controls/QskDrawer.h controls/QskEvent.h controls/QskFlickAnimator.h controls/QskFocusIndicator.h @@ -266,6 +267,7 @@ list(APPEND SOURCES controls/QskControl.cpp controls/QskControlPrivate.cpp controls/QskDirtyItemFilter.cpp + controls/QskDrawer.cpp controls/QskEvent.cpp controls/QskFlickAnimator.cpp controls/QskFocusIndicator.cpp @@ -340,7 +342,6 @@ list(APPEND SOURCES ) list(APPEND HEADERS - layouts/QskDrawer.h layouts/QskGridBox.h layouts/QskGridLayoutEngine.h layouts/QskIndexedLayoutBox.h @@ -359,7 +360,6 @@ list(APPEND PRIVATE_HEADERS ) list(APPEND SOURCES - layouts/QskDrawer.cpp layouts/QskGridBox.cpp layouts/QskGridLayoutEngine.cpp layouts/QskIndexedLayoutBox.cpp diff --git a/src/controls/QskDrawer.cpp b/src/controls/QskDrawer.cpp new file mode 100644 index 00000000..ec00c84e --- /dev/null +++ b/src/controls/QskDrawer.cpp @@ -0,0 +1,135 @@ +#include "QskDrawer.h" +#include "QskAspect.h" +#include "QskControl.h" + +#include +#include +#include +#include + +QSK_SUBCONTROL( QskDrawer, Panel ) +QSK_SUBCONTROL( QskDrawer, Overlay ) + +class QskDrawer::PrivateData +{ + public: + QskControl* content = nullptr; + QskBox* contentBox = nullptr; + Qt::Edge edge = Qt::LeftEdge; +}; + +QskDrawer::QskDrawer( QQuickItem* parentItem ) + : Inherited ( parentItem ) + , m_data( new PrivateData ) +{ + setZ( 1 ); + + setPopupFlag( PopupFlag::CloseOnPressOutside, true ); + + m_data->contentBox = new QskBox(this); + m_data->contentBox->setSubcontrolProxy( QskBox::Panel, Panel ); + m_data->contentBox->setPanel( true ); + + setSubcontrolProxy( Inherited::Overlay, Overlay ); + + setFaderAspect( Panel | QskAspect::Metric ); + + connect(this, &QskDrawer::closed, this, [this]() { + startTransition( Panel | QskAspect::Metric, + animationHint( Panel | QskAspect::Position ), + 0.0, 1.0 ); + }); +} + +QskDrawer::~QskDrawer() +{ +} + +Qt::Edge QskDrawer::edge() const +{ + return m_data->edge; +} + +void QskDrawer::setEdge( Qt::Edge edge ) +{ + if( m_data->edge == edge ) + return; + + update(); + m_data->edge = edge; + edgeChanged( edge ); +} + +void QskDrawer::setContent( QskControl* content ) +{ + content->setParentItem( m_data->contentBox ); + m_data->content = content; +} + +void QskDrawer::updateLayout() +{ + if ( !isOpen() && !isFading() ) + return; + + const auto padding = paddingHint( Panel ); + + auto contentSize = m_data->content->preferredSize(); + contentSize = contentSize.grownBy( padding ); + + const auto parentSize = parentItem()->size(); + + switch( m_data->edge ) + { + case Qt::Edge::LeftEdge: + { + qreal x = metric( faderAspect() ) * contentSize.width() * -1.0; + + qskSetItemGeometry( m_data->contentBox, + x, 0, contentSize.width(), parentSize.height() ); + break; + } + case Qt::Edge::RightEdge: + { + qreal x = ( metric( faderAspect() ) * contentSize.width() ) + + parentSize.width() - contentSize.width(); + + qskSetItemGeometry( m_data->contentBox, + x, 0, contentSize.width(), parentSize.height() ); + break; + } + + case Qt::Edge::TopEdge: + { + qreal y = metric( faderAspect() ) * contentSize.height(); + + qskSetItemGeometry( m_data->contentBox, + 0, -y, parentSize.width(), contentSize.height() ); + break; + } + + case Qt::Edge::BottomEdge: + { + qreal y = metric( faderAspect() ) * contentSize.height() + parentSize.height() - + contentSize.height(); + + qskSetItemGeometry( m_data->contentBox, + 0, y, parentSize.width(), contentSize.height() ); + break; + } + } + + m_data->content->setGeometry( QPointF( padding.left(), padding.top() ), + m_data->contentBox->size().shrunkBy( padding ) ); + + Inherited::updateLayout(); +} + +void QskDrawer::aboutToShow() +{ + startTransition( Panel | QskAspect::Metric, + animationHint( Panel | QskAspect::Position ), 1.0, 0.0 ); + + Inherited::aboutToShow(); +} + +#include "moc_QskDrawer.cpp" diff --git a/src/layouts/QskDrawer.h b/src/controls/QskDrawer.h similarity index 96% rename from src/layouts/QskDrawer.h rename to src/controls/QskDrawer.h index dee88cfb..240f3f5d 100644 --- a/src/layouts/QskDrawer.h +++ b/src/controls/QskDrawer.h @@ -1,8 +1,9 @@ -#include "QskPopup.h" - #ifndef QSK_DRAWER_H #define QSK_DRAWER_H +#include "QskPopup.h" +#include + class QSK_EXPORT QskDrawer : public QskPopup { Q_OBJECT @@ -13,22 +14,23 @@ class QSK_EXPORT QskDrawer : public QskPopup public: QSK_SUBCONTROLS( Panel, Overlay ) + QskDrawer( QQuickItem* parentItem = nullptr ); ~QskDrawer() override; + void setEdge( Qt::Edge edge ); Qt::Edge edge() const; void updateLayout() override; void setContent( QskControl* t ); - void setEdge( Qt::Edge edge ); - - protected: - void aboutToShow() override; Q_SIGNALS: void edgeChanged( Qt::Edge ); + protected: + void aboutToShow() override; + private: class PrivateData; std::unique_ptr< PrivateData > m_data; diff --git a/src/layouts/QskDrawer.cpp b/src/layouts/QskDrawer.cpp deleted file mode 100644 index 52c9fcff..00000000 --- a/src/layouts/QskDrawer.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "QskDrawer.h" -#include "QskAspect.h" -#include "QskControl.h" - -#include -#include -#include -#include - -QSK_SUBCONTROL( QskDrawer, Panel ) -QSK_SUBCONTROL( QskDrawer, Overlay ) - -class QskDrawer::PrivateData { - public: - QskControl* content; - QskBox* contentBox; - Qt::Edge edge = Qt::LeftEdge; -}; - -QskDrawer::QskDrawer( QQuickItem* parentItem ): - Inherited ( parentItem ) - , m_data( new PrivateData { } ) -{ - setZ( 1 ); - - setPopupFlag( PopupFlag::CloseOnPressOutside, true ); - - m_data->contentBox = new QskBox(this); - m_data->contentBox->setSubcontrolProxy( QskBox::Panel, Panel ); - m_data->contentBox->setPanel( true ); - - setSubcontrolProxy( Inherited::Overlay, Overlay ); - - setFaderAspect( Panel | QskAspect::Metric ); - - connect(this, &QskDrawer::closed, this, [this]() { - startTransition( Panel | QskAspect::Metric, - animationHint( Panel | QskAspect::Position ), - 0.0, 1.0 ); - }); -} - -QskDrawer::~QskDrawer() -{ -} - -Qt::Edge QskDrawer::edge() const { - return m_data->edge; -} - -void QskDrawer::setEdge( Qt::Edge edge ) { - if( m_data->edge == edge ) - { - return; - } - - update(); - m_data->edge = edge; - edgeChanged( edge ); -} - -void QskDrawer::setContent( QskControl* content ) { - content->setParentItem( m_data->contentBox ); - m_data->content = content; -} - -void QskDrawer::updateLayout() { - const auto& padding = paddingHint( Panel ); - const auto& contentSize = m_data->content->preferredSize() - .grownBy( padding ); - const auto& parentSize = parentItem()->size(); - - switch( m_data->edge ) { - case Qt::Edge::LeftEdge: - { - qreal x = metric( faderAspect() ) * contentSize.width() * -1.0; - - qskSetItemGeometry( m_data->contentBox, - x, 0, - contentSize.width(), parentSize.height() ); - break; - } - case Qt::Edge::RightEdge: - { - qreal x = ( metric( faderAspect() ) * contentSize.width() ) - + parentSize.width() - - contentSize.width(); - - qskSetItemGeometry( m_data->contentBox, - x, 0, - contentSize.width(), parentSize.height() ); - break; - } - - case Qt::Edge::TopEdge: - { - qreal y = metric( faderAspect() ) * contentSize.height(); - - qskSetItemGeometry( m_data->contentBox, - 0, -y, - parentSize.width(), contentSize.height() ); - break; - } - - case Qt::Edge::BottomEdge: - { - qreal y = metric( faderAspect() ) * contentSize.height() + parentSize.height() - - contentSize.height(); - - qskSetItemGeometry( m_data->contentBox, - 0, y, - parentSize.width(), contentSize.height() ); - break; - } - } - m_data->content->setGeometry( QPointF( padding.left(), padding.top() ), - m_data->contentBox->size().shrunkBy( padding ) ); - - Inherited::updateLayout(); -} - -void QskDrawer::aboutToShow() -{ - startTransition( Panel | QskAspect::Metric, - animationHint( Panel | QskAspect::Position ), - 1.0, 0.0 ); - Inherited::aboutToShow(); -} - -#include "moc_QskDrawer.cpp"