qskinny/examples/automotive/MainWindow.cpp

121 lines
3.0 KiB
C++
Raw Normal View History

2017-07-25 07:24:27 +02:00
#include "MainWindow.h"
#include "RadioControl.h"
#include "SoundControl.h"
#include <QskGraphic.h>
2017-07-25 21:34:27 +02:00
#include <QskGraphicIO.h>
2017-07-25 07:24:27 +02:00
#include <QskGraphicLabel.h>
#include <QskLinearBox.h>
#include <QskTextLabel.h>
#include <QDate>
2017-07-25 11:33:33 +02:00
#include <QImage>
2017-07-25 07:24:27 +02:00
2017-07-25 10:47:40 +02:00
namespace
{
2017-07-25 11:33:33 +02:00
class ButtonBar : public QskLinearBox
2017-07-25 07:24:27 +02:00
{
2017-07-25 11:33:33 +02:00
public:
ButtonBar( QQuickItem* parentItem = nullptr ):
QskLinearBox( parentItem )
{
2017-07-25 21:34:27 +02:00
QColor c( Qt::black );
c.setAlphaF( 0.5 );
setBackgroundColor( c );
2017-07-25 11:33:33 +02:00
2017-07-25 21:34:27 +02:00
setMargins( QMarginsF( 20, 15, 20, 15 ) );
setSpacing( 20 );
setSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::MinimumExpanding );
2017-07-25 11:33:33 +02:00
}
void addIcon( const char* name )
{
auto* label = new QskGraphicLabel( this );
2017-07-25 21:34:27 +02:00
/*
The label should adjust vertically and be stretched horizontally
according to its aspect ratio.
*/
label->setSizePolicy( QskSizePolicy::Constrained, QskSizePolicy::Ignored );
const QString fileName = QString( ":/qvg/%1.qvg" ).arg( name );
label->setGraphic( QskGraphicIO::read( fileName ) );
2017-07-25 11:33:33 +02:00
}
protected:
virtual QSizeF contentsSizeHint() const override final
{
2017-07-25 21:34:27 +02:00
return QSizeF( -1, 20 );
2017-07-25 11:33:33 +02:00
}
};
2017-07-25 07:24:27 +02:00
}
MainWindow::MainWindow()
2017-07-25 11:33:33 +02:00
{
const QImage image( ":/images/background.jpg" );
2017-07-25 07:24:27 +02:00
auto backgroundImage = new QskGraphicLabel( contentItem() );
backgroundImage->setGraphic( QskGraphic::fromImage( image ) );
backgroundImage->setFillMode( QskGraphicLabel::Stretch );
2017-07-25 11:33:33 +02:00
auto header = headerBar();
auto content = mainContent();
auto footer = footerBar();
auto layout = new QskLinearBox( Qt::Vertical, contentItem() );
2017-07-25 07:24:27 +02:00
2017-07-25 11:33:33 +02:00
layout->addItem( header );
2017-07-25 21:34:27 +02:00
layout->setStretchFactor( header, 1 );
2017-07-25 11:33:33 +02:00
layout->addItem( content );
2017-07-25 21:34:27 +02:00
layout->setStretchFactor( content, 10 );
2017-07-25 11:33:33 +02:00
layout->addItem( footer );
2017-07-25 21:34:27 +02:00
layout->setStretchFactor( footer, 1 );
setAutoLayoutChildren( true );
2017-07-25 07:24:27 +02:00
}
2017-07-25 11:33:33 +02:00
QQuickItem* MainWindow::headerBar() const
2017-07-25 07:24:27 +02:00
{
2017-07-25 11:33:33 +02:00
auto* header = new ButtonBar();
2017-07-25 21:34:27 +02:00
header->addIcon( "bluetooth" );
header->addIcon( "location" );
header->addIcon( "phone" );
2017-07-25 11:33:33 +02:00
auto dateLabel = new QskTextLabel( QDate::currentDate().toString(), header );
2017-07-25 07:24:27 +02:00
dateLabel->setColor( QskTextLabel::Text, Qt::white );
2017-07-25 21:34:27 +02:00
header->addIcon( "user" );
header->addIcon( "bookmark" );
header->addIcon( "menu" );
2017-07-25 11:33:33 +02:00
return header;
2017-07-25 07:24:27 +02:00
}
2017-07-25 11:33:33 +02:00
QQuickItem* MainWindow::mainContent() const
2017-07-25 07:24:27 +02:00
{
// RadioControl* radioControl = new RadioControl( m_layout );
// m_layout->setRetainSizeWhenHidden( radioControl, true );
// radioControl->setVisible( false );
2017-07-25 11:33:33 +02:00
return new SoundControl();
2017-07-25 07:24:27 +02:00
}
2017-07-25 11:33:33 +02:00
QQuickItem* MainWindow::footerBar() const
2017-07-25 07:24:27 +02:00
{
2017-07-25 11:33:33 +02:00
auto* footer = new ButtonBar();
2017-07-25 21:34:27 +02:00
footer->addIcon( "cloud" );
footer->addIcon( "man" );
footer->addIcon( "bus" );
footer->addIcon( "plane" );
footer->addIcon( "train" );
2017-07-25 11:33:33 +02:00
footer->addStretch( 10 );
return footer;
2017-07-25 07:24:27 +02:00
}