~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/ui/qg_linetypebox.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
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
 */
 
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
 */
 
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
 */
 
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 -"));
 
76
        }
 
77
 
 
78
    if (showByLayer) {
 
79
        addItem(QIcon(":ui/linetype00.png"), tr("By Layer"));
 
80
        addItem(QIcon(":ui/linetype00.png"), tr("By Block"));
 
81
    }
 
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)"));
 
102
 
 
103
    connect(this, SIGNAL(activated(int)),
 
104
            this, SLOT(slotLineTypeChanged(int)));
 
105
 
 
106
    setCurrentIndex(0);
 
107
    slotLineTypeChanged(currentIndex());
 
108
}
 
109
 
 
110
/**
 
111
 * Sets the currently selected linetype item to the given linetype.
 
112
 */
 
113
void QG_LineTypeBox::setLineType(RS2::LineType t) {
 
114
 
 
115
    RS_DEBUG->print("QG_LineTypeBox::setLineType %d\n", (int)t);
 
116
 
 
117
        int offset = (int)showByLayer*2 + (int)showUnchanged;
 
118
 
 
119
    switch (t) {
 
120
    case RS2::LineByLayer:
 
121
        if (showByLayer) {
 
122
            setCurrentIndex(0 + (int)showUnchanged);
 
123
        } else {
 
124
                RS_DEBUG->print(RS_Debug::D_WARNING,
 
125
                "QG_LineTypeBox::setLineType: "
 
126
                                "Combobox doesn't support linetype BYLAYER");
 
127
        }
 
128
        break;
 
129
    case RS2::LineByBlock:
 
130
        if (showByLayer) {
 
131
            setCurrentIndex(1 + (int)showUnchanged);
 
132
        } else {
 
133
                RS_DEBUG->print(RS_Debug::D_WARNING,
 
134
                "QG_LineTypeBox::setLineType: "
 
135
                                "Combobox doesn't support linetype BYBLOCK");
 
136
        }
 
137
        break;
 
138
                
 
139
        case RS2::SolidLine:
 
140
                setCurrentIndex(1 + offset);
 
141
                break;
 
142
 
 
143
        case RS2::DotLine:
 
144
                setCurrentIndex(2 + offset);
 
145
                break;
 
146
        case RS2::DotLine2:
 
147
                setCurrentIndex(3 + offset);
 
148
                break;
 
149
        case RS2::DotLineX2:
 
150
                setCurrentIndex(4 + offset);
 
151
                break;
 
152
 
 
153
        case RS2::DashLine:
 
154
                setCurrentIndex(5 + offset);
 
155
                break;
 
156
        case RS2::DashLine2:
 
157
                setCurrentIndex(6 + offset);
 
158
                break;
 
159
        case RS2::DashLineX2:
 
160
                setCurrentIndex(7 + offset);
 
161
                break;
 
162
        
 
163
        case RS2::DashDotLine:
 
164
                setCurrentIndex(8 + offset);
 
165
                break;
 
166
        case RS2::DashDotLine2:
 
167
                setCurrentIndex(9 + offset);
 
168
                break;
 
169
        case RS2::DashDotLineX2:
 
170
                setCurrentIndex(10 + offset);
 
171
                break;
 
172
        
 
173
        case RS2::DivideLine:
 
174
                setCurrentIndex(11 + offset);
 
175
                break;
 
176
        case RS2::DivideLine2:
 
177
                setCurrentIndex(12 + offset);
 
178
                break;
 
179
        case RS2::DivideLineX2:
 
180
                setCurrentIndex(13 + offset);
 
181
                break;
 
182
        
 
183
        case RS2::CenterLine:
 
184
                setCurrentIndex(14 + offset);
 
185
                break;
 
186
        case RS2::CenterLine2:
 
187
                setCurrentIndex(15 + offset);
 
188
                break;
 
189
        case RS2::CenterLineX2:
 
190
                setCurrentIndex(16 + offset);
 
191
                break;
 
192
        
 
193
        case RS2::BorderLine:
 
194
                setCurrentIndex(17 + offset);
 
195
                break;
 
196
        case RS2::BorderLine2:
 
197
                setCurrentIndex(18 + offset);
 
198
                break;
 
199
        case RS2::BorderLineX2:
 
200
                setCurrentIndex(19 + offset);
 
201
                break;
 
202
        
 
203
    default:
 
204
        break;
 
205
    }
 
206
 
 
207
    slotLineTypeChanged(currentIndex());
 
208
}
 
209
 
 
210
/**
 
211
 * Sets the pixmap showing the linetype of the "By Layer" item.
 
212
 *
 
213
 * @todo needs an update, but not used currently
 
214
 */
 
215
void QG_LineTypeBox::setLayerLineType(RS2::LineType t) {
 
216
    if (showByLayer) {
 
217
        QPixmap pixmap;
 
218
        switch(t) {
 
219
        case RS2::NoPen:
 
220
            pixmap = QPixmap(":ui/linetype00.png");
 
221
            break;
 
222
        default:
 
223
        case RS2::SolidLine:
 
224
            pixmap = QPixmap(":ui/linetype01.png");
 
225
            break;
 
226
        case RS2::DashLine:
 
227
            pixmap = QPixmap(":ui/linetype02.png");
 
228
            break;
 
229
        case RS2::DotLine:
 
230
            pixmap = QPixmap(":ui/linetype03.png");
 
231
            break;
 
232
        case RS2::DashDotLine:
 
233
            pixmap = QPixmap(":ui/linetype04.png");
 
234
            break;
 
235
        case RS2::DivideLine:
 
236
            pixmap = QPixmap(":ui/linetype05.png");
 
237
            break;
 
238
        }
 
239
 
 
240
        setItemIcon(0, QIcon(pixmap));
 
241
        setItemText(0, tr("By Layer"));
 
242
 
 
243
        // needed for the first time a layer is added:
 
244
        slotLineTypeChanged(currentIndex());
 
245
    }
 
246
}
 
247
 
 
248
/**
 
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.
 
253
 */
 
254
void QG_LineTypeBox::slotLineTypeChanged(int index) {
 
255
 
 
256
    RS_DEBUG->print("QG_LineTypeBox::slotLineTypeChanged %d\n", index);
 
257
        
 
258
        unchanged = false;
 
259
 
 
260
    if (showByLayer) {
 
261
        switch (index) {
 
262
        case 0:
 
263
                        if (showUnchanged) {
 
264
                                unchanged = true;
 
265
                        }
 
266
                        else {
 
267
                currentLineType = RS2::LineByLayer;
 
268
                        }
 
269
            break;
 
270
 
 
271
        case 1:
 
272
                        if (showUnchanged) {
 
273
                                currentLineType = RS2::LineByLayer;
 
274
                        }
 
275
                        else {
 
276
                currentLineType = RS2::LineByBlock;
 
277
                        }
 
278
            break;
 
279
                        
 
280
        default:
 
281
            currentLineType = (RS2::LineType)(index-2-(int)showUnchanged);
 
282
            break;
 
283
        }
 
284
    } else {
 
285
        currentLineType = 
 
286
                        (RS2::LineType)(index-(int)showByLayer*2-(int)showUnchanged);
 
287
    }
 
288
 
 
289
    RS_DEBUG->print("Current linetype is (%d): %d\n",
 
290
                    index, currentLineType);
 
291
 
 
292
    emit lineTypeChanged(currentLineType);
 
293
}
 
294
 
 
295
 
 
296