qskinny/examples/iot-dashboard/RoundedIcon.cpp

47 lines
1.1 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>
RoundedIcon::RoundedIcon(const QString& iconName, const QskGradient& gradient, QQuickItem* parent)
: QskBox(parent)
, m_iconName(iconName)
, m_gradient(gradient)
{
setPanel(true);
setPolishOnResize( true );
setGradientHint(Panel, gradient);
setBoxShapeHint(Panel, 6 );
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
if(QFile::exists(fileName))
{
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()
{
2020-08-26 12:45:57 +00:00
if(m_graphicLabel)
{
m_graphicLabel->setSize( {36, 36});
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;
}