2021-04-29 07:49:08 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (C) 2021 Edelhirsch Software GmbH
|
2023-04-06 09:23:37 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Claus
|
2021-04-29 07:49:08 +02:00
|
|
|
*****************************************************************************/
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
#include "MenuBar.h"
|
2023-01-04 16:33:29 +01:00
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
#include <QskGraphicLabel.h>
|
|
|
|
#include <QskPushButton.h>
|
2022-12-22 18:15:04 +01:00
|
|
|
|
|
|
|
QSK_SUBCONTROL( MenuBar, Panel )
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
namespace
|
2021-04-26 06:22:35 +02:00
|
|
|
{
|
2023-03-08 16:02:05 +01:00
|
|
|
class Button final : public QskPushButton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Button( const QString& name, QQuickItem* parent = nullptr )
|
|
|
|
: QskPushButton( name, parent )
|
|
|
|
{
|
|
|
|
initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Fixed );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
setCheckable( true );
|
|
|
|
setExclusive( true );
|
|
|
|
setIconSource( name );
|
|
|
|
}
|
|
|
|
};
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
class Logo final : public QskGraphicLabel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Logo( QQuickItem* parent = nullptr )
|
|
|
|
: QskGraphicLabel( "main-icon", parent )
|
|
|
|
{
|
|
|
|
setGraphicStrutSize( QSizeF( 40, -1 ) );
|
|
|
|
setFillMode( QskGraphicLabel::Pad );
|
|
|
|
setAlignment( Qt::AlignCenter );
|
|
|
|
|
|
|
|
initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Fixed );
|
|
|
|
}
|
|
|
|
};
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 09:31:16 +02:00
|
|
|
MenuBar::MenuBar( QQuickItem* parent )
|
|
|
|
: QskLinearBox( Qt::Vertical, parent )
|
2023-01-04 16:33:29 +01:00
|
|
|
, m_currentIndex( Cube::FrontPos )
|
2021-04-26 06:22:35 +02:00
|
|
|
{
|
2023-03-08 16:02:05 +01:00
|
|
|
setSection( QskAspect::Header );
|
|
|
|
|
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
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
populate();
|
|
|
|
}
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
void MenuBar::populate()
|
|
|
|
{
|
|
|
|
auto logo = new Logo();
|
|
|
|
auto logoutButton = new Button( "Logout");
|
|
|
|
|
|
|
|
const QPair< Cube::Position, QString > entries[] =
|
2023-01-03 14:48:59 +01:00
|
|
|
{
|
|
|
|
{ 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-03-08 16:02:05 +01:00
|
|
|
auto button = new Button( entry.second );
|
2022-12-22 18:15:04 +01:00
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
const int id = entry.first;
|
|
|
|
m_buttons[ id ] = button;
|
|
|
|
|
|
|
|
connect( button, &QskPushButton::pressed,
|
|
|
|
this, [ this, id ]() { Q_EMIT pageChangeRequested( id ); } );
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
addSpacer( 35 );
|
|
|
|
addItem( logo );
|
|
|
|
addSpacer( 60 );
|
|
|
|
|
|
|
|
for ( auto button : m_buttons )
|
|
|
|
addItem( button );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2023-03-08 16:02:05 +01:00
|
|
|
addStretch( 1 ); // fill the space at the bottom
|
|
|
|
addItem( logoutButton );
|
2022-12-22 18:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuBar::setActivePage( const int index )
|
|
|
|
{
|
|
|
|
m_currentIndex = index;
|
2023-03-08 16:02:05 +01:00
|
|
|
m_buttons[ m_currentIndex ]->setChecked( true );
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
|
|
|
|
2021-04-26 08:43:46 +02:00
|
|
|
#include "moc_MenuBar.cpp"
|