2021-04-29 07:49:08 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (C) 2021 Edelhirsch Software GmbH
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
#include "MenuBar.h"
|
2023-01-03 14:48:59 +01:00
|
|
|
#include "MainItem.h"
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
QSK_SUBCONTROL( MenuBarTopLabel, Graphic )
|
|
|
|
|
2022-12-22 18:15:04 +01:00
|
|
|
QSK_SUBCONTROL( MenuButton, Panel )
|
|
|
|
QSK_SUBCONTROL( MenuButton, Text )
|
|
|
|
QSK_SUBCONTROL( MenuButton, Graphic )
|
|
|
|
|
|
|
|
QSK_SUBCONTROL( MenuBar, Panel )
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2022-12-22 18:15:04 +01:00
|
|
|
MenuButton::MenuButton( const QString& name, QQuickItem* parent )
|
|
|
|
: QskPushButton( name, parent )
|
2021-04-26 06:22:35 +02:00
|
|
|
{
|
2022-12-22 18:15:04 +01:00
|
|
|
setCheckable( true );
|
2021-08-04 18:55:18 +02:00
|
|
|
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2022-12-22 18:15:04 +01:00
|
|
|
setSubcontrolProxy( QskPushButton::Panel, MenuButton::Panel );
|
|
|
|
setSubcontrolProxy( QskPushButton::Text, MenuButton::Text );
|
|
|
|
setSubcontrolProxy( QskPushButton::Graphic, MenuButton::Graphic );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2022-12-22 18:15:04 +01:00
|
|
|
setGraphicSource( name );
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 09:31:16 +02:00
|
|
|
MenuBar::MenuBar( QQuickItem* parent )
|
|
|
|
: QskLinearBox( Qt::Vertical, parent )
|
2022-12-22 18:15:04 +01:00
|
|
|
, m_currentIndex( 0 )
|
2021-04-26 06:22:35 +02:00
|
|
|
{
|
|
|
|
setPanel( true );
|
2021-08-04 15:06:04 +02:00
|
|
|
setSubcontrolProxy( QskBox::Panel, MenuBar::Panel );
|
|
|
|
|
2023-01-02 10:22:23 +01:00
|
|
|
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Preferred );
|
2022-12-21 17:26:52 +01:00
|
|
|
setSpacing( 0 );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2021-08-26 17:02:31 +02:00
|
|
|
auto graphicLabel = new MenuBarTopLabel( "main-icon", this );
|
2021-04-26 06:22:35 +02:00
|
|
|
graphicLabel->setMargins( marginHint( MenuBarTopLabel::Graphic ) );
|
|
|
|
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
|
|
|
|
2023-01-03 14:48:59 +01:00
|
|
|
// ### unify the information with the one from MainItem
|
|
|
|
QVector< QPair< Cube::Position, QString > > entries =
|
|
|
|
{
|
|
|
|
{ Cube::FrontPos, "Dashboard" },
|
|
|
|
{ Cube::RightPos, "Rooms" },
|
|
|
|
{ Cube::BackPos, "Devices" },
|
|
|
|
{ Cube::LeftPos, "Statistics" },
|
|
|
|
{ Cube::TopPos, "Storage" },
|
|
|
|
{ Cube::BottomPos, "Members" },
|
|
|
|
};
|
|
|
|
|
|
|
|
for( const auto& entry : entries )
|
2021-04-26 06:22:35 +02:00
|
|
|
{
|
2023-01-03 14:48:59 +01:00
|
|
|
auto* button = new MenuButton( entry.second, this );
|
|
|
|
m_buttons.append( button );
|
2022-12-22 18:15:04 +01:00
|
|
|
|
2023-01-03 14:48:59 +01:00
|
|
|
connect( button, &QskPushButton::pressed, this, [ this, entry ]()
|
2022-12-22 18:15:04 +01:00
|
|
|
{
|
2023-01-03 14:48:59 +01:00
|
|
|
for( auto* button : qAsConst( m_buttons ) )
|
|
|
|
{
|
|
|
|
// the right button will be set to checked after this
|
|
|
|
button->setChecked( false );
|
|
|
|
}
|
2022-12-22 18:15:04 +01:00
|
|
|
|
2023-01-03 14:48:59 +01:00
|
|
|
Q_EMIT pageChangeRequested( entry.first );
|
|
|
|
} );
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
|
|
|
|
2023-01-03 14:48:59 +01:00
|
|
|
m_buttons.at( m_currentIndex )->setChecked( true );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
addSpacer( 0, 1 ); // fill the space at the bottom
|
|
|
|
|
2022-12-22 18:15:04 +01:00
|
|
|
new MenuButton( "Logout", this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuBar::setActivePage( const int index )
|
|
|
|
{
|
2023-01-03 14:48:59 +01:00
|
|
|
m_buttons.at( m_currentIndex )->setChecked( false );
|
2022-12-22 18:15:04 +01:00
|
|
|
m_currentIndex = index;
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
|
|
|
|
2021-04-26 08:43:46 +02:00
|
|
|
#include "moc_MenuBar.cpp"
|