211 lines
4.1 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "Image.h"
2017-07-21 18:21:34 +02:00
// QQuickImagePrivate is not exported, so we
// we can't derive here
class Image::PrivateData
2017-07-21 18:21:34 +02:00
{
public:
PrivateData():
sourceSizeAdjustment( false ),
deferredUpdates( true ),
dirtyPolish( false ),
dirtyUpdate( false )
{
}
bool sourceSizeAdjustment : 1;
bool deferredUpdates : 1;
bool dirtyPolish : 1;
bool dirtyUpdate : 1;
};
Image::Image( QQuickItem* parent ):
2017-07-21 18:21:34 +02:00
Inherited( parent ),
m_data( new PrivateData() )
{
}
Image::~Image()
2017-07-21 18:21:34 +02:00
{
}
void Image::setVisible( bool on )
2017-07-21 18:21:34 +02:00
{
// QQuickItem::setVisible is no slot
Inherited::setVisible( on );
}
void Image::show()
2017-07-21 18:21:34 +02:00
{
Inherited::setVisible( true );
}
void Image::hide()
2017-07-21 18:21:34 +02:00
{
Inherited::setVisible( false );
}
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();
}
}
bool Image::sourceSizeAdjustment() const
2017-07-21 18:21:34 +02:00
{
return m_data->sourceSizeAdjustment;
}
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();
}
}
}
bool Image::deferredUpdates() const
2017-07-21 18:21:34 +02:00
{
return m_data->deferredUpdates;
}
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();
}
}
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();
}
}
}
void Image::geometryChanged( const QRectF& newGeometry,
2017-07-21 18:21:34 +02:00
const QRectF& oldGeometry )
{
Inherited::geometryChanged( newGeometry, oldGeometry );
if ( newGeometry.size() != oldGeometry.size() )
{
if ( m_data->sourceSizeAdjustment )
{
if ( m_data->deferredUpdates )
{
setImplicitSize( newGeometry.width(), newGeometry.height() );
polish();
}
else
{
setSourceSize( newGeometry.size().toSize() );
}
}
}
}
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 )
setSourceSize( QSize( width(), height() ) );
}
m_data->dirtyPolish = false;
Inherited::updatePolish();
}
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 );
}
bool Image::hasHeightForWidth() const
2017-07-21 18:21:34 +02:00
{
// TODO
return false;
}
qreal Image::heightForWidth( qreal width ) const
2017-07-21 18:21:34 +02:00
{
// TODO
Q_UNUSED( width )
return -1.0;
}
bool Image::hasWidthForHeight() const
2017-07-21 18:21:34 +02:00
{
// TODO
return false;
}
qreal Image::widthForHeight( qreal height ) const
2017-07-21 18:21:34 +02:00
{
// TODO
Q_UNUSED( height )
return -1.0;
}
#include "moc_Image.cpp"