From d3e34f5f97f548b1fdde200098cac9f784fb5f21 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 24 Sep 2021 14:47:56 +0200 Subject: [PATCH] IOT dashboard: Use cube effect --- examples/iotdashboard/MainItem.cpp | 64 ++++++++++++++++++++++++++ examples/iotdashboard/MainItem.h | 27 +++++++++++ examples/iotdashboard/MainWindow.cpp | 9 +--- examples/iotdashboard/iotdashboard.pro | 2 + 4 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 examples/iotdashboard/MainItem.cpp create mode 100644 examples/iotdashboard/MainItem.h diff --git a/examples/iotdashboard/MainItem.cpp b/examples/iotdashboard/MainItem.cpp new file mode 100644 index 00000000..7ded215b --- /dev/null +++ b/examples/iotdashboard/MainItem.cpp @@ -0,0 +1,64 @@ +#include "MainItem.h" + +#include "MainContent.h" +#include "MenuBar.h" + +#include +#include +#include +#include + +#include +#include +#include + +MainItem::MainItem( QQuickItem* parent ) + : QskControl( parent ) + , m_cube( new QskStackBox( false, this ) ) + , m_mainLayout( new QskLinearBox( Qt::Horizontal, m_cube ) ) +{ + setAutoLayoutChildren( true ); + setAcceptedMouseButtons( Qt::LeftButton ); + setFiltersChildMouseEvents( true ); + + m_panRecognizer.setOrientations( Qt::Horizontal ); + m_panRecognizer.setMinDistance( 50 ); + m_panRecognizer.setWatchedItem( this ); + + m_mainLayout->setSpacing( 0 ); + + (void) new MenuBar( m_mainLayout ); + (void) new MainContent( m_mainLayout ); + + m_cube->addItem( m_mainLayout ); +} + +void MainItem::gestureEvent( QskGestureEvent* event ) +{ + if( event->gesture()->state() == QskGesture::Finished ) + { + // ### here start animation + } +} + +bool MainItem::gestureFilter( QQuickItem* item, QEvent* event ) +{ + auto& recognizer = m_panRecognizer; + + if( event->type() == QEvent::MouseButtonPress ) + { + const auto mouseEvent = static_cast< QMouseEvent* >( event ); + + if( ( item != this ) || ( recognizer.timeout() < 0 ) ) + { + if( recognizer.hasProcessedBefore( mouseEvent ) ) + { + return false; + } + } + + recognizer.setTimeout( ( item == this ) ? -1 : 100 ); + } + + return recognizer.processEvent( item, event, false ); +} diff --git a/examples/iotdashboard/MainItem.h b/examples/iotdashboard/MainItem.h new file mode 100644 index 00000000..5dae0251 --- /dev/null +++ b/examples/iotdashboard/MainItem.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +#include + +class QskBox; +class QskLinearBox; +class QskStackBox; + +class MainItem : public QskControl +{ + Q_OBJECT + + public: + MainItem( QQuickItem* parent = nullptr ); + + protected: + bool gestureFilter( QQuickItem*, QEvent* ) override final; + void gestureEvent( QskGestureEvent* ) override final; + + private: + QskStackBox* m_cube; + QskLinearBox* m_mainLayout; + QskPanGestureRecognizer m_panRecognizer; +}; diff --git a/examples/iotdashboard/MainWindow.cpp b/examples/iotdashboard/MainWindow.cpp index 3794c622..1a8dec58 100644 --- a/examples/iotdashboard/MainWindow.cpp +++ b/examples/iotdashboard/MainWindow.cpp @@ -3,9 +3,8 @@ * This file may be used under the terms of the 3-clause BSD License *****************************************************************************/ +#include "MainItem.h" #include "MainWindow.h" -#include "MainContent.h" -#include "MenuBar.h" #include @@ -14,11 +13,7 @@ MainWindow::MainWindow() setPreferredSize( QSize( 1024, 600 ) ); setTitle( "IOT dashboard" ); - auto layout = new QskLinearBox( Qt::Horizontal, contentItem() ); - layout->setSpacing( 0 ); - - (void) new MenuBar( layout ); - (void) new MainContent( layout ); + (void) new MainItem( contentItem() ); } #include "moc_MainWindow.cpp" diff --git a/examples/iotdashboard/iotdashboard.pro b/examples/iotdashboard/iotdashboard.pro index 67a0e84e..9d0c63cf 100644 --- a/examples/iotdashboard/iotdashboard.pro +++ b/examples/iotdashboard/iotdashboard.pro @@ -14,6 +14,7 @@ SOURCES += \ LightDisplaySkinlet.cpp \ LightDisplay.cpp \ MainContent.cpp \ + MainItem.cpp \ MenuBar.cpp \ MyDevices.cpp \ PieChart.cpp \ @@ -45,6 +46,7 @@ HEADERS += \ LightDisplaySkinlet.h \ LightDisplay.h \ MainContent.h \ + MainItem.h \ MainWindow.h \ MenuBar.h \ MyDevices.h \