Rev 3328 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1770 | cbradney | 1 | #include <qimage.h> |
2 | #include <qlayout.h> |
||
3 | #include <qpopupmenu.h> |
||
4 | #include <qpixmap.h> |
||
5 | #include <qbuttongroup.h> |
||
6 | |||
7 | #include "autoformbuttongroup.h" |
||
8 | #include "autoformbuttongroup.moc" |
||
9 | #include "fpointarray.h" |
||
10 | #include "scpainter.h" |
||
11 | |||
12 | AutoformButtonGroup::AutoformButtonGroup( QWidget* parent ) : QButtonGroup( parent, "autoformbuttongroup" ) |
||
13 | { |
||
14 | this->setExclusive( true ); |
||
15 | this->setColumnLayout(0, Qt::Vertical ); |
||
16 | this->layout()->setSpacing( 0 ); |
||
17 | this->layout()->setMargin( 0 ); |
||
18 | buttonGroup1Layout = new QGridLayout( this->layout() ); |
||
19 | buttonGroup1Layout->setAlignment( Qt::AlignTop ); |
||
20 | toolButton1 = new QToolButton( this, "toolButton1" ); |
||
21 | toolButton1->setToggleButton( true ); |
||
22 | toolButton1->setPixmap(getIconPixmap(0)); |
||
23 | buttonGroup1Layout->addWidget( toolButton1, 0, 0 ); |
||
24 | toolButton2 = new QToolButton( this, "toolButton2" ); |
||
25 | toolButton2->setToggleButton( true ); |
||
26 | toolButton2->setPixmap(getIconPixmap(1)); |
||
27 | buttonGroup1Layout->addWidget( toolButton2, 0, 1 ); |
||
28 | toolButton3 = new QToolButton( this, "toolButton3" ); |
||
29 | toolButton3->setToggleButton( true ); |
||
30 | toolButton3->setPixmap(getIconPixmap(2)); |
||
31 | buttonGroup1Layout->addWidget( toolButton3, 0, 2 ); |
||
32 | toolButton4 = new QToolButton( this, "toolButton4" ); |
||
33 | toolButton4->setToggleButton( true ); |
||
34 | toolButton4->setPixmap(getIconPixmap(3)); |
||
35 | buttonGroup1Layout->addWidget( toolButton4, 0, 3 ); |
||
36 | |||
37 | toolButton5 = new QToolButton( this, "toolButton3" ); |
||
38 | toolButton5->setToggleButton( true ); |
||
39 | toolButton5->setPixmap(getIconPixmap(4)); |
||
40 | buttonGroup1Layout->addWidget( toolButton5, 1, 0 ); |
||
41 | toolButton6 = new QToolButton( this, "toolButton4" ); |
||
42 | toolButton6->setToggleButton( true ); |
||
43 | toolButton6->setPixmap(getIconPixmap(5)); |
||
44 | buttonGroup1Layout->addWidget( toolButton6, 1, 1 ); |
||
45 | toolButton7 = new QToolButton( this, "toolButton3" ); |
||
46 | toolButton7->setToggleButton( true ); |
||
47 | toolButton7->setPixmap(getIconPixmap(6)); |
||
48 | buttonGroup1Layout->addWidget( toolButton7, 1, 2 ); |
||
49 | toolButton8 = new QToolButton( this, "toolButton4" ); |
||
50 | toolButton8->setToggleButton( true ); |
||
51 | toolButton8->setPixmap(getIconPixmap(7)); |
||
52 | buttonGroup1Layout->addWidget( toolButton8, 1, 3 ); |
||
53 | |||
54 | toolButton9 = new QToolButton( this, "toolButton4" ); |
||
55 | toolButton9->setToggleButton( true ); |
||
56 | toolButton9->setPixmap(getIconPixmap(8)); |
||
57 | buttonGroup1Layout->addWidget( toolButton9, 2, 0 ); |
||
58 | toolButton10 = new QToolButton( this, "toolButton4" ); |
||
59 | toolButton10->setToggleButton( true ); |
||
60 | toolButton10->setPixmap(getIconPixmap(9)); |
||
61 | buttonGroup1Layout->addWidget( toolButton10, 2, 1 ); |
||
62 | toolButton11 = new QToolButton( this, "toolButton4" ); |
||
63 | toolButton11->setToggleButton( true ); |
||
64 | toolButton11->setPixmap(getIconPixmap(10)); |
||
65 | buttonGroup1Layout->addWidget( toolButton11, 2, 2 ); |
||
66 | toolButton12 = new QToolButton( this, "toolButton4" ); |
||
67 | toolButton12->setToggleButton( true ); |
||
68 | toolButton12->setPixmap(getIconPixmap(11)); |
||
69 | buttonGroup1Layout->addWidget( toolButton12, 2, 3 ); |
||
70 | |||
71 | toolButton13 = new QToolButton( this, "toolButton4" ); |
||
72 | toolButton13->setToggleButton( true ); |
||
73 | toolButton13->setPixmap(getIconPixmap(12)); |
||
74 | buttonGroup1Layout->addWidget( toolButton13, 3, 0 ); |
||
75 | toolButton14 = new QToolButton( this, "toolButton4" ); |
||
76 | toolButton14->setToggleButton( true ); |
||
77 | toolButton14->setPixmap(getIconPixmap(13)); |
||
78 | buttonGroup1Layout->addWidget( toolButton14, 3, 1 ); |
||
79 | toolButton15 = new QToolButton( this, "toolButton4" ); |
||
80 | toolButton15->setToggleButton( true ); |
||
81 | toolButton15->setPixmap(getIconPixmap(14)); |
||
82 | buttonGroup1Layout->addWidget( toolButton15, 3, 2 ); |
||
83 | toolButton16 = new QToolButton( this, "toolButton4" ); |
||
84 | toolButton16->setToggleButton( true ); |
||
85 | toolButton16->setPixmap(getIconPixmap(15)); |
||
86 | buttonGroup1Layout->addWidget( toolButton16, 3, 3 ); |
||
87 | |||
88 | toolButton17 = new QToolButton( this, "toolButton4" ); |
||
89 | toolButton17->setToggleButton( true ); |
||
90 | toolButton17->setPixmap(getIconPixmap(16)); |
||
91 | buttonGroup1Layout->addWidget( toolButton17, 4, 0 ); |
||
92 | toolButton18 = new QToolButton( this, "toolButton4" ); |
||
93 | toolButton18->setToggleButton( true ); |
||
94 | toolButton18->setPixmap(getIconPixmap(17)); |
||
95 | buttonGroup1Layout->addWidget( toolButton18, 4, 1 ); |
||
96 | |||
97 | connect(this, SIGNAL(clicked(int)), this, SLOT(selForm(int))); |
||
98 | |||
99 | } |
||
100 | |||
101 | double* AutoformButtonGroup::getShapeData(int a, int *n) |
||
102 | { |
||
103 | double *vals; |
||
104 | static double AutoShapes0[] = {0.0, 0.0, 0.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, |
||
105 | 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 0.0, 100.0, |
||
106 | 0.0, 100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0}; |
||
107 | static double AutoShapes1[] = {100.0, 50.0, 100.0, 77.615235, 50.0, 100.0, |
||
108 | 77.615235, 100.0, 50.0, 100.0, |
||
109 | 22.385765, 100.0, |
||
110 | 0.0, 50.0, 0.0, 77.615235, 0.0, 50.0, 0.0, 22.385765, 50.0, 0.0, |
||
111 | 22.385765, 0.0, |
||
112 | 50.0, 0.0, 77.615235, 0.0, 100.0, 50.0, 100.0, 22.385765}; |
||
113 | static double AutoShapes2[] = {0.0, 0.0, 0.0, 0.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, |
||
114 | 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0}; |
||
115 | static double AutoShapes3[] = {0.0, 25.0, 0.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0, |
||
116 | 25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 75.0, 0.0, 75.0, 0.0, |
||
117 | 75.0, 0.0, 75.0, 0.0, 75.0, 25.0, 75.0, 25.0, 75.0, 25.0, 75.0, 25.0, |
||
118 | 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 75.0, 100.0, 75.0, |
||
119 | 100.0, 75.0, 100.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, |
||
120 | 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 25.0, 100.0, 25.0, 100.0, |
||
121 | 25.0, 100.0, 25.0, 100.0, 25.0, 75.0, 25.0, 75.0, 25.0, 75.0, 25.0, 75.0, |
||
122 | 0.0, 75.0, 0.0, 75.0, 0.0, 75.0, 0.0, 75.0, 0.0, 25.0, 0.0, 25.0}; |
||
123 | static double AutoShapes4[] = {0.0, 50.0, 0.0, 50.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, |
||
124 | 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 100.0, 25.0, 100.0, 25.0, |
||
125 | 100.0, 25.0, 100.0, 25.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0, |
||
126 | 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 100.0, 50.0, 100.0, |
||
127 | 50.0, 100.0, 50.0, 100.0, 0.0, 50.0, 0.0, 50.0}; |
||
128 | static double AutoShapes5[] = {0.0, 25.0, 0.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, |
||
129 | 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 100.0, 50.0, 100.0, 50.0, |
||
130 | 100.0, 50.0, 100.0, 50.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, |
||
131 | 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 0.0, 75.0, 0.0, 75.0, |
||
132 | 0.0, 75.0, 0.0, 75.0, 0.0, 25.0, 0.0, 25.0}; |
||
133 | static double AutoShapes6[] = {0.0, 50.0, 0.0, 50.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, |
||
134 | 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 75.0, 50.0, 75.0, 50.0, |
||
135 | 75.0, 50.0, 75.0, 50.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, 75.0, 100.0, |
||
136 | 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 50.0, 25.0, 50.0, |
||
137 | 25.0, 50.0, 25.0, 50.0, 0.0, 50.0, 0.0, 50.0}; |
||
138 | static double AutoShapes7[] = {0.0, 50.0, 0.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, 25.0, 50.0, |
||
139 | 25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 25.0, 0.0, 75.0, 0.0, 75.0, 0.0, |
||
140 | 75.0, 0.0, 75.0, 0.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, 75.0, 50.0, |
||
141 | 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 50.0, 100.0, 50.0, 100.0, |
||
142 | 50.0, 100.0, 50.0, 100.0, 0.0, 50.0, 0.0, 50.0}; |
||
143 | static double AutoShapes8[] = {0.0, 50.0, 0.0, 22.385765, 100.0, 0.0, 44.77716, 0.0, 100.0, 0.0, 100.0, 0.0, |
||
144 | 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 44.77716, 100.0, 0.0, 50.0, |
||
145 | 0.0, 77.615235}; |
||
146 | static double AutoShapes9[] = {100.0, 50.0, 100.0, 77.615235, 0.0, 100.0, |
||
147 | 55.22284, 100.0, 0.0, 100.0, 0.0, 100.0, |
||
148 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 55.22281, 0.0, 100.0, 50.0, 100.0, 22.385765}; |
||
149 | static double AutoShapes10[] = {100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 0.0, |
||
150 | 100.0, 0.0, 100.0, 0.0, 44.7715, |
||
151 | 50.0, 0.0, 22.3858, 0.0, 50.0, 0.0, 77.6152, 0.0, 100.0, 100.0, 100.0, |
||
152 | 44.7715}; |
||
153 | static double AutoShapes11[] = {100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 55.2285, 50.0, 100.0, |
||
154 | 22.3858, 100.0, 50.0, 100.0, 77.6152, 100.0, 100.0, 0.0, 100.0, 55.2285}; |
||
155 | static double AutoShapes12[] = {0.0, 50.0, 0.0, 50.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, |
||
156 | 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 0.0, 50.0, 0.0, 50.0}; |
||
157 | static double AutoShapes13[] = {0.0, 0.0, 0.0, 0.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, |
||
158 | 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0}; |
||
159 | static double AutoShapes14[] = {0.0, 100.0, 0.0, 100.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, 50.0, 0.0, |
||
160 | 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 0.0, 100.0}; |
||
161 | static double AutoShapes15[] = {0.0, 0.0, 0.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, |
||
162 | 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 50.0, 100.0, 0.0, 0.0, 0.0, 0.0}; |
||
163 | static double AutoShapes16[] = {25.0, 0.0, 25.0, 0.0, 75.0, 0.0, 75.0, 0.0, 75.0, 0.0, 75.0, 13.8071, |
||
164 | 100.0, 25.0, 86.1929, 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 75.0, 100.0, 75.0, |
||
165 | 100.0, 75.0, 86.1929, 75.0, 75.0, 100.0, 75.0, 86.1929, 75.0, 100.0, 75.0, 100.0, |
||
166 | 25.0, 100.0, 25.0, 100.0, 25.0, 100.0, 25.0, 86.1929, 0.0, 75.0, 13.8071, 75.0, |
||
167 | 0.0, 75.0, 0.0, 75.0, 0.0, 25.0, 0.0, 25.0, 0.0, 25.0, 13.8071, 25.0, |
||
168 | 25.0, 0.0, 25.0, 13.8071}; |
||
169 | static double AutoShapes17[] = {100.0, 50.0, 100.0, 77.6152, 50.0, 100.0, 77.6152, 100.0, 50.0, 100.0, 22.3858, 100.0, |
||
170 | 0.0, 50.0, 0.0, 77.6152, 0.0, 50.0, 0.0, 22.3858, 50.0, 0.0, 22.3858, 0.0, |
||
171 | 50.0, 0.0, 77.6152, 0.0, 100.0, 50.0, 100.0, 22.3858, -1.0, -1.0, -1.0, -1.0, |
||
172 | 75.0, 50.0, 75.0, 63.8076, 50.0, 75.0, 63.8076, 75.0, 50.0, 75.0, 36.1929, 75.0, |
||
173 | 25.0, 50.0, 25.0, 63.8076, 25.0, 50.0, 25.0, 36.1929, 50.0, 25.0, 36.1929, 25.0, |
||
174 | 50.0, 25.0, 63.8076, 25.0, 75.0, 50.0, 75.0, 36.1929}; |
||
175 | switch (a) |
||
176 | { |
||
177 | case 0: |
||
178 | *n = 32; |
||
179 | vals = AutoShapes0; |
||
180 | break; |
||
181 | case 1: |
||
182 | *n = 32; |
||
183 | vals = AutoShapes1; |
||
184 | break; |
||
185 | case 2: |
||
186 | *n = 24; |
||
187 | vals = AutoShapes2; |
||
188 | break; |
||
189 | case 3: |
||
190 | *n = 96; |
||
191 | vals = AutoShapes3; |
||
192 | break; |
||
193 | case 4: |
||
194 | *n = 56; |
||
195 | vals = AutoShapes4; |
||
196 | break; |
||
197 | case 5: |
||
198 | *n = 56; |
||
199 | vals = AutoShapes5; |
||
200 | break; |
||
201 | case 6: |
||
202 | *n = 56; |
||
203 | vals = AutoShapes6; |
||
204 | break; |
||
205 | case 7: |
||
206 | *n = 56; |
||
207 | vals = AutoShapes7; |
||
208 | break; |
||
209 | case 8: |
||
210 | *n = 24; |
||
211 | vals = AutoShapes8; |
||
212 | break; |
||
213 | case 9: |
||
214 | *n = 24; |
||
215 | vals = AutoShapes9; |
||
216 | break; |
||
217 | case 10: |
||
218 | *n = 24; |
||
219 | vals = AutoShapes10; |
||
220 | break; |
||
221 | case 11: |
||
222 | *n = 24; |
||
223 | vals = AutoShapes11; |
||
224 | break; |
||
225 | case 12: |
||
226 | *n = 24; |
||
227 | vals = AutoShapes12; |
||
228 | break; |
||
229 | case 13: |
||
230 | *n = 24; |
||
231 | vals = AutoShapes13; |
||
232 | break; |
||
233 | case 14: |
||
234 | *n = 24; |
||
235 | vals = AutoShapes14; |
||
236 | break; |
||
237 | case 15: |
||
238 | *n = 24; |
||
239 | vals = AutoShapes15; |
||
240 | break; |
||
241 | case 16: |
||
242 | *n = 64; |
||
243 | vals = AutoShapes16; |
||
244 | break; |
||
245 | case 17: |
||
246 | *n = 68; |
||
247 | vals = AutoShapes17; |
||
248 | break; |
||
249 | } |
||
250 | return vals; |
||
251 | } |
||
252 | |||
253 | void AutoformButtonGroup::selForm(int a) |
||
254 | { |
||
255 | int n; |
||
256 | |||
257 | double* AutoShapes; |
||
258 | AutoShapes = getShapeData(a, &n); |
||
259 | emit FormSel(a, n, AutoShapes); |
||
260 | } |
||
261 | |||
262 | QPixmap AutoformButtonGroup::getIconPixmap(int nr) |
||
263 | { |
||
264 | int count = 0; |
||
265 | double* AutoShapes; |
||
266 | FPointArray Path; |
||
267 | QPixmap Ico(22, 22); |
||
268 | Path.resize(0); |
||
269 | AutoShapes = getShapeData(nr, &count); |
||
270 | for (int a = 0; a < count-3; a += 4) |
||
271 | { |
||
272 | if (AutoShapes[a] < 0) |
||
273 | { |
||
274 | Path.setMarker(); |
||
275 | continue; |
||
276 | } |
||
277 | double x1 = 16 * AutoShapes[a] / 100.0; |
||
278 | double y1 = 16 * AutoShapes[a+1] / 100.0; |
||
279 | double x2 = 16 * AutoShapes[a+2] / 100.0; |
||
280 | double y2 = 16 * AutoShapes[a+3] / 100.0; |
||
281 | Path.addPoint(x1, y1); |
||
282 | Path.addPoint(x2, y2); |
||
283 | } |
||
284 | ScPainter *painter = new ScPainter(&Ico, 22, 22); |
||
285 | painter->setBrush(qRgb(230, 230, 230)); |
||
286 | painter->setPen(qRgb(0, 0, 0)); |
||
287 | painter->setFillMode(1); |
||
288 | painter->translate(3.0, 3.0); |
||
289 | painter->setupPolygon(&Path); |
||
290 | painter->setLineWidth(1.0); |
||
291 | painter->drawPolygon(); |
||
292 | painter->drawPolyLine(); |
||
293 | painter->end(); |
||
294 | delete painter; |
||
295 | QImage image; |
||
296 | image = Ico.convertToImage(); |
||
297 | image = image.convertDepth(32); |
||
298 | image.setAlphaBuffer(true); |
||
299 | int wi = image.width(); |
||
300 | int hi = image.height(); |
||
301 | for( int yi=0; yi < hi; ++yi ) |
||
302 | { |
||
303 | QRgb *s = (QRgb*)(image.scanLine( yi )); |
||
304 | for(int xi=0; xi < wi; ++xi ) |
||
305 | { |
||
306 | if((*s) == 0xffffffff) |
||
307 | (*s) &= 0x00ffffff; |
||
308 | s++; |
||
309 | } |
||
310 | } |
||
311 | Ico.convertFromImage(image); |
||
312 | return Ico; |
||
313 | } |