qskinny/examples/iot-dashboard/MyDevices.cpp

79 lines
2.5 KiB
C++
Raw Normal View History

2020-08-17 15:19:05 +00:00
#include "MyDevices.h"
2021-03-31 08:08:30 +00:00
#include "Skin.h"
2020-08-17 15:19:05 +00:00
#include "RoundedIcon.h"
2020-08-26 12:45:57 +00:00
#include <QskGraphic.h>
#include <QskGraphicLabel.h>
2020-08-17 15:19:05 +00:00
#include <QskGridBox.h>
#include <QskTextLabel.h>
2020-08-26 12:45:57 +00:00
#include <QImage>
2020-09-08 15:16:30 +00:00
namespace
{
2020-08-17 15:19:05 +00:00
class Device : public QskLinearBox
{
2020-09-08 15:16:30 +00:00
public:
2021-03-31 16:02:34 +00:00
Device( const QString& name, const QskGradient& gradient, QQuickItem* parent ) // ### remove gradient and style
2020-09-08 15:16:30 +00:00
: QskLinearBox( Qt::Vertical, parent )
, m_name( name )
{
setDefaultAlignment( Qt::AlignCenter );
setAutoAddChildren( false );
2021-03-31 16:02:34 +00:00
m_icon = new RoundedIcon( QString(), this );
2020-09-08 15:16:30 +00:00
m_icon->setOpacity( 0.15 );
m_icon->setFixedWidth( 60 );
addItem( m_icon );
auto* textLabel = new QskTextLabel( name, this );
textLabel->setFontRole( QskSkin::TinyFont );
textLabel->setAlignment( Qt::AlignHCenter );
addItem( textLabel );
auto fileName = name.toLower();
fileName.replace( ' ', '-' );
fileName = ":/images/" + fileName + ".png";
QImage image( fileName );
auto graphic = QskGraphic::fromImage( image );
m_graphicLabel = new QskGraphicLabel( graphic, this );
}
protected:
void updateLayout() override
{
QskLinearBox::updateLayout();
m_graphicLabel->setSize( {36, 36} );
m_graphicLabel->setPosition( { m_icon->position().x() + ( m_icon->width() - m_graphicLabel->width() ) / 2,
( m_icon->position().y() + m_icon->height() - m_graphicLabel->height() ) / 2 } );
}
private:
QString m_name;
RoundedIcon* m_icon;
QskGraphicLabel* m_graphicLabel;
2020-08-17 15:19:05 +00:00
};
}
2020-09-17 14:47:34 +00:00
MyDevices::MyDevices( QQuickItem* parent )
: Box( "My devices", parent )
2020-08-17 15:19:05 +00:00
{
2020-09-08 15:16:30 +00:00
auto* content = new QskGridBox( this );
2020-08-17 15:19:05 +00:00
2020-09-08 15:16:30 +00:00
QskGradient gradient1( QskGradient::Vertical, "#FF3122", "#FF7D34" );
QskGradient gradient2( QskGradient::Vertical, "#6100FF", "#6776FF" );
2020-08-17 15:19:05 +00:00
2020-09-08 15:16:30 +00:00
auto* lamps = new Device( "Lamps", gradient1, content );
content->addItem( lamps, 0, 0 );
2020-08-17 15:19:05 +00:00
2020-09-08 15:16:30 +00:00
auto* musicSystem = new Device( "Music System", gradient2, content );
content->addItem( musicSystem, 0, 1 );
2020-08-17 15:19:05 +00:00
2020-09-08 15:16:30 +00:00
auto* ac = new Device( "AC", gradient2, content );
content->addItem( ac, 1, 0 );
2020-08-17 15:19:05 +00:00
2020-09-08 15:16:30 +00:00
auto* router = new Device( "Router", gradient1, content );
content->addItem( router, 1, 1 );
2020-08-17 15:19:05 +00:00
}