1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #include "arrowchooser.h"
8 
9 #include <QImage>
10 #include <QPalette>
11 #include <QPixmap>
12 
13 #include "commonstrings.h"
14 #include "fpointarray.h"
15 #include "scpainter.h"
16 #include "scribusstructs.h"
17 #include "util_math.h"
18 
ArrowChooser(QWidget * pa,ArrowDirection direction)19 ArrowChooser::ArrowChooser(QWidget* pa, ArrowDirection direction) : QComboBox(pa)
20 {
21 	setEditable(false);
22 	clear();
23 	setIconSize(QSize(22, 22));
24 	addItem(CommonStrings::tr_None);
25 	setArrowDirection(direction);
26 }
27 
setArrowDirection(ArrowDirection direction)28 void ArrowChooser::setArrowDirection(ArrowDirection direction)
29 {
30 	m_arrowDirection = direction;
31 }
32 
rebuildList(QList<ArrowDesc> * arrowStyles)33 void ArrowChooser::rebuildList(QList<ArrowDesc> *arrowStyles)
34 {
35 	FPointArray path;
36 
37 	clear();
38 
39 	const QPalette& pal = this->palette();
40 	QColor textColor = pal.color(QPalette::Active, QPalette::Text);
41 
42 	addItem(CommonStrings::tr_None);
43 	for (int i = 0; i < arrowStyles->count(); ++i)
44 	{
45 		QImage image(22, 22, QImage::Format_ARGB32_Premultiplied);
46 		image.fill(0);
47 		ScPainter *painter = new ScPainter(&image, 22, 22);
48 //		painter->clear();
49 		painter->setBrush(textColor);
50 		painter->setPen(textColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
51 		painter->setFillMode(ScPainter::Solid);
52 		painter->translate(3.0, 3.0);
53 		path.resize(0);
54 		path = arrowStyles->at(i).points.copy();
55 		FPoint min = getMinClipF(&path);
56 		path.translate(-min.x(), -min.y());
57 		FPoint max = path.widthHeight();
58 		QTransform mm;
59 		QTransform mm2;
60 		if (m_arrowDirection == ArrowDirection::StartArrow)
61 		{
62 			mm2.scale(-1, 1);
63 			mm2.translate(-max.x(), 0);
64 		}
65 		mm.scale(16.0 / qMax(max.x(), max.y()), 16.0 / qMax(max.x(), max.y()));
66 		path.map(mm2 * mm);
67 		painter->setupPolygon(&path);
68 		painter->drawPolygon();
69 		painter->drawPolyLine();
70 		painter->end();
71 		delete painter;
72 /*		int wi = image.width();
73 		int hi = image.height();
74 		for( int yi=0; yi < hi; ++yi )
75 		{
76 			QRgb *s = (QRgb*)(image.scanLine( yi ));
77 			for(int xi=0; xi < wi; ++xi )
78 			{
79 				if ((*s) == 0xffffffff)
80 					(*s) &= 0x00ffffff;
81 				s++;
82 			}
83 		} */
84 		QPixmap ico = QPixmap::fromImage(image);
85 		addItem(ico, arrowStyles->at(i).name);
86 	}
87 }
88