|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #include <qgridlayout.h> |
|
20 #include "newPartDialog.h" |
|
21 #include "file.h" |
|
22 |
|
23 // ------------------------------------- |
|
24 enum { |
|
25 LICENSE_CCAL, |
|
26 LICENSE_NonCA, |
|
27 LICENSE_None |
|
28 }; |
|
29 |
|
30 // ------------------------------------- |
|
31 enum { |
|
32 BFCBOX_CCW, |
|
33 BFCBOX_CW, |
|
34 BFCBOX_None, |
|
35 }; |
|
36 |
|
37 // ============================================================================= |
|
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
39 // ============================================================================= |
|
40 NewPartDialog::NewPartDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { |
|
41 lb_brickIcon = new QLabel; |
|
42 lb_brickIcon->setPixmap (getIcon ("brick")); |
|
43 |
|
44 lb_name = new QLabel ("Name:"); |
|
45 le_name = new QLineEdit; |
|
46 le_name->setMinimumWidth (320); |
|
47 |
|
48 lb_author = new QLabel ("Author:"); |
|
49 le_author = new QLineEdit; |
|
50 |
|
51 rb_license = new RadioBox ("License", { |
|
52 "CCAL Redistributable", |
|
53 "Non-redistributable", |
|
54 "Don't append a license", |
|
55 }, LICENSE_CCAL); |
|
56 |
|
57 rb_BFC = new RadioBox ("BFC Winding", { |
|
58 "CCW", |
|
59 "CW", |
|
60 "No winding" |
|
61 }, BFCBOX_CCW); |
|
62 |
|
63 QHBoxLayout* boxes = new QHBoxLayout; |
|
64 boxes->addWidget (rb_license); |
|
65 boxes->addWidget (rb_BFC); |
|
66 |
|
67 IMPLEMENT_DIALOG_BUTTONS |
|
68 |
|
69 QGridLayout* layout = new QGridLayout; |
|
70 layout->addWidget (lb_brickIcon, 0, 0); |
|
71 layout->addWidget (lb_name, 0, 1); |
|
72 layout->addWidget (le_name, 0, 2); |
|
73 layout->addWidget (lb_author, 1, 1); |
|
74 layout->addWidget (le_author, 1, 2); |
|
75 layout->addLayout (boxes, 2, 1, 1, 2); |
|
76 layout->addWidget (bbx_buttons, 3, 2); |
|
77 |
|
78 setLayout (layout); |
|
79 setWindowIcon (getIcon ("brick")); |
|
80 setWindowTitle (APPNAME ": New Part"); |
|
81 } |
|
82 |
|
83 // ============================================================================= |
|
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
85 // ============================================================================= |
|
86 void NewPartDialog::StaticDialog () { |
|
87 NewPartDialog dlg (g_win); |
|
88 if (dlg.exec ()) { |
|
89 newFile (); |
|
90 |
|
91 short idx; |
|
92 str zAuthor = dlg.le_author->text (); |
|
93 vector<LDObject*>& objs = g_curfile->m_objs; |
|
94 |
|
95 idx = dlg.rb_BFC->value (); |
|
96 const LDBFC::Type eBFCType = |
|
97 (idx == BFCBOX_CCW) ? LDBFC::CertifyCCW : |
|
98 (idx == BFCBOX_CW) ? LDBFC::CertifyCW : |
|
99 LDBFC::NoCertify; |
|
100 |
|
101 idx = dlg.rb_license->value (); |
|
102 const char* sLicense = |
|
103 (idx == LICENSE_CCAL) ? "Redistributable under CCAL version 2.0 : see CAreadme.txt" : |
|
104 (idx == LICENSE_NonCA) ? "Not redistributable : see NonCAreadme.txt" : |
|
105 null; |
|
106 |
|
107 objs.push_back (new LDComment (dlg.le_name->text ())); |
|
108 objs.push_back (new LDComment ("Name: <untitled>.dat")); |
|
109 objs.push_back (new LDComment (fmt ("Author: %s", zAuthor.chars()))); |
|
110 objs.push_back (new LDComment (fmt ("!LDRAW_ORG Unofficial_Part"))); |
|
111 |
|
112 if (sLicense != null) |
|
113 objs.push_back (new LDComment (fmt ("!LICENSE %s", sLicense))); |
|
114 |
|
115 objs.push_back (new LDEmpty); |
|
116 objs.push_back (new LDBFC (eBFCType)); |
|
117 objs.push_back (new LDEmpty); |
|
118 |
|
119 g_win->refresh (); |
|
120 } |
|
121 } |