QmlDesigner: Add default icons for sound, font, and shader assets
Also create proper icon sizes for hdpi screens for all assets. Change-Id: Ie082030c7fe4893f90c5a75162b509416b73e5d4 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
@@ -79,6 +79,11 @@ static const QStringList &supportedAudioSuffixes()
|
|||||||
return retList;
|
return retList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QPixmap defaultPixmapForType(const QString &type, const QSize &size)
|
||||||
|
{
|
||||||
|
return QPixmap(QStringLiteral(":/ItemLibrary/images/asset_%1_%2.png").arg(type).arg(size.width()));
|
||||||
|
}
|
||||||
|
|
||||||
static QPixmap generateFontImage(const QFileInfo &info, const QSize &size)
|
static QPixmap generateFontImage(const QFileInfo &info, const QSize &size)
|
||||||
{
|
{
|
||||||
static QHash<QString, QPixmap> fontImageCache;
|
static QHash<QString, QPixmap> fontImageCache;
|
||||||
@@ -92,12 +97,12 @@ static QPixmap generateFontImage(const QFileInfo &info, const QSize &size)
|
|||||||
while (!done) {
|
while (!done) {
|
||||||
QRawFont font(file, pixelSize);
|
QRawFont font(file, pixelSize);
|
||||||
if (!font.isValid())
|
if (!font.isValid())
|
||||||
return pixmap;
|
break;
|
||||||
QGlyphRun gr;
|
QGlyphRun gr;
|
||||||
gr.setRawFont(font);
|
gr.setRawFont(font);
|
||||||
QVector<quint32> indices = font.glyphIndexesForString("Abc");
|
QVector<quint32> indices = font.glyphIndexesForString("Abc");
|
||||||
if (indices.isEmpty())
|
if (indices.isEmpty())
|
||||||
return pixmap;
|
break;
|
||||||
const QVector<QPointF> advances = font.advancesForGlyphIndexes(indices);
|
const QVector<QPointF> advances = font.advancesForGlyphIndexes(indices);
|
||||||
QVector<QPointF> positions;
|
QVector<QPointF> positions;
|
||||||
QPointF totalAdvance;
|
QPointF totalAdvance;
|
||||||
@@ -110,7 +115,7 @@ static QPixmap generateFontImage(const QFileInfo &info, const QSize &size)
|
|||||||
gr.setPositions(positions);
|
gr.setPositions(positions);
|
||||||
QRectF bounds = gr.boundingRect();
|
QRectF bounds = gr.boundingRect();
|
||||||
if (bounds.width() <= 0 || bounds.height() <= 0)
|
if (bounds.width() <= 0 || bounds.height() <= 0)
|
||||||
return pixmap;
|
break;
|
||||||
|
|
||||||
bounds.moveCenter({size.width() / 2., size.height() / 2.});
|
bounds.moveCenter({size.width() / 2., size.height() / 2.});
|
||||||
|
|
||||||
@@ -132,6 +137,10 @@ static QPixmap generateFontImage(const QFileInfo &info, const QSize &size)
|
|||||||
painter.drawGlyphRun(bounds.bottomLeft(), gr);
|
painter.drawGlyphRun(bounds.bottomLeft(), gr);
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!done)
|
||||||
|
pixmap = defaultPixmapForType("font", size);
|
||||||
|
|
||||||
fontImageCache[key] = pixmap;
|
fontImageCache[key] = pixmap;
|
||||||
}
|
}
|
||||||
return fontImageCache[key];
|
return fontImageCache[key];
|
||||||
@@ -163,6 +172,10 @@ public:
|
|||||||
pixmap.load(info.absoluteFilePath());
|
pixmap.load(info.absoluteFilePath());
|
||||||
else if (supportedFontSuffixes().contains(suffix))
|
else if (supportedFontSuffixes().contains(suffix))
|
||||||
pixmap = generateFontImage(info, iconSize);
|
pixmap = generateFontImage(info, iconSize);
|
||||||
|
else if (supportedAudioSuffixes().contains(suffix))
|
||||||
|
pixmap = defaultPixmapForType("sound", iconSize);
|
||||||
|
else if (supportedShaderSuffixes().contains(suffix))
|
||||||
|
pixmap = defaultPixmapForType("shader", iconSize);
|
||||||
|
|
||||||
if (pixmap.isNull())
|
if (pixmap.isNull())
|
||||||
return QFileIconProvider::icon(info);
|
return QFileIconProvider::icon(info);
|
||||||
@@ -176,8 +189,13 @@ public:
|
|||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generated icon sizes should match ItemLibraryResourceView needed icon sizes
|
// Generated icon sizes should contain all ItemLibraryResourceView needed icon sizes, and their
|
||||||
QList<QSize> iconSizes = {{192, 192}, {128, 128}, {96, 96}, {48, 48}, {32, 32}};
|
// x2 versions for HDPI sceens
|
||||||
|
QList<QSize> iconSizes = {{384, 384}, {192, 192}, // Large
|
||||||
|
{256, 256}, {128, 128}, // Drag
|
||||||
|
{96, 96}, // Medium
|
||||||
|
{48, 48}, // Small
|
||||||
|
{64, 64}, {32, 32}}; // List
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
After Width: | Height: | Size: 238 B |
After Width: | Height: | Size: 287 B |
After Width: | Height: | Size: 339 B |
After Width: | Height: | Size: 190 B |
After Width: | Height: | Size: 755 B |
After Width: | Height: | Size: 193 B |
After Width: | Height: | Size: 203 B |
After Width: | Height: | Size: 220 B |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 499 B |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 773 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 640 B |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 895 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.7 KiB |
@@ -5,5 +5,29 @@
|
|||||||
<file>images/item-default-icon@2x.png</file>
|
<file>images/item-default-icon@2x.png</file>
|
||||||
<file>images/item-3D_model-icon.png</file>
|
<file>images/item-3D_model-icon.png</file>
|
||||||
<file>images/item-3D_model-icon@2x.png</file>
|
<file>images/item-3D_model-icon@2x.png</file>
|
||||||
|
<file>images/asset_font_32.png</file>
|
||||||
|
<file>images/asset_font_48.png</file>
|
||||||
|
<file>images/asset_font_64.png</file>
|
||||||
|
<file>images/asset_font_96.png</file>
|
||||||
|
<file>images/asset_font_128.png</file>
|
||||||
|
<file>images/asset_font_192.png</file>
|
||||||
|
<file>images/asset_font_256.png</file>
|
||||||
|
<file>images/asset_font_384.png</file>
|
||||||
|
<file>images/asset_shader_32.png</file>
|
||||||
|
<file>images/asset_shader_48.png</file>
|
||||||
|
<file>images/asset_shader_64.png</file>
|
||||||
|
<file>images/asset_shader_96.png</file>
|
||||||
|
<file>images/asset_shader_128.png</file>
|
||||||
|
<file>images/asset_shader_192.png</file>
|
||||||
|
<file>images/asset_shader_256.png</file>
|
||||||
|
<file>images/asset_shader_384.png</file>
|
||||||
|
<file>images/asset_sound_32.png</file>
|
||||||
|
<file>images/asset_sound_48.png</file>
|
||||||
|
<file>images/asset_sound_64.png</file>
|
||||||
|
<file>images/asset_sound_96.png</file>
|
||||||
|
<file>images/asset_sound_128.png</file>
|
||||||
|
<file>images/asset_sound_192.png</file>
|
||||||
|
<file>images/asset_sound_256.png</file>
|
||||||
|
<file>images/asset_sound_384.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|