diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 88df97a9..808f4e2c 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -232,20 +232,17 @@ namespace } { - auto drawer = new Drawer( parentItem() ); - drawer->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed ); - drawer->setEdge( Qt::RightEdge ); - auto burger = new QskPushButton( "≡", this ); burger->setEmphasis( QskPushButton::LowEmphasis ); connect( burger, &QskPushButton::clicked, - drawer, &QskPopup::open ); + this, &Header::drawerRequested ); } } Q_SIGNALS: void enabledToggled( bool ); + void drawerRequested(); }; class MainView : public QskMainView @@ -268,6 +265,13 @@ namespace connect( header, &Header::enabledToggled, tabView, &TabView::setPagesEnabled ); + auto drawer = new Drawer( this ); + drawer->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed ); + drawer->setEdge( Qt::RightEdge ); + + connect( header, &Header::drawerRequested, + drawer, &QskPopup::open ); + setHeader( header ); setBody( tabView ); } diff --git a/playground/CMakeLists.txt b/playground/CMakeLists.txt index 7fc3449a..83b1d635 100644 --- a/playground/CMakeLists.txt +++ b/playground/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(invoker) add_subdirectory(shadows) add_subdirectory(shapes) add_subdirectory(charts) +add_subdirectory(drawer) if (BUILD_INPUTCONTEXT) add_subdirectory(inputpanel) diff --git a/playground/drawer/CMakeLists.txt b/playground/drawer/CMakeLists.txt new file mode 100644 index 00000000..bb40707e --- /dev/null +++ b/playground/drawer/CMakeLists.txt @@ -0,0 +1,6 @@ +############################################################################ +# QSkinny - Copyright (C) 2016 Uwe Rathmann +# SPDX-License-Identifier: BSD-3-Clause +############################################################################ + +qsk_add_example(drawer main.cpp) diff --git a/playground/drawer/main.cpp b/playground/drawer/main.cpp new file mode 100644 index 00000000..76717669 --- /dev/null +++ b/playground/drawer/main.cpp @@ -0,0 +1,182 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include "SkinnyShortcut.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace +{ + inline qreal distanceToEdge( + const QRectF& rect, const QPointF& pos, int edge ) + { + qreal dt = 10e6; + switch( edge ) + { + case Qt::TopEdge: + dt = pos.y() - rect.top(); + break; + + case Qt::BottomEdge: + dt = rect.bottom() - pos.y(); + break; + + case Qt::LeftEdge: + dt = pos.x() - rect.left(); + break; + + case Qt::RightEdge: + dt = rect.right() - pos.x(); + break; + } + + return std::abs( dt ); + } + + class Drawer : public QskDrawer + { + public: + Drawer( Qt::Edge edge, QQuickItem* parent ) + : QskDrawer( parent ) + { +#if 1 + setAnimationHint( Panel | QskAspect::Position, 2000 ); +#endif + + setEdge( edge ); + setOverlay( true ); + + auto content = new QskControl( this ); + + switch( edge ) + { + case Qt::LeftEdge: + content->setBackgroundColor( QskRgb::Tomato ); + setFixedWidth( 100 ); + break; + + case Qt::RightEdge: + setFixedWidth( 200 ); + content->setBackgroundColor( QskRgb::Orchid ); + break; + + case Qt::TopEdge: + setFixedHeight( 100 ); + content->setBackgroundColor( QskRgb::Wheat ); + break; + + case Qt::BottomEdge: + setFixedHeight( 200 ); + content->setBackgroundColor( QskRgb::Wheat ); + break; + } + } + }; + + class DrawerBox : public QskControl + { + public: + DrawerBox( QQuickItem* parent = nullptr ) + : QskControl( parent ) + { + setBackgroundColor( QskRgb::LightSteelBlue ); + + setMargins( 50 ); + setAutoLayoutChildren( true ); + + (void) new QskPushButton( this ); + + for ( int i = 0; i < 4; i++ ) + { + const auto edge = static_cast< Qt::Edge >( 1 << i ); + m_drawers[i] = new Drawer( edge, this ); + } + + setAcceptedMouseButtons( Qt::LeftButton ); + } + + protected: + virtual bool contains( const QPointF& pos ) const + { + if ( auto control = qskControlCast( parentItem() ) ) + { + // we want to catch clicks on the margins of the parent + + auto r = rect(); + if ( !r.contains( pos ) ) + { + r = r.marginsAdded( control->margins() ); + return r.contains( pos ); + } + + return false; + } + + return QskControl::contains( pos ); + } + + void mousePressEvent( QMouseEvent* event ) override + { + const auto pos = qskMousePosition( event ); + + int drawerIndex = -1; + qreal minDist = 10e6; + + for ( int i = 0; i < 4; i++ ) + { + const auto edge = static_cast< Qt::Edge >( 1 << i ); + const auto dist = distanceToEdge( rect(), pos, edge ); + + if ( dist < minDist ) + { + minDist = dist; + drawerIndex = i; + } + } + + if ( drawerIndex >= 0 ) + m_drawers[drawerIndex]->open(); + } + + private: + Drawer* m_drawers[4]; + }; + + class MainBox : public QskControl + { + public: + MainBox( QQuickItem* parent = nullptr ) + : QskControl( parent ) + { + setBackgroundColor( QskRgb::LemonChiffon ); + setMargins( 40 ); + setAutoLayoutChildren( true ); + + ( void ) new DrawerBox( this ); + } + }; +} + +int main( int argc, char* argv[] ) +{ + QGuiApplication app( argc, argv ); + + SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts ); + + QskWindow window; + window.addItem( new MainBox() ); + window.resize( 600, 600 ); + window.show(); + + return app.exec(); +}