1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26
27 #include "qg_linetypebox.h"
28
29 #include "rs_debug.h"
30
31 /**
32 * Default Constructor. You must call init manually if you choose
33 * to use this constructor.
34 */
QG_LineTypeBox(QWidget * parent)35 QG_LineTypeBox::QG_LineTypeBox(QWidget* parent)
36 : QComboBox(parent) {
37
38 showByLayer = false;
39 showUnchanged = false;
40 unchanged = false;
41 }
42
43 /**
44 * Constructor that calls init and provides a fully functional
45 * combobox for choosing linetypes.
46 *
47 * @param showByLayer true: Show attribute ByLayer, ByBlock.
48 */
QG_LineTypeBox(bool showByLayer,bool showUnchanged,QWidget * parent,const char * name)49 QG_LineTypeBox::QG_LineTypeBox(bool showByLayer, bool showUnchanged,
50 QWidget* parent, const char* name)
51 : QComboBox(parent) {
52 setObjectName(name);
53 unchanged = false;
54 init(showByLayer, showUnchanged);
55 }
56
57
58 /**
59 * Destructor
60 */
~QG_LineTypeBox()61 QG_LineTypeBox::~QG_LineTypeBox() {}
62
63
64 /**
65 * Initialisation (called from constructor or manually but only
66 * once).
67 *
68 * @param showByLayer true: Show attribute ByLayer, ByBlock.
69 */
init(bool showByLayer,bool showUnchanged)70 void QG_LineTypeBox::init(bool showByLayer, bool showUnchanged) {
71 this->showByLayer = showByLayer;
72 this->showUnchanged = showUnchanged;
73
74 if (showUnchanged) {
75 addItem(QIcon(":ui/linetype00.png"), tr("- Unchanged -"), RS2::LineTypeUnchanged);
76 }
77
78 if (showByLayer) {
79 addItem(QIcon(":ui/linetype00.png"), tr("By Layer"), RS2::LineByLayer);
80 addItem(QIcon(":ui/linetype00.png"), tr("By Block"), RS2::LineByBlock);
81 }
82 addItem(QIcon(":ui/linetype00.png"), tr("No Pen"),RS2::NoPen);
83 addItem(QIcon(":ui/linetype01.png"), tr("Continuous"), RS2::SolidLine);
84 addItem(QIcon(":ui/linetype02.png"), tr("Dot"),RS2::DotLine);
85 addItem(QIcon(":ui/linetype02.png"), tr("Dot (tiny)"),RS2::DotLineTiny);
86 addItem(QIcon(":ui/linetype02.png"), tr("Dot (small)"), RS2::DotLine2);
87 addItem(QIcon(":ui/linetype02.png"), tr("Dot (large)"), RS2::DotLineX2);
88 addItem(QIcon(":ui/linetype03.png"), tr("Dash"),RS2::DashLine);
89 addItem(QIcon(":ui/linetype03.png"), tr("Dash (tiny)"),RS2::DashLineTiny);
90 addItem(QIcon(":ui/linetype03.png"), tr("Dash (small)"),RS2::DashLine2);
91 addItem(QIcon(":ui/linetype03.png"), tr("Dash (large)"),RS2::DashLineX2);
92 addItem(QIcon(":ui/linetype04.png"), tr("Dash Dot"),RS2::DashDotLine);
93 addItem(QIcon(":ui/linetype04.png"), tr("Dash Dot (tiny)"),RS2::DashDotLineTiny);
94 addItem(QIcon(":ui/linetype04.png"), tr("Dash Dot (small)"),RS2::DashDotLine2);
95 addItem(QIcon(":ui/linetype04.png"), tr("Dash Dot (large)"),RS2::DashDotLineX2);
96 addItem(QIcon(":ui/linetype05.png"), tr("Divide"),RS2::DivideLine);
97 addItem(QIcon(":ui/linetype05.png"), tr("Divide (tiny)"),RS2::DivideLineTiny);
98 addItem(QIcon(":ui/linetype05.png"), tr("Divide (small)"),RS2::DivideLine2);
99 addItem(QIcon(":ui/linetype05.png"), tr("Divide (large)"),RS2::DivideLineX2);
100 addItem(QIcon(":ui/linetype06.png"), tr("Center"),RS2::CenterLine);
101 addItem(QIcon(":ui/linetype06.png"), tr("Center (tiny)"),RS2::CenterLineTiny);
102 addItem(QIcon(":ui/linetype06.png"), tr("Center (small)"),RS2::CenterLine2);
103 addItem(QIcon(":ui/linetype06.png"), tr("Center (large)"),RS2::CenterLineX2);
104 addItem(QIcon(":ui/linetype07.png"), tr("Border"),RS2::BorderLine);
105 addItem(QIcon(":ui/linetype07.png"), tr("Border (tiny)"),RS2::BorderLineTiny);
106 addItem(QIcon(":ui/linetype07.png"), tr("Border (small)"),RS2::BorderLine2);
107 addItem(QIcon(":ui/linetype07.png"), tr("Border (large)"),RS2::BorderLineX2);
108
109 connect(this, SIGNAL(activated(int)),
110 this, SLOT(slotLineTypeChanged(int)));
111
112 setCurrentIndex(0);
113 slotLineTypeChanged(currentIndex());
114 }
115
116 /**
117 * Sets the currently selected linetype item to the given linetype.
118 */
setLineType(RS2::LineType t)119 void QG_LineTypeBox::setLineType(RS2::LineType t) {
120
121 RS_DEBUG->print("QG_LineTypeBox::setLineType %d\n", (int)t);
122
123 switch (t) {
124 case RS2::LineByLayer:
125 if (showByLayer) {
126 setCurrentIndex(0 + (int)showUnchanged);
127 } else {
128 RS_DEBUG->print(RS_Debug::D_WARNING,
129 "QG_LineTypeBox::setLineType: "
130 "Combobox doesn't support linetype BYLAYER");
131 }
132 break;
133 case RS2::LineByBlock:
134 if (showByLayer) {
135 setCurrentIndex(1 + (int)showUnchanged);
136 } else {
137 RS_DEBUG->print(RS_Debug::D_WARNING,
138 "QG_LineTypeBox::setLineType: "
139 "Combobox doesn't support linetype BYBLOCK");
140 }
141 break;
142 default:{
143 int index=findData(t);
144 if(t>=0){
145 setCurrentIndex(index);
146 }else{
147 RS_DEBUG->print(RS_Debug::D_WARNING,
148 "QG_LineTypeBox::setLineType: "
149 "Combobox doesn't support linetype %d",(int) t);
150 }
151 }
152
153 }
154
155 slotLineTypeChanged(currentIndex());
156 }
157
158 /**
159 * Sets the pixmap showing the linetype of the "By Layer" item.
160 *
161 * @todo needs an update, but not used currently
162 */
setLayerLineType(RS2::LineType t)163 void QG_LineTypeBox::setLayerLineType(RS2::LineType t) {
164 if (showByLayer) {
165 QPixmap pixmap;
166 switch(t) {
167 case RS2::NoPen:
168 pixmap = QPixmap(":ui/linetype00.png");
169 break;
170 default:
171 case RS2::SolidLine:
172 pixmap = QPixmap(":ui/linetype01.png");
173 break;
174 case RS2::DashLine:
175 pixmap = QPixmap(":ui/linetype02.png");
176 break;
177 case RS2::DotLine:
178 pixmap = QPixmap(":ui/linetype03.png");
179 break;
180 case RS2::DashDotLine:
181 pixmap = QPixmap(":ui/linetype04.png");
182 break;
183 case RS2::DivideLine:
184 pixmap = QPixmap(":ui/linetype05.png");
185 break;
186 }
187
188 setItemIcon(0, QIcon(pixmap));
189 setItemText(0, tr("By Layer"));
190
191 // needed for the first time a layer is added:
192 slotLineTypeChanged(currentIndex());
193 }
194 }
195
196 /**
197 * Called when the linetype has changed. This method
198 * sets the current linetype to the value chosen or even
199 * offers a dialog to the user that allows him/ her to
200 * choose an individual linetype.
201 */
slotLineTypeChanged(int index)202 void QG_LineTypeBox::slotLineTypeChanged(int index) {
203
204 RS_DEBUG->print("QG_LineTypeBox::slotLineTypeChanged %d\n", index);
205
206 unchanged = false;
207
208 if (showByLayer) {
209 switch (index) {
210 case 0:
211 if (showUnchanged) {
212 unchanged = true;
213 }
214 else {
215 currentLineType = RS2::LineByLayer;
216 }
217 break;
218
219 case 1:
220 if (showUnchanged) {
221 currentLineType = RS2::LineByLayer;
222 }
223 else {
224 currentLineType = RS2::LineByBlock;
225 }
226 break;
227
228 default:
229 currentLineType = (RS2::LineType) itemData(index).toInt();
230 }
231 } else {
232 currentLineType = (RS2::LineType) itemData(index).toInt();
233 }
234
235 // RS_DEBUG->print(RS_Debug::D_ERROR, "Current linetype is (%d): %d\n", index, currentLineType);
236
237 emit lineTypeChanged(currentLineType);
238 }
239
240
241
242