qskinny/examples/iot-dashboard/MenuBar.cpp

54 lines
1.6 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>
MenuItem::MenuItem( const QString& name, QQuickItem* parent ) : QskLinearBox( Qt::Horizontal, parent ),
m_name( name )
{
setAutoLayoutChildren( true );
setAutoAddChildren( true );
2020-06-12 06:37:15 +00:00
setPreferredWidth( 140 );
2020-05-22 09:48:05 +00:00
QString fileName = ":/images/" + name.toLower() + ".png";
QImage image( fileName );
auto graphic = QskGraphic::fromImage( image );
auto* graphicLabel = new QskGraphicLabel( graphic, this );
2020-06-12 06:37:15 +00:00
graphicLabel->setSizePolicy(QskSizePolicy::Fixed, QskSizePolicy::Fixed);
// graphicLabel->setFixedSize( 32, 32 );
2020-05-22 09:48:05 +00:00
auto* textLabel = new QskTextLabel( name, this );
textLabel->setTextColor( Qt::white ); // ### style
textLabel->setFontRole(QskSkin::SmallFont);
2020-05-22 09:48:05 +00:00
}
2020-05-22 07:47:09 +00:00
MenuBar::MenuBar( QQuickItem *parent ) : QskLinearBox( Qt::Vertical, parent )
{
2020-05-22 09:48:05 +00:00
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Preferred );
2020-05-22 07:47:09 +00:00
setAutoLayoutChildren( true );
setAutoAddChildren( true );
2020-06-12 06:37:15 +00:00
setBackgroundColor( "#6D7BFB" ); // ### style
2020-05-22 07:47:09 +00:00
2020-06-12 06:37:15 +00:00
auto* mainIcon = ":/images/main-icon.png";
QImage image(mainIcon);
auto graphic = QskGraphic::fromImage( image );
auto* graphicLabel = new QskGraphicLabel( graphic, this );
graphicLabel->setMargins( { 50, 35, 50, 50 });
m_entries = { "Dashboard", "Rooms", "Devices", "Statistics", "Storage", "Members" };
2020-05-22 07:47:09 +00:00
for( const auto entry : m_entries )
{
2020-05-22 09:48:05 +00:00
auto* menuItem = new MenuItem( entry, this );
2020-05-22 07:47:09 +00:00
}
2020-05-22 09:48:05 +00:00
addSpacer( 0, 1 ); // fill the space at the bottom
2020-05-22 07:47:09 +00:00
}