]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_widthbox.cpp
GPL compliance check...
[architektonas] / src / widgets / qg_widthbox.cpp
1 // qg_widthbox.cpp
2 //
3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // Portions copyright (C) 2001-2003 RibbonSoft
6 // Copyright (C) 2010 Underground Software
7 // See the README and GPLv2 files for licensing and warranty information
8 //
9 // JLH = James L. Hammons <jlhamm@acm.org>
10 //
11 // Who  When        What
12 // ---  ----------  -----------------------------------------------------------
13 // JLH  05/11/2010  Added this text. :-)
14 //
15
16 #include "qg_widthbox.h"
17
18 #include "rs_debug.h"
19
20 /**
21  * Default Constructor. You must call init manually if you choose
22  * to use this constructor.
23  */
24 QG_WidthBox::QG_WidthBox(QWidget * parent, const char */*name*/): QComboBox(parent)
25 {
26     showByLayer = false;
27     showUnchanged = false;
28     unchanged = false;
29 }
30
31 /**
32  * Constructor that calls init and provides a fully functional
33  * combobox for choosing widths.
34  *
35  * @param showByLayer true: Show attributes ByLayer, ByBlock
36  */
37 QG_WidthBox::QG_WidthBox(bool showByLayer, bool showUnchanged, QWidget * parent, const char */*name*/):
38         QComboBox(parent)
39 {
40     init(showByLayer, showUnchanged);
41 }
42
43 /**
44  * Destructor
45  */
46 QG_WidthBox::~QG_WidthBox()
47 {
48 }
49
50 /**
51  * Initialisation (called from constructor or manually but only
52  * once).
53  *
54  * @param showByLayer true: Show attributes ByLayer, ByBlock
55  */
56 void QG_WidthBox::init(bool showByLayer, bool showUnchanged)
57 {
58         this->showByLayer = showByLayer;
59         this->showUnchanged = showUnchanged;
60
61         if (showUnchanged)
62 //              addItem(QIcon(width00_xpm), tr("- Unchanged -"));
63                 addItem(QIcon(":/res/width00.xpm"), tr("- Unchanged -"));
64
65         if (showByLayer)
66 //              addItem(QIcon(width00_xpm), tr("By Layer"));
67 //              addItem(QIcon(width00_xpm), tr("By Block"));
68                 addItem(QIcon(":/res/width00.xpm"), tr("By Layer"));
69                 addItem(QIcon(":/res/width00.xpm"), tr("By Block"));
70
71 /*      addItem(QIcon(width01_xpm), tr("Default"));
72         addItem(QIcon(width01_xpm), tr("0.00mm"));
73         addItem(QIcon(width01_xpm), tr("0.05mm"));
74         addItem(QIcon(width01_xpm), tr("0.09mm"));
75         addItem(QIcon(width01_xpm), tr("0.13mm (ISO)"));
76         addItem(QIcon(width01_xpm), tr("0.15mm"));
77         addItem(QIcon(width01_xpm), tr("0.18mm (ISO)"));
78         addItem(QIcon(width01_xpm), tr("0.20mm"));
79         addItem(QIcon(width01_xpm), tr("0.25mm (ISO)"));
80         addItem(QIcon(width01_xpm), tr("0.30mm"));
81         addItem(QIcon(width03_xpm), tr("0.35mm (ISO)"));
82         addItem(QIcon(width03_xpm), tr("0.40mm"));
83         addItem(QIcon(width04_xpm), tr("0.50mm (ISO)"));
84         addItem(QIcon(width05_xpm), tr("0.53mm"));
85         addItem(QIcon(width05_xpm), tr("0.60mm"));
86         addItem(QIcon(width06_xpm), tr("0.70mm (ISO)"));
87         addItem(QIcon(width07_xpm), tr("0.80mm"));
88         addItem(QIcon(width08_xpm), tr("0.90mm"));
89         addItem(QIcon(width09_xpm), tr("1.00mm (ISO)"));
90         addItem(QIcon(width10_xpm), tr("1.06mm"));
91         addItem(QIcon(width10_xpm), tr("1.20mm"));
92         addItem(QIcon(width12_xpm), tr("1.40mm (ISO)"));
93         addItem(QIcon(width12_xpm), tr("1.58mm"));
94         addItem(QIcon(width12_xpm), tr("2.00mm (ISO)"));
95         addItem(QIcon(width12_xpm), tr("2.11mm"));*/
96         addItem(QIcon(":/res/width01.xpm"), tr("Default"));
97         addItem(QIcon(":/res/width01.xpm"), tr("0.00mm"));
98         addItem(QIcon(":/res/width01.xpm"), tr("0.05mm"));
99         addItem(QIcon(":/res/width01.xpm"), tr("0.09mm"));
100         addItem(QIcon(":/res/width01.xpm"), tr("0.13mm (ISO)"));
101         addItem(QIcon(":/res/width01.xpm"), tr("0.15mm"));
102         addItem(QIcon(":/res/width01.xpm"), tr("0.18mm (ISO)"));
103         addItem(QIcon(":/res/width01.xpm"), tr("0.20mm"));
104         addItem(QIcon(":/res/width01.xpm"), tr("0.25mm (ISO)"));
105         addItem(QIcon(":/res/width01.xpm"), tr("0.30mm"));
106         addItem(QIcon(":/res/width03.xpm"), tr("0.35mm (ISO)"));
107         addItem(QIcon(":/res/width03.xpm"), tr("0.40mm"));
108         addItem(QIcon(":/res/width04.xpm"), tr("0.50mm (ISO)"));
109         addItem(QIcon(":/res/width05.xpm"), tr("0.53mm"));
110         addItem(QIcon(":/res/width05.xpm"), tr("0.60mm"));
111         addItem(QIcon(":/res/width06.xpm"), tr("0.70mm (ISO)"));
112         addItem(QIcon(":/res/width07.xpm"), tr("0.80mm"));
113         addItem(QIcon(":/res/width08.xpm"), tr("0.90mm"));
114         addItem(QIcon(":/res/width09.xpm"), tr("1.00mm (ISO)"));
115         addItem(QIcon(":/res/width10.xpm"), tr("1.06mm"));
116         addItem(QIcon(":/res/width10.xpm"), tr("1.20mm"));
117         addItem(QIcon(":/res/width12.xpm"), tr("1.40mm (ISO)"));
118         addItem(QIcon(":/res/width12.xpm"), tr("1.58mm"));
119         addItem(QIcon(":/res/width12.xpm"), tr("2.00mm (ISO)"));
120         addItem(QIcon(":/res/width12.xpm"), tr("2.11mm"));
121
122         connect(this, SIGNAL(activated(int)), this, SLOT(slotWidthChanged(int)));
123
124         setCurrentIndex(0);
125         slotWidthChanged(currentIndex());
126 }
127
128 RS2::LineWidth QG_WidthBox::getWidth()
129 {
130         return currentWidth;
131 }
132
133 /**
134  * Sets the currently selected width item to the given width.
135  */
136 void QG_WidthBox::setWidth(RS2::LineWidth w)
137 {
138         RS_DEBUG->print("QG_WidthBox::setWidth %d\n", (int)w);
139         int offset = (int)showByLayer * 2 + (int)showUnchanged;
140
141         switch (w)
142         {
143         case RS2::WidthByLayer:
144                 if (showByLayer)
145                         setCurrentIndex(0 + (int)showUnchanged);
146                 else
147                         RS_DEBUG->print(RS_Debug::D_WARNING, "QG_WidthBox::setWidth: Unsupported width.");
148                 break;
149         case RS2::WidthByBlock:
150                 if (showByLayer)
151                         setCurrentIndex(1 + (int)showUnchanged);
152                 else
153                         RS_DEBUG->print(RS_Debug::D_WARNING, "QG_WidthBox::setWidth: Unsupported width.");
154                 break;
155         case RS2::WidthDefault:
156                 setCurrentIndex(0 + offset);
157                 break;
158         case RS2::Width00:
159                 setCurrentIndex(1 + offset);
160                 break;
161         case RS2::Width01:
162                 setCurrentIndex(2 + offset);
163                 break;
164         case RS2::Width02:
165                 setCurrentIndex(3 + offset);
166                 break;
167         case RS2::Width03:
168                 setCurrentIndex(4 + offset);
169                 break;
170         case RS2::Width04:
171                 setCurrentIndex(5 + offset);
172                 break;
173         case RS2::Width05:
174                 setCurrentIndex(6 + offset);
175                 break;
176         case RS2::Width06:
177                 setCurrentIndex(7 + offset);
178                 break;
179         case RS2::Width07:
180                 setCurrentIndex(8 + offset);
181                 break;
182         case RS2::Width08:
183                 setCurrentIndex(9 + offset);
184                 break;
185         case RS2::Width09:
186                 setCurrentIndex(10 + offset);
187                 break;
188         case RS2::Width10:
189                 setCurrentIndex(11 + offset);
190                 break;
191         case RS2::Width11:
192                 setCurrentIndex(12 + offset);
193                 break;
194         case RS2::Width12:
195                 setCurrentIndex(13 + offset);
196                 break;
197         case RS2::Width13:
198                 setCurrentIndex(14 + offset);
199                 break;
200         case RS2::Width14:
201                 setCurrentIndex(15 + offset);
202                 break;
203         case RS2::Width15:
204                 setCurrentIndex(16 + offset);
205                 break;
206         case RS2::Width16:
207                 setCurrentIndex(17 + offset);
208                 break;
209         case RS2::Width17:
210                 setCurrentIndex(18 + offset);
211                 break;
212         case RS2::Width18:
213                 setCurrentIndex(19 + offset);
214                 break;
215         case RS2::Width19:
216                 setCurrentIndex(20 + offset);
217                 break;
218         case RS2::Width20:
219                 setCurrentIndex(21 + offset);
220                 break;
221         case RS2::Width21:
222                 setCurrentIndex(22 + offset);
223                 break;
224         case RS2::Width22:
225                 setCurrentIndex(23 + offset);
226                 break;
227         case RS2::Width23:
228                 setCurrentIndex(24 + offset);
229                 break;
230         default:
231                 break;
232         }
233
234         slotWidthChanged(currentIndex());
235 }
236
237 /**
238  * Sets the pixmap showing the width of the "By Layer" item.
239  */
240 void QG_WidthBox::setLayerWidth(RS2::LineWidth w)
241 {
242         if (showByLayer)
243         {
244                 QPixmap pixmap;
245
246                 switch(w)
247                 {
248                 default:
249                 case RS2::Width00:
250 //                      pixmap = QPixmap(width00_xpm);
251                         pixmap = QPixmap(":/res/width00.xpm");
252                         break;
253                 case RS2::Width01:
254                 case RS2::Width02:
255 //                      pixmap = QPixmap(width01_xpm);
256                         pixmap = QPixmap(":/res/width01.xpm");
257                         break;
258                 case RS2::Width03:
259                 case RS2::Width04:
260 //                      pixmap = QPixmap(width02_xpm);
261                         pixmap = QPixmap(":/res/width02.xpm");
262                         break;
263                 case RS2::Width05:
264                 case RS2::Width06:
265 //                      pixmap = QPixmap(width03_xpm);
266                         pixmap = QPixmap(":/res/width03.xpm");
267                         break;
268                 case RS2::Width07:
269                 case RS2::Width08:
270 //                      pixmap = QPixmap(width04_xpm);
271                         pixmap = QPixmap(":/res/width04.xpm");
272                         break;
273                 case RS2::Width09:
274                 case RS2::Width10:
275 //                      pixmap = QPixmap(width05_xpm);
276                         pixmap = QPixmap(":/res/width05.xpm");
277                         break;
278                 case RS2::Width11:
279                 case RS2::Width12:
280 //                      pixmap = QPixmap(width06_xpm);
281                         pixmap = QPixmap(":/res/width06.xpm");
282                         break;
283                 case RS2::Width13:
284                 case RS2::Width14:
285 //                      pixmap = QPixmap(width07_xpm);
286                         pixmap = QPixmap(":/res/width07.xpm");
287                         break;
288                 case RS2::Width15:
289                 case RS2::Width16:
290 //                      pixmap = QPixmap(width08_xpm);
291                         pixmap = QPixmap(":/res/width08.xpm");
292                         break;
293                 case RS2::Width17:
294                 case RS2::Width18:
295 //                      pixmap = QPixmap(width09_xpm);
296                         pixmap = QPixmap(":/res/width09.xpm");
297                         break;
298                 case RS2::Width19:
299                 case RS2::Width20:
300 //                      pixmap = QPixmap(width10_xpm);
301                         pixmap = QPixmap(":/res/width10.xpm");
302                         break;
303                 case RS2::Width21:
304                 case RS2::Width22:
305 //                      pixmap = QPixmap(width11_xpm);
306                         pixmap = QPixmap(":/res/width11.xpm");
307                         break;
308                 case RS2::Width23:
309                         //case RS2::Width24:
310 //                      pixmap = QPixmap(width12_xpm);
311                         pixmap = QPixmap(":/res/width12.xpm");
312                         break;
313                 }
314
315 //              changeItem(pixmap, tr("By Layer"), 0);
316                 setItemIcon(0, QIcon(pixmap));
317                 setItemText(0, tr("By Layer"));
318
319                 // ???needed for the first time a layer is added:
320                 slotWidthChanged(currentIndex());
321         }
322 }
323
324 bool QG_WidthBox::isUnchanged()
325 {
326         return unchanged;
327 }
328
329 /**
330  * Called when the width has changed. This method
331  * sets the current width to the value chosen or even
332  * offers a dialog to the user that allows him/ her to
333  * choose an individual width.
334  */
335 void QG_WidthBox::slotWidthChanged(int index)
336 {
337         RS_DEBUG->print("QG_WidthBox::slotWidthChanged %d\n", index);
338
339         bool done = false;
340
341         if (showUnchanged && index == 0)
342         {
343                 unchanged = true;
344                 done = true;
345         }
346         else
347         {
348                 unchanged = false;
349         }
350
351         if (!done && showByLayer)
352         {
353                 if (index == 0 + (int)showUnchanged)
354                 {
355                         currentWidth = RS2::WidthByLayer;
356                         done = true;
357                 }
358                 else if (index == 1 + (int)showUnchanged)
359                 {
360                         currentWidth = RS2::WidthByBlock;
361                         done = true;
362                 }
363         }
364
365         if (!done)
366         {
367                 switch (index - ((int)showByLayer * 2) - ((int)showUnchanged))
368                 {
369                 case 0:
370                         currentWidth = RS2::WidthDefault;
371                         break;
372                 case 1:
373                         currentWidth = RS2::Width00;
374                         break;
375                 case 2:
376                         currentWidth = RS2::Width01;
377                         break;
378                 case 3:
379                         currentWidth = RS2::Width02;
380                         break;
381                 case 4:
382                         currentWidth = RS2::Width03;
383                         break;
384                 case 5:
385                         currentWidth = RS2::Width04;
386                         break;
387                 case 6:
388                         currentWidth = RS2::Width05;
389                         break;
390                 case 7:
391                         currentWidth = RS2::Width06;
392                         break;
393                 case 8:
394                         currentWidth = RS2::Width07;
395                         break;
396                 case 9:
397                         currentWidth = RS2::Width08;
398                         break;
399                 case 10:
400                         currentWidth = RS2::Width09;
401                         break;
402                 case 11:
403                         currentWidth = RS2::Width10;
404                         break;
405                 case 12:
406                         currentWidth = RS2::Width11;
407                         break;
408                 case 13:
409                         currentWidth = RS2::Width12;
410                         break;
411                 case 14:
412                         currentWidth = RS2::Width13;
413                         break;
414                 case 15:
415                         currentWidth = RS2::Width14;
416                         break;
417                 case 16:
418                         currentWidth = RS2::Width15;
419                         break;
420                 case 17:
421                         currentWidth = RS2::Width16;
422                         break;
423                 case 18:
424                         currentWidth = RS2::Width17;
425                         break;
426                 case 19:
427                         currentWidth = RS2::Width18;
428                         break;
429                 case 20:
430                         currentWidth = RS2::Width19;
431                         break;
432                 case 21:
433                         currentWidth = RS2::Width20;
434                         break;
435                 case 22:
436                         currentWidth = RS2::Width21;
437                         break;
438                 case 23:
439                         currentWidth = RS2::Width22;
440                         break;
441                 case 24:
442                         currentWidth = RS2::Width23;
443                         break;
444                 default:
445                         break;
446                 }
447         }
448         //currentWidth = (RS2::LineWidth)(index-1);
449         //currentWidth = (RS2::LineWidth)(currentText().left(4).toDouble()*100);
450         //}
451
452         RS_DEBUG->print("Current width is (%d): %d\n", index, ((int)currentWidth));
453
454         emit widthChanged(currentWidth);
455 }