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. :-)
16 #include "qg_widthbox.h"
21 * Default Constructor. You must call init manually if you choose
22 * to use this constructor.
24 QG_WidthBox::QG_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 QG_WidthBox::QG_WidthBox(bool showByLayer, bool showUnchanged, QWidget * parent, const char */*name*/):
40 init(showByLayer, showUnchanged);
46 QG_WidthBox::~QG_WidthBox()
51 * Initialisation (called from constructor or manually but only
54 * @param showByLayer true: Show attributes ByLayer, ByBlock
56 void QG_WidthBox::init(bool showByLayer, bool showUnchanged)
58 this->showByLayer = showByLayer;
59 this->showUnchanged = showUnchanged;
62 // addItem(QIcon(width00_xpm), tr("- Unchanged -"));
63 addItem(QIcon(":/res/width00.xpm"), tr("- Unchanged -"));
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"));
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"));
122 connect(this, SIGNAL(activated(int)), this, SLOT(slotWidthChanged(int)));
125 slotWidthChanged(currentIndex());
128 RS2::LineWidth QG_WidthBox::getWidth()
134 * Sets the currently selected width item to the given width.
136 void QG_WidthBox::setWidth(RS2::LineWidth w)
138 RS_DEBUG->print("QG_WidthBox::setWidth %d\n", (int)w);
139 int offset = (int)showByLayer * 2 + (int)showUnchanged;
143 case RS2::WidthByLayer:
145 setCurrentIndex(0 + (int)showUnchanged);
147 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_WidthBox::setWidth: Unsupported width.");
149 case RS2::WidthByBlock:
151 setCurrentIndex(1 + (int)showUnchanged);
153 RS_DEBUG->print(RS_Debug::D_WARNING, "QG_WidthBox::setWidth: Unsupported width.");
155 case RS2::WidthDefault:
156 setCurrentIndex(0 + offset);
159 setCurrentIndex(1 + offset);
162 setCurrentIndex(2 + offset);
165 setCurrentIndex(3 + offset);
168 setCurrentIndex(4 + offset);
171 setCurrentIndex(5 + offset);
174 setCurrentIndex(6 + offset);
177 setCurrentIndex(7 + offset);
180 setCurrentIndex(8 + offset);
183 setCurrentIndex(9 + offset);
186 setCurrentIndex(10 + offset);
189 setCurrentIndex(11 + offset);
192 setCurrentIndex(12 + offset);
195 setCurrentIndex(13 + offset);
198 setCurrentIndex(14 + offset);
201 setCurrentIndex(15 + offset);
204 setCurrentIndex(16 + offset);
207 setCurrentIndex(17 + offset);
210 setCurrentIndex(18 + offset);
213 setCurrentIndex(19 + offset);
216 setCurrentIndex(20 + offset);
219 setCurrentIndex(21 + offset);
222 setCurrentIndex(22 + offset);
225 setCurrentIndex(23 + offset);
228 setCurrentIndex(24 + offset);
234 slotWidthChanged(currentIndex());
238 * Sets the pixmap showing the width of the "By Layer" item.
240 void QG_WidthBox::setLayerWidth(RS2::LineWidth w)
250 // pixmap = QPixmap(width00_xpm);
251 pixmap = QPixmap(":/res/width00.xpm");
255 // pixmap = QPixmap(width01_xpm);
256 pixmap = QPixmap(":/res/width01.xpm");
260 // pixmap = QPixmap(width02_xpm);
261 pixmap = QPixmap(":/res/width02.xpm");
265 // pixmap = QPixmap(width03_xpm);
266 pixmap = QPixmap(":/res/width03.xpm");
270 // pixmap = QPixmap(width04_xpm);
271 pixmap = QPixmap(":/res/width04.xpm");
275 // pixmap = QPixmap(width05_xpm);
276 pixmap = QPixmap(":/res/width05.xpm");
280 // pixmap = QPixmap(width06_xpm);
281 pixmap = QPixmap(":/res/width06.xpm");
285 // pixmap = QPixmap(width07_xpm);
286 pixmap = QPixmap(":/res/width07.xpm");
290 // pixmap = QPixmap(width08_xpm);
291 pixmap = QPixmap(":/res/width08.xpm");
295 // pixmap = QPixmap(width09_xpm);
296 pixmap = QPixmap(":/res/width09.xpm");
300 // pixmap = QPixmap(width10_xpm);
301 pixmap = QPixmap(":/res/width10.xpm");
305 // pixmap = QPixmap(width11_xpm);
306 pixmap = QPixmap(":/res/width11.xpm");
310 // pixmap = QPixmap(width12_xpm);
311 pixmap = QPixmap(":/res/width12.xpm");
315 // changeItem(pixmap, tr("By Layer"), 0);
316 setItemIcon(0, QIcon(pixmap));
317 setItemText(0, tr("By Layer"));
319 // ???needed for the first time a layer is added:
320 slotWidthChanged(currentIndex());
324 bool QG_WidthBox::isUnchanged()
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.
335 void QG_WidthBox::slotWidthChanged(int index)
337 RS_DEBUG->print("QG_WidthBox::slotWidthChanged %d\n", index);
341 if (showUnchanged && index == 0)
351 if (!done && showByLayer)
353 if (index == 0 + (int)showUnchanged)
355 currentWidth = RS2::WidthByLayer;
358 else if (index == 1 + (int)showUnchanged)
360 currentWidth = RS2::WidthByBlock;
367 switch (index - ((int)showByLayer * 2) - ((int)showUnchanged))
370 currentWidth = RS2::WidthDefault;
373 currentWidth = RS2::Width00;
376 currentWidth = RS2::Width01;
379 currentWidth = RS2::Width02;
382 currentWidth = RS2::Width03;
385 currentWidth = RS2::Width04;
388 currentWidth = RS2::Width05;
391 currentWidth = RS2::Width06;
394 currentWidth = RS2::Width07;
397 currentWidth = RS2::Width08;
400 currentWidth = RS2::Width09;
403 currentWidth = RS2::Width10;
406 currentWidth = RS2::Width11;
409 currentWidth = RS2::Width12;
412 currentWidth = RS2::Width13;
415 currentWidth = RS2::Width14;
418 currentWidth = RS2::Width15;
421 currentWidth = RS2::Width16;
424 currentWidth = RS2::Width17;
427 currentWidth = RS2::Width18;
430 currentWidth = RS2::Width19;
433 currentWidth = RS2::Width20;
436 currentWidth = RS2::Width21;
439 currentWidth = RS2::Width22;
442 currentWidth = RS2::Width23;
448 //currentWidth = (RS2::LineWidth)(index-1);
449 //currentWidth = (RS2::LineWidth)(currentText().left(4).toDouble()*100);
452 RS_DEBUG->print("Current width is (%d): %d\n", index, ((int)currentWidth));
454 emit widthChanged(currentWidth);