2021-09-24 14:47:56 +02:00
|
|
|
#include "MainItem.h"
|
|
|
|
|
2022-07-14 14:26:45 +02:00
|
|
|
#include "DashboardPage.h"
|
2021-09-24 14:47:56 +02:00
|
|
|
#include "MenuBar.h"
|
2022-07-14 14:43:21 +02:00
|
|
|
#include "RoomsPage.h"
|
2021-09-24 14:47:56 +02:00
|
|
|
|
|
|
|
#include <QskGesture.h>
|
|
|
|
#include <QskEvent.h>
|
|
|
|
#include <QskLinearBox.h>
|
2022-08-02 09:36:22 +02:00
|
|
|
#include <QskStackBoxAnimator.h>
|
2021-09-24 14:47:56 +02:00
|
|
|
|
|
|
|
#include <QQuickFramebufferObject>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
|
2022-08-02 09:36:22 +02:00
|
|
|
Cube::Cube( QQuickItem* parent )
|
|
|
|
: QskStackBox( false, parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cube::startAnimation( Qsk::Direction direction )
|
|
|
|
{
|
2022-08-03 09:40:18 +02:00
|
|
|
using Animator = QskStackBoxAnimator4;
|
|
|
|
|
|
|
|
auto animator = qobject_cast< Animator* >( this->animator() );
|
2022-08-02 09:36:22 +02:00
|
|
|
|
|
|
|
if ( animator == nullptr )
|
|
|
|
{
|
2022-08-03 09:40:18 +02:00
|
|
|
animator = new Animator( this );
|
2022-08-02 09:36:22 +02:00
|
|
|
animator->setEasingCurve( QEasingCurve::InOutQuad );
|
|
|
|
animator->setDuration( 1000 );
|
2022-08-03 09:40:18 +02:00
|
|
|
|
|
|
|
setAnimator( animator );
|
2022-08-02 09:36:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto orientation = ( direction == Qsk::LeftToRight || direction == Qsk::RightToLeft )
|
|
|
|
? Qt::Horizontal : Qt::Vertical;
|
|
|
|
animator->setOrientation( orientation );
|
|
|
|
|
|
|
|
const bool inverted = ( direction == Qsk::LeftToRight || direction == Qsk::TopToBottom );
|
|
|
|
animator->setInverted( inverted );
|
|
|
|
|
2022-10-07 19:00:40 +02:00
|
|
|
int newIndex = 0;
|
2022-08-02 09:36:22 +02:00
|
|
|
|
|
|
|
switch( direction )
|
|
|
|
{
|
2022-08-03 09:40:18 +02:00
|
|
|
case Qsk::LeftToRight:
|
|
|
|
case Qsk::TopToBottom:
|
|
|
|
newIndex = currentIndex() + 1;
|
|
|
|
break;
|
|
|
|
case Qsk::RightToLeft:
|
|
|
|
case Qsk::BottomToTop:
|
|
|
|
newIndex = currentIndex() - 1;
|
|
|
|
break;
|
2022-08-02 09:36:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
newIndex %= itemCount();
|
|
|
|
if( newIndex < 0 )
|
|
|
|
newIndex += itemCount();
|
|
|
|
|
|
|
|
setCurrentIndex( newIndex );
|
|
|
|
}
|
|
|
|
|
2021-09-24 14:47:56 +02:00
|
|
|
MainItem::MainItem( QQuickItem* parent )
|
|
|
|
: QskControl( parent )
|
2022-08-02 09:36:22 +02:00
|
|
|
, m_cube( new Cube( this ) )
|
2021-09-24 14:47:56 +02:00
|
|
|
, m_mainLayout( new QskLinearBox( Qt::Horizontal, m_cube ) )
|
2022-07-14 14:43:21 +02:00
|
|
|
, m_otherLayout( new QskLinearBox( Qt::Horizontal, m_cube ) )
|
2021-09-24 14:47:56 +02:00
|
|
|
{
|
|
|
|
setAutoLayoutChildren( true );
|
|
|
|
setAcceptedMouseButtons( Qt::LeftButton );
|
|
|
|
setFiltersChildMouseEvents( true );
|
|
|
|
|
2022-08-02 09:36:22 +02:00
|
|
|
m_panRecognizer.setOrientations( Qt::Horizontal | Qt::Vertical );
|
2021-09-24 14:47:56 +02:00
|
|
|
m_panRecognizer.setMinDistance( 50 );
|
|
|
|
m_panRecognizer.setWatchedItem( this );
|
|
|
|
|
|
|
|
m_mainLayout->setSpacing( 0 );
|
|
|
|
|
2022-07-14 14:43:21 +02:00
|
|
|
m_otherLayout->setSpacing( 0 );
|
|
|
|
|
2021-09-24 14:47:56 +02:00
|
|
|
(void) new MenuBar( m_mainLayout );
|
2022-07-14 14:26:45 +02:00
|
|
|
(void) new DashboardPage( m_mainLayout );
|
2021-09-24 14:47:56 +02:00
|
|
|
|
2022-07-14 14:43:21 +02:00
|
|
|
(void) new MenuBar( m_otherLayout );
|
|
|
|
(void) new RoomsPage( m_otherLayout );
|
|
|
|
|
2021-09-24 14:47:56 +02:00
|
|
|
m_cube->addItem( m_mainLayout );
|
2022-07-14 14:43:21 +02:00
|
|
|
m_cube->addItem( m_otherLayout );
|
|
|
|
|
|
|
|
m_cube->setCurrentItem( m_mainLayout );
|
2021-09-24 14:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainItem::gestureEvent( QskGestureEvent* event )
|
|
|
|
{
|
2022-08-02 09:36:22 +02:00
|
|
|
if( event->gesture()->state() == QskGesture::Finished
|
|
|
|
&& event->gesture()->type() == QskGesture::Pan )
|
2021-09-24 14:47:56 +02:00
|
|
|
{
|
2022-08-02 09:36:22 +02:00
|
|
|
auto* panGesture = static_cast< const QskPanGesture* >( event->gesture().get() );
|
|
|
|
|
|
|
|
const auto delta = panGesture->origin() - panGesture->position();
|
|
|
|
|
|
|
|
Qsk::Direction direction;
|
|
|
|
|
|
|
|
if( qAbs( delta.x() ) > qAbs( delta.y() ) )
|
|
|
|
{
|
|
|
|
direction = ( delta.x() < 0 ) ? Qsk::LeftToRight : Qsk::RightToLeft;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
direction = ( delta.y() < 0 ) ? Qsk::TopToBottom : Qsk::BottomToTop;
|
|
|
|
}
|
|
|
|
|
2022-08-03 09:40:18 +02:00
|
|
|
m_cube->startAnimation( direction );
|
2021-09-24 14:47:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2022-09-09 09:15:26 +02:00
|
|
|
|
|
|
|
#include "moc_MainItem.cpp"
|