|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 Santeri 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 <QAbstractButton> |
|
20 #include <qboxlayout.h> |
|
21 #include "setContentsDialog.h" |
|
22 #include "file.h" |
|
23 #include "gui.h" |
|
24 #include "history.h" |
|
25 |
|
26 // ============================================================================= |
|
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
28 // ============================================================================= |
|
29 SetContentsDialog::SetContentsDialog (LDObject* obj, QWidget* parent) : QDialog(parent) { |
|
30 setWindowTitle (APPNAME ": Set Contents"); |
|
31 |
|
32 lb_contents = new QLabel ("Set contents:", parent); |
|
33 |
|
34 le_contents = new QLineEdit (parent); |
|
35 le_contents->setText (obj->getContents ().chars()); |
|
36 le_contents->setWhatsThis ("The LDraw code of this object. The code written " |
|
37 "here is expected to be valid LDraw code, invalid code here results " |
|
38 "the object being turned into an error object. Please do refer to the " |
|
39 "<a href=\"http://www.ldraw.org/article/218.html\">official file format " |
|
40 "standard</a> for further information."); |
|
41 le_contents->setMinimumWidth (384); |
|
42 |
|
43 if (obj->getType() == LDObject::Gibberish) { |
|
44 lb_error = new QLabel; |
|
45 lb_error->setText (fmt ("<span style=\"color: #900\">%s</span>", |
|
46 static_cast<LDGibberish*> (obj)->zReason.chars())); |
|
47 |
|
48 QPixmap qErrorPixmap = getIcon ("error").scaledToHeight (16); |
|
49 |
|
50 lb_errorIcon = new QLabel; |
|
51 lb_errorIcon->setPixmap (qErrorPixmap); |
|
52 } |
|
53 |
|
54 IMPLEMENT_DIALOG_BUTTONS |
|
55 |
|
56 QVBoxLayout* layout = new QVBoxLayout; |
|
57 layout->addWidget (lb_contents); |
|
58 layout->addWidget (le_contents); |
|
59 |
|
60 QHBoxLayout* layout2 = new QHBoxLayout; |
|
61 |
|
62 if (obj->getType() == LDObject::Gibberish) { |
|
63 layout2->addWidget (lb_errorIcon); |
|
64 layout2->addWidget (lb_error); |
|
65 } |
|
66 |
|
67 layout2->addWidget (bbx_buttons); |
|
68 layout->addLayout (layout2); |
|
69 setLayout (layout); |
|
70 |
|
71 setWindowTitle (APPNAME ": Set Contents"); |
|
72 setWindowIcon (getIcon ("set-contents")); |
|
73 } |
|
74 |
|
75 // ============================================================================= |
|
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
77 // ============================================================================= |
|
78 void SetContentsDialog::slot_handleButtons (QAbstractButton* qButton) { |
|
79 qButton = qButton; |
|
80 } |
|
81 |
|
82 // ============================================================================= |
|
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
84 // ============================================================================= |
|
85 void SetContentsDialog::staticDialog (LDObject* obj) { |
|
86 if (!obj) |
|
87 return; |
|
88 |
|
89 SetContentsDialog dlg (obj, g_win); |
|
90 if (dlg.exec () == false) |
|
91 return; |
|
92 |
|
93 LDObject* oldobj = obj; |
|
94 |
|
95 // Reinterpret it from the text of the input field |
|
96 obj = parseLine (dlg.le_contents->text ().toStdString ().c_str ()); |
|
97 |
|
98 // Mark down the history now before we perform the replacement (which |
|
99 // destroys the old object) |
|
100 History::addEntry (new EditHistory ({(ulong) oldobj->getIndex (g_curfile)}, |
|
101 {oldobj->clone ()}, {obj->clone ()})); |
|
102 |
|
103 oldobj->replace (obj); |
|
104 |
|
105 // Rebuild stuff after this |
|
106 g_win->refresh (); |
|
107 } |