qskinny/examples/iot-dashboard/MenuBar.cpp

89 lines
2.5 KiB
C++
Raw Normal View History

2020-05-22 07:47:09 +00:00
#include "MenuBar.h"
2020-05-22 09:48:05 +00:00
#include <QskGraphic.h>
#include <QskGraphicLabel.h>
#include <QskGraphicIO.h>
#include <QskSkin.h>
2020-05-22 07:47:09 +00:00
#include <QskTextLabel.h>
2020-05-22 09:48:05 +00:00
#include <QtGui/QImage>
2021-04-07 14:29:45 +00:00
QSK_SUBCONTROL( MenuBarTopLabel, Graphic )
2021-03-26 12:16:48 +00:00
QSK_SUBCONTROL( MenuBarGraphicLabel, Graphic )
2021-03-26 11:56:51 +00:00
QSK_SUBCONTROL( MenuBarLabel, Text )
2020-06-12 10:53:28 +00:00
QSK_SUBCONTROL( MenuItem, Panel )
2021-03-26 12:47:09 +00:00
QSK_STATE( MenuItem, Active, ( QskAspect::FirstUserState << 1 ) )
2020-05-22 09:48:05 +00:00
MenuItem::MenuItem( const QString& name, QQuickItem* parent ) : QskLinearBox( Qt::Horizontal, parent ),
m_name( name )
{
setAutoLayoutChildren( true );
setAutoAddChildren( true );
2021-03-26 09:38:27 +00:00
setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
2021-03-26 08:45:33 +00:00
setSpacing( 6 );
2020-06-12 10:53:28 +00:00
2021-03-26 08:45:33 +00:00
setAcceptHoverEvents( true );
setPanel( true );
2020-05-22 09:48:05 +00:00
2021-04-07 14:35:35 +00:00
QString fileName = ":/images/" + name.toLower() + ".png";
2020-05-22 09:48:05 +00:00
QImage image( fileName );
auto graphic = QskGraphic::fromImage( image );
2021-03-26 12:16:48 +00:00
auto* graphicLabel = new MenuBarGraphicLabel( graphic, this );
2021-03-26 08:45:33 +00:00
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
2021-04-07 14:35:35 +00:00
graphicLabel->setFixedWidth( metric( MenuBarGraphicLabel::Graphic | QskAspect::Size ) );
2020-05-22 09:48:05 +00:00
2021-03-26 11:56:51 +00:00
new MenuBarLabel( name, this );
2020-06-12 10:53:28 +00:00
}
QskAspect::Subcontrol MenuItem::effectiveSubcontrol( QskAspect::Subcontrol subControl ) const
{
2021-03-26 08:45:33 +00:00
if( subControl == QskBox::Panel )
{
2020-06-12 10:53:28 +00:00
return MenuItem::Panel;
2021-03-26 08:45:33 +00:00
}
2020-06-12 10:53:28 +00:00
return subControl;
2020-05-22 09:48:05 +00:00
}
2020-06-12 10:53:28 +00:00
2021-03-26 08:52:45 +00:00
QSK_SUBCONTROL( MenuBar, Panel )
2021-03-26 08:45:33 +00:00
MenuBar::MenuBar( QQuickItem* parent ) : QskLinearBox( Qt::Vertical, parent )
2020-05-22 07:47:09 +00:00
{
2021-03-26 08:52:45 +00:00
setPanel( true );
2020-05-22 09:48:05 +00:00
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Preferred );
2021-03-26 08:45:33 +00:00
setSpacing( 8 );
2020-05-22 07:47:09 +00:00
2020-06-12 06:37:15 +00:00
auto* mainIcon = ":/images/main-icon.png";
2021-03-26 08:45:33 +00:00
QImage image( mainIcon );
2020-06-12 06:37:15 +00:00
auto graphic = QskGraphic::fromImage( image );
2021-04-07 14:29:45 +00:00
auto* graphicLabel = new MenuBarTopLabel( graphic, this );
graphicLabel->setMargins( marginHint( MenuBarTopLabel::Graphic ) );
2021-03-26 08:45:33 +00:00
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
2020-06-12 06:37:15 +00:00
2020-06-12 10:53:28 +00:00
m_entryStrings = { "Dashboard", "Rooms", "Devices", "Statistics", "Storage", "Members" };
2020-05-22 07:47:09 +00:00
2021-03-26 08:52:45 +00:00
for( const auto& entryString : qAsConst( m_entryStrings ) )
2020-05-22 07:47:09 +00:00
{
2020-06-12 10:53:28 +00:00
auto* entry = new MenuItem( entryString, this );
2021-03-26 08:45:33 +00:00
m_entries.append( entry );
2020-05-22 07:47:09 +00:00
}
2020-05-22 09:48:05 +00:00
2021-03-26 12:47:09 +00:00
m_entries.at( m_activeEntry )->setSkinState( MenuItem::Active );
2020-06-12 10:53:28 +00:00
2020-05-22 09:48:05 +00:00
addSpacer( 0, 1 ); // fill the space at the bottom
2020-06-12 10:53:28 +00:00
new MenuItem( "Logout", this );
2020-05-22 07:47:09 +00:00
}
2021-03-26 08:52:45 +00:00
QskAspect::Subcontrol MenuBar::effectiveSubcontrol( QskAspect::Subcontrol subControl ) const
{
if( subControl == QskBox::Panel )
{
return MenuBar::Panel;
}
return subControl;
}