forked from qt-creator/qt-creator
Utils: New ThemeHelper class with icon handling tools
http://blog.qt.io/blog/author/didesous/ announced new designs/themes for Qt Creator. This patch implements the helper functions for the loading and theme-specific recoloring of icons. Change-Id: Ie6e96eeecb70dccd6b95338c653a9d3b760557cc Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
This commit is contained in:
@@ -515,13 +515,31 @@ QString StyleHelper::dpiSpecificImageFile(const QString &fileName)
|
||||
{
|
||||
// See QIcon::addFile()
|
||||
if (qApp->devicePixelRatio() > 1.0) {
|
||||
const QFileInfo fi(fileName);
|
||||
const QString at2xfileName = fi.path() + QLatin1Char('/')
|
||||
+ fi.completeBaseName() + QStringLiteral("@2x.") + fi.suffix();
|
||||
if (QFile::exists(at2xfileName))
|
||||
return at2xfileName;
|
||||
const QString atDprfileName =
|
||||
imageFileWithResolution(fileName, qRound(qApp->devicePixelRatio()));
|
||||
if (QFile::exists(atDprfileName))
|
||||
return atDprfileName;
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
QString StyleHelper::imageFileWithResolution(const QString &fileName, int dpr)
|
||||
{
|
||||
const QFileInfo fi(fileName);
|
||||
return dpr == 1 ? fileName :
|
||||
fi.path() + QLatin1Char('/') + fi.completeBaseName()
|
||||
+ QLatin1Char('@') + QString::number(dpr)
|
||||
+ QLatin1String("x.") + fi.suffix();
|
||||
}
|
||||
|
||||
QList<int> StyleHelper::availableImageResolutions(const QString &fileName)
|
||||
{
|
||||
QList<int> result;
|
||||
const int maxResolutions = qApp->devicePixelRatio();
|
||||
for (int i = 1; i <= maxResolutions; ++i)
|
||||
if (QFile::exists(imageFileWithResolution(fileName, i)))
|
||||
result.append(i);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
Reference in New Issue
Block a user