]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_linetypebox.cpp
dcec0cedf992f828825a823181cc356abb815967
[architektonas] / src / widgets / qg_linetypebox.cpp
1 // qg_linetypebox.cpp
2 //
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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/11/2010  Added this text. :-)
13 //
14
15 #include "qg_linetypebox.h"
16
17 #include "rs_debug.h"
18
19 /**
20  * Default Constructor. You must call init manually if you choose
21  * to use this constructor.
22  */
23 QG_LineTypeBox::QG_LineTypeBox(QWidget * parent, const char */*name*/): QComboBox(parent)
24 {
25         showByLayer = false;
26         showUnchanged = false;
27         unchanged = false;
28 }
29
30 /**
31  * Constructor that calls init and provides a fully functional
32  * combobox for choosing linetypes.
33  *
34  * @param showByLayer true: Show attribute ByLayer, ByBlock.
35  */
36 QG_LineTypeBox::QG_LineTypeBox(bool showByLayer, bool showUnchanged, QWidget * parent,
37         const char */*name*/): QComboBox(parent)
38 {
39         unchanged = false;
40     init(showByLayer, showUnchanged);
41 }
42
43 /**
44  * Destructor
45  */
46 QG_LineTypeBox::~QG_LineTypeBox()
47 {
48 }
49
50 /**
51  * Initialisation (called from constructor or manually but only
52  * once).
53  *
54  * @param showByLayer true: Show attribute ByLayer, ByBlock.
55  */
56 void QG_LineTypeBox::init(bool showByLayer, bool showUnchanged)
57 {
58         this->showByLayer = showByLayer;
59         this->showUnchanged = showUnchanged;
60
61         if (showUnchanged)
62 //              addItem(QIcon(linetype00_xpm), tr("- Unchanged -"));
63                 addItem(QIcon(":/res/linetype00.xpm"), tr("- Unchanged -"));
64
65         if (showByLayer)
66         {
67 //              addItem(QIcon(linetype00_xpm), tr("By Layer"));
68 //              addItem(QIcon(linetype00_xpm), tr("By Block"));
69                 addItem(QIcon(":/res/linetype00.xpm"), tr("By Layer"));
70                 addItem(QIcon(":/res/linetype00.xpm"), tr("By Block"));
71         }
72
73 /*      addItem(QIcon(linetype00_xpm), tr("No Pen"));
74         addItem(QIcon(linetype01_xpm), tr("Continuous"));
75         addItem(QIcon(linetype02_xpm), tr("Dot"));
76         addItem(QIcon(linetype02_xpm), tr("Dot (small)"));
77         addItem(QIcon(linetype02_xpm), tr("Dot (large)"));
78         addItem(QIcon(linetype03_xpm), tr("Dash"));
79         addItem(QIcon(linetype03_xpm), tr("Dash (small)"));
80         addItem(QIcon(linetype03_xpm), tr("Dash (large)"));
81         addItem(QIcon(linetype04_xpm), tr("Dash Dot"));
82         addItem(QIcon(linetype04_xpm), tr("Dash Dot (small)"));
83         addItem(QIcon(linetype04_xpm), tr("Dash Dot (large)"));
84         addItem(QIcon(linetype05_xpm), tr("Divide"));
85         addItem(QIcon(linetype05_xpm), tr("Divide (small)"));
86         addItem(QIcon(linetype05_xpm), tr("Divide (large)"));
87         addItem(QIcon(linetype06_xpm), tr("Center"));
88         addItem(QIcon(linetype06_xpm), tr("Center (small)"));
89         addItem(QIcon(linetype06_xpm), tr("Center (large)"));
90         addItem(QIcon(linetype07_xpm), tr("Border"));
91         addItem(QIcon(linetype07_xpm), tr("Border (small)"));
92         addItem(QIcon(linetype07_xpm), tr("Border (large)"));*/
93         addItem(QIcon(":/res/linetype00.xpm"), tr("No Pen"));
94         addItem(QIcon(":/res/linetype01.xpm"), tr("Continuous"));
95         addItem(QIcon(":/res/linetype02.xpm"), tr("Dot"));
96         addItem(QIcon(":/res/linetype02.xpm"), tr("Dot (small)"));
97         addItem(QIcon(":/res/linetype02.xpm"), tr("Dot (large)"));
98         addItem(QIcon(":/res/linetype03.xpm"), tr("Dash"));
99         addItem(QIcon(":/res/linetype03.xpm"), tr("Dash (small)"));
100         addItem(QIcon(":/res/linetype03.xpm"), tr("Dash (large)"));
101         addItem(QIcon(":/res/linetype04.xpm"), tr("Dash Dot"));
102         addItem(QIcon(":/res/linetype04.xpm"), tr("Dash Dot (small)"));
103         addItem(QIcon(":/res/linetype04.xpm"), tr("Dash Dot (large)"));
104         addItem(QIcon(":/res/linetype05.xpm"), tr("Divide"));
105         addItem(QIcon(":/res/linetype05.xpm"), tr("Divide (small)"));
106         addItem(QIcon(":/res/linetype05.xpm"), tr("Divide (large)"));
107         addItem(QIcon(":/res/linetype06.xpm"), tr("Center"));
108         addItem(QIcon(":/res/linetype06.xpm"), tr("Center (small)"));
109         addItem(QIcon(":/res/linetype06.xpm"), tr("Center (large)"));
110         addItem(QIcon(":/res/linetype07.xpm"), tr("Border"));
111         addItem(QIcon(":/res/linetype07.xpm"), tr("Border (small)"));
112         addItem(QIcon(":/res/linetype07.xpm"), tr("Border (large)"));
113
114         connect(this, SIGNAL(activated(int)), this, SLOT(slotLineTypeChanged(int)));
115
116         setCurrentIndex(0);
117         slotLineTypeChanged(currentIndex());
118 }
119
120 RS2::LineType QG_LineTypeBox::getLineType()
121 {
122         return currentLineType;
123 }
124
125 /**
126  * Sets the currently selected linetype item to the given linetype.
127  */
128 void QG_LineTypeBox::setLineType(RS2::LineType t)
129 {
130         RS_DEBUG->print("QG_LineTypeBox::setLineType %d\n", (int)t);
131
132         int offset = (int)showByLayer * 2 + (int)showUnchanged;
133
134         switch (t)
135         {
136         case RS2::LineByLayer:
137                 if (showByLayer)
138                         setCurrentIndex(0 + (int)showUnchanged);
139                 else
140                         RS_DEBUG->print(RS_Debug::D_WARNING, "QG_LineTypeBox::setLineType: "
141                                 "Combobox doesn't support linetype BYLAYER");
142                 break;
143         case RS2::LineByBlock:
144                 if (showByLayer)
145                         setCurrentIndex(1 + (int)showUnchanged);
146                 else
147                         RS_DEBUG->print(RS_Debug::D_WARNING, "QG_LineTypeBox::setLineType: "
148                                 "Combobox doesn't support linetype BYBLOCK");
149                 break;
150
151         case RS2::SolidLine:
152                 setCurrentIndex(1 + offset);
153                 break;
154
155         case RS2::DotLine:
156                 setCurrentIndex(2 + offset);
157                 break;
158         case RS2::DotLine2:
159                 setCurrentIndex(3 + offset);
160                 break;
161         case RS2::DotLineX2:
162                 setCurrentIndex(4 + offset);
163                 break;
164
165         case RS2::DashLine:
166                 setCurrentIndex(5 + offset);
167                 break;
168         case RS2::DashLine2:
169                 setCurrentIndex(6 + offset);
170                 break;
171         case RS2::DashLineX2:
172                 setCurrentIndex(7 + offset);
173                 break;
174
175         case RS2::DashDotLine:
176                 setCurrentIndex(8 + offset);
177                 break;
178         case RS2::DashDotLine2:
179                 setCurrentIndex(9 + offset);
180                 break;
181         case RS2::DashDotLineX2:
182                 setCurrentIndex(10 + offset);
183                 break;
184
185         case RS2::DivideLine:
186                 setCurrentIndex(11 + offset);
187                 break;
188         case RS2::DivideLine2:
189                 setCurrentIndex(12 + offset);
190                 break;
191         case RS2::DivideLineX2:
192                 setCurrentIndex(13 + offset);
193                 break;
194
195         case RS2::CenterLine:
196                 setCurrentIndex(14 + offset);
197                 break;
198         case RS2::CenterLine2:
199                 setCurrentIndex(15 + offset);
200                 break;
201         case RS2::CenterLineX2:
202                 setCurrentIndex(16 + offset);
203                 break;
204
205         case RS2::BorderLine:
206                 setCurrentIndex(17 + offset);
207                 break;
208         case RS2::BorderLine2:
209                 setCurrentIndex(18 + offset);
210                 break;
211         case RS2::BorderLineX2:
212                 setCurrentIndex(19 + offset);
213                 break;
214
215         default:
216                 break;
217         }
218
219         slotLineTypeChanged(currentIndex());
220 }
221
222 /**
223  * Sets the pixmap showing the linetype of the "By Layer" item.
224  *
225  * @todo needs an update, but not used currently
226  */
227 void QG_LineTypeBox::setLayerLineType(RS2::LineType t)
228 {
229         if (showByLayer)
230         {
231                 QPixmap pixmap;
232                 switch(t)
233                 {
234                 case RS2::NoPen:
235 //                      pixmap = QPixmap(linetype00_xpm);
236                         pixmap = QPixmap(":/res/linetype00.xpm");
237                         break;
238                 default:
239                 case RS2::SolidLine:
240 //                      pixmap = QPixmap(linetype01_xpm);
241                         pixmap = QPixmap(":/res/linetype01.xpm");
242                         break;
243                 case RS2::DashLine:
244 //                      pixmap = QPixmap(linetype02_xpm);
245                         pixmap = QPixmap(":/res/linetype02.xpm");
246                         break;
247                 case RS2::DotLine:
248 //                      pixmap = QPixmap(linetype03_xpm);
249                         pixmap = QPixmap(":/res/linetype03.xpm");
250                         break;
251                 case RS2::DashDotLine:
252 //                      pixmap = QPixmap(linetype04_xpm);
253                         pixmap = QPixmap(":/res/linetype04.xpm");
254                         break;
255                 case RS2::DivideLine:
256 //                      pixmap = QPixmap(linetype05_xpm);
257                         pixmap = QPixmap(":/res/linetype05.xpm");
258                         break;
259                 }
260
261 //              changeItem(pixmap, tr("By Layer"), 0);
262                 setItemIcon(0, QIcon(pixmap));
263                 setItemText(0, tr("By Layer"));
264
265                 // needed for the first time a layer is added:
266                 slotLineTypeChanged(currentIndex());
267         }
268 }
269
270 bool QG_LineTypeBox::isUnchanged()
271 {
272         return unchanged;
273 }
274
275 /**
276  * Called when the linetype has changed. This method
277  * sets the current linetype to the value chosen or even
278  * offers a dialog to the user that allows him/ her to
279  * choose an individual linetype.
280  */
281 void QG_LineTypeBox::slotLineTypeChanged(int index)
282 {
283         RS_DEBUG->print("QG_LineTypeBox::slotLineTypeChanged %d\n", index);
284
285         unchanged = false;
286
287         if (showByLayer)
288         {
289                 switch (index)
290                 {
291                 case 0:
292                         if (showUnchanged)
293                                 unchanged = true;
294                         else
295                                 currentLineType = RS2::LineByLayer;
296                         break;
297
298                 case 1:
299                         if (showUnchanged)
300                                 currentLineType = RS2::LineByLayer;
301                         else
302                                 currentLineType = RS2::LineByBlock;
303                         break;
304
305                 default:
306                         currentLineType = (RS2::LineType)(index - 2 - (int)showUnchanged);
307                         break;
308                 }
309         }
310         else
311                 currentLineType = (RS2::LineType)(index - (int)showByLayer * 2 - (int)showUnchanged);
312
313         RS_DEBUG->print("Current linetype is (%d): %d\n", index, currentLineType);
314
315         emit lineTypeChanged(currentLineType);
316 }