qskinny/examples/iot-dashboard/RoundedIcon.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

2020-08-14 10:48:15 +00:00
#include "RoundedIcon.h"
#include <QskBoxShapeMetrics.h>
#include <QskGraphic.h>
#include <QskGraphicLabel.h>
#include <QImage>
2021-03-26 08:45:33 +00:00
RoundedIcon::RoundedIcon( const QString& iconName, const QskGradient& gradient, QQuickItem* parent )
: QskBox( parent )
, m_iconName( iconName )
, m_gradient( gradient )
2020-08-14 10:48:15 +00:00
{
2021-03-26 08:45:33 +00:00
setPanel( true );
2020-08-14 10:48:15 +00:00
setPolishOnResize( true );
2021-03-26 08:45:33 +00:00
setGradientHint( Panel, gradient );
setBoxShapeHint( Panel, 6 );
2020-08-14 10:48:15 +00:00
2021-03-26 08:45:33 +00:00
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Constrained );
2020-08-14 10:48:15 +00:00
QString fileName = ":/images/" + iconName + ".png";
2020-08-26 12:45:57 +00:00
2021-03-26 08:45:33 +00:00
if( QFile::exists( fileName ) )
2020-08-26 12:45:57 +00:00
{
QImage image( fileName );
auto graphic = QskGraphic::fromImage( image );
m_graphicLabel = new QskGraphicLabel( graphic, this );
}
2020-08-14 10:48:15 +00:00
}
void RoundedIcon::updateLayout()
{
2021-03-26 08:45:33 +00:00
if( m_graphicLabel )
2020-08-26 12:45:57 +00:00
{
2021-03-26 08:45:33 +00:00
m_graphicLabel->setSize( {36, 36} );
2020-08-26 12:45:57 +00:00
m_graphicLabel->setPosition( { ( width() - m_graphicLabel->width() ) / 2, ( height() - m_graphicLabel->height() ) / 2 } );
}
2020-08-14 10:48:15 +00:00
}
QSizeF RoundedIcon::contentsSizeHint( Qt::SizeHint /*which*/, const QSizeF& size ) const
{
QSizeF ret = size;
ret.setHeight( size.width() );
return ret;
}