Exemple #1
0
QPixmap * getWidePixmap(QColor rgb)
{
	static ScPixmapCache<QRgb> pxCache;

	QRgb index=rgb.rgb();
	if (pxCache.contains(index))
		return pxCache[index];

	QPixmap *pm = new QPixmap(30, 15);
	pm->fill(rgb);
	pxCache.insert(index, pm);
	return pm;
}
Exemple #2
0
QPixmap * getFancyPixmap(const ScColor& col, ScribusDoc* doc)
{
	static ScPixmapCache<quint64> pxCache;

	static QPixmap alertIcon;
	static QPixmap cmykIcon;
	static QPixmap rgbIcon;
	static QPixmap labIcon;
	static QPixmap spotIcon;
	static QPixmap regIcon;
	static bool iconsInitialized = false;

	if ( !iconsInitialized )
	{
		IconManager* im=IconManager::instance();
		alertIcon = im->loadPixmap("alert.png");
		cmykIcon = im->loadPixmap("cmyk.png");
		rgbIcon = im->loadPixmap("rgb.png");
		labIcon = im->loadPixmap("lab.png");
		spotIcon = im->loadPixmap("spot.png");
		regIcon = im->loadPixmap("register.png");
		iconsInitialized = true;
	}

	quint64 res = code64(col);
	if (pxCache.contains(res))
		return pxCache[res];

	QPixmap *pa = new QPixmap(60, 15);
	QPixmap *pm = getSmallPixmap(ScColorEngine::getDisplayColor(col, doc));
//	QPixmap *pm=getSmallPixmap(col.getRawRGBColor());
	pa->fill(Qt::white);
	paintAlert(*pm, *pa, 0, 0);
	if (ScColorEngine::isOutOfGamut(col, doc))
		paintAlert(alertIcon, *pa, 15, 0);
	if (col.getColorModel() == colorModelCMYK)   // || (col.isSpotColor()))
		paintAlert(cmykIcon, *pa, 30, 0);
	else if (col.getColorModel() == colorModelRGB)
		paintAlert(rgbIcon, *pa, 30, 0);
	else if (col.getColorModel() == colorModelLab)
		paintAlert(labIcon, *pa, 30, 0);
	if (col.isSpotColor())
		paintAlert(spotIcon, *pa, 46, 2);
	if (col.isRegistrationColor())
		paintAlert(regIcon, *pa, 45, 0);
	pxCache.insert(res, pa);
	return pa;
}
Exemple #3
0
/**
 * QPixmaps are really slow with Qt/Mac 3.3.4. Really, *really*, slow.
 * So we better cache them.
 */
QPixmap * getSmallPixmap(QColor rgb)
{
	static ScPixmapCache<QRgb> pxCache;

	QRgb index=rgb.rgb();
	if (pxCache.contains(index))
		return pxCache[index];

	QPixmap *pm = new QPixmap(15, 15);
	pm->fill(rgb);
	QPainter p;
	p.begin(pm);
	p.setBrush(Qt::NoBrush);
	QPen b(Qt::black, 1);
	p.setPen(b);
	p.drawRect(0, 0, 15, 15);
	p.end();
	pxCache.insert(index, pm);
	return pm;
}
Exemple #4
0
QPixmap loadIcon(const QString nam, bool forceUseColor)
{
	static ScPixmapCache<QString> pxCache;
	if (pxCache.contains(nam))
		return *pxCache[nam];

	QString iconFilePath(QString("%1%2").arg(ScPaths::instance().iconDir()).arg(nam));
	QPixmap *pm = new QPixmap();
	
	if (!QFile::exists(iconFilePath))
		qWarning("Unable to load icon %s: File not found", iconFilePath.toLatin1().constData());
	else
	{
		pm->load(iconFilePath);
		if (pm->isNull())
			qWarning("Unable to load icon %s: Got null pixmap", iconFilePath.toLatin1().constData());
		if (PrefsManager::instance()->appPrefs.uiPrefs.grayscaleIcons && !forceUseColor)
			iconToGrayscale(pm);
	}
	pxCache.insert(nam, pm);
	return *pm;
}
Exemple #5
0
QPixmap loadIcon(const QString nam, bool forceUseColor)
{
	static ScPixmapCache<QString> pxCache;
	if (pxCache.contains(nam))
		return *pxCache[nam];

	QString iconFilePath(QString("%1%2").arg(ScPaths::instance().iconDir()).arg(nam));
	QPixmap *pm = new QPixmap();
	
	if (!QFile::exists(iconFilePath))
		qWarning("Unable to load icon %s: File not found", iconFilePath.toAscii().constData());
	else
	{
		pm->load(iconFilePath);
		if (pm->isNull())
			qWarning("Unable to load icon %s: Got null pixmap", iconFilePath.toAscii().constData());
		if (PrefsManager::instance()->appPrefs.grayscaleIcons && !forceUseColor)
		{
			QImage qi(pm->toImage());
			int h=qi.height();
			int w=qi.width();
			QRgb c_rgb;
			for (int i=0;i<w;++i)
			{
				for (int j=0;j<h;++j)
				{
					c_rgb=qi.pixel(i,j);
					int k = qMin(qRound(0.3 * qRed(c_rgb) + 0.59 * qGreen(c_rgb) + 0.11 * qBlue(c_rgb)), 255);
					qi.setPixel(i, j, qRgba(k, k, k, qAlpha(c_rgb)));
				}
			}
			*pm=QPixmap::fromImage(qi);
		}
	}
	pxCache.insert(nam, pm);
	return *pm;
}