qskinny/examples/iot-dashboard/TopBar.cpp

99 lines
2.8 KiB
C++
Raw Normal View History

2020-06-12 13:51:13 +00:00
#include "TopBar.h"
#include "PieChartPainted.h"
2020-06-12 13:51:13 +00:00
#include <QskSkin.h>
#include <QskTextLabel.h>
#include <QTime>
2021-03-31 13:33:37 +00:00
QSK_SUBCONTROL( TimeTitleLabel, Text )
QSK_SUBCONTROL( TimeLabel, Text )
2021-03-31 08:25:50 +00:00
QSK_SUBCONTROL( TopBarItem, Item1 )
QSK_SUBCONTROL( TopBarItem, Item2 )
QSK_SUBCONTROL( TopBarItem, Item3 )
QSK_SUBCONTROL( TopBarItem, Item4 )
2021-03-26 16:35:53 +00:00
QSK_SUBCONTROL( TopBar, Panel )
2021-03-31 08:25:50 +00:00
namespace
{
QskAspect::Subcontrol subcontrolForIndex( int index )
{
switch( index )
{
case 0:
return TopBarItem::Item1;
case 1:
return TopBarItem::Item2;
case 2:
return TopBarItem::Item3;
default:
return TopBarItem::Item4;
}
}
}
2021-03-31 13:33:37 +00:00
TopBarItem::TopBarItem( int index, const QString& name, const QskGradient& gradient, int progress, int value, QQuickItem* parent )
: QskLinearBox( Qt::Vertical, parent )
, m_name( name )
2020-06-12 13:51:13 +00:00
{
setAutoLayoutChildren( true );
setAutoAddChildren( true );
2021-03-26 08:45:33 +00:00
setSpacing( 15 );
2020-06-12 13:51:13 +00:00
auto* textLabel = new QskTextLabel( name, this );
2021-03-31 08:25:50 +00:00
textLabel->setFontRole( QskSkin::SmallFont );
2020-08-12 12:47:46 +00:00
auto* pieChartAndDisplay = new QskLinearBox( Qt::Horizontal, this );
2021-03-26 08:45:33 +00:00
pieChartAndDisplay->setSpacing( 10 );
2021-03-31 08:25:50 +00:00
QskAspect::Subcontrol subcontrol = subcontrolForIndex( index );
QColor textColor = color( subcontrol | QskAspect::TextColor );
2021-03-31 13:33:37 +00:00
new PieChartPainted( textColor, gradient, progress, value, pieChartAndDisplay );
2020-08-12 12:47:46 +00:00
auto* display = new QskLinearBox( Qt::Vertical, pieChartAndDisplay );
2021-03-26 08:45:33 +00:00
display->setSpacing( 0 );
display->addSpacer( 0, 1 );
2021-03-31 13:33:37 +00:00
2021-03-26 08:45:33 +00:00
auto* displayValue = new QskTextLabel( QString::number( value ), display );
displayValue->setFontRole( QskSkin::MediumFont );
2021-03-31 13:33:37 +00:00
2021-03-26 08:45:33 +00:00
auto* displayUnit = new QskTextLabel( "kwH", display );
displayUnit->setFontRole( QskSkin::SmallFont );
display->addSpacer( 0, 1 );
2020-08-12 12:47:46 +00:00
2020-06-12 13:51:13 +00:00
}
2021-03-26 08:45:33 +00:00
TopBar::TopBar( QQuickItem* parent ) : QskLinearBox( Qt::Horizontal, parent )
2020-06-12 13:51:13 +00:00
{
2021-03-26 16:35:53 +00:00
setPanel( true );
2021-03-26 08:45:33 +00:00
setAutoLayoutChildren( true );
setAutoAddChildren( true );
setSizePolicy( QskSizePolicy::Preferred, QskSizePolicy::Fixed );
2020-06-12 13:51:13 +00:00
QStringList itemStrings = { "Living Room", "Bedroom", "Bathroom", "Kitchen" };
int progressValues[] = {25, 45, 15, 86};
int values[] = {175, 205, 115, 289};
2020-06-12 13:51:13 +00:00
2021-03-31 08:25:50 +00:00
for( int i = 0; i < itemStrings.count(); i++ )
2020-06-12 13:51:13 +00:00
{
2021-03-31 08:25:50 +00:00
QskAspect::Subcontrol subcontrol = subcontrolForIndex( i );
QskGradient gradient = gradientHint( subcontrol );
2021-03-31 08:25:50 +00:00
auto* item = new TopBarItem( i, itemStrings.at( i ), gradient, progressValues[i], values[i], this );
2021-03-26 08:45:33 +00:00
m_entries.append( item );
2020-06-12 13:51:13 +00:00
}
2021-03-26 08:45:33 +00:00
auto* timeControl = new QskLinearBox( Qt::Vertical, this );
2021-03-31 13:33:37 +00:00
new TimeTitleLabel( "Current time", timeControl );
2020-06-12 13:51:13 +00:00
auto now = QTime::currentTime();
auto timeString = now.toString();
2021-03-31 13:33:37 +00:00
new TimeLabel( timeString, timeControl );
2020-06-12 13:51:13 +00:00
}