2016-12-30 16:22:28 -05:00
/*
2017-01-02 17:12:20 -05:00
* Copyright 2012 Marco Martin < mart @ kde . org >
* Copyright 2014 David Edmundson < davidedmudnson @ kde . org >
2017-01-02 17:05:30 -05:00
* Copyright 2016 Smith AR < audoban @ openmailbox . org >
* Michail Vourlakos < mvourlakos @ gmail . com >
2016-12-30 16:22:28 -05:00
*
2017-01-02 17:12:20 -05:00
* This file is part of Latte - Dock and is a Fork of PlasmaCore : : IconItem
2016-12-30 16:22:28 -05:00
*
2017-01-02 17:05:30 -05:00
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
2016-12-30 16:22:28 -05:00
*
2017-01-02 17:05:30 -05:00
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
2016-12-30 16:22:28 -05:00
*/
2017-01-02 17:05:30 -05:00
2016-12-30 16:22:28 -05:00
# include "iconitem.h"
2018-12-02 02:05:52 +02:00
// local
2018-12-07 18:44:09 +02:00
# include "../liblatte2/extras.h"
2016-12-30 16:22:28 -05:00
2018-12-02 02:05:52 +02:00
// Qt
2016-12-30 16:22:28 -05:00
# include <QDebug>
# include <QPainter>
# include <QPaintEngine>
# include <QQuickWindow>
# include <QPixmap>
# include <QSGSimpleTextureNode>
# include <QuickAddons/ManagedTextureNode>
2018-12-02 02:05:52 +02:00
// KDE
2016-12-30 16:22:28 -05:00
# include <KIconTheme>
# include <KIconThemes/KIconLoader>
# include <KIconThemes/KIconEffect>
namespace Latte {
IconItem : : IconItem ( QQuickItem * parent )
: QQuickItem ( parent ) ,
2017-03-15 20:06:23 +02:00
m_lastValidSourceName ( QString ( ) ) ,
2016-12-30 16:22:28 -05:00
m_smooth ( false ) ,
m_active ( false ) ,
m_textureChanged ( false ) ,
2017-05-27 23:56:19 +03:00
m_sizeChanged ( false ) ,
2019-03-27 20:57:02 +02:00
m_usesPlasmaTheme ( false ) ,
m_colorGroup ( Plasma : : Theme : : NormalColorGroup )
2016-12-30 16:22:28 -05:00
{
setFlag ( ItemHasContents , true ) ;
connect ( KIconLoader : : global ( ) , SIGNAL ( iconLoaderSettingsChanged ( ) ) ,
this , SIGNAL ( implicitWidthChanged ( ) ) ) ;
connect ( KIconLoader : : global ( ) , SIGNAL ( iconLoaderSettingsChanged ( ) ) ,
this , SIGNAL ( implicitHeightChanged ( ) ) ) ;
connect ( this , & QQuickItem : : enabledChanged ,
this , & IconItem : : enabledChanged ) ;
connect ( this , & QQuickItem : : windowChanged ,
this , & IconItem : : schedulePixmapUpdate ) ;
connect ( this , SIGNAL ( overlaysChanged ( ) ) ,
this , SLOT ( schedulePixmapUpdate ( ) ) ) ;
2019-02-12 18:18:12 +02:00
connect ( this , SIGNAL ( providesColorsChanged ( ) ) ,
this , SLOT ( schedulePixmapUpdate ( ) ) ) ;
2016-12-30 16:22:28 -05:00
//initialize implicit size to the Dialog size
setImplicitWidth ( KIconLoader : : global ( ) - > currentSize ( KIconLoader : : Dialog ) ) ;
setImplicitHeight ( KIconLoader : : global ( ) - > currentSize ( KIconLoader : : Dialog ) ) ;
2017-02-03 00:22:28 -05:00
setSmooth ( true ) ;
2016-12-30 16:22:28 -05:00
}
IconItem : : ~ IconItem ( )
{
}
void IconItem : : setSource ( const QVariant & source )
{
if ( source = = m_source ) {
return ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_source = source ;
QString sourceString = source . toString ( ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
// If the QIcon was created with QIcon::fromTheme(), try to load it as svg
if ( source . canConvert < QIcon > ( ) & & ! source . value < QIcon > ( ) . name ( ) . isEmpty ( ) ) {
sourceString = source . value < QIcon > ( ) . name ( ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( ! sourceString . isEmpty ( ) ) {
2019-02-13 20:58:44 +02:00
setLastValidSourceName ( sourceString ) ;
2019-02-15 19:19:12 +02:00
setLastLoadedSourceId ( sourceString ) ;
2019-02-13 20:58:44 +02:00
2016-12-30 16:22:28 -05:00
//If a url in the form file:// is passed, take the image pointed by that from disk
QUrl url ( sourceString ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( url . isLocalFile ( ) ) {
m_icon = QIcon ( ) ;
m_imageIcon = QImage ( url . path ( ) ) ;
m_svgIconName . clear ( ) ;
m_svgIcon . reset ( ) ;
} else {
if ( ! m_svgIcon ) {
m_svgIcon = std : : make_unique < Plasma : : Svg > ( this ) ;
2019-03-27 20:57:02 +02:00
m_svgIcon - > setColorGroup ( m_colorGroup ) ;
2016-12-30 16:22:28 -05:00
m_svgIcon - > setStatus ( Plasma : : Svg : : Normal ) ;
2017-02-03 00:22:28 -05:00
m_svgIcon - > setUsingRenderingCache ( false ) ;
2016-12-30 16:22:28 -05:00
m_svgIcon - > setDevicePixelRatio ( ( window ( ) ? window ( ) - > devicePixelRatio ( ) : qApp - > devicePixelRatio ( ) ) ) ;
connect ( m_svgIcon . get ( ) , & Plasma : : Svg : : repaintNeeded , this , & IconItem : : schedulePixmapUpdate ) ;
}
2017-01-16 14:07:49 -05:00
2017-05-27 23:56:19 +03:00
if ( m_usesPlasmaTheme ) {
//try as a svg icon from plasma theme
m_svgIcon - > setImagePath ( QLatin1String ( " icons/ " ) + sourceString . split ( ' - ' ) . first ( ) ) ;
m_svgIcon - > setContainsMultipleImages ( true ) ;
//invalidate the image path to recalculate it later
} else {
m_svgIcon - > setImagePath ( QString ( ) ) ;
}
2016-12-30 16:22:28 -05:00
//success?
if ( m_svgIcon - > isValid ( ) & & m_svgIcon - > hasElement ( sourceString ) ) {
m_icon = QIcon ( ) ;
m_svgIconName = sourceString ;
//ok, svg not available from the plasma theme
} else {
//try to load from iconloader an svg with Plasma::Svg
const auto * iconTheme = KIconLoader : : global ( ) - > theme ( ) ;
QString iconPath ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( iconTheme ) {
iconPath = iconTheme - > iconPath ( sourceString + QLatin1String ( " .svg " )
, static_cast < int > ( qMin ( width ( ) , height ( ) ) )
, KIconLoader : : MatchBest ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( iconPath . isEmpty ( ) ) {
iconPath = iconTheme - > iconPath ( sourceString + QLatin1String ( " .svgz " )
, static_cast < int > ( qMin ( width ( ) , height ( ) ) )
, KIconLoader : : MatchBest ) ;
}
} else {
qWarning ( ) < < " KIconLoader has no theme set " ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( ! iconPath . isEmpty ( ) ) {
m_svgIcon - > setImagePath ( iconPath ) ;
m_svgIconName = sourceString ;
//fail, use QIcon
} else {
//if we started with a QIcon use that.
m_icon = source . value < QIcon > ( ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( m_icon . isNull ( ) ) {
m_icon = QIcon : : fromTheme ( sourceString ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_svgIconName . clear ( ) ;
m_svgIcon . reset ( ) ;
m_imageIcon = QImage ( ) ;
}
}
}
} else if ( source . canConvert < QIcon > ( ) ) {
m_icon = source . value < QIcon > ( ) ;
2019-02-15 19:19:12 +02:00
m_iconCounter + + ;
setLastLoadedSourceId ( " _icon_ " + QString : : number ( m_iconCounter ) ) ;
2016-12-30 16:22:28 -05:00
m_imageIcon = QImage ( ) ;
m_svgIconName . clear ( ) ;
m_svgIcon . reset ( ) ;
} else if ( source . canConvert < QImage > ( ) ) {
m_imageIcon = source . value < QImage > ( ) ;
2019-02-15 19:19:12 +02:00
m_iconCounter + + ;
setLastLoadedSourceId ( " _image_ " + QString : : number ( m_iconCounter ) ) ;
m_icon = QIcon ( ) ;
2016-12-30 16:22:28 -05:00
m_svgIconName . clear ( ) ;
m_svgIcon . reset ( ) ;
} else {
m_icon = QIcon ( ) ;
m_imageIcon = QImage ( ) ;
m_svgIconName . clear ( ) ;
m_svgIcon . reset ( ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( width ( ) > 0 & & height ( ) > 0 ) {
schedulePixmapUpdate ( ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
emit sourceChanged ( ) ;
emit validChanged ( ) ;
}
QVariant IconItem : : source ( ) const
{
return m_source ;
}
2019-02-15 19:19:12 +02:00
void IconItem : : setLastLoadedSourceId ( QString id )
{
if ( m_lastLoadedSourceId = = id ) {
return ;
}
m_lastLoadedSourceId = id ;
}
2017-03-15 20:06:23 +02:00
QString IconItem : : lastValidSourceName ( )
{
return m_lastValidSourceName ;
}
void IconItem : : setLastValidSourceName ( QString name )
{
if ( m_lastValidSourceName = = name | | name = = " " | | name = = " application-x-executable " ) {
return ;
}
m_lastValidSourceName = name ;
emit lastValidSourceNameChanged ( ) ;
}
2019-03-27 20:57:02 +02:00
void IconItem : : setColorGroup ( Plasma : : Theme : : ColorGroup group )
{
if ( m_colorGroup = = group ) {
return ;
}
m_colorGroup = group ;
if ( m_svgIcon ) {
m_svgIcon - > setColorGroup ( group ) ;
}
emit colorGroupChanged ( ) ;
}
Plasma : : Theme : : ColorGroup IconItem : : colorGroup ( ) const
{
return m_colorGroup ;
}
2016-12-30 16:22:28 -05:00
void IconItem : : setOverlays ( const QStringList & overlays )
{
if ( overlays = = m_overlays ) {
return ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_overlays = overlays ;
emit overlaysChanged ( ) ;
}
QStringList IconItem : : overlays ( ) const
{
return m_overlays ;
}
bool IconItem : : isActive ( ) const
{
return m_active ;
}
void IconItem : : setActive ( bool active )
{
if ( m_active = = active ) {
return ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_active = active ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( isComponentComplete ( ) ) {
schedulePixmapUpdate ( ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
emit activeChanged ( ) ;
}
2019-02-12 18:18:12 +02:00
bool IconItem : : providesColors ( ) const
{
return m_providesColors ;
}
void IconItem : : setProvidesColors ( const bool provides )
{
if ( m_providesColors = = provides ) {
return ;
}
m_providesColors = provides ;
emit providesColorsChanged ( ) ;
}
2016-12-30 16:22:28 -05:00
void IconItem : : setSmooth ( const bool smooth )
{
if ( smooth = = m_smooth ) {
return ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_smooth = smooth ;
update ( ) ;
}
bool IconItem : : smooth ( ) const
{
return m_smooth ;
}
bool IconItem : : isValid ( ) const
{
return ! m_icon . isNull ( ) | | m_svgIcon | | ! m_imageIcon . isNull ( ) ;
}
int IconItem : : paintedWidth ( ) const
{
return boundingRect ( ) . size ( ) . toSize ( ) . width ( ) ;
}
int IconItem : : paintedHeight ( ) const
{
return boundingRect ( ) . size ( ) . toSize ( ) . height ( ) ;
}
2017-05-27 23:56:19 +03:00
bool IconItem : : usesPlasmaTheme ( ) const
{
return m_usesPlasmaTheme ;
}
void IconItem : : setUsesPlasmaTheme ( bool usesPlasmaTheme )
{
if ( m_usesPlasmaTheme = = usesPlasmaTheme ) {
return ;
}
m_usesPlasmaTheme = usesPlasmaTheme ;
// Reload icon with new settings
const QVariant src = m_source ;
m_source . clear ( ) ;
setSource ( src ) ;
update ( ) ;
emit usesPlasmaThemeChanged ( ) ;
}
2016-12-30 16:22:28 -05:00
void IconItem : : updatePolish ( )
{
QQuickItem : : updatePolish ( ) ;
loadPixmap ( ) ;
}
QSGNode * IconItem : : updatePaintNode ( QSGNode * oldNode , UpdatePaintNodeData * updatePaintNodeData )
{
Q_UNUSED ( updatePaintNodeData )
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( m_iconPixmap . isNull ( ) | | width ( ) < 1.0 | | height ( ) < 1.0 ) {
delete oldNode ;
return nullptr ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
ManagedTextureNode * textureNode = dynamic_cast < ManagedTextureNode * > ( oldNode ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( ! textureNode | | m_textureChanged ) {
2016-12-30 16:32:48 -05:00
if ( oldNode )
2016-12-30 16:22:28 -05:00
delete oldNode ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
textureNode = new ManagedTextureNode ;
2019-04-24 00:44:23 +03:00
textureNode - > setTexture ( QSharedPointer < QSGTexture > ( window ( ) - > createTextureFromImage ( m_iconPixmap . toImage ( ) , QQuickWindow : : TextureCanUseAtlas ) ) ) ;
textureNode - > setFiltering ( smooth ( ) ? QSGTexture : : Linear : QSGTexture : : Nearest ) ;
2016-12-30 16:22:28 -05:00
m_sizeChanged = true ;
m_textureChanged = false ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( m_sizeChanged ) {
const auto iconSize = qMin ( boundingRect ( ) . size ( ) . width ( ) , boundingRect ( ) . size ( ) . height ( ) ) ;
const QRectF destRect ( QPointF ( boundingRect ( ) . center ( ) - QPointF ( iconSize / 2 , iconSize / 2 ) ) , QSizeF ( iconSize , iconSize ) ) ;
textureNode - > setRect ( destRect ) ;
m_sizeChanged = false ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
return textureNode ;
}
void IconItem : : schedulePixmapUpdate ( )
{
polish ( ) ;
}
void IconItem : : enabledChanged ( )
{
schedulePixmapUpdate ( ) ;
}
2019-02-12 18:18:12 +02:00
QColor IconItem : : backgroundColor ( ) const
{
return m_backgroundColor ;
}
void IconItem : : setBackgroundColor ( QColor background )
{
if ( m_backgroundColor = = background ) {
return ;
}
m_backgroundColor = background ;
emit backgroundColorChanged ( ) ;
}
QColor IconItem : : glowColor ( ) const
{
return m_glowColor ;
}
void IconItem : : setGlowColor ( QColor glow )
{
if ( m_glowColor = = glow ) {
return ;
}
m_glowColor = glow ;
emit glowColorChanged ( ) ;
}
void IconItem : : updateColors ( )
{
QImage icon = m_iconPixmap . toImage ( ) ;
if ( icon . format ( ) ! = QImage : : Format_Invalid ) {
float rtotal = 0 , gtotal = 0 , btotal = 0 ;
float total = 0.0f ;
for ( int row = 0 ; row < icon . height ( ) ; + + row ) {
QRgb * line = ( QRgb * ) icon . scanLine ( row ) ;
for ( int col = 0 ; col < icon . width ( ) ; + + col ) {
QRgb pix = line [ col ] ;
int r = qRed ( pix ) ;
int g = qGreen ( pix ) ;
int b = qBlue ( pix ) ;
int a = qAlpha ( pix ) ;
float saturation = ( qMax ( r , qMax ( g , b ) ) - qMin ( r , qMin ( g , b ) ) ) / 255.0f ;
float relevance = .1 + .9 * ( a / 255.0f ) * saturation ;
rtotal + = ( float ) ( r * relevance ) ;
gtotal + = ( float ) ( g * relevance ) ;
btotal + = ( float ) ( b * relevance ) ;
total + = relevance * 255 ;
}
}
int nr = ( rtotal / total ) * 255 ;
int ng = ( gtotal / total ) * 255 ;
int nb = ( btotal / total ) * 255 ;
QColor tempColor ( nr , ng , nb ) ;
if ( tempColor . hsvSaturationF ( ) > 0.15f ) {
tempColor . setHsvF ( tempColor . hueF ( ) , 0.65f , tempColor . valueF ( ) ) ;
}
tempColor . setHsvF ( tempColor . hueF ( ) , tempColor . saturationF ( ) , 0.55f ) ; //original 0.90f ???
setBackgroundColor ( tempColor ) ;
tempColor . setHsvF ( tempColor . hueF ( ) , tempColor . saturationF ( ) , 1.0f ) ;
setGlowColor ( tempColor ) ;
}
}
2016-12-30 16:22:28 -05:00
void IconItem : : loadPixmap ( )
{
if ( ! isComponentComplete ( ) ) {
return ;
}
2017-01-16 14:07:49 -05:00
2017-02-03 00:22:28 -05:00
const auto size = qMin ( width ( ) , height ( ) ) ;
2016-12-30 16:22:28 -05:00
//final pixmap to paint
QPixmap result ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( size < = 0 ) {
m_iconPixmap = QPixmap ( ) ;
update ( ) ;
return ;
} else if ( m_svgIcon ) {
m_svgIcon - > resize ( size , size ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( m_svgIcon - > hasElement ( m_svgIconName ) ) {
result = m_svgIcon - > pixmap ( m_svgIconName ) ;
} else if ( ! m_svgIconName . isEmpty ( ) ) {
const auto * iconTheme = KIconLoader : : global ( ) - > theme ( ) ;
QString iconPath ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( iconTheme ) {
iconPath = iconTheme - > iconPath ( m_svgIconName + QLatin1String ( " .svg " )
, static_cast < int > ( qMin ( width ( ) , height ( ) ) )
, KIconLoader : : MatchBest ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( iconPath . isEmpty ( ) ) {
2016-12-30 16:32:48 -05:00
iconPath = iconTheme - > iconPath ( m_svgIconName + QLatin1String ( " .svgz " ) ,
2016-12-30 16:22:28 -05:00
static_cast < int > ( qMin ( width ( ) , height ( ) ) )
, KIconLoader : : MatchBest ) ;
}
} else {
qWarning ( ) < < " KIconLoader has no theme set " ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( ! iconPath . isEmpty ( ) ) {
m_svgIcon - > setImagePath ( iconPath ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
result = m_svgIcon - > pixmap ( ) ;
}
} else if ( ! m_icon . isNull ( ) ) {
2017-02-03 00:22:28 -05:00
result = m_icon . pixmap ( QSize ( static_cast < int > ( size ) , static_cast < int > ( size ) )
* ( window ( ) ? window ( ) - > devicePixelRatio ( ) : qApp - > devicePixelRatio ( ) ) ) ;
2016-12-30 16:22:28 -05:00
} else if ( ! m_imageIcon . isNull ( ) ) {
result = QPixmap : : fromImage ( m_imageIcon ) ;
} else {
m_iconPixmap = QPixmap ( ) ;
update ( ) ;
return ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
// Strangely KFileItem::overlays() returns empty string-values, so
// we need to check first whether an overlay must be drawn at all.
// It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional
// setup time.
2019-04-04 23:55:44 +03:00
for ( const QString & overlay : m_overlays ) {
2016-12-30 16:22:28 -05:00
if ( ! overlay . isEmpty ( ) ) {
// There is at least one overlay, draw all overlays above m_pixmap
// and cancel the check
KIconLoader : : global ( ) - > drawOverlays ( m_overlays , result , KIconLoader : : Desktop ) ;
break ;
}
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( ! isEnabled ( ) ) {
result = KIconLoader : : global ( ) - > iconEffect ( ) - > apply ( result , KIconLoader : : Desktop , KIconLoader : : DisabledState ) ;
} else if ( m_active ) {
result = KIconLoader : : global ( ) - > iconEffect ( ) - > apply ( result , KIconLoader : : Desktop , KIconLoader : : ActiveState ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
m_iconPixmap = result ;
2019-02-12 18:18:12 +02:00
2019-02-15 19:19:12 +02:00
if ( m_providesColors & & m_lastLoadedSourceId ! = m_lastColorsSourceId ) {
m_lastColorsSourceId = m_lastLoadedSourceId ;
2019-02-12 18:18:12 +02:00
updateColors ( ) ;
}
2016-12-30 16:22:28 -05:00
m_textureChanged = true ;
//don't animate initial setting
update ( ) ;
}
void IconItem : : itemChange ( ItemChange change , const ItemChangeData & value )
{
QQuickItem : : itemChange ( change , value ) ;
}
void IconItem : : geometryChanged ( const QRectF & newGeometry , const QRectF & oldGeometry )
{
if ( newGeometry . size ( ) ! = oldGeometry . size ( ) ) {
m_sizeChanged = true ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( newGeometry . width ( ) > 1 & & newGeometry . height ( ) > 1 ) {
schedulePixmapUpdate ( ) ;
} else {
update ( ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
const auto oldSize = qMin ( oldGeometry . size ( ) . width ( ) , oldGeometry . size ( ) . height ( ) ) ;
const auto newSize = qMin ( newGeometry . size ( ) . width ( ) , newGeometry . size ( ) . height ( ) ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
if ( ! almost_equal ( oldSize , newSize , 2 ) ) {
emit paintedSizeChanged ( ) ;
}
}
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
QQuickItem : : geometryChanged ( newGeometry , oldGeometry ) ;
}
void IconItem : : componentComplete ( )
{
QQuickItem : : componentComplete ( ) ;
schedulePixmapUpdate ( ) ;
}
}