qskinny/examples/hmi-demo/MainWindow.cpp

110 lines
2.9 KiB
C++
Raw Normal View History

2017-07-25 05:24:27 +00:00
#include "MainWindow.h"
#include "RadioControl.h"
#include "SoundControl.h"
#include <QskGraphic.h>
#include <QskGraphicLabel.h>
#include <QskLinearBox.h>
#include <QskTextLabel.h>
#include <QDate>
2017-07-25 09:33:33 +00:00
#include <QImage>
2017-07-25 05:24:27 +00:00
2017-07-25 08:47:40 +00:00
namespace
{
2017-07-25 09:33:33 +00:00
class ButtonBar : public QskLinearBox
2017-07-25 05:24:27 +00:00
{
2017-07-25 09:33:33 +00:00
public:
ButtonBar( QQuickItem* parentItem = nullptr ):
QskLinearBox( parentItem )
{
setOpacity( 0.5 );
setBackgroundColor( Qt::black );
setMargins( QMarginsF( 20, 0, 20, 0 ) );
setSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Fixed );
}
void addIcon( const char* name )
{
const QString fileName = QString( ":/images/%1" ).arg( name );
auto* label = new QskGraphicLabel( this );
label->setFixedSize( 76, 36 );
label->setMargins( QMarginsF( 20, 7, 20, 7 ) );
label->setGraphic( QskGraphic::fromImage( QImage( fileName ) ) );
}
protected:
virtual QSizeF contentsSizeHint() const override final
{
return QSizeF( -1, 50 );
}
};
2017-07-25 05:24:27 +00:00
}
MainWindow::MainWindow()
2017-07-25 05:24:27 +00:00
{
setPreferredSize( QSize( 1024, 576 ) );
setAutoLayoutChildren( true );
2017-07-25 09:33:33 +00:00
populate();
}
2017-07-25 05:24:27 +00:00
2017-07-25 09:33:33 +00:00
void MainWindow::populate()
{
const QImage image( ":/images/background.jpg" );
2017-07-25 05:24:27 +00:00
auto backgroundImage = new QskGraphicLabel( contentItem() );
backgroundImage->setGraphic( QskGraphic::fromImage( image ) );
backgroundImage->setFillMode( QskGraphicLabel::Stretch );
2017-07-25 09:33:33 +00:00
auto header = headerBar();
auto content = mainContent();
auto footer = footerBar();
auto layout = new QskLinearBox( Qt::Vertical, contentItem() );
2017-07-25 05:24:27 +00:00
2017-07-25 09:33:33 +00:00
layout->addItem( header );
layout->addItem( content );
layout->addItem( footer );
2017-07-25 05:24:27 +00:00
}
2017-07-25 09:33:33 +00:00
QQuickItem* MainWindow::headerBar() const
2017-07-25 05:24:27 +00:00
{
2017-07-25 09:33:33 +00:00
auto* header = new ButtonBar();
header->addIcon( "ic_pan_tool_white_48dp_2x.png" );
header->addIcon( "ic_star_rate_white_18dp_2x.png" );
header->addIcon( "ic_airplanemode_active_white_18dp_2x.png" );
auto dateLabel = new QskTextLabel( QDate::currentDate().toString(), header );
2017-07-25 05:24:27 +00:00
dateLabel->setColor( QskTextLabel::Text, Qt::white );
2017-07-25 09:33:33 +00:00
header->addIcon( "ic_face_white_48px.svg" );
header->addIcon( "ic_extension_white_48dp_2x.png" );
header->addIcon( "ic_build_white_24dp_2x.png" );
return header;
2017-07-25 05:24:27 +00:00
}
2017-07-25 09:33:33 +00:00
QQuickItem* MainWindow::mainContent() const
2017-07-25 05:24:27 +00:00
{
// RadioControl* radioControl = new RadioControl( m_layout );
// m_layout->setRetainSizeWhenHidden( radioControl, true );
// radioControl->setVisible( false );
2017-07-25 09:33:33 +00:00
return new SoundControl();
2017-07-25 05:24:27 +00:00
}
2017-07-25 09:33:33 +00:00
QQuickItem* MainWindow::footerBar() const
2017-07-25 05:24:27 +00:00
{
2017-07-25 09:33:33 +00:00
auto* footer = new ButtonBar();
footer->addIcon( "ic_pan_tool_white_48dp_2x.png" );
footer->addIcon( "ic_star_rate_white_18dp_2x.png" );
footer->addIcon( "ic_airplanemode_active_white_18dp_2x.png" );
footer->addStretch( 10 );
return footer;
2017-07-25 05:24:27 +00:00
}