Fix dock app icon is empty or size error

Change-Id: Ifb6a383ffcb11cc67c87e83cf952df124b4af452
This commit is contained in:
石博文 2017-02-21 11:40:16 +08:00
parent 90e102335b
commit 26f189d5a8
Notes: Deepin Code Review 2017-02-21 15:00:01 +08:00
Code-Review+1: Felix Yan <yanran@deepin.com>
Code-Review+2: 石博文 <sbw@sbw.so>
Verified+1: Anonymous Coward #1000004
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 21 Feb 2017 14:59:56 +0800
Reviewed-on: https://cr.deepin.io/20494
Project: dde/dde-dock
Branch: refs/heads/master
2 changed files with 30 additions and 16 deletions

View File

@ -14,27 +14,41 @@ ThemeAppIcon::~ThemeAppIcon()
}
QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
const QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
{
QPixmap pixmap(size, size);
QPixmap pixmap;
do {
if (iconName.startsWith("data:image/"))
{
const QStringList strs = iconName.split("base64,");
if (strs.size() == 2)
pixmap.loadFromData(QByteArray::fromBase64(strs.at(1).toLatin1()));
if (!pixmap.isNull())
break;
}
if (QFile::exists(iconName))
{
pixmap = QPixmap(iconName);
if (!pixmap.isNull())
break;
}
if (QFile::exists(iconName)) {
pixmap = QPixmap(iconName);
if (!pixmap.isNull())
return pixmap;
}
if (iconName.startsWith("data:image/"))
{
const QStringList strs = iconName.split("base64,");
if (strs.size() == 2)
pixmap.loadFromData(QByteArray::fromBase64(strs.at(1).toLatin1()));
} else {
const QIcon icon = QIcon::fromTheme(iconName, QIcon::fromTheme("application-x-desktop"));
pixmap = icon.pixmap(QSize(size, size));
}
if (!pixmap.isNull())
break;
if (pixmap.isNull())
pixmap = QPixmap(":/icons/resources/application-x-desktop.svg");
if (!pixmap.isNull())
break;
Q_UNREACHABLE();
} while (false);
return pixmap.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}

View File

@ -10,7 +10,7 @@ public:
explicit ThemeAppIcon(QObject *parent = 0);
~ThemeAppIcon();
static QPixmap getIcon(const QString iconName, const int size);
static const QPixmap getIcon(const QString iconName, const int size);
};
#endif // THEMEAPPICON_H