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
9 // JLH = James L. Hammons <jlhamm@acm.org>
12 // --- ---------- -----------------------------------------------------------
13 // JLH 05/11/2010 Added this text. :-)
21 * Default Constructor. You must call init manually if you choose
22 * to use this constructor.
24 WidthBox::WidthBox(QWidget * parent, const char */*name*/): QComboBox(parent)
27 showUnchanged = false;
32 * Constructor that calls init and provides a fully functional
33 * combobox for choosing widths.
35 * @param showByLayer true: Show attributes ByLayer, ByBlock
37 WidthBox::WidthBox(bool showByLayer, bool showUnchanged, QWidget * parent, const char */*name*/):
40 init(showByLayer, showUnchanged);
51 * Initialisation (called from constructor or manually but only
54 * @param showByLayer true: Show attributes ByLayer, ByBlock
56 void WidthBox::init(bool showByLayer, bool showUnchanged)
58 this->showByLayer = showByLayer;
59 this->showUnchanged = showUnchanged;
62 addItem(QIcon(":/res/width00.xpm"), tr("- Unchanged -"));
65 addItem(QIcon(":/res/width00.xpm"), tr("By Layer"));
66 addItem(QIcon(":/res/width00.xpm"), tr("By Block"));
68 addItem(QIcon(":/res/width01.xpm"), tr("Default"));
69 addItem(QIcon(":/res/width01.xpm"), tr("0.00mm"));
70 addItem(QIcon(":/res/width01.xpm"), tr("0.05mm"));
71 addItem(QIcon(":/res/width01.xpm"), tr("0.09mm"));
72 addItem(QIcon(":/res/width01.xpm"), tr("0.13mm (ISO)"));
73 addItem(QIcon(":/res/width01.xpm"), tr("0.15mm"));
74 addItem(QIcon(":/res/width01.xpm"), tr("0.18mm (ISO)"));
75 addItem(QIcon(":/res/width01.xpm"), tr("0.20mm"));
76 addItem(QIcon(":/res/width01.xpm"), tr("0.25mm (ISO)"));
77 addItem(QIcon(":/res/width01.xpm"), tr("0.30mm"));
78 addItem(QIcon(":/res/width03.xpm"), tr("0.35mm (ISO)"));
79 addItem(QIcon(":/res/width03.xpm"), tr("0.40mm"));
80 addItem(QIcon(":/res/width04.xpm"), tr("0.50mm (ISO)"));
81 addItem(QIcon(":/res/width05.xpm"), tr("0.53mm"));
82 addItem(QIcon(":/res/width05.xpm"), tr("0.60mm"));
83 addItem(QIcon(":/res/width06.xpm"), tr("0.70mm (ISO)"));
84 addItem(QIcon(":/res/width07.xpm"), tr("0.80mm"));
85 addItem(QIcon(":/res/width08.xpm"), tr("0.90mm"));
86 addItem(QIcon(":/res/width09.xpm"), tr("1.00mm (ISO)"));
87 addItem(QIcon(":/res/width10.xpm"), tr("1.06mm"));
88 addItem(QIcon(":/res/width10.xpm"), tr("1.20mm"));
89 addItem(QIcon(":/res/width12.xpm"), tr("1.40mm (ISO)"));
90 addItem(QIcon(":/res/width12.xpm"), tr("1.58mm"));
91 addItem(QIcon(":/res/width12.xpm"), tr("2.00mm (ISO)"));
92 addItem(QIcon(":/res/width12.xpm"), tr("2.11mm"));
94 connect(this, SIGNAL(activated(int)), this, SLOT(slotWidthChanged(int)));
97 slotWidthChanged(currentIndex());
100 RS2::LineWidth WidthBox::getWidth()
106 * Sets the currently selected width item to the given width.
108 void WidthBox::setWidth(RS2::LineWidth w)
110 DEBUG->print("WidthBox::setWidth %d\n", (int)w);
111 int offset = (int)showByLayer * 2 + (int)showUnchanged;
115 case RS2::WidthByLayer:
117 setCurrentIndex(0 + (int)showUnchanged);
119 DEBUG->print(Debug::D_WARNING, "WidthBox::setWidth: Unsupported width.");
121 case RS2::WidthByBlock:
123 setCurrentIndex(1 + (int)showUnchanged);
125 DEBUG->print(Debug::D_WARNING, "WidthBox::setWidth: Unsupported width.");
127 case RS2::WidthDefault:
128 setCurrentIndex(0 + offset);
131 setCurrentIndex(1 + offset);
134 setCurrentIndex(2 + offset);
137 setCurrentIndex(3 + offset);
140 setCurrentIndex(4 + offset);
143 setCurrentIndex(5 + offset);
146 setCurrentIndex(6 + offset);
149 setCurrentIndex(7 + offset);
152 setCurrentIndex(8 + offset);
155 setCurrentIndex(9 + offset);
158 setCurrentIndex(10 + offset);
161 setCurrentIndex(11 + offset);
164 setCurrentIndex(12 + offset);
167 setCurrentIndex(13 + offset);
170 setCurrentIndex(14 + offset);
173 setCurrentIndex(15 + offset);
176 setCurrentIndex(16 + offset);
179 setCurrentIndex(17 + offset);
182 setCurrentIndex(18 + offset);
185 setCurrentIndex(19 + offset);
188 setCurrentIndex(20 + offset);
191 setCurrentIndex(21 + offset);
194 setCurrentIndex(22 + offset);
197 setCurrentIndex(23 + offset);
200 setCurrentIndex(24 + offset);
206 slotWidthChanged(currentIndex());
210 * Sets the pixmap showing the width of the "By Layer" item.
212 void WidthBox::setLayerWidth(RS2::LineWidth w)
222 pixmap = QPixmap(":/res/width00.xpm");
226 pixmap = QPixmap(":/res/width01.xpm");
230 pixmap = QPixmap(":/res/width02.xpm");
234 pixmap = QPixmap(":/res/width03.xpm");
238 pixmap = QPixmap(":/res/width04.xpm");
242 pixmap = QPixmap(":/res/width05.xpm");
246 pixmap = QPixmap(":/res/width06.xpm");
250 pixmap = QPixmap(":/res/width07.xpm");
254 pixmap = QPixmap(":/res/width08.xpm");
258 pixmap = QPixmap(":/res/width09.xpm");
262 pixmap = QPixmap(":/res/width10.xpm");
266 pixmap = QPixmap(":/res/width11.xpm");
270 pixmap = QPixmap(":/res/width12.xpm");
274 setItemIcon(0, QIcon(pixmap));
275 setItemText(0, tr("By Layer"));
277 // ???needed for the first time a layer is added:
278 slotWidthChanged(currentIndex());
282 bool WidthBox::isUnchanged()
288 * Called when the width has changed. This method
289 * sets the current width to the value chosen or even
290 * offers a dialog to the user that allows him/ her to
291 * choose an individual width.
293 void WidthBox::slotWidthChanged(int index)
295 DEBUG->print("WidthBox::slotWidthChanged %d\n", index);
299 if (showUnchanged && index == 0)
309 if (!done && showByLayer)
311 if (index == 0 + (int)showUnchanged)
313 currentWidth = RS2::WidthByLayer;
316 else if (index == 1 + (int)showUnchanged)
318 currentWidth = RS2::WidthByBlock;
325 switch (index - ((int)showByLayer * 2) - ((int)showUnchanged))
328 currentWidth = RS2::WidthDefault;
331 currentWidth = RS2::Width00;
334 currentWidth = RS2::Width01;
337 currentWidth = RS2::Width02;
340 currentWidth = RS2::Width03;
343 currentWidth = RS2::Width04;
346 currentWidth = RS2::Width05;
349 currentWidth = RS2::Width06;
352 currentWidth = RS2::Width07;
355 currentWidth = RS2::Width08;
358 currentWidth = RS2::Width09;
361 currentWidth = RS2::Width10;
364 currentWidth = RS2::Width11;
367 currentWidth = RS2::Width12;
370 currentWidth = RS2::Width13;
373 currentWidth = RS2::Width14;
376 currentWidth = RS2::Width15;
379 currentWidth = RS2::Width16;
382 currentWidth = RS2::Width17;
385 currentWidth = RS2::Width18;
388 currentWidth = RS2::Width19;
391 currentWidth = RS2::Width20;
394 currentWidth = RS2::Width21;
397 currentWidth = RS2::Width22;
400 currentWidth = RS2::Width23;
406 //currentWidth = (RS2::LineWidth)(index-1);
407 //currentWidth = (RS2::LineWidth)(currentText().left(4).toDouble()*100);
410 DEBUG->print("Current width is (%d): %d\n", index, ((int)currentWidth));
412 emit widthChanged(currentWidth);