Speedometer: Add some API
This commit is contained in:
parent
554f07c5b4
commit
b7c54d6916
@ -13,7 +13,8 @@
|
|||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow() :
|
||||||
|
m_layout( nullptr )
|
||||||
{
|
{
|
||||||
const QImage image( QStringLiteral( ":/images/background.jpg" ) );
|
const QImage image( QStringLiteral( ":/images/background.jpg" ) );
|
||||||
|
|
||||||
@ -21,27 +22,27 @@ MainWindow::MainWindow()
|
|||||||
backgroundImage->setGraphic( QskGraphic::fromImage( image ) );
|
backgroundImage->setGraphic( QskGraphic::fromImage( image ) );
|
||||||
backgroundImage->setFillMode( QskGraphicLabel::Stretch );
|
backgroundImage->setFillMode( QskGraphicLabel::Stretch );
|
||||||
|
|
||||||
|
m_layout = new QskLinearBox( Qt::Vertical, contentItem() );
|
||||||
|
|
||||||
auto header = headerBar();
|
auto header = headerBar();
|
||||||
auto content = mainContent();
|
auto content = mainContent();
|
||||||
auto footer = footerBar();
|
auto footer = footerBar();
|
||||||
|
|
||||||
auto layout = new QskLinearBox( Qt::Vertical, contentItem() );
|
m_layout->addItem( header );
|
||||||
|
m_layout->setStretchFactor( header, 1 );
|
||||||
|
|
||||||
layout->addItem( header );
|
m_layout->addItem( content );
|
||||||
layout->setStretchFactor( header, 1 );
|
m_layout->setStretchFactor( content, 10 );
|
||||||
|
|
||||||
layout->addItem( content );
|
m_layout->addItem( footer );
|
||||||
layout->setStretchFactor( content, 10 );
|
m_layout->setStretchFactor( footer, 1 );
|
||||||
|
|
||||||
layout->addItem( footer );
|
|
||||||
layout->setStretchFactor( footer, 1 );
|
|
||||||
|
|
||||||
setAutoLayoutChildren( true );
|
setAutoLayoutChildren( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem* MainWindow::headerBar() const
|
QQuickItem* MainWindow::headerBar() const
|
||||||
{
|
{
|
||||||
auto* header = new ButtonBar();
|
auto* header = new ButtonBar( m_layout );
|
||||||
header->addIndicator( "bluetooth" );
|
header->addIndicator( "bluetooth" );
|
||||||
header->addIndicator( "location" );
|
header->addIndicator( "location" );
|
||||||
header->addIndicator( "phone" );
|
header->addIndicator( "phone" );
|
||||||
@ -57,13 +58,13 @@ QQuickItem* MainWindow::headerBar() const
|
|||||||
|
|
||||||
QQuickItem* MainWindow::mainContent() const
|
QQuickItem* MainWindow::mainContent() const
|
||||||
{
|
{
|
||||||
return new SpeedometerDisplay();
|
return new SpeedometerDisplay( m_layout );
|
||||||
//return new SoundControl(); ###
|
//return new SoundControl(); ###
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem* MainWindow::footerBar() const
|
QQuickItem* MainWindow::footerBar() const
|
||||||
{
|
{
|
||||||
auto* footer = new ButtonBar();
|
auto* footer = new ButtonBar( m_layout );
|
||||||
|
|
||||||
footer->addIndicator( "cloud" );
|
footer->addIndicator( "cloud" );
|
||||||
footer->addIndicator( "man" );
|
footer->addIndicator( "man" );
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <QskWindow.h>
|
#include <QskWindow.h>
|
||||||
|
|
||||||
|
class QskLinearBox;
|
||||||
|
|
||||||
class QQuickItem;
|
class QQuickItem;
|
||||||
|
|
||||||
class MainWindow : public QskWindow
|
class MainWindow : public QskWindow
|
||||||
@ -14,6 +16,8 @@ private:
|
|||||||
QQuickItem* headerBar() const;
|
QQuickItem* headerBar() const;
|
||||||
QQuickItem* mainContent() const;
|
QQuickItem* mainContent() const;
|
||||||
QQuickItem* footerBar() const;
|
QQuickItem* footerBar() const;
|
||||||
|
|
||||||
|
QskLinearBox* m_layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,13 +9,25 @@ QSK_SUBCONTROL( Speedometer, Numbers )
|
|||||||
QSK_SUBCONTROL( Speedometer, Needle )
|
QSK_SUBCONTROL( Speedometer, Needle )
|
||||||
|
|
||||||
Speedometer::Speedometer( QQuickItem* parent ) :
|
Speedometer::Speedometer( QQuickItem* parent ) :
|
||||||
QskControl( parent )
|
QskControl( parent ),
|
||||||
|
m_value( 0.0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF Speedometer::contentsSizeHint() const
|
QSizeF Speedometer::contentsSizeHint() const
|
||||||
{
|
{
|
||||||
return QSizeF( 300, 300 );
|
return { 300, 300 };
|
||||||
|
}
|
||||||
|
|
||||||
|
float Speedometer::value() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Speedometer::setValue( float value )
|
||||||
|
{
|
||||||
|
m_value = value;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_Speedometer.cpp"
|
#include "moc_Speedometer.cpp"
|
||||||
|
@ -13,6 +13,12 @@ public:
|
|||||||
Speedometer( QQuickItem* parent = nullptr );
|
Speedometer( QQuickItem* parent = nullptr );
|
||||||
|
|
||||||
virtual QSizeF contentsSizeHint() const override;
|
virtual QSizeF contentsSizeHint() const override;
|
||||||
|
|
||||||
|
float value() const;
|
||||||
|
void setValue( float value ); // angle; should be within a set range
|
||||||
|
|
||||||
|
private:
|
||||||
|
float m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPEEDOMETER_H
|
#endif // SPEEDOMETER_H
|
||||||
|
@ -5,19 +5,40 @@
|
|||||||
#include <QskLinearBox.h>
|
#include <QskLinearBox.h>
|
||||||
#include <QskTextLabel.h>
|
#include <QskTextLabel.h>
|
||||||
|
|
||||||
|
#include <QTime>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
SpeedometerDisplay::SpeedometerDisplay( QQuickItem *parent ) :
|
SpeedometerDisplay::SpeedometerDisplay( QQuickItem *parent ) :
|
||||||
QskControl( parent )
|
QskControl( parent )
|
||||||
{
|
{
|
||||||
QskLinearBox* box = new QskLinearBox( Qt::Horizontal, this );
|
qsrand( QTime::currentTime().msec() );
|
||||||
|
|
||||||
|
auto box = new QskLinearBox( Qt::Horizontal, this );
|
||||||
box->setAutoAddChildren( true );
|
box->setAutoAddChildren( true );
|
||||||
box->setAutoLayoutChildren( true );
|
box->setAutoLayoutChildren( true );
|
||||||
box->setMargins( QMarginsF( 40, 20, 40, 20 ) );
|
box->setMargins( QMarginsF( 40, 20, 40, 20 ) );
|
||||||
box->setAlignment( 0, Qt::AlignHCenter );
|
box->setAlignment( 0, Qt::AlignHCenter );
|
||||||
|
|
||||||
QskTextLabel* label = new QskTextLabel( QStringLiteral( "text" ), box );
|
auto revCounter = new Speedometer( box );
|
||||||
label->setFixedSize( QSizeF( 300, 300 ) );
|
revCounter->setFixedSize( QSizeF( 300, 300 ) );
|
||||||
label->setAlignment( Qt::AlignHCenter | Qt::AlignCenter );
|
// revCounter->setSizePolicy( QskSizePolicy::Maximum, QskSizePolicy::Maximum );
|
||||||
|
revCounter->setValue( 270 );
|
||||||
|
|
||||||
Speedometer* speedometer = new Speedometer( box );
|
auto speedometer = new Speedometer( box );
|
||||||
speedometer->setFixedSize( QSizeF( 400, 400 ) );
|
speedometer->setFixedSize( QSizeF( 300, 300 ) );
|
||||||
|
// speedometer->setSizePolicy( QskSizePolicy::Maximum, QskSizePolicy::Maximum );
|
||||||
|
speedometer->setValue( 270 );
|
||||||
|
|
||||||
|
auto timer = new QTimer( this );
|
||||||
|
connect( timer, &QTimer::timeout, this, [ speedometer ]() {
|
||||||
|
int newValue = speedometer->value() + qrand() % 3 - 0.8;
|
||||||
|
speedometer->setValue( newValue );
|
||||||
|
});
|
||||||
|
timer->setInterval( 16 );
|
||||||
|
timer->start();
|
||||||
|
|
||||||
|
auto fuelGauge = new Speedometer( box );
|
||||||
|
fuelGauge->setFixedSize( QSizeF( 200, 200 ) );
|
||||||
|
fuelGauge->setValue( 270 );
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ QSGNode* SpeedometerSkinlet::updateNeedleNode( const Speedometer* speedometer, Q
|
|||||||
float xStart = center.x() - needleWidth ;
|
float xStart = center.x() - needleWidth ;
|
||||||
float yStart = center.y();
|
float yStart = center.y();
|
||||||
|
|
||||||
float angle = 315; // ### API
|
float angle = speedometer->value();
|
||||||
qreal cosine = qCos( qDegreesToRadians( angle ) );
|
qreal cosine = qCos( qDegreesToRadians( angle ) );
|
||||||
qreal sine = qSin( qDegreesToRadians( angle ) );
|
qreal sine = qSin( qDegreesToRadians( angle ) );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user