Image ProjectExporter::getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const
{
    Drawable* im = nullptr;

    ScopedPointer<Drawable> im1 (getSmallIcon());
    ScopedPointer<Drawable> im2 (getBigIcon());

    if (im1 != nullptr && im2 != nullptr)
    {
        if (im1->getWidth() >= size && im2->getWidth() >= size)
            im = im1->getWidth() < im2->getWidth() ? im1 : im2;
        else if (im1->getWidth() >= size)
            im = im1;
        else if (im2->getWidth() >= size)
            im = im2;
    }
    else
    {
        im = im1 != nullptr ? im1 : im2;
    }

    if (im == nullptr)
        return Image();

    if (returnNullIfNothingBigEnough && im->getWidth() < size && im->getHeight() < size)
        return Image();

    return rescaleImageForIcon (*im, size);
}
Exemple #2
0
QPixmap * KviIconManager::getImage(const QString & szId, bool bCanBeNumber, QString * pszRetPath)
{
	if(szId.isEmpty())
		return NULL;

	if(bCanBeNumber)
	{
		bool bOk;
		int iIdx = szId.toInt(&bOk);
		if(bOk)
		{
			// was a number : this is not a filename
			if(iIdx >= 0)
				return getSmallIcon(iIdx % KviIconManager::IconCount);
		} else {
			if(szId.startsWith("$icon"))
			{
				QString szTmp = szId.trimmed();
				szTmp.replace("$icon(","");
				szTmp.replace(")","");
				szTmp = szTmp.trimmed();
				szTmp.replace("\"","");
				iIdx = getSmallIconIdFromName(szTmp.trimmed());
				if(iIdx >= 0)
					return getSmallIcon(iIdx % KviIconManager::IconCount);
				
			}
		}
	}

	KviCachedPixmap * pCache = getPixmapWithCache(szId);
	if(!pCache)
		return NULL;

	if(pszRetPath)
		*pszRetPath = pCache->path();

	return pCache->pixmap();
}
Exemple #3
0
QPixmap * KviIconManager::getBigIcon(const QString & szName)
{
	QPixmap * pPix = getPixmap(szName);
	if(pPix)
		return pPix;

	bool bOk;
	int iIdx = szName.toInt(&bOk);
	if(bOk && (iIdx >= 0))
	{
		// was a number : this is not a filename
		// it was a small icon: scale it and cache it
		QString szTmpName = szName;
		szTmpName += ".scaled16to32";
		pPix = getPixmap(szTmpName);
		if(pPix)
			return pPix;
		pPix = getSmallIcon(iIdx % KviIconManager::IconCount);
		if(pPix)
		{
			QImage tmp = pPix->toImage();
			QImage tmp2 = tmp.scaled(32,32,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
			QPixmap * pPix2 = new QPixmap();
			*pPix2 = QPixmap::fromImage(tmp2);
			KviCachedPixmap * pCache = new KviCachedPixmap(pPix2,QString());
			addToCache(szTmpName,pCache);
			return pCache->pixmap();
		}
	}

	pPix = getPixmap("kvi_bigicon_unknown.png");
	if(pPix)
		return pPix;
	KviCachedPixmap * pCache = new KviCachedPixmap(new QPixmap(32,32),QString());
	addToCache(szName,pCache);
	return pCache->pixmap();
}