forked from qt-creator/qt-creator
Utils: Cache the last QIcon created from a Utils::Icon
This rarely changes, but was re-computed/re-painted for each text mark etc. Change-Id: I9f4b0f2f2a88f0a267ecdd0faa983677eb634751 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -169,23 +169,27 @@ Icon::Icon(const FilePath &imageFileName)
|
||||
|
||||
QIcon Icon::icon() const
|
||||
{
|
||||
if (m_iconSourceList.isEmpty()) {
|
||||
if (m_iconSourceList.isEmpty())
|
||||
return QIcon();
|
||||
} else if (m_style == None) {
|
||||
|
||||
if (m_style == None)
|
||||
return QIcon(m_iconSourceList.constFirst().first.toString());
|
||||
} else {
|
||||
QIcon result;
|
||||
|
||||
const int maxDpr = qRound(qApp->devicePixelRatio());
|
||||
if (maxDpr == m_lastDevicePixelRatio)
|
||||
return m_lastIcon;
|
||||
|
||||
m_lastDevicePixelRatio = maxDpr;
|
||||
m_lastIcon = QIcon();
|
||||
for (int dpr = 1; dpr <= maxDpr; dpr++) {
|
||||
const MasksAndColors masks = masksAndColors(m_iconSourceList, dpr);
|
||||
const QPixmap combinedMask = Utils::combinedMask(masks, m_style);
|
||||
result.addPixmap(masksToIcon(masks, combinedMask, m_style));
|
||||
m_lastIcon.addPixmap(masksToIcon(masks, combinedMask, m_style));
|
||||
|
||||
const QColor disabledColor = creatorTheme()->color(Theme::IconsDisabledColor);
|
||||
result.addPixmap(maskToColorAndAlpha(combinedMask, disabledColor), QIcon::Disabled);
|
||||
}
|
||||
return result;
|
||||
m_lastIcon.addPixmap(maskToColorAndAlpha(combinedMask, disabledColor), QIcon::Disabled);
|
||||
}
|
||||
return m_lastIcon;
|
||||
}
|
||||
|
||||
QPixmap Icon::pixmap(QIcon::Mode iconMode) const
|
||||
|
@@ -88,6 +88,8 @@ public:
|
||||
private:
|
||||
QVector<IconMaskAndColor> m_iconSourceList;
|
||||
IconStyleOptions m_style = None;
|
||||
mutable int m_lastDevicePixelRatio = -1;
|
||||
mutable QIcon m_lastIcon;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
Reference in New Issue
Block a user