Exemple #1
0
void ArrowChooser::rebuildList(QList<ArrowDesc> *arrowStyles)
{
	clear();
	FPointArray Path;
	Path.resize(0);
	addItem(CommonStrings::tr_None);
	for (int a = 0; a < arrowStyles->count(); ++a)
	{
		QImage image(22, 22, QImage::Format_ARGB32);
		ScPainter *painter = new ScPainter(&image, 22, 22);
		painter->clear();
		painter->setBrush(qRgb(0, 0, 0));
		painter->setPen(qRgb(0, 0, 0));
		painter->setFillMode(1);
		painter->translate(3.0, 3.0);
		Path.resize(0);
		Path = arrowStyles->at(a).points.copy();
		FPoint min = getMinClipF(&Path);
		Path.translate(-min.x(), -min.y());
		FPoint max = Path.WidthHeight();
		QMatrix mm;
		QMatrix mm2;
		if (arrowDirection)
		{
			mm2.scale(-1, 1);
			mm2.translate(-max.x(), 0);
		}
		mm.scale(16.0 / qMax(max.x(), max.y()), 16.0 / qMax(max.x(), max.y()));
		Path.map(mm2 * mm);
		painter->setupPolygon(&Path);
		painter->setLineWidth(1.0);
		painter->drawPolygon();
		painter->drawPolyLine();
		painter->end();
		delete painter;
		int wi = image.width();
		int hi = image.height();
    	for( int yi=0; yi < hi; ++yi )
		{
			QRgb *s = (QRgb*)(image.scanLine( yi ));
			for(int xi=0; xi < wi; ++xi )
			{
				if((*s) == 0xffffffff)
					(*s) &= 0x00ffffff;
				s++;
			}
    	}
    	QPixmap Ico;
		Ico=QPixmap::fromImage(image);
		addItem(Ico, arrowStyles->at(a).name);
	}
}
void ShapeView::updateShapeList()
{
	clear();
	setWordWrap(true);
	for (QHash<QString, shapeData>::Iterator it = m_Shapes.begin(); it != m_Shapes.end(); ++it)
	{
		int w = it.value().width + 4;
		int h = it.value().height + 4;
		QImage Ico(w, h, QImage::Format_ARGB32_Premultiplied);
		Ico.fill(0);
		ScPainter *painter = new ScPainter(&Ico, w, h);
		painter->setBrush(qRgb(0, 0, 0));
		painter->setPen(qRgb(0, 0, 0), 1.0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
		painter->setFillMode(ScPainter::Solid);
		painter->setStrokeMode(ScPainter::Solid);
		painter->translate(2.0, 2.0);
		painter->setupPolygon(&it.value().path);
		painter->drawPolygon();
		painter->end();
		delete painter;
		QPixmap pm;
		if (w >= h)
			pm = QPixmap::fromImage(Ico.scaledToWidth(48, Qt::SmoothTransformation));
		else
			pm = QPixmap::fromImage(Ico.scaledToHeight(48, Qt::SmoothTransformation));
		QPixmap pm2(48, 48);
		pm2.fill(palette().color(QPalette::Base));
		QPainter p;
		p.begin(&pm2);
		p.drawPixmap(24 - pm.width() / 2, 24 - pm.height() / 2, pm);
		p.end();
		QListWidgetItem *item = new QListWidgetItem(pm2, it.value().name, this);
		item->setData(Qt::UserRole, it.key());
		item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
	}
}