// -------- Icon Loader Engine -------- //
QIconLoaderEngine::QIconLoaderEngine(const QString &iconName)
- : m_iconName(iconName), m_key(0)
+ : m_iconName(iconName),
+ m_key(0)
{
ensureLoaded();
}
QIconLoaderEngine::~QIconLoaderEngine()
{
- while (!m_entries.isEmpty())
+ while (!m_entries.isEmpty()) {
delete m_entries.takeLast();
+ }
Q_ASSERT(m_entries.size() == 0);
}
QIconLoaderEngine::QIconLoaderEngine(const QIconLoaderEngine &other)
- : QIconEngine(other),
- m_iconName(other.m_iconName),
- m_key(0)
+ : QIconEngine(other),
+ m_iconName(other.m_iconName),
+ m_key(0)
{
ensureLoaded();
}
return new QIconLoaderEngine(*this);
}
-bool QIconLoaderEngine::read(QDataStream &in) {
+bool QIconLoaderEngine::read(QDataStream &in)
+{
in >> m_iconName;
return true;
}
void QIconLoaderEngine::ensureLoaded()
{
- if (!(iconLoaderInstance()->themeKey() == m_key)) {
-
- while (!m_entries.isEmpty())
+ if (iconLoaderInstance()->themeKey() != m_key) {
+ while (!m_entries.isEmpty()) {
delete m_entries.takeLast();
+ }
Q_ASSERT(m_entries.size() == 0);
m_entries = iconLoaderInstance()->loadIcon(m_iconName);
}
void QIconLoaderEngine::paint(QPainter *painter, const QRect &rect,
- QIcon::Mode mode, QIcon::State state)
+ QIcon::Mode mode, QIcon::State state)
{
painter->drawPixmap(rect, pixmap(rect.size(), mode, state));
}
static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
{
if (dir.type == QIconDirInfo::Fixed) {
- return dir.size == iconsize;
-
+ return (dir.size == iconsize);
} else if (dir.type == QIconDirInfo::Scalable) {
- return iconsize <= dir.maxSize &&
- iconsize >= dir.minSize;
-
+ return (iconsize <= dir.maxSize && iconsize >= dir.minSize);
} else if (dir.type == QIconDirInfo::Threshold) {
- return iconsize >= dir.size - dir.threshold &&
- iconsize <= dir.size + dir.threshold;
+ return (iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold);
}
Q_ASSERT(1); // Not a valid value
return qAbs(dir.size - iconsize);
} else if (dir.type == QIconDirInfo::Scalable) {
- if (iconsize < dir.minSize)
+ if (iconsize < dir.minSize) {
return dir.minSize - iconsize;
- else if (iconsize > dir.maxSize)
+ } else if (iconsize > dir.maxSize) {
return iconsize - dir.maxSize;
- else
+ } else {
return 0;
-
+ }
} else if (dir.type == QIconDirInfo::Threshold) {
- if (iconsize < dir.size - dir.threshold)
+ if (iconsize < dir.size - dir.threshold) {
return dir.minSize - iconsize;
- else if (iconsize > dir.size + dir.threshold)
+ } else if (iconsize > dir.size + dir.threshold) {
return iconsize - dir.maxSize;
- else return 0;
+ } else {
+ return 0;
+ }
}
Q_ASSERT(1); // Not a valid value
*
*/
QSize QIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode,
- QIcon::State state)
+ QIcon::State state)
{
QIconLoaderEngineEntry *entry = entryForSize(size);
if (entry) {
}
QPixmap QIconLoaderEngine::pixmap(const QSize &size, QIcon::Mode mode,
- QIcon::State state)
+ QIcon::State state)
{
QIconLoaderEngineEntry *entry = entryForSize(size);
- if (entry)
+ if (entry) {
return entry->pixmap(size, mode, state);
-
+ }
return QPixmap();
}
QIconLoaderEngine(const QString& iconName = QString());
~QIconLoaderEngine();
- void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
- QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
- QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
- QList<QSize> availableSizes(QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off) const;
- QString iconName() const;
- QIconEngine *clone() const;
- bool read(QDataStream &in);
- bool write(QDataStream &out) const;
- QString key() const;
+ void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) final;
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) final;
+ QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) final;
+ QList<QSize> availableSizes(QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off) const final;
+ QString iconName() const final;
+ QIconEngine *clone() const final;
+ bool read(QDataStream &in) final;
+ bool write(QDataStream &out) const final;
+ QString key() const final;
private:
void ensureLoaded();
QIconLoaderEngineEntry *entryForSize(const QSize &size);
QIconLoaderEngine(const QIconLoaderEngine &other);
+
QThemeIconEntries m_entries;
QString m_iconName;
uint m_key;