forked from qt-creator/qt-creator
Icon: Aggregate QVector instead of deriving from it
In this way we hide the public interface of QVector for Icon. Change-Id: I7722779b3b6781ff2cbcab0e2e9894dbd0435218 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -58,7 +58,7 @@ static QPixmap maskToColorAndAlpha(const QPixmap &mask, const QColor &color)
|
||||
|
||||
using MaskAndColor = QPair<QPixmap, QColor>;
|
||||
using MasksAndColors = QList<MaskAndColor>;
|
||||
static MasksAndColors masksAndColors(const Icon &icon, int dpr)
|
||||
static MasksAndColors masksAndColors(const QVector<IconMaskAndColor> &icon, int dpr)
|
||||
{
|
||||
MasksAndColors result;
|
||||
for (const IconMaskAndColor &i: icon) {
|
||||
@@ -157,27 +157,27 @@ static QPixmap masksToIcon(const MasksAndColors &masks, const QPixmap &combinedM
|
||||
Icon::Icon() = default;
|
||||
|
||||
Icon::Icon(std::initializer_list<IconMaskAndColor> args, Icon::IconStyleOptions style)
|
||||
: QVector<IconMaskAndColor>(args)
|
||||
: m_iconSourceList(args)
|
||||
, m_style(style)
|
||||
{
|
||||
}
|
||||
|
||||
Icon::Icon(const FilePath &imageFileName)
|
||||
{
|
||||
append({imageFileName, Theme::Color(-1)});
|
||||
m_iconSourceList.append({imageFileName, Theme::Color(-1)});
|
||||
}
|
||||
|
||||
QIcon Icon::icon() const
|
||||
{
|
||||
if (isEmpty()) {
|
||||
if (m_iconSourceList.isEmpty()) {
|
||||
return QIcon();
|
||||
} else if (m_style == None) {
|
||||
return QIcon(constFirst().first.toString());
|
||||
return QIcon(m_iconSourceList.constFirst().first.toString());
|
||||
} else {
|
||||
QIcon result;
|
||||
const int maxDpr = qRound(qApp->devicePixelRatio());
|
||||
for (int dpr = 1; dpr <= maxDpr; dpr++) {
|
||||
const MasksAndColors masks = masksAndColors(*this, dpr);
|
||||
const MasksAndColors masks = masksAndColors(m_iconSourceList, dpr);
|
||||
const QPixmap combinedMask = Utils::combinedMask(masks, m_style);
|
||||
result.addPixmap(masksToIcon(masks, combinedMask, m_style));
|
||||
|
||||
@@ -190,13 +190,13 @@ QIcon Icon::icon() const
|
||||
|
||||
QPixmap Icon::pixmap(QIcon::Mode iconMode) const
|
||||
{
|
||||
if (isEmpty()) {
|
||||
if (m_iconSourceList.isEmpty()) {
|
||||
return QPixmap();
|
||||
} else if (m_style == None) {
|
||||
return QPixmap(StyleHelper::dpiSpecificImageFile(constFirst().first.toString()));
|
||||
return QPixmap(StyleHelper::dpiSpecificImageFile(m_iconSourceList.constFirst().first.toString()));
|
||||
} else {
|
||||
const MasksAndColors masks =
|
||||
masksAndColors(*this, qRound(qApp->devicePixelRatio()));
|
||||
masksAndColors(m_iconSourceList, qRound(qApp->devicePixelRatio()));
|
||||
const QPixmap combinedMask = Utils::combinedMask(masks, m_style);
|
||||
return iconMode == QIcon::Disabled
|
||||
? maskToColorAndAlpha(combinedMask, creatorTheme()->color(Theme::IconsDisabledColor))
|
||||
@@ -206,8 +206,8 @@ QPixmap Icon::pixmap(QIcon::Mode iconMode) const
|
||||
|
||||
FilePath Icon::imageFilePath() const
|
||||
{
|
||||
QTC_ASSERT(length() == 1, return {});
|
||||
return first().first;
|
||||
QTC_ASSERT(m_iconSourceList.length() == 1, return {});
|
||||
return m_iconSourceList.first().first;
|
||||
}
|
||||
|
||||
QIcon Icon::sideBarIcon(const Icon &classic, const Icon &flat)
|
||||
|
@@ -46,7 +46,7 @@ using IconMaskAndColor = QPair<FilePath, Theme::Color>;
|
||||
|
||||
// Returns a recolored icon with shadow and custom disabled state for a
|
||||
// series of grayscalemask|Theme::Color mask pairs
|
||||
class QTCREATOR_UTILS_EXPORT Icon : public QVector<IconMaskAndColor>
|
||||
class QTCREATOR_UTILS_EXPORT Icon
|
||||
{
|
||||
public:
|
||||
enum IconStyleOption {
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
static QIcon combinedIcon(const QList<Icon> &icons);
|
||||
|
||||
private:
|
||||
QVector<IconMaskAndColor> m_iconSourceList;
|
||||
IconStyleOptions m_style = None;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user