3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/11/2010 Added this text. :-)
17 #include "linetypebox.h"
22 * Default Constructor. You must call init manually if you choose
23 * to use this constructor.
25 LineTypeBox::LineTypeBox(QWidget * parent, const char */*name*/): QComboBox(parent)
28 showUnchanged = false;
33 * Constructor that calls init and provides a fully functional
34 * combobox for choosing linetypes.
36 * @param showByLayer true: Show attribute ByLayer, ByBlock.
38 LineTypeBox::LineTypeBox(bool showByLayer, bool showUnchanged, QWidget * parent,
39 const char */*name*/): QComboBox(parent)
42 init(showByLayer, showUnchanged);
48 LineTypeBox::~LineTypeBox()
53 * Initialisation (called from constructor or manually but only
56 * @param showByLayer true: Show attribute ByLayer, ByBlock.
58 void LineTypeBox::init(bool showByLayer, bool showUnchanged)
60 this->showByLayer = showByLayer;
61 this->showUnchanged = showUnchanged;
64 // addItem(QIcon(linetype00_xpm), tr("- Unchanged -"));
65 addItem(QIcon(":/res/linetype00.xpm"), tr("- Unchanged -"));
69 // addItem(QIcon(linetype00_xpm), tr("By Layer"));
70 // addItem(QIcon(linetype00_xpm), tr("By Block"));
71 addItem(QIcon(":/res/linetype00.xpm"), tr("By Layer"));
72 addItem(QIcon(":/res/linetype00.xpm"), tr("By Block"));
75 /* addItem(QIcon(linetype00_xpm), tr("No Pen"));
76 addItem(QIcon(linetype01_xpm), tr("Continuous"));
77 addItem(QIcon(linetype02_xpm), tr("Dot"));
78 addItem(QIcon(linetype02_xpm), tr("Dot (small)"));
79 addItem(QIcon(linetype02_xpm), tr("Dot (large)"));
80 addItem(QIcon(linetype03_xpm), tr("Dash"));
81 addItem(QIcon(linetype03_xpm), tr("Dash (small)"));
82 addItem(QIcon(linetype03_xpm), tr("Dash (large)"));
83 addItem(QIcon(linetype04_xpm), tr("Dash Dot"));
84 addItem(QIcon(linetype04_xpm), tr("Dash Dot (small)"));
85 addItem(QIcon(linetype04_xpm), tr("Dash Dot (large)"));
86 addItem(QIcon(linetype05_xpm), tr("Divide"));
87 addItem(QIcon(linetype05_xpm), tr("Divide (small)"));
88 addItem(QIcon(linetype05_xpm), tr("Divide (large)"));
89 addItem(QIcon(linetype06_xpm), tr("Center"));
90 addItem(QIcon(linetype06_xpm), tr("Center (small)"));
91 addItem(QIcon(linetype06_xpm), tr("Center (large)"));
92 addItem(QIcon(linetype07_xpm), tr("Border"));
93 addItem(QIcon(linetype07_xpm), tr("Border (small)"));
94 addItem(QIcon(linetype07_xpm), tr("Border (large)"));*/
95 addItem(QIcon(":/res/linetype00.xpm"), tr("No Pen"));
96 addItem(QIcon(":/res/linetype01.xpm"), tr("Continuous"));
97 addItem(QIcon(":/res/linetype02.xpm"), tr("Dot"));
98 addItem(QIcon(":/res/linetype02.xpm"), tr("Dot (small)"));
99 addItem(QIcon(":/res/linetype02.xpm"), tr("Dot (large)"));
100 addItem(QIcon(":/res/linetype03.xpm"), tr("Dash"));
101 addItem(QIcon(":/res/linetype03.xpm"), tr("Dash (small)"));
102 addItem(QIcon(":/res/linetype03.xpm"), tr("Dash (large)"));
103 addItem(QIcon(":/res/linetype04.xpm"), tr("Dash Dot"));
104 addItem(QIcon(":/res/linetype04.xpm"), tr("Dash Dot (small)"));
105 addItem(QIcon(":/res/linetype04.xpm"), tr("Dash Dot (large)"));
106 addItem(QIcon(":/res/linetype05.xpm"), tr("Divide"));
107 addItem(QIcon(":/res/linetype05.xpm"), tr("Divide (small)"));
108 addItem(QIcon(":/res/linetype05.xpm"), tr("Divide (large)"));
109 addItem(QIcon(":/res/linetype06.xpm"), tr("Center"));
110 addItem(QIcon(":/res/linetype06.xpm"), tr("Center (small)"));
111 addItem(QIcon(":/res/linetype06.xpm"), tr("Center (large)"));
112 addItem(QIcon(":/res/linetype07.xpm"), tr("Border"));
113 addItem(QIcon(":/res/linetype07.xpm"), tr("Border (small)"));
114 addItem(QIcon(":/res/linetype07.xpm"), tr("Border (large)"));
116 connect(this, SIGNAL(activated(int)), this, SLOT(slotLineTypeChanged(int)));
119 slotLineTypeChanged(currentIndex());
122 RS2::LineType LineTypeBox::getLineType()
124 return currentLineType;
128 * Sets the currently selected linetype item to the given linetype.
130 void LineTypeBox::setLineType(RS2::LineType t)
132 DEBUG->print("LineTypeBox::setLineType %d\n", (int)t);
134 int offset = (int)showByLayer * 2 + (int)showUnchanged;
138 case RS2::LineByLayer:
140 setCurrentIndex(0 + (int)showUnchanged);
142 DEBUG->print(Debug::D_WARNING, "LineTypeBox::setLineType: "
143 "Combobox doesn't support linetype BYLAYER");
145 case RS2::LineByBlock:
147 setCurrentIndex(1 + (int)showUnchanged);
149 DEBUG->print(Debug::D_WARNING, "LineTypeBox::setLineType: "
150 "Combobox doesn't support linetype BYBLOCK");
154 setCurrentIndex(1 + offset);
158 setCurrentIndex(2 + offset);
161 setCurrentIndex(3 + offset);
164 setCurrentIndex(4 + offset);
168 setCurrentIndex(5 + offset);
171 setCurrentIndex(6 + offset);
173 case RS2::DashLineX2:
174 setCurrentIndex(7 + offset);
177 case RS2::DashDotLine:
178 setCurrentIndex(8 + offset);
180 case RS2::DashDotLine2:
181 setCurrentIndex(9 + offset);
183 case RS2::DashDotLineX2:
184 setCurrentIndex(10 + offset);
187 case RS2::DivideLine:
188 setCurrentIndex(11 + offset);
190 case RS2::DivideLine2:
191 setCurrentIndex(12 + offset);
193 case RS2::DivideLineX2:
194 setCurrentIndex(13 + offset);
197 case RS2::CenterLine:
198 setCurrentIndex(14 + offset);
200 case RS2::CenterLine2:
201 setCurrentIndex(15 + offset);
203 case RS2::CenterLineX2:
204 setCurrentIndex(16 + offset);
207 case RS2::BorderLine:
208 setCurrentIndex(17 + offset);
210 case RS2::BorderLine2:
211 setCurrentIndex(18 + offset);
213 case RS2::BorderLineX2:
214 setCurrentIndex(19 + offset);
221 slotLineTypeChanged(currentIndex());
225 * Sets the pixmap showing the linetype of the "By Layer" item.
227 * @todo needs an update, but not used currently
229 void LineTypeBox::setLayerLineType(RS2::LineType t)
237 // pixmap = QPixmap(linetype00_xpm);
238 pixmap = QPixmap(":/res/linetype00.xpm");
242 // pixmap = QPixmap(linetype01_xpm);
243 pixmap = QPixmap(":/res/linetype01.xpm");
246 // pixmap = QPixmap(linetype02_xpm);
247 pixmap = QPixmap(":/res/linetype02.xpm");
250 // pixmap = QPixmap(linetype03_xpm);
251 pixmap = QPixmap(":/res/linetype03.xpm");
253 case RS2::DashDotLine:
254 // pixmap = QPixmap(linetype04_xpm);
255 pixmap = QPixmap(":/res/linetype04.xpm");
257 case RS2::DivideLine:
258 // pixmap = QPixmap(linetype05_xpm);
259 pixmap = QPixmap(":/res/linetype05.xpm");
263 // changeItem(pixmap, tr("By Layer"), 0);
264 setItemIcon(0, QIcon(pixmap));
265 setItemText(0, tr("By Layer"));
267 // needed for the first time a layer is added:
268 slotLineTypeChanged(currentIndex());
272 bool LineTypeBox::isUnchanged()
278 * Called when the linetype has changed. This method
279 * sets the current linetype to the value chosen or even
280 * offers a dialog to the user that allows him/ her to
281 * choose an individual linetype.
283 void LineTypeBox::slotLineTypeChanged(int index)
285 DEBUG->print("LineTypeBox::slotLineTypeChanged %d\n", index);
297 currentLineType = RS2::LineByLayer;
302 currentLineType = RS2::LineByLayer;
304 currentLineType = RS2::LineByBlock;
308 currentLineType = (RS2::LineType)(index - 2 - (int)showUnchanged);
313 currentLineType = (RS2::LineType)(index - (int)showByLayer * 2 - (int)showUnchanged);
315 DEBUG->print("Current linetype is (%d): %d\n", index, currentLineType);
317 emit lineTypeChanged(currentLineType);