IOT dashboard: fix menu bar
This commit is contained in:
parent
db706737be
commit
978183916f
|
@ -61,7 +61,7 @@ Cube::Position Cube::s_neighbors[ Cube::NumPositions ][ 4 ] =
|
|||
|
||||
Cube::Cube( QQuickItem* parent )
|
||||
: QskStackBox( false, parent )
|
||||
, m_currentPosition( FrontPos )
|
||||
, m_destination( FrontPos )
|
||||
, m_previousPosition( FrontPos )
|
||||
{
|
||||
// The code below covers the case where we need 2 cube movements to get
|
||||
|
@ -73,11 +73,16 @@ Cube::Cube( QQuickItem* parent )
|
|||
{
|
||||
const bool animationIsFinished = ( position == qFloor( position ) );
|
||||
|
||||
if( animationIsFinished && position != m_currentPosition )
|
||||
if( animationIsFinished)
|
||||
{
|
||||
qDebug() << "finished." << position << m_destination << ( position == m_destination );
|
||||
}
|
||||
|
||||
if( animationIsFinished && position != m_destination )
|
||||
{
|
||||
QTimer::singleShot( 0, this, [this]()
|
||||
{
|
||||
switchToPosition( m_currentPosition );
|
||||
switchToPosition( m_destination );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
@ -85,8 +90,7 @@ Cube::Cube( QQuickItem* parent )
|
|||
|
||||
void Cube::doSwitch( Qsk::Direction direction, Position position )
|
||||
{
|
||||
m_previousPosition = m_currentPosition;
|
||||
m_currentPosition = position;
|
||||
m_previousPosition = m_destination;
|
||||
|
||||
using Animator = QskStackBoxAnimator4;
|
||||
|
||||
|
@ -109,13 +113,11 @@ void Cube::doSwitch( Qsk::Direction direction, Position position )
|
|||
animator->setInverted( inverted );
|
||||
|
||||
setCurrentIndex( position );
|
||||
Q_EMIT cubeIndexChanged( position ); // ### do we need this?
|
||||
Q_EMIT cubeIndexChanged( position );
|
||||
}
|
||||
|
||||
void Cube::switchPosition( const Qsk::Direction direction )
|
||||
{
|
||||
// ### needs to go to the other function:
|
||||
|
||||
// keep track of from where we went to top and bottom,
|
||||
// so that going up and down will result in going back
|
||||
// to the same position:
|
||||
|
@ -123,19 +125,17 @@ void Cube::switchPosition( const Qsk::Direction direction )
|
|||
// keeping track of the edges here, because that doesn't
|
||||
// make sense wrt. being upside down etc.)
|
||||
|
||||
Position position;
|
||||
|
||||
if( ( m_currentPosition == TopPos && direction == Qsk::BottomToTop )
|
||||
|| ( m_currentPosition == BottomPos && direction == Qsk::TopToBottom ) )
|
||||
if( ( m_destination == TopPos && direction == Qsk::BottomToTop )
|
||||
|| ( m_destination == BottomPos && direction == Qsk::TopToBottom ) )
|
||||
{
|
||||
position = m_previousPosition;
|
||||
m_destination = m_previousPosition; // ### doesn't work completely yet
|
||||
}
|
||||
else
|
||||
{
|
||||
position = neighbor( m_currentPosition, direction );
|
||||
m_destination = neighbor( m_destination, direction );
|
||||
}
|
||||
|
||||
doSwitch( direction, position );
|
||||
doSwitch( direction, m_destination );
|
||||
}
|
||||
|
||||
void Cube::switchToPosition( const Position position )
|
||||
|
@ -143,10 +143,14 @@ void Cube::switchToPosition( const Position position )
|
|||
if( currentIndex() == position )
|
||||
return;
|
||||
|
||||
const auto from = static_cast< Position >( currentIndex() );
|
||||
const auto direction = this->direction( from, m_currentPosition );
|
||||
m_destination = position;
|
||||
|
||||
doSwitch( direction, position );
|
||||
const auto from = static_cast< Position >( currentIndex() );
|
||||
const auto direction = this->direction( from, position );
|
||||
const auto currentPosition = static_cast< Position >( currentIndex() );
|
||||
const auto intermediatePosition = neighbor( currentPosition, direction );
|
||||
|
||||
doSwitch( direction, intermediatePosition );
|
||||
}
|
||||
|
||||
Cube::Position Cube::neighbor( const Position position, const Qsk::Direction direction ) const
|
||||
|
|
|
@ -41,7 +41,7 @@ class Cube : public QskStackBox
|
|||
Qsk::Direction direction( const Position from, const Position to ) const;
|
||||
void doSwitch( Qsk::Direction direction, Position position );
|
||||
|
||||
Position m_currentPosition;
|
||||
Position m_destination;
|
||||
Position m_previousPosition;
|
||||
|
||||
static Position s_neighbors[ NumPositions ][ 4 ];
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "MenuBar.h"
|
||||
#include "MainItem.h"
|
||||
|
||||
QSK_SUBCONTROL( MenuBarTopLabel, Graphic )
|
||||
|
||||
|
@ -40,21 +41,35 @@ MenuBar::MenuBar( QQuickItem* parent )
|
|||
graphicLabel->setMargins( marginHint( MenuBarTopLabel::Graphic ) );
|
||||
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||
|
||||
QVector< QString > entryStrings = { "Dashboard", "Rooms", "Devices", "Statistics", "Storage", "Members" };
|
||||
|
||||
for( int i = 0; i < entryStrings.count(); ++i )
|
||||
// ### unify the information with the one from MainItem
|
||||
QVector< QPair< Cube::Position, QString > > entries =
|
||||
{
|
||||
auto* button = new MenuButton( entryStrings.at( i ), this );
|
||||
{ Cube::FrontPos, "Dashboard" },
|
||||
{ Cube::RightPos, "Rooms" },
|
||||
{ Cube::BackPos, "Devices" },
|
||||
{ Cube::LeftPos, "Statistics" },
|
||||
{ Cube::TopPos, "Storage" },
|
||||
{ Cube::BottomPos, "Members" },
|
||||
};
|
||||
|
||||
connect( button, &QskPushButton::pressed, this, [ this, i ]()
|
||||
for( const auto& entry : entries )
|
||||
{
|
||||
auto* button = new MenuButton( entry.second, this );
|
||||
m_buttons.append( button );
|
||||
|
||||
connect( button, &QskPushButton::pressed, this, [ this, entry ]()
|
||||
{
|
||||
Q_EMIT pageChangeRequested( i );
|
||||
} );
|
||||
for( auto* button : qAsConst( m_buttons ) )
|
||||
{
|
||||
// the right button will be set to checked after this
|
||||
button->setChecked( false );
|
||||
}
|
||||
|
||||
m_entries.append( button );
|
||||
Q_EMIT pageChangeRequested( entry.first );
|
||||
} );
|
||||
}
|
||||
|
||||
m_entries.at( m_currentIndex )->setChecked( true );
|
||||
m_buttons.at( m_currentIndex )->setChecked( true );
|
||||
|
||||
addSpacer( 0, 1 ); // fill the space at the bottom
|
||||
|
||||
|
@ -63,7 +78,7 @@ MenuBar::MenuBar( QQuickItem* parent )
|
|||
|
||||
void MenuBar::setActivePage( const int index )
|
||||
{
|
||||
m_entries.at( m_currentIndex )->setChecked( false );
|
||||
m_buttons.at( m_currentIndex )->setChecked( false );
|
||||
m_currentIndex = index;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,6 @@ class MenuBar final : public QskLinearBox
|
|||
void setActivePage( const int index );
|
||||
|
||||
private:
|
||||
QList< MenuButton* > m_entries;
|
||||
QVector< MenuButton* > m_buttons;
|
||||
uint m_currentIndex;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue