src/dialogs/newpartdialog.cpp

Sat, 24 Mar 2018 12:54:28 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 12:54:28 +0200
changeset 1326
69a90bd2dba2
parent 1323
05b3e173c900
permissions
-rw-r--r--

Happy new year 2018

954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QLineEdit>
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QRadioButton>
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QCheckBox>
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1117
diff changeset
22 #include "../lddocument.h"
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "newpartdialog.h"
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "ui_newpartdialog.h"
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 NewPartDialog::NewPartDialog (QWidget *parent) :
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 QDialog (parent),
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 ui (*new Ui_NewPart)
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 {
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
30 this->ui.setupUi (this);
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1312
diff changeset
32 QString authortext = config::defaultName();
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1312
diff changeset
34 if (not config::defaultUser().isEmpty())
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1312
diff changeset
35 authortext.append(format(" [%1]", config::defaultUser()));
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
37 this->ui.author->setText (authortext);
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1312
diff changeset
38 this->ui.useCaLicense->setChecked (config::useCaLicense());
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 }
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
41 NewPartDialog::~NewPartDialog()
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 {
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
43 delete &this->ui;
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
44 }
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
46 Winding NewPartDialog::winding() const
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
47 {
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
48 if (this->ui.windingCcw->isChecked())
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
49 return CounterClockwise;
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
50 else if (this->ui.windingCw->isChecked())
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
51 return Clockwise;
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
52 else
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
53 return NoWinding;
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 }
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 bool NewPartDialog::useCaLicense() const
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 {
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
58 return this->ui.useCaLicense->isChecked();
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 }
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 QString NewPartDialog::author() const
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
63 return this->ui.author->text();
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
66 QString NewPartDialog::description() const
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 {
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
68 return this->ui.title->text();
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
71 void NewPartDialog::fillHeader (LDDocument* document) const
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 {
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
73 document->header.description = this->description();
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
74 document->header.type = LDHeader::Part;
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
75 document->header.author = this->author();
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
77 if (this->useCaLicense())
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
78 document->header.license = LDHeader::CaLicense;
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
79 else
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
80 document->header.license = LDHeader::UnspecifiedLicense;
1028
5877e49e9a28 Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
81
1312
f2974f3ac1ab remove LDBfc
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
82 document->setWinding(this->winding());
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }

mercurial