6#include "QskGraphicLabel.h"
8#include "QskColorFilter.h"
10#include "QskGraphicProvider.h"
11#include "QskSkinManager.h"
18class QskGraphicLabel::PrivateData
21 PrivateData(
const QUrl& sourceUrl )
25 , isSourceDirty( !sourceUrl.isEmpty() )
35 bool isSourceDirty : 1;
39QskGraphicLabel::QskGraphicLabel(
const QUrl& source, QQuickItem* parent )
41 , m_data( new PrivateData( source ) )
43 initSizePolicy( QskSizePolicy::Expanding, QskSizePolicy::Expanding );
45 if ( !m_data->source.isEmpty() )
49QskGraphicLabel::QskGraphicLabel( QQuickItem* parent )
54QskGraphicLabel::QskGraphicLabel(
const QString& source, QQuickItem* parent )
59QskGraphicLabel::QskGraphicLabel(
const QskGraphic& graphic, QQuickItem* parent )
62 m_data->graphic = graphic;
65QskGraphicLabel::~QskGraphicLabel()
69void QskGraphicLabel::setPanel(
bool on )
71 if ( on == m_data->hasPanel )
74 m_data->hasPanel = on;
79 Q_EMIT panelChanged( on );
82bool QskGraphicLabel::hasPanel()
const
84 return m_data->hasPanel;
87bool QskGraphicLabel::isEmpty()
const
89 return m_data->graphic.isNull() && m_data->source.isEmpty();
92QUrl QskGraphicLabel::source()
const
94 return m_data->source;
97void QskGraphicLabel::setSource(
const QString& source )
99 setSource( QUrl( source ) );
102void QskGraphicLabel::setSource(
const QUrl& url )
104 if ( url == m_data->source )
107 m_data->graphic.reset();
108 m_data->isSourceDirty =
true;
109 m_data->source = url;
115 Q_EMIT sourceChanged();
120 return m_data->graphic;
123void QskGraphicLabel::setGraphic(
const QskGraphic& graphic )
125 if ( m_data->graphic != graphic )
127 const bool keepImplicitSize = graphicStrutSize().isValid()
128 || ( m_data->graphic.defaultSize() == graphic.defaultSize() );
130 m_data->graphic = graphic;
132 if ( !keepImplicitSize )
139 m_data->isSourceDirty =
false;
141 if ( !m_data->source.isEmpty() )
143 m_data->source.clear();
144 Q_EMIT sourceChanged();
148void QskGraphicLabel::setGraphicRole(
int role )
151 Q_EMIT graphicRoleChanged( role );
154void QskGraphicLabel::resetGraphicRole()
160int QskGraphicLabel::graphicRole()
const
173void QskGraphicLabel::setMirror(
bool on )
175 if ( on != m_data->mirror )
179 if ( !( graphicStrutSize().isEmpty() || m_data->graphic.isEmpty() ) )
182 Q_EMIT mirrorChanged();
186bool QskGraphicLabel::mirror()
const
188 return m_data->mirror;
191void QskGraphicLabel::setGraphicStrutSize(
const QSizeF& size )
194 if ( newSize.width() < 0.0 )
195 newSize.setWidth( -1.0 );
197 if ( newSize.height() < 0.0 )
198 newSize.setHeight( -1.0 );
201 Q_EMIT graphicStrutSizeChanged();
204QSizeF QskGraphicLabel::graphicStrutSize()
const
209void QskGraphicLabel::resetGraphicStrutSize()
212 Q_EMIT graphicStrutSizeChanged();
215void QskGraphicLabel::setFillMode( FillMode mode )
217 if ( mode != m_data->fillMode )
219 m_data->fillMode = mode;
221 if ( !m_data->graphic.isEmpty() )
224 Q_EMIT fillModeChanged( mode );
228QskGraphicLabel::FillMode QskGraphicLabel::fillMode()
const
230 return static_cast< QskGraphicLabel::FillMode
>( m_data->fillMode );
233void QskGraphicLabel::setAlignment( Qt::Alignment alignment )
236 Q_EMIT alignmentChanged( alignment );
239void QskGraphicLabel::resetAlignment()
242 Q_EMIT alignmentChanged( alignment() );
245Qt::Alignment QskGraphicLabel::alignment()
const
247 return alignmentHint( Graphic, Qt::AlignLeft | Qt::AlignVCenter );
250QskGraphic QskGraphicLabel::loadSource(
const QUrl& url )
const
252 return Qsk::loadGraphic( url );
255void QskGraphicLabel::updateResources()
257 if ( !m_data->source.isEmpty() && m_data->isSourceDirty )
258 m_data->graphic = loadSource( m_data->source );
260 m_data->isSourceDirty =
false;
263QSizeF QskGraphicLabel::effectiveSourceSize()
const
265 const auto strutSize = graphicStrutSize();
267 if ( strutSize.width() >= 0 && strutSize.height() >= 0 )
273 if ( !m_data->source.isEmpty() && m_data->isSourceDirty )
276 m_data->graphic = loadSource( m_data->source );
277 m_data->isSourceDirty =
false;
281 if ( !m_data->graphic.isEmpty() )
283 const QSizeF defaultSize = m_data->graphic.defaultSize();
285 if ( strutSize.width() <= 0 && strutSize.height() <= 0 )
290 else if ( strutSize.width() <= 0 )
293 const qreal f = strutSize.height() / defaultSize.height();
294 sz.setWidth( f * defaultSize.width() );
295 sz.setHeight( strutSize.height() );
300 const qreal f = strutSize.width() / defaultSize.width();
301 sz.setWidth( strutSize.width() );
302 sz.setHeight( f * defaultSize.height() );
330 if ( event->type() == QEvent::StyleChange )
332 if ( !m_data->source.isEmpty() && qskSkinManager->skin()->hasGraphicProvider() )
335 m_data->isSourceDirty =
true;
342#include "moc_QskGraphicLabel.cpp"
void geometryChangeEvent(QskGeometryChangeEvent *) override
void changeEvent(QEvent *) override
A paint device for scalable graphics.
virtual void geometryChangeEvent(QskGeometryChangeEvent *)
virtual void changeEvent(QEvent *)
bool resetGraphicRoleHint(QskAspect)
Removes a graphic role hint from the local table.
bool setAlignmentHint(QskAspect, Qt::Alignment)
Sets an alignment hint.
bool setStrutSizeHint(QskAspect, const QSizeF &)
Sets a metric hint.
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.
bool setGraphicRoleHint(QskAspect, int role)
Sets a graphic role hint.
int graphicRoleHint(QskAspect, QskSkinHintStatus *=nullptr) const
A Retrieves a graphic role hint.
bool resetAlignmentHint(QskAspect)
Removes an alignment hint from the local table.
bool resetStrutSizeHint(QskAspect)
Removes a strut size hint from the local table.
QskColorFilter effectiveGraphicFilter(QskAspect::Subcontrol) const
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.