2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
2019-06-20 12:02:28 +02:00
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
2017-07-21 18:21:34 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
#include "Image.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
// QQuickImagePrivate is not exported, so we
|
|
|
|
// we can't derive here
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
class Image::PrivateData
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
PrivateData()
|
|
|
|
: sourceSizeAdjustment( false )
|
|
|
|
, deferredUpdates( true )
|
|
|
|
, dirtyPolish( false )
|
|
|
|
, dirtyUpdate( false )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sourceSizeAdjustment : 1;
|
|
|
|
|
|
|
|
bool deferredUpdates : 1;
|
|
|
|
bool dirtyPolish : 1;
|
|
|
|
bool dirtyUpdate : 1;
|
|
|
|
};
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
Image::Image( QQuickItem* parent )
|
|
|
|
: Inherited( parent )
|
|
|
|
, m_data( new PrivateData() )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
Image::~Image()
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::setVisible( bool on )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
// QQuickItem::setVisible is no slot
|
|
|
|
Inherited::setVisible( on );
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::show()
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
Inherited::setVisible( true );
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::hide()
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
Inherited::setVisible( false );
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::setSourceSizeAdjustment( bool on )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
if ( on != m_data->sourceSizeAdjustment )
|
|
|
|
{
|
|
|
|
m_data->sourceSizeAdjustment = on;
|
|
|
|
Q_EMIT sourceSizeAdjustmentChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
bool Image::sourceSizeAdjustment() const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
return m_data->sourceSizeAdjustment;
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::setDeferredUpdates( bool on )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
if ( on != m_data->deferredUpdates )
|
|
|
|
{
|
|
|
|
m_data->deferredUpdates = on;
|
|
|
|
|
|
|
|
if ( !on )
|
|
|
|
{
|
|
|
|
// when having blocked updates we reschedule them
|
|
|
|
|
|
|
|
if ( m_data->dirtyPolish )
|
|
|
|
polish();
|
|
|
|
|
|
|
|
if ( m_data->dirtyUpdate )
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
bool Image::deferredUpdates() const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
return m_data->deferredUpdates;
|
|
|
|
}
|
|
|
|
|
2020-10-31 09:58:33 +01:00
|
|
|
void Image::setSourceSize( const QSize& size )
|
|
|
|
{
|
2020-10-31 10:03:56 +01:00
|
|
|
if ( !( size.isEmpty() && sourceSize().isEmpty() ) )
|
2020-10-31 09:58:33 +01:00
|
|
|
QQuickImage::setSourceSize( size );
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::componentComplete()
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
if ( m_data->deferredUpdates && m_data->sourceSizeAdjustment )
|
|
|
|
{
|
|
|
|
// QQuickImage::componentComplete() calls load
|
|
|
|
// long before we have the final geometry
|
|
|
|
|
|
|
|
polish();
|
|
|
|
QQuickItem::componentComplete();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Inherited::componentComplete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::itemChange( QQuickItem::ItemChange change,
|
2017-07-21 18:21:34 +02:00
|
|
|
const QQuickItem::ItemChangeData& value )
|
|
|
|
{
|
|
|
|
Inherited::itemChange( change, value );
|
|
|
|
|
|
|
|
if ( change == ItemVisibleHasChanged )
|
|
|
|
{
|
|
|
|
if ( value.boolValue )
|
|
|
|
{
|
|
|
|
if ( m_data->dirtyPolish )
|
|
|
|
polish();
|
|
|
|
|
|
|
|
if ( m_data->dirtyUpdate )
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 17:51:31 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
|
|
|
|
|
|
|
|
void Image::geometryChange(
|
|
|
|
const QRectF& newGeometry, const QRectF& oldGeometry )
|
|
|
|
{
|
|
|
|
Inherited::geometryChange( newGeometry, oldGeometry );
|
|
|
|
|
|
|
|
if ( newGeometry.size() != oldGeometry.size() )
|
|
|
|
adjustSourceSize( newGeometry.size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
void Image::geometryChanged(
|
|
|
|
const QRectF& newGeometry, const QRectF& oldGeometry )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
Inherited::geometryChanged( newGeometry, oldGeometry );
|
|
|
|
|
|
|
|
if ( newGeometry.size() != oldGeometry.size() )
|
2020-10-26 17:51:31 +01:00
|
|
|
adjustSourceSize( newGeometry.size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void Image::adjustSourceSize( const QSizeF& size )
|
|
|
|
{
|
|
|
|
if ( m_data->sourceSizeAdjustment )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-10-26 17:51:31 +01:00
|
|
|
if ( m_data->deferredUpdates )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-10-26 17:51:31 +01:00
|
|
|
setImplicitSize( size.width(), size.height() );
|
|
|
|
polish();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setSourceSize( size.toSize() );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
void Image::updatePolish()
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
if ( m_data->deferredUpdates )
|
|
|
|
{
|
|
|
|
if ( !isVisible() )
|
|
|
|
{
|
|
|
|
m_data->dirtyPolish = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_data->sourceSizeAdjustment )
|
2017-12-07 14:59:29 +01:00
|
|
|
setSourceSize( QSize( int( width() ), int( height() ) ) );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m_data->dirtyPolish = false;
|
|
|
|
|
|
|
|
Inherited::updatePolish();
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
QSGNode* Image::updatePaintNode( QSGNode* oldNode, UpdatePaintNodeData* data )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
if ( m_data->deferredUpdates )
|
|
|
|
{
|
|
|
|
if ( !isVisible() )
|
|
|
|
{
|
|
|
|
m_data->dirtyUpdate = true;
|
|
|
|
return oldNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data->dirtyUpdate = false;
|
|
|
|
|
|
|
|
return Inherited::updatePaintNode( oldNode, data );
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
bool Image::hasHeightForWidth() const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
qreal Image::heightForWidth( qreal width ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
Q_UNUSED( width )
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
bool Image::hasWidthForHeight() const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
qreal Image::widthForHeight( qreal height ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
Q_UNUSED( height )
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:36 +02:00
|
|
|
#include "moc_Image.cpp"
|