6#include "QskStatusIndicator.h"
7#include "QskColorFilter.h"
9#include "QskGraphicProvider.h"
26 StatusData(
const QUrl& url )
28 , isDirty( !url.isEmpty() )
34 if ( !source.isEmpty() && isDirty )
36 graphic = indicator->loadSource( source );
47class QskStatusIndicator::PrivateData
56 QMap< int, StatusData > map;
57 mutable QList< int > statusList;
60QskStatusIndicator::QskStatusIndicator( QQuickItem* parent )
62 , m_data( new PrivateData() )
64 initSizePolicy( QskSizePolicy::Expanding, QskSizePolicy::Expanding );
67QskStatusIndicator::~QskStatusIndicator()
71QUrl QskStatusIndicator::source(
int status )
const
73 const auto it = m_data->map.constFind( status );
74 if ( it != m_data->map.constEnd() )
80void QskStatusIndicator::setSource(
int status,
const QString& source )
82 setSource( status, QUrl( source ) );
85void QskStatusIndicator::setSource(
int status,
const QUrl& url )
87 bool hasChanged =
false;
89 const auto it = m_data->map.find( status );
90 if ( it != m_data->map.end() )
92 if ( it->source != url )
96 it->isDirty = !url.isEmpty();
103 m_data->map.insert( status, StatusData( url ) );
104 m_data->statusList.clear();
113 if ( status == m_data->currentStatus )
118QskGraphic QskStatusIndicator::graphic(
int status )
const
120 const auto it = m_data->map.find( status );
121 if ( it != m_data->map.end() )
123 it->ensureGraphic(
this );
130void QskStatusIndicator::setGraphic(
int status,
const QskGraphic& graphic )
132 bool hasChanged =
false;
134 const auto it = m_data->map.find( status );
135 if ( it != m_data->map.end() )
137 if ( !it->source.isEmpty() || graphic != it->graphic )
141 it->graphic = graphic;
148 m_data->map.insert( status, StatusData( graphic ) );
149 m_data->statusList.clear();
157 if ( status == m_data->currentStatus )
162QskColorFilter QskStatusIndicator::graphicFilter(
int status )
const
168void QskStatusIndicator::setGraphicRole(
int role )
171 Q_EMIT graphicRoleChanged( role );
174void QskStatusIndicator::resetGraphicRole()
180int QskStatusIndicator::graphicRole()
const
185int QskStatusIndicator::status()
const
187 return m_data->currentStatus;
190bool QskStatusIndicator::hasStatus(
int status )
const
192 return m_data->map.contains( status );
195void QskStatusIndicator::setStatus(
int status )
197 if ( status == m_data->currentStatus )
200 const auto it = m_data->map.constFind( status );
201 if ( it == m_data->map.constEnd() )
203 qWarning() <<
"QskStatusIndicator: invalid status:" << status;
207 m_data->currentStatus = status;
208 Q_EMIT statusChanged( m_data->currentStatus );
219QList< int > QskStatusIndicator::statusList()
const
226 if ( m_data->statusList.isEmpty() && !m_data->map.isEmpty() )
227 m_data->statusList = m_data->map.keys();
229 return m_data->statusList;
234 if ( event->type() == QEvent::StyleChange )
236 for (
auto& statusData : m_data->map )
238 if ( !statusData.source.isEmpty() )
240 statusData.graphic.reset();
241 statusData.isDirty =
true;
249void QskStatusIndicator::updateLayout()
251 const auto it = m_data->map.find( m_data->currentStatus );
252 if ( it != m_data->map.end() )
253 it->ensureGraphic(
this );
256QskGraphic QskStatusIndicator::loadSource(
const QUrl& url )
const
258 return Qsk::loadGraphic( url );
261#include "moc_QskStatusIndicator.cpp"
A paint device for scalable graphics.
virtual void changeEvent(QEvent *)
bool resetGraphicRoleHint(QskAspect)
Removes a graphic role hint from the local table.
bool setGraphicRoleHint(QskAspect, int role)
Sets a graphic role hint.
int graphicRoleHint(QskAspect, QskSkinHintStatus *=nullptr) const
A Retrieves a graphic role hint.
QskColorFilter effectiveGraphicFilter(QskAspect::Subcontrol) const
void changeEvent(QEvent *) override