qskinny/examples/automotive/MainWindow.cpp
Peter Hartmann 60a4f2ff1f Speedometer: inherit from QskRangeControl and make skinnable (#62)
* Speedometer: Inherit from QskRangeControl

We don't need start/endAngle() etc. and value() anymore,
but can use the methods from QskRangeControl.

* Speedometer: Make it skinnable

* automotive example: Only use two specially created skins

... because the default skins do not have hints for e.g. the speedometer.

Also, display the speedometer page by default.
2018-05-09 08:31:43 +02:00

83 lines
1.9 KiB
C++

#include "MainWindow.h"
#include "ButtonBar.h"
#include "SkinFactory.h"
#include "SoundControl.h"
#include "SpeedometerDisplay.h"
#include <QskGraphic.h>
#include <QskGraphicIO.h>
#include <QskGraphicLabel.h>
#include <QskLinearBox.h>
#include <QskTextLabel.h>
#include <QDate>
#include <QImage>
#define SPEEDO 1
MainWindow::MainWindow()
{
const QImage image( QStringLiteral( ":/images/background.jpg" ) );
auto backgroundImage = new QskGraphicLabel( contentItem() );
backgroundImage->setGraphic( QskGraphic::fromImage( image ) );
backgroundImage->setFillMode( QskGraphicLabel::Stretch );
auto header = headerBar();
auto content = mainContent();
auto footer = footerBar();
auto layout = new QskLinearBox( Qt::Vertical, contentItem() );
layout->addItem( header );
layout->setStretchFactor( header, 1 );
layout->addItem( content );
layout->setStretchFactor( content, 10 );
layout->addItem( footer );
layout->setStretchFactor( footer, 1 );
setAutoLayoutChildren( true );
}
QQuickItem* MainWindow::headerBar() const
{
auto* header = new ButtonBar();
header->addIndicator( "bluetooth" );
header->addIndicator( "location" );
header->addIndicator( "phone" );
(void) new QskTextLabel( QDate::currentDate().toString(), header );
header->addIndicator( "user" );
header->addIndicator( "bookmark" );
header->addIndicator( "menu" );
return header;
}
QQuickItem* MainWindow::mainContent() const
{
#if SPEEDO
return new SpeedometerDisplay();
#else
return new SoundControl();
#endif
}
QQuickItem* MainWindow::footerBar() const
{
auto* footer = new ButtonBar();
footer->addIndicator( "cloud" );
footer->addIndicator( "man" );
footer->addIndicator( "bus" );
footer->addIndicator( "plane" );
footer->addIndicator( "train" );
footer->addStretch( 10 );
return footer;
}