zz_setContentsDialog.cpp

Wed, 10 Apr 2013 16:17:22 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 10 Apr 2013 16:17:22 +0300
changeset 95
0a8ad4e3e7c1
parent 90
03f718ed5b33
child 104
6e29bb0e83c5
permissions
-rw-r--r--

Added history support for adding objects.

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"
90
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
24 #include "history.h"
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
29 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
30 setWindowTitle (APPNAME_DISPLAY ": Set Contents");
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 qContentsLabel = new QLabel ("Set contents:", parent);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 qContents = new QLineEdit (parent);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 qContents->setText (obj->getContents ().chars());
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 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
37 "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
38 "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
39 "<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
40 "standard</a> for further information.");
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 qContents->setMinimumWidth (384);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
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
43 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
44 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
45 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
46 static_cast<LDGibberish*> (obj)->zReason.chars()));
82
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
47
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
48 QPixmap qErrorPixmap = QPixmap ("icons/error.png").scaledToHeight (16);
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
49
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
50 qErrorIcon = new QLabel;
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
51 qErrorIcon->setPixmap (qErrorPixmap);
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
52 }
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
39
110669124caf Begin work on dialogs for adding objects. Comments functional!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
54 IMPLEMENT_DIALOG_BUTTONS
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 QVBoxLayout* layout = new QVBoxLayout;
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 layout->addWidget (qContentsLabel);
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 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
59
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 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
61
82
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
62 if (obj->getType() == OBJ_Gibberish) {
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
63 layout2->addWidget (qErrorIcon);
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
64 layout2->addWidget (qErrorLabel);
82
e61c50fdb8cc Touched up the error icon, show the error icon in the set contents dialog if the contents are gibberish.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 61
diff changeset
65 }
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
66
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
67 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
68 layout->addLayout (layout2);
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 setLayout (layout);
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
70
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
71 setWindowTitle (APPNAME_DISPLAY " - setting contents");
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
72 setWindowIcon (QIcon ("icons/set-contents.png"));
15
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
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
78 void SetContentsDialog::slot_handleButtons (QAbstractButton* qButton) {
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 qButton = qButton;
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 }
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 // =============================================================================
30
31ff9aabd506 Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 // =============================================================================
90
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
85 void SetContentsDialog::staticDialog (LDObject* obj) {
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 if (!obj)
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 return;
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
90
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
89 SetContentsDialog dlg (obj, g_ForgeWindow);
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
90 if (dlg.exec () == false)
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
91 return;
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
92
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
93 LDObject* oldobj = obj;
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
94
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
95 // Reinterpret it from the text of the input field
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
96 obj = parseLine (dlg.qContents->text ().toStdString ().c_str ());
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
97
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
98 // Mark down the history now before we perform the replacement (which
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
99 // destroys the old object)
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
100 History::addEntry (new SetContentsHistory (oldobj->getIndex (g_CurrentFile),
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
101 oldobj->clone (), obj->clone ()));
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
102
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
103 oldobj->replace (obj);
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
104
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
105 // Rebuild stuff after this
03f718ed5b33 Added history handling for set contents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
106 g_ForgeWindow->refresh ();
15
a78ccb3976b6 oops, forgot the new dialog files out
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 }

mercurial