diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f93b7b48..4fc0a28a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -340,6 +340,7 @@ list(APPEND SOURCES ) list(APPEND HEADERS + layouts/QskDrawer.h layouts/QskGridBox.h layouts/QskGridLayoutEngine.h layouts/QskIndexedLayoutBox.h @@ -358,6 +359,7 @@ list(APPEND PRIVATE_HEADERS ) list(APPEND SOURCES + layouts/QskDrawer.cpp layouts/QskGridBox.cpp layouts/QskGridLayoutEngine.cpp layouts/QskIndexedLayoutBox.cpp diff --git a/src/layouts/QskDrawer.cpp b/src/layouts/QskDrawer.cpp new file mode 100644 index 00000000..52b1c1df --- /dev/null +++ b/src/layouts/QskDrawer.cpp @@ -0,0 +1,118 @@ +#include "QskDrawer.h" +#include "QskAnimationHint.h" +#include "QskAspect.h" +#include "QskControl.h" +#include "QskPopup.h" +#include "QskBox.h" +#include +#include +#include +#include + +#include +#include +#include +#include + +QSK_SUBCONTROL( QskDrawer, DasPanel ) + +class QskDrawer::PrivateData { +public: + QskControl* control = nullptr; + QskBox* content; + Qt::Edge edge = Qt::LeftEdge; +}; + +QskDrawer::QskDrawer( QQuickItem* parentItem ) : + Inherited ( parentItem ) + , m_data( new PrivateData { } ) +{ + using Q = QskDrawer; + setZ( 1 ); + + setPolishOnResize( true ); + this->setPopupFlags( PopupFlag::CloseOnPressOutside ); + setPopupFlag( PopupFlag::CloseOnPressOutside, true ); + + m_data->content = new QskBox(this); + m_data->content->setSubcontrolProxy( QskBox::Panel, QskDrawer::DasPanel ); + m_data->content->setClip( true ); + + setAnimationHint( QskDrawer::DasPanel | QskAspect::Metric, QskAnimationHint(300) ); + setModal( false ); + setFaderAspect( QskDrawer::DasPanel | QskAspect::Metric ); + setMetric( DasPanel, 0.1); + setFaderAspect( DasPanel | QskAspect::Metric ); + + setSkinHint( Q::Overlay | QskAspect::Style, false ); + + initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); +} + +QskDrawer::~QskDrawer() +{ +} + +Qt::Edge QskDrawer::edge() const { + return m_data->edge; +} + +void QskDrawer::setEdge( Qt::Edge edge ) { + if( m_data->edge == edge ) { + return; + } + + m_data->edge = edge; + edgeChanged( edge ); +} + +void QskDrawer::setContent( QskControl* t ) { + m_data->control = t; + t->setParentItem( m_data->content ); + // polish(); +} + +void QskDrawer::updateLayout() { + if( !m_data->control ) { + return; + } + + auto rect = parentItem()->childrenRect(); + rect.setSize( {200, 400} ); //m_data->content->preferredSize() ); + + switch( m_data->edge ) { + case Qt::Edge::LeftEdge: + case Qt::Edge::RightEdge: + // rect.setWidth( m_data->control->preferredSize().width() ); + break; + + case Qt::Edge::TopEdge: + case Qt::Edge::BottomEdge: + // rect.setHeight( m_data->control->preferredSize().height() ); + break; + + } + + auto size = rect.size(); + qreal off = metric( faderAspect() ) * size.width(); + + qskSetItemGeometry( m_data->content, -off, 0, size.width(), size.height()); + + m_data->content->polish(); + + Inherited::updateLayout(); +} + +QSizeF QskDrawer::contentsSizeHint( Qt::SizeHint, const QSizeF& ) const { + return {200, 200}; +} + + +void QskDrawer::aboutToShow() +{ + startTransition( DasPanel | QskAspect::Metric, QskAnimationHint(2000), 1.0, .0 ); + Inherited::aboutToShow(); +} + + +#include "moc_QskDrawer.cpp" diff --git a/src/layouts/QskDrawer.h b/src/layouts/QskDrawer.h new file mode 100644 index 00000000..981037dc --- /dev/null +++ b/src/layouts/QskDrawer.h @@ -0,0 +1,43 @@ +#include "QskGlobal.h" +#include "QskPopup.h" + +#include +#include +#include + +#ifndef QSK_DRAWER_H +#define QSK_DRAWER_H + +class QSK_EXPORT QskDrawer : public QskPopup +{ + Q_OBJECT + + using Inherited = QskPopup; + + Q_PROPERTY( Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged ) + + public: + QSK_SUBCONTROLS( DasPanel ) + QskDrawer( QQuickItem* parentItem = nullptr ); + ~QskDrawer() override; + + Qt::Edge edge() const; + + void updateLayout() override; + + void setContent( QskControl* t ); + void setEdge( Qt::Edge edge ); + + protected: + void aboutToShow() override; + QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const override; + + Q_SIGNALS: + void edgeChanged( Qt::Edge ); + + private: + class PrivateData; + std::unique_ptr< PrivateData > m_data; +}; + +#endif