zz_newPartDialog.cpp

Tue, 09 Apr 2013 17:41:19 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 09 Apr 2013 17:41:19 +0300
changeset 79
f8917e9d07f6
parent 76
42284126072a
child 104
6e29bb0e83c5
permissions
-rw-r--r--

Extracted actions from ForgeWindow into their own files. The ACTION macro now manages meta, instances and callback definitions all in one. Too bad I still need to extern these actions in gui.cpp... maybe someday I'll find a way around it :)

76
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri `arezey` Piippo
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <qgridlayout.h>
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "zz_newPartDialog.h"
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "file.h"
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 // -------------------------------------
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 enum {
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 LICENSE_CCAL,
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LICENSE_NonCA,
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 LICENSE_None
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 };
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 // -------------------------------------
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 enum {
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 BFCBOX_CCW,
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 BFCBOX_CW,
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 BFCBOX_None,
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 };
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 // =============================================================================
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 // =============================================================================
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 NewPartDialog::NewPartDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 qLB_Icon = new QLabel;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 qLB_Icon->setPixmap (QPixmap ("icons/brick.png"));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 qLB_NameLabel = new QLabel ("Name:");
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 qLE_Name = new QLineEdit;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 qLE_Name->setMinimumWidth (320);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 qLB_AuthorLabel = new QLabel ("Author:");
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 qLE_Author = new QLineEdit;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 qLB_LicenseLabel = new QLabel ("License:");
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 qCB_LicenseBox = new QComboBox;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 qCB_LicenseBox->addItems ({
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 "CCAL Redistributable",
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 "Non-redistributable",
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 "[none]",
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 });
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 qLB_BFCLabel = new QLabel ("BFC:");
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 qCB_BFCBox = new QComboBox;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 qCB_BFCBox->addItems ({
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 "CCW",
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 "CW",
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 "No winding"
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 });
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 IMPLEMENT_DIALOG_BUTTONS
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 QGridLayout* layout = new QGridLayout;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 layout->addWidget (qLB_Icon, 0, 0);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 layout->addWidget (qLB_NameLabel, 0, 1);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 layout->addWidget (qLE_Name, 0, 2);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 layout->addWidget (qLB_AuthorLabel, 1, 1);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 layout->addWidget (qLE_Author, 1, 2);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 layout->addWidget (qLB_LicenseLabel, 2, 1);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 layout->addWidget (qCB_LicenseBox, 2, 2);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 layout->addWidget (qLB_BFCLabel, 3, 1);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 layout->addWidget (qCB_BFCBox, 3, 2);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 layout->addWidget (qButtons, 4, 2);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 setLayout (layout);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 setWindowIcon (QIcon ("icons/brick.png"));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 setWindowTitle (APPNAME_DISPLAY " - new part");
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 // =============================================================================
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 // =============================================================================
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 void NewPartDialog::StaticDialog () {
79
f8917e9d07f6 Extracted actions from ForgeWindow into their own files. The ACTION macro now manages meta, instances and callback definitions all in one. Too bad I still need to extern these actions in gui.cpp... maybe someday I'll find a way around it :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
90 NewPartDialog dlg (g_ForgeWindow);
76
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 if (dlg.exec ()) {
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 newFile ();
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 short idx;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 str zAuthor = dlg.qLE_Author->text ();
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 vector<LDObject*>& objs = g_CurrentFile->objects;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 idx = dlg.qCB_BFCBox->currentIndex ();
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 const LDBFCType_e eBFCType =
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 (idx == BFCBOX_CCW) ? BFC_CertifyCCW :
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 (idx == BFCBOX_CW) ? BFC_CertifyCW :
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 BFC_NoCertify;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 idx = dlg.qCB_LicenseBox->currentIndex ();
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 const char* sLicense =
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 (idx == LICENSE_CCAL) ? "Redistributable under CCAL version 2.0 : see CAreadme.txt" :
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 (idx == LICENSE_NonCA) ? "Not redistributable : see NonCAreadme.txt" :
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 nullptr;
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 objs.push_back (new LDComment (dlg.qLE_Name->text ()));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 objs.push_back (new LDComment ("Name: <untitled>.dat"));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 objs.push_back (new LDComment (str::mkfmt ("Author: %s", zAuthor.chars())));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 objs.push_back (new LDComment (str::mkfmt ("!LDRAW_ORG Unofficial_Part")));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 if (sLicense != nullptr)
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 objs.push_back (new LDComment (str::mkfmt ("!LICENSE %s", sLicense)));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 objs.push_back (new LDEmpty);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 objs.push_back (new LDBFC (eBFCType));
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 objs.push_back (new LDEmpty);
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
79
f8917e9d07f6 Extracted actions from ForgeWindow into their own files. The ACTION macro now manages meta, instances and callback definitions all in one. Too bad I still need to extern these actions in gui.cpp... maybe someday I'll find a way around it :)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
122 g_ForgeWindow->refresh ();
76
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 }
42284126072a Added a New Part dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 }

mercurial