2021-04-29 07:49:08 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (C) 2021 Edelhirsch Software GmbH
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
#include "RoundedIcon.h"
|
|
|
|
|
|
|
|
#include <QskBoxShapeMetrics.h>
|
|
|
|
#include <QskGraphic.h>
|
|
|
|
#include <QskGraphicLabel.h>
|
|
|
|
|
|
|
|
#include <QImage>
|
2021-04-26 08:38:10 +02:00
|
|
|
#include <QFile>
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
QSK_SUBCONTROL( RoundedIcon, Panel )
|
|
|
|
QSK_SUBCONTROL( RoundedIcon, Icon )
|
|
|
|
QSK_STATE( RoundedIcon, Bright, ( QskAspect::FirstUserState << 1 ) )
|
|
|
|
QSK_STATE( RoundedIcon, Small, ( QskAspect::FirstUserState << 2 ) )
|
|
|
|
|
|
|
|
RoundedIcon::RoundedIcon( const QString& iconName, bool isBright, bool isSmall, QQuickItem* parent )
|
|
|
|
: QskBox( parent )
|
|
|
|
{
|
|
|
|
setPanel( true );
|
|
|
|
setPolishOnResize( true );
|
2021-08-04 18:55:18 +02:00
|
|
|
setSubcontrolProxy( QskBox::Panel, Panel );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
if( isSmall )
|
|
|
|
{
|
|
|
|
setSkinState( skinState() | Small );
|
|
|
|
}
|
|
|
|
|
|
|
|
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Constrained );
|
|
|
|
const qreal size = metric( RoundedIcon::Panel | QskAspect::Size );
|
|
|
|
setFixedWidth( size );
|
|
|
|
|
|
|
|
if( isBright )
|
|
|
|
{
|
|
|
|
setSkinState( Bright );
|
|
|
|
}
|
|
|
|
|
2021-08-04 18:55:18 +02:00
|
|
|
const QString fileName( ":/images/" + iconName + ".png" );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
if( QFile::exists( fileName ) )
|
|
|
|
{
|
|
|
|
QImage image( fileName );
|
|
|
|
auto graphic = QskGraphic::fromImage( image );
|
|
|
|
m_graphicLabel = new QskGraphicLabel( graphic, this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoundedIcon::updateLayout()
|
|
|
|
{
|
|
|
|
if( m_graphicLabel )
|
|
|
|
{
|
2021-08-04 18:55:18 +02:00
|
|
|
const auto size = metric( Icon | QskAspect::Size );
|
|
|
|
|
|
|
|
QRectF r( 0.0, 0.0, size, size );
|
|
|
|
r.moveCenter( rect().center() );
|
|
|
|
|
|
|
|
m_graphicLabel->setGeometry( r );
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF RoundedIcon::contentsSizeHint( Qt::SizeHint /*which*/, const QSizeF& size ) const
|
|
|
|
{
|
|
|
|
QSizeF ret = size;
|
|
|
|
ret.setHeight( size.width() );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2021-04-26 08:43:46 +02:00
|
|
|
|
|
|
|
#include "moc_RoundedIcon.cpp"
|