3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -----------------------------------------------------------
11 // JLH 05/11/2010 Added this text. :-)
14 #include "qg_widthbox.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"*/
32 * Default Constructor. You must call init manually if you choose
33 * to use this constructor.
35 QG_WidthBox::QG_WidthBox(QWidget * parent, const char */*name*/): QComboBox(parent)
38 showUnchanged = false;
43 * Constructor that calls init and provides a fully functional
44 * combobox for choosing widths.
46 * @param showByLayer true: Show attributes ByLayer, ByBlock
48 QG_WidthBox::QG_WidthBox(bool showByLayer, bool showUnchanged, QWidget * parent, const char */*name*/):
51 init(showByLayer, showUnchanged);
57 QG_WidthBox::~QG_WidthBox()
62 * Initialisation (called from constructor or manually but only
65 * @param showByLayer true: Show attributes ByLayer, ByBlock
67 void QG_WidthBox::init(bool showByLayer, bool showUnchanged)
69 this->showByLayer = showByLayer;
70 this->showUnchanged = showUnchanged;
73 // addItem(QIcon(width00_xpm), tr("- Unchanged -"));
74 addItem(QIcon(":/res/width00.xpm"), tr("- Unchanged -"));
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"));
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"));
133 connect(this, SIGNAL(activated(int)), this, SLOT(slotWidthChanged(int)));
136 slotWidthChanged(currentIndex());
139 RS2::LineWidth QG_WidthBox::getWidth()
145 * Sets the currently selected width item to the given width.
147 void QG_WidthBox::setWidth(RS2::LineWidth w)
149 RS_DEBUG->print("QG_WidthBox::setWidth %d\n", (int)w);
150 int offset = (int)showByLayer * 2 + (int)showUnchanged;
154 case RS2::WidthByLayer:
156 setCurrentIndex(0 + (int)showUnchanged);
158 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_WidthBox::setWidth: Unsupported width.");
160 case RS2::WidthByBlock:
162 setCurrentIndex(1 + (int)showUnchanged);
164 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_WidthBox::setWidth: Unsupported width.");
166 case RS2::WidthDefault:
167 setCurrentIndex(0 + offset);
170 setCurrentIndex(1 + offset);
173 setCurrentIndex(2 + offset);
176 setCurrentIndex(3 + offset);
179 setCurrentIndex(4 + offset);
182 setCurrentIndex(5 + offset);
185 setCurrentIndex(6 + offset);
188 setCurrentIndex(7 + offset);
191 setCurrentIndex(8 + offset);
194 setCurrentIndex(9 + offset);
197 setCurrentIndex(10 + offset);
200 setCurrentIndex(11 + offset);
203 setCurrentIndex(12 + offset);
206 setCurrentIndex(13 + offset);
209 setCurrentIndex(14 + offset);
212 setCurrentIndex(15 + offset);
215 setCurrentIndex(16 + offset);
218 setCurrentIndex(17 + offset);
221 setCurrentIndex(18 + offset);
224 setCurrentIndex(19 + offset);
227 setCurrentIndex(20 + offset);
230 setCurrentIndex(21 + offset);
233 setCurrentIndex(22 + offset);
236 setCurrentIndex(23 + offset);
239 setCurrentIndex(24 + offset);
245 slotWidthChanged(currentIndex());
249 * Sets the pixmap showing the width of the "By Layer" item.
251 void QG_WidthBox::setLayerWidth(RS2::LineWidth w)
261 // pixmap = QPixmap(width00_xpm);
262 pixmap = QPixmap(":/res/width00.xpm");
266 // pixmap = QPixmap(width01_xpm);
267 pixmap = QPixmap(":/res/width01.xpm");
271 // pixmap = QPixmap(width02_xpm);
272 pixmap = QPixmap(":/res/width02.xpm");
276 // pixmap = QPixmap(width03_xpm);
277 pixmap = QPixmap(":/res/width03.xpm");
281 // pixmap = QPixmap(width04_xpm);
282 pixmap = QPixmap(":/res/width04.xpm");
286 // pixmap = QPixmap(width05_xpm);
287 pixmap = QPixmap(":/res/width05.xpm");
291 // pixmap = QPixmap(width06_xpm);
292 pixmap = QPixmap(":/res/width06.xpm");
296 // pixmap = QPixmap(width07_xpm);
297 pixmap = QPixmap(":/res/width07.xpm");
301 // pixmap = QPixmap(width08_xpm);
302 pixmap = QPixmap(":/res/width08.xpm");
306 // pixmap = QPixmap(width09_xpm);
307 pixmap = QPixmap(":/res/width09.xpm");
311 // pixmap = QPixmap(width10_xpm);
312 pixmap = QPixmap(":/res/width10.xpm");
316 // pixmap = QPixmap(width11_xpm);
317 pixmap = QPixmap(":/res/width11.xpm");
321 // pixmap = QPixmap(width12_xpm);
322 pixmap = QPixmap(":/res/width12.xpm");
326 // changeItem(pixmap, tr("By Layer"), 0);
327 setItemIcon(0, QIcon(pixmap));
328 setItemText(0, tr("By Layer"));
330 // ???needed for the first time a layer is added:
331 slotWidthChanged(currentIndex());
335 bool QG_WidthBox::isUnchanged()
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.
346 void QG_WidthBox::slotWidthChanged(int index)
348 RS_DEBUG->print("QG_WidthBox::slotWidthChanged %d\n", index);
352 if (showUnchanged && index == 0)
362 if (!done && showByLayer)
364 if (index == 0 + (int)showUnchanged)
366 currentWidth = RS2::WidthByLayer;
369 else if (index == 1 + (int)showUnchanged)
371 currentWidth = RS2::WidthByBlock;
378 switch (index - ((int)showByLayer * 2) - ((int)showUnchanged))
381 currentWidth = RS2::WidthDefault;
384 currentWidth = RS2::Width00;
387 currentWidth = RS2::Width01;
390 currentWidth = RS2::Width02;
393 currentWidth = RS2::Width03;
396 currentWidth = RS2::Width04;
399 currentWidth = RS2::Width05;
402 currentWidth = RS2::Width06;
405 currentWidth = RS2::Width07;
408 currentWidth = RS2::Width08;
411 currentWidth = RS2::Width09;
414 currentWidth = RS2::Width10;
417 currentWidth = RS2::Width11;
420 currentWidth = RS2::Width12;
423 currentWidth = RS2::Width13;
426 currentWidth = RS2::Width14;
429 currentWidth = RS2::Width15;
432 currentWidth = RS2::Width16;
435 currentWidth = RS2::Width17;
438 currentWidth = RS2::Width18;
441 currentWidth = RS2::Width19;
444 currentWidth = RS2::Width20;
447 currentWidth = RS2::Width21;
450 currentWidth = RS2::Width22;
453 currentWidth = RS2::Width23;
459 //currentWidth = (RS2::LineWidth)(index-1);
460 //currentWidth = (RS2::LineWidth)(currentText().left(4).toDouble()*100);
463 RS_DEBUG->print("Current width is (%d): %d\n", index, ((int)currentWidth));
465 emit widthChanged(currentWidth);