IOT dashboard: fix menu bar
This commit is contained in:
parent
4b1a03cf1d
commit
3fbbd6cb3f
@ -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 );
|
||||
|
@ -4,7 +4,8 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "MenuBar.h"
|
||||
#include "MainItem.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
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"
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <QskPushButton.h>
|
||||
#include <QskTextLabel.h>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user