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