mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Use a better scoped singleton
This commit is contained in:
parent
7684f4fdcf
commit
fd02b83b47
@ -9,9 +9,9 @@
|
|||||||
Loading the sprites atlas image must be deferred until all image plugins
|
Loading the sprites atlas image must be deferred until all image plugins
|
||||||
are loaded, otherwise reading the image will cause a deadlock!
|
are loaded, otherwise reading the image will cause a deadlock!
|
||||||
*/
|
*/
|
||||||
static const QImage *atlas(const QString &fileName)
|
static const QImage &atlas(const QString &fileName)
|
||||||
{
|
{
|
||||||
static QImage *img = new QImage(fileName);
|
static QImage img(fileName);
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,18 +86,18 @@ QImage Sprites::icon(const QString &name) const
|
|||||||
if (_imageFile.isEmpty())
|
if (_imageFile.isEmpty())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
const QImage *img = atlas(_imageFile);
|
const QImage &img = atlas(_imageFile);
|
||||||
if (img->isNull())
|
if (img.isNull())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
QMap<QString, Sprite>::const_iterator it = _sprites.find(name);
|
QMap<QString, Sprite>::const_iterator it = _sprites.find(name);
|
||||||
if (it == _sprites.constEnd())
|
if (it == _sprites.constEnd())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
if (!img->rect().contains(it->rect()))
|
if (!img.rect().contains(it->rect()))
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
QImage ret(img->copy(it->rect()));
|
QImage ret(img.copy(it->rect()));
|
||||||
ret.setDevicePixelRatio(it->pixelRatio());
|
ret.setDevicePixelRatio(it->pixelRatio());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user