From 3fbbd6cb3f58c96e4c2ab7d5d1aefd34d6ee0a19 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Wed, 4 Jan 2023 16:33:29 +0100 Subject: [PATCH] IOT dashboard: fix menu bar --- examples/iotdashboard/MainItem.cpp | 14 +++++++++++--- examples/iotdashboard/MenuBar.cpp | 18 +++++++++++------- examples/iotdashboard/MenuBar.h | 4 +++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/examples/iotdashboard/MainItem.cpp b/examples/iotdashboard/MainItem.cpp index 9c89e77d..523232c8 100644 --- a/examples/iotdashboard/MainItem.cpp +++ b/examples/iotdashboard/MainItem.cpp @@ -122,6 +122,11 @@ Cube::Cube( QQuickItem* parent ) } ); } } ); + + QTimer::singleShot( 0, this, [this]() + { + Q_EMIT cubeIndexChanged( m_destination ); + } ); } void Cube::doSwitch( Qsk::Direction direction, Position position ) @@ -161,7 +166,11 @@ void Cube::doSwitch( Qsk::Direction direction, Position position ) updateEdge( direction, position ); setCurrentIndex( position ); - Q_EMIT cubeIndexChanged( position ); // ### connect to menu bar + + if( position == m_destination ) + { + Q_EMIT cubeIndexChanged( position ); + } } void Cube::switchPosition( const Qsk::Direction direction ) @@ -248,8 +257,7 @@ MainItem::MainItem( QQuickItem* parent ) m_cube->switchToPosition( position ); } ); - // ### fix: -// connect( m_cube, &QskStackBox::currentIndexChanged, m_menuBar, &MenuBar::setActivePage ); + connect( m_cube, &Cube::cubeIndexChanged, m_menuBar, &MenuBar::setActivePage ); auto* const dashboardPage = new DashboardPage( m_cube ); auto* const roomsPage = new RoomsPage( m_cube ); diff --git a/examples/iotdashboard/MenuBar.cpp b/examples/iotdashboard/MenuBar.cpp index 0aefe966..a26536ef 100644 --- a/examples/iotdashboard/MenuBar.cpp +++ b/examples/iotdashboard/MenuBar.cpp @@ -4,7 +4,8 @@ *****************************************************************************/ #include "MenuBar.h" -#include "MainItem.h" + +#include QSK_SUBCONTROL( MenuBarTopLabel, Graphic ) @@ -29,7 +30,7 @@ MenuButton::MenuButton( const QString& name, QQuickItem* parent ) MenuBar::MenuBar( QQuickItem* parent ) : QskLinearBox( Qt::Vertical, parent ) - , m_currentIndex( 0 ) + , m_currentIndex( Cube::FrontPos ) { setPanel( true ); setSubcontrolProxy( QskBox::Panel, MenuBar::Panel ); @@ -42,7 +43,7 @@ MenuBar::MenuBar( QQuickItem* parent ) graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); // ### unify the information with the one from MainItem - QVector< QPair< Cube::Position, QString > > entries = + const QVector< QPair< Cube::Position, QString > > entries = { { Cube::FrontPos, "Dashboard" }, { Cube::RightPos, "Rooms" }, @@ -55,7 +56,7 @@ MenuBar::MenuBar( QQuickItem* parent ) for( const auto& entry : entries ) { auto* button = new MenuButton( entry.second, this ); - m_buttons.append( button ); + m_buttons[ entry.first ] = button; connect( button, &QskPushButton::pressed, this, [ this, entry ]() { @@ -69,8 +70,6 @@ MenuBar::MenuBar( QQuickItem* parent ) } ); } - m_buttons.at( m_currentIndex )->setChecked( true ); - addSpacer( 0, 1 ); // fill the space at the bottom new MenuButton( "Logout", this ); @@ -78,8 +77,13 @@ MenuBar::MenuBar( QQuickItem* parent ) void MenuBar::setActivePage( const int index ) { - m_buttons.at( m_currentIndex )->setChecked( false ); + m_buttons[ m_currentIndex ]->setChecked( false ); m_currentIndex = index; + + QTimer::singleShot( 0, this, [this]() + { + m_buttons[ m_currentIndex ]->setChecked( true ); + } ); } #include "moc_MenuBar.cpp" diff --git a/examples/iotdashboard/MenuBar.h b/examples/iotdashboard/MenuBar.h index 70bf9e75..a4cbfdf4 100644 --- a/examples/iotdashboard/MenuBar.h +++ b/examples/iotdashboard/MenuBar.h @@ -10,6 +10,8 @@ #include #include +#include "MainItem.h" + class MenuBarTopLabel final : public QskGraphicLabel { Q_OBJECT @@ -50,6 +52,6 @@ class MenuBar final : public QskLinearBox void setActivePage( const int index ); private: - QVector< MenuButton* > m_buttons; + MenuButton* m_buttons[ Cube::NumPositions ]; uint m_currentIndex; };