1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
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.
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.
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
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
27
#include "qg_linetypebox.h"
32
* Default Constructor. You must call init manually if you choose
33
* to use this constructor.
35
QG_LineTypeBox::QG_LineTypeBox(QWidget* parent)
39
showUnchanged = false;
44
* Constructor that calls init and provides a fully functional
45
* combobox for choosing linetypes.
47
* @param showByLayer true: Show attribute ByLayer, ByBlock.
49
QG_LineTypeBox::QG_LineTypeBox(bool showByLayer, bool showUnchanged,
50
QWidget* parent, const char* name)
54
init(showByLayer, showUnchanged);
61
QG_LineTypeBox::~QG_LineTypeBox() {}
65
* Initialisation (called from constructor or manually but only
68
* @param showByLayer true: Show attribute ByLayer, ByBlock.
70
void QG_LineTypeBox::init(bool showByLayer, bool showUnchanged) {
71
this->showByLayer = showByLayer;
72
this->showUnchanged = showUnchanged;
75
addItem(QIcon(":ui/linetype00.png"), tr("- Unchanged -"));
79
addItem(QIcon(":ui/linetype00.png"), tr("By Layer"));
80
addItem(QIcon(":ui/linetype00.png"), tr("By Block"));
82
addItem(QIcon(":ui/linetype00.png"), tr("No Pen"));
83
addItem(QIcon(":ui/linetype01.png"), tr("Continuous"));
84
addItem(QIcon(":ui/linetype02.png"), tr("Dot"));
85
addItem(QIcon(":ui/linetype02.png"), tr("Dot (small)"));
86
addItem(QIcon(":ui/linetype02.png"), tr("Dot (large)"));
87
addItem(QIcon(":ui/linetype03.png"), tr("Dash"));
88
addItem(QIcon(":ui/linetype03.png"), tr("Dash (small)"));
89
addItem(QIcon(":ui/linetype03.png"), tr("Dash (large)"));
90
addItem(QIcon(":ui/linetype04.png"), tr("Dash Dot"));
91
addItem(QIcon(":ui/linetype04.png"), tr("Dash Dot (small)"));
92
addItem(QIcon(":ui/linetype04.png"), tr("Dash Dot (large)"));
93
addItem(QIcon(":ui/linetype05.png"), tr("Divide"));
94
addItem(QIcon(":ui/linetype05.png"), tr("Divide (small)"));
95
addItem(QIcon(":ui/linetype05.png"), tr("Divide (large)"));
96
addItem(QIcon(":ui/linetype06.png"), tr("Center"));
97
addItem(QIcon(":ui/linetype06.png"), tr("Center (small)"));
98
addItem(QIcon(":ui/linetype06.png"), tr("Center (large)"));
99
addItem(QIcon(":ui/linetype07.png"), tr("Border"));
100
addItem(QIcon(":ui/linetype07.png"), tr("Border (small)"));
101
addItem(QIcon(":ui/linetype07.png"), tr("Border (large)"));
103
connect(this, SIGNAL(activated(int)),
104
this, SLOT(slotLineTypeChanged(int)));
107
slotLineTypeChanged(currentIndex());
111
* Sets the currently selected linetype item to the given linetype.
113
void QG_LineTypeBox::setLineType(RS2::LineType t) {
115
RS_DEBUG->print("QG_LineTypeBox::setLineType %d\n", (int)t);
117
int offset = (int)showByLayer*2 + (int)showUnchanged;
120
case RS2::LineByLayer:
122
setCurrentIndex(0 + (int)showUnchanged);
124
RS_DEBUG->print(RS_Debug::D_WARNING,
125
"QG_LineTypeBox::setLineType: "
126
"Combobox doesn't support linetype BYLAYER");
129
case RS2::LineByBlock:
131
setCurrentIndex(1 + (int)showUnchanged);
133
RS_DEBUG->print(RS_Debug::D_WARNING,
134
"QG_LineTypeBox::setLineType: "
135
"Combobox doesn't support linetype BYBLOCK");
140
setCurrentIndex(1 + offset);
144
setCurrentIndex(2 + offset);
147
setCurrentIndex(3 + offset);
150
setCurrentIndex(4 + offset);
154
setCurrentIndex(5 + offset);
157
setCurrentIndex(6 + offset);
159
case RS2::DashLineX2:
160
setCurrentIndex(7 + offset);
163
case RS2::DashDotLine:
164
setCurrentIndex(8 + offset);
166
case RS2::DashDotLine2:
167
setCurrentIndex(9 + offset);
169
case RS2::DashDotLineX2:
170
setCurrentIndex(10 + offset);
173
case RS2::DivideLine:
174
setCurrentIndex(11 + offset);
176
case RS2::DivideLine2:
177
setCurrentIndex(12 + offset);
179
case RS2::DivideLineX2:
180
setCurrentIndex(13 + offset);
183
case RS2::CenterLine:
184
setCurrentIndex(14 + offset);
186
case RS2::CenterLine2:
187
setCurrentIndex(15 + offset);
189
case RS2::CenterLineX2:
190
setCurrentIndex(16 + offset);
193
case RS2::BorderLine:
194
setCurrentIndex(17 + offset);
196
case RS2::BorderLine2:
197
setCurrentIndex(18 + offset);
199
case RS2::BorderLineX2:
200
setCurrentIndex(19 + offset);
207
slotLineTypeChanged(currentIndex());
211
* Sets the pixmap showing the linetype of the "By Layer" item.
213
* @todo needs an update, but not used currently
215
void QG_LineTypeBox::setLayerLineType(RS2::LineType t) {
220
pixmap = QPixmap(":ui/linetype00.png");
224
pixmap = QPixmap(":ui/linetype01.png");
227
pixmap = QPixmap(":ui/linetype02.png");
230
pixmap = QPixmap(":ui/linetype03.png");
232
case RS2::DashDotLine:
233
pixmap = QPixmap(":ui/linetype04.png");
235
case RS2::DivideLine:
236
pixmap = QPixmap(":ui/linetype05.png");
240
setItemIcon(0, QIcon(pixmap));
241
setItemText(0, tr("By Layer"));
243
// needed for the first time a layer is added:
244
slotLineTypeChanged(currentIndex());
249
* Called when the linetype has changed. This method
250
* sets the current linetype to the value chosen or even
251
* offers a dialog to the user that allows him/ her to
252
* choose an individual linetype.
254
void QG_LineTypeBox::slotLineTypeChanged(int index) {
256
RS_DEBUG->print("QG_LineTypeBox::slotLineTypeChanged %d\n", index);
267
currentLineType = RS2::LineByLayer;
273
currentLineType = RS2::LineByLayer;
276
currentLineType = RS2::LineByBlock;
281
currentLineType = (RS2::LineType)(index-2-(int)showUnchanged);
286
(RS2::LineType)(index-(int)showByLayer*2-(int)showUnchanged);
289
RS_DEBUG->print("Current linetype is (%d): %d\n",
290
index, currentLineType);
292
emit lineTypeChanged(currentLineType);