zz_setContentsDialog.cpp

Mon, 25 Mar 2013 00:44:11 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 25 Mar 2013 00:44:11 +0200
changeset 66
12aca5d5a51e
parent 61
109b07334fa0
child 82
e61c50fdb8cc
permissions
-rw-r--r--

Restructured inlining to use a proper caching.. one cache per sub-file reference? What was I thinking? *whacks self with a 55295.dat*

30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
1 /*
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
2 * LDForge: LDraw parts authoring CAD
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
3 * Copyright (C) 2013 Santeri `arezey` Piippo
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
4 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
5 * This program is free software: you can redistribute it and/or modify
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
6 * it under the terms of the GNU General Public License as published by
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
8 * (at your option) any later version.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
9 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
10 * This program is distributed in the hope that it will be useful,
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
13 * GNU General Public License for more details.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
14 *
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
15 * You should have received a copy of the GNU General Public License
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
17 */
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
18
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QAbstractButton>
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <qboxlayout.h>
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "zz_setContentsDialog.h"
26
83184d9407c7 Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
22 #include "file.h"
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "gui.h"
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
28 SetContentsDialog::SetContentsDialog (LDObject* obj, QWidget* parent) : QDialog(parent) {
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 setWindowTitle (APPNAME_DISPLAY ": Set Contents");
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 qContentsLabel = new QLabel ("Set contents:", parent);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 qContents = new QLineEdit (parent);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 qContents->setText (obj->getContents ().chars());
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 qContents->setWhatsThis ("The LDraw code of this object. The code written "
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 "here is expected to be valid LDraw code, invalid code here results "
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 "the object being turned into an error object. Please do refer to the "
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 "<a href=\"http://www.ldraw.org/article/218.html\">official file format "
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 "standard</a> for further information.");
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 qContents->setMinimumWidth (384);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
61
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
42 if (obj->getType() == OBJ_Gibberish) {
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
43 qErrorLabel = new QLabel;
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
44 qErrorLabel->setText (str::mkfmt ("<span style=\"color: #900\">%s</span>",
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
45 static_cast<LDGibberish*> (obj)->zReason.chars()));
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
46 }
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
47
39
110669124caf Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
48 IMPLEMENT_DIALOG_BUTTONS
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 QVBoxLayout* layout = new QVBoxLayout;
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 layout->addWidget (qContentsLabel);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 layout->addWidget (qContents);
61
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
53
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
54 QHBoxLayout* layout2 = new QHBoxLayout;
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
55
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
56 if (obj->getType() == OBJ_Gibberish)
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
57 layout2->addWidget (qErrorLabel);
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
58
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
59 layout2->addWidget (qButtons);
109b07334fa0 If editing contents of a gibberish object, show the reason for the gibberishness in the dialog. Clamp the bounding box scale to at least 1.0 so that polygons are visible in new files.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 39
diff changeset
60 layout->addLayout (layout2);
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 setLayout (layout);
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
62
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
63 setWindowTitle (APPNAME_DISPLAY " - setting contents");
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
64 setWindowIcon (QIcon ("icons/set-contents.png"));
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 }
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
70 void SetContentsDialog::slot_handleButtons (QAbstractButton* qButton) {
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 qButton = qButton;
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 }
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
77 void SetContentsDialog::staticDialog (LDObject* obj, ForgeWindow* parent) {
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 if (!obj)
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 return;
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
81 SetContentsDialog dlg (obj, parent);
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 if (dlg.exec ()) {
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 LDObject* oldobj = obj;
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 // Reinterpret it from the text of the input field
25
c74bb88f537d Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
86 obj = parseLine (dlg.qContents->text ().toStdString ().c_str ());
29
55406ce7446e Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
87 oldobj->replace (obj);
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 // Rebuild stuff after this
32
5d22b7ecf110 Made the GL renderer background color configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
90 parent->refresh ();
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 }
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 }

mercurial