|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 Santeri `arezey` 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 "zz_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 qLB_Icon = new QLabel; |
|
42 qLB_Icon->setPixmap (QPixmap ("icons/brick.png")); |
|
43 |
|
44 qLB_NameLabel = new QLabel ("Name:"); |
|
45 qLE_Name = new QLineEdit; |
|
46 qLE_Name->setMinimumWidth (320); |
|
47 |
|
48 qLB_AuthorLabel = new QLabel ("Author:"); |
|
49 qLE_Author = new QLineEdit; |
|
50 |
|
51 qLB_LicenseLabel = new QLabel ("License:"); |
|
52 qCB_LicenseBox = new QComboBox; |
|
53 qCB_LicenseBox->addItems ({ |
|
54 "CCAL Redistributable", |
|
55 "Non-redistributable", |
|
56 "[none]", |
|
57 }); |
|
58 |
|
59 qLB_BFCLabel = new QLabel ("BFC:"); |
|
60 qCB_BFCBox = new QComboBox; |
|
61 qCB_BFCBox->addItems ({ |
|
62 "CCW", |
|
63 "CW", |
|
64 "No winding" |
|
65 }); |
|
66 |
|
67 IMPLEMENT_DIALOG_BUTTONS |
|
68 |
|
69 QGridLayout* layout = new QGridLayout; |
|
70 layout->addWidget (qLB_Icon, 0, 0); |
|
71 layout->addWidget (qLB_NameLabel, 0, 1); |
|
72 layout->addWidget (qLE_Name, 0, 2); |
|
73 layout->addWidget (qLB_AuthorLabel, 1, 1); |
|
74 layout->addWidget (qLE_Author, 1, 2); |
|
75 layout->addWidget (qLB_LicenseLabel, 2, 1); |
|
76 layout->addWidget (qCB_LicenseBox, 2, 2); |
|
77 layout->addWidget (qLB_BFCLabel, 3, 1); |
|
78 layout->addWidget (qCB_BFCBox, 3, 2); |
|
79 layout->addWidget (qButtons, 4, 2); |
|
80 |
|
81 setLayout (layout); |
|
82 setWindowIcon (QIcon ("icons/brick.png")); |
|
83 setWindowTitle (APPNAME_DISPLAY " - new part"); |
|
84 } |
|
85 |
|
86 // ============================================================================= |
|
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
88 // ============================================================================= |
|
89 void NewPartDialog::StaticDialog () { |
|
90 NewPartDialog dlg (g_qWindow); |
|
91 if (dlg.exec ()) { |
|
92 newFile (); |
|
93 |
|
94 short idx; |
|
95 str zAuthor = dlg.qLE_Author->text (); |
|
96 vector<LDObject*>& objs = g_CurrentFile->objects; |
|
97 |
|
98 idx = dlg.qCB_BFCBox->currentIndex (); |
|
99 const LDBFCType_e eBFCType = |
|
100 (idx == BFCBOX_CCW) ? BFC_CertifyCCW : |
|
101 (idx == BFCBOX_CW) ? BFC_CertifyCW : |
|
102 BFC_NoCertify; |
|
103 |
|
104 idx = dlg.qCB_LicenseBox->currentIndex (); |
|
105 const char* sLicense = |
|
106 (idx == LICENSE_CCAL) ? "Redistributable under CCAL version 2.0 : see CAreadme.txt" : |
|
107 (idx == LICENSE_NonCA) ? "Not redistributable : see NonCAreadme.txt" : |
|
108 nullptr; |
|
109 |
|
110 objs.push_back (new LDComment (dlg.qLE_Name->text ())); |
|
111 objs.push_back (new LDComment ("Name: <untitled>.dat")); |
|
112 objs.push_back (new LDComment (str::mkfmt ("Author: %s", zAuthor.chars()))); |
|
113 objs.push_back (new LDComment (str::mkfmt ("!LDRAW_ORG Unofficial_Part"))); |
|
114 |
|
115 if (sLicense != nullptr) |
|
116 objs.push_back (new LDComment (str::mkfmt ("!LICENSE %s", sLicense))); |
|
117 |
|
118 objs.push_back (new LDEmpty); |
|
119 objs.push_back (new LDBFC (eBFCType)); |
|
120 objs.push_back (new LDEmpty); |
|
121 |
|
122 g_qWindow->refresh (); |
|
123 } |
|
124 } |