qskinny/examples/iot-dashboard/MenuBar.cpp

94 lines
2.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>
2020-06-12 10:53:28 +00:00
QSK_SUBCONTROL( MenuItem, Panel )
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 );
2020-06-12 10:53:28 +00:00
setFixedSize( {140, 40} );
setMargins({0, 0, 0, 0});
setPadding({30, 0, 30, 0});
setSpacing(6);
setAcceptHoverEvents(true);
setPanel(true);
2020-05-22 09:48:05 +00:00
2020-06-12 10:53:28 +00:00
QString fileName = ":/images/" + name.toLower() + ".png"; // width: 14
2020-05-22 09:48:05 +00:00
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);
2020-06-12 10:53:28 +00:00
graphicLabel->setFixedWidth(14);
graphicLabel->setAlignment(Qt::AlignCenter);
2020-05-22 09:48:05 +00:00
auto* textLabel = new QskTextLabel( name, this );
textLabel->setTextColor( Qt::white ); // ### style
2020-06-12 10:53:28 +00:00
textLabel->setFontRole(QskSkin::SmallFont); // ### style
}
QskAspect::Subcontrol MenuItem::effectiveSubcontrol( QskAspect::Subcontrol subControl ) const
{
if ( subControl == QskBox::Panel )
return MenuItem::Panel;
return subControl;
2020-05-22 09:48:05 +00:00
}
2020-06-12 10:53:28 +00:00
void MenuItem::setActive(bool active)
{
QColor color;
if(active) {
color = Qt::white;
color.setAlphaF(0.14);
} else {
color = Qt::transparent;
}
setBackgroundColor(color);
}
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 10:53:28 +00:00
setSpacing(8);
setMargins({0, 35, 0, 12});
2020-05-22 07:47:09 +00:00
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 );
2020-06-12 10:53:28 +00:00
graphicLabel->setAlignment(Qt::AlignTop);
graphicLabel->setMargins( { 50, 0, 50, 54 });
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
2020-06-12 10:53:28 +00:00
for( const auto entryString : m_entryStrings )
2020-05-22 07:47:09 +00:00
{
2020-06-12 10:53:28 +00:00
auto* entry = new MenuItem( entryString, this );
m_entries.append(entry);
2020-05-22 07:47:09 +00:00
}
2020-05-22 09:48:05 +00:00
2020-06-12 10:53:28 +00:00
m_entries.at(m_activeEntry)->setActive(true);
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
}