Sat, 16 Mar 2013 03:11:19 +0200
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
0 | 1 | #include <QtGui> |
2 | ||
3 | #include "common.h" | |
4 | #include "draw.h" | |
5 | #include "gui.h" | |
6 | #include "model.h" | |
7 | #include "io.h" | |
8 | ||
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
9 | #include "zz_setContentsDialog.h" |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
10 | |
0 | 11 | LDForgeWindow::LDForgeWindow () { |
12 | R = new renderer; | |
13 | ||
14 | qObjList = new QTreeWidget; | |
15 | qObjList->setHeaderHidden (true); | |
16 | qObjList->setMaximumWidth (256); | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
17 | qObjList->setSelectionMode (QTreeWidget::MultiSelection); |
0 | 18 | |
19 | qMessageLog = new QTextEdit; | |
20 | qMessageLog->setReadOnly (true); | |
21 | qMessageLog->setMaximumHeight (96); | |
22 | ||
23 | QWidget* w = new QWidget; | |
24 | QGridLayout* layout = new QGridLayout; | |
25 | layout->setColumnMinimumWidth (0, 192); | |
26 | layout->setColumnStretch (0, 1); | |
27 | layout->addWidget (R, 0, 0); | |
28 | layout->addWidget (qObjList, 0, 1); | |
29 | layout->addWidget (qMessageLog, 1, 0, 1, 2); | |
30 | w->setLayout (layout); | |
31 | setCentralWidget (w); | |
32 | ||
33 | createMenuActions (); | |
34 | createMenus (); | |
35 | createToolbars (); | |
36 | ||
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
37 | setTitle (); |
0 | 38 | setMinimumSize (320, 200); |
39 | resize (800, 600); | |
40 | } | |
41 | ||
42 | #define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ | |
43 | qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ | |
44 | qAct_##OBJECT->setStatusTip (tr (DESCR)); \ | |
45 | connect (qAct_##OBJECT, SIGNAL (triggered ()), this, SLOT (slot_##OBJECT ())); | |
46 | ||
47 | void LDForgeWindow::createMenuActions () { | |
48 | // Long menu names go here so my cool action definition table doesn't get out of proportions | |
49 | const char* sNewCdLineText = "New Conditional Line", | |
50 | *sNewQuadText = "New Quadrilateral", | |
51 | *sAboutText = "About " APPNAME_DISPLAY; | |
52 | ||
53 | MAKE_ACTION (new, "&New", "file-new", "Create a new part model.") | |
5
727e02d6b87a
rename file-specific icons to file-*
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
54 | MAKE_ACTION (open, "&Open", "file-open", "Load a part model from a file.") |
727e02d6b87a
rename file-specific icons to file-*
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
55 | MAKE_ACTION (save, "&Save", "file-save", "Save the part model.") |
727e02d6b87a
rename file-specific icons to file-*
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
56 | MAKE_ACTION (saveAs, "Save &As", "file-save-as", "Save the part to a specific file.") |
0 | 57 | MAKE_ACTION (exit, "&Exit", "exit", "Close " APPNAME_DISPLAY ".") |
58 | ||
59 | MAKE_ACTION (cut, "Cut", "cut", "Cut the current selection to clipboard.") | |
60 | MAKE_ACTION (copy, "Copy", "copy", "Copy the current selection to clipboard.") | |
61 | MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.") | |
62 | MAKE_ACTION (about, sAboutText, "about", "Shows information about " APPNAME_DISPLAY ".") | |
63 | MAKE_ACTION (aboutQt, "About Qt", "aboutQt", "Shows information about Qt.") | |
64 | ||
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
65 | MAKE_ACTION (setContents, "Set Contents", "set-contents", "Set the raw code of this object.") |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
66 | |
0 | 67 | MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.") |
68 | MAKE_ACTION (newLine, "New Line", "add-line", "Creates a new line.") | |
69 | MAKE_ACTION (newTriangle, "New Triangle", "add-triangle", "Creates a new triangle.") | |
70 | MAKE_ACTION (newQuad, sNewQuadText, "add-quad", "Creates a new quadrilateral.") | |
71 | MAKE_ACTION (newCondLine, sNewCdLineText, "add-condline", "Creates a new conditional line."); | |
72 | MAKE_ACTION (newComment, "New Comment", "add-comment", "Creates a new comment."); | |
73 | MAKE_ACTION (newVector, "New Vector", "add-vector", "Creates a new vector.") | |
74 | MAKE_ACTION (newVertex, "New Vertex", "add-vertex", "Creates a new vertex.") | |
75 | ||
76 | // Keyboard shortcuts | |
77 | qAct_new->setShortcut (Qt::CTRL | Qt::Key_N); | |
78 | qAct_open->setShortcut (Qt::CTRL | Qt::Key_O); | |
79 | qAct_save->setShortcut (Qt::CTRL | Qt::Key_S); | |
80 | qAct_saveAs->setShortcut (Qt::CTRL | Qt::SHIFT | Qt::Key_S); | |
81 | ||
82 | qAct_cut->setShortcut (Qt::CTRL | Qt::Key_X); | |
83 | qAct_copy->setShortcut (Qt::CTRL | Qt::Key_C); | |
84 | qAct_paste->setShortcut (Qt::CTRL | Qt::Key_V); | |
85 | ||
86 | // things not implemented yet | |
87 | QAction* qaDisabledActions[] = { | |
88 | qAct_save, | |
89 | qAct_saveAs, | |
90 | qAct_newSubfile, | |
91 | qAct_newLine, | |
92 | qAct_newTriangle, | |
93 | qAct_newQuad, | |
94 | qAct_newCondLine, | |
95 | qAct_newComment, | |
96 | qAct_newVector, | |
97 | qAct_newVertex, | |
98 | qAct_cut, | |
99 | qAct_copy, | |
100 | qAct_paste, | |
101 | qAct_about | |
102 | }; | |
103 | ||
104 | for (ushort i = 0; i < sizeof qaDisabledActions / sizeof *qaDisabledActions; ++i) | |
105 | qaDisabledActions[i]->setEnabled (false); | |
106 | } | |
107 | ||
108 | void LDForgeWindow::createMenus () { | |
109 | // File menu | |
110 | qFileMenu = menuBar ()->addMenu (tr ("&File")); | |
111 | qFileMenu->addAction (qAct_new); // New | |
112 | qFileMenu->addAction (qAct_open); // Open | |
113 | qFileMenu->addAction (qAct_save); // Save | |
114 | qFileMenu->addAction (qAct_saveAs); // Save As | |
115 | qFileMenu->addSeparator (); // ------- | |
116 | qFileMenu->addAction (qAct_exit); // Exit | |
117 | ||
118 | // Edit menu | |
119 | qInsertMenu = menuBar ()->addMenu (tr ("&Insert")); | |
120 | qInsertMenu->addAction (qAct_newSubfile); // New Subfile | |
121 | qInsertMenu->addAction (qAct_newLine); // New Line | |
122 | qInsertMenu->addAction (qAct_newTriangle); // New Triangle | |
123 | qInsertMenu->addAction (qAct_newQuad); // New Quad | |
124 | qInsertMenu->addAction (qAct_newCondLine); // New Conditional Line | |
125 | qInsertMenu->addAction (qAct_newComment); // New Comment | |
126 | qInsertMenu->addAction (qAct_newVector); // New Vector | |
127 | qInsertMenu->addAction (qAct_newVertex); // New Vertex | |
128 | ||
129 | qEditMenu = menuBar ()->addMenu (tr ("&Edit")); | |
130 | qEditMenu->addAction (qAct_cut); // Cut | |
131 | qEditMenu->addAction (qAct_copy); // Copy | |
132 | qEditMenu->addAction (qAct_paste); // Paste | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
133 | qEditMenu->addSeparator (); // ----- |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
134 | qEditMenu->addAction (qAct_setContents); // Set Contents |
0 | 135 | |
136 | // Help menu | |
137 | qHelpMenu = menuBar ()->addMenu (tr ("&Help")); | |
138 | qHelpMenu->addAction (qAct_about); // About | |
139 | qHelpMenu->addAction (qAct_aboutQt); // About Qt | |
140 | } | |
141 | ||
142 | void LDForgeWindow::createToolbars () { | |
143 | qFileToolBar = new QToolBar ("File"); | |
144 | qFileToolBar->addAction (qAct_new); | |
145 | qFileToolBar->addAction (qAct_open); | |
146 | qFileToolBar->addAction (qAct_save); | |
147 | qFileToolBar->addAction (qAct_saveAs); | |
148 | addToolBar (qFileToolBar); | |
149 | ||
150 | qInsertToolBar = new QToolBar ("Insert"); | |
151 | qInsertToolBar->addAction (qAct_newSubfile); | |
152 | qInsertToolBar->addAction (qAct_newLine); | |
153 | qInsertToolBar->addAction (qAct_newTriangle); | |
154 | qInsertToolBar->addAction (qAct_newQuad); | |
155 | qInsertToolBar->addAction (qAct_newCondLine); | |
156 | qInsertToolBar->addAction (qAct_newComment); | |
157 | qInsertToolBar->addAction (qAct_newVector); | |
158 | qInsertToolBar->addAction (qAct_newVertex); | |
159 | addToolBar (qInsertToolBar); | |
160 | ||
161 | qEditToolBar = new QToolBar ("Edit"); | |
162 | qEditToolBar->addAction (qAct_cut); | |
163 | qEditToolBar->addAction (qAct_copy); | |
164 | qEditToolBar->addAction (qAct_paste); | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
165 | qEditToolBar->addAction (qAct_setContents); |
0 | 166 | addToolBar (qEditToolBar); |
167 | } | |
168 | ||
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
169 | void LDForgeWindow::setTitle () { |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
170 | str zTitle = APPNAME_DISPLAY " v" VERSION_STRING; |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
171 | |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
172 | // Append our current file if we have one |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
173 | if (g_CurrentFile) { |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
174 | zTitle.appendformat (": %s", basename (g_CurrentFile->zFileName.chars())); |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
175 | |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
176 | if (g_CurrentFile->objects.size() > 0 && |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
177 | g_CurrentFile->objects[0]->getType() == OBJ_Comment) |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
178 | { |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
179 | // Append title |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
180 | LDComment* comm = static_cast<LDComment*> (g_CurrentFile->objects[0]); |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
181 | zTitle.appendformat (":%s", comm->zText.chars()); |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
182 | } |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
183 | } |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
184 | |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
185 | setWindowTitle (zTitle.chars()); |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
186 | } |
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
187 | |
0 | 188 | void LDForgeWindow::slot_new () { |
189 | printf ("new file\n"); | |
190 | ||
191 | closeModel (); | |
192 | newModel (); | |
193 | } | |
194 | ||
195 | void LDForgeWindow::slot_open () { | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
196 | str name = QFileDialog::getOpenFileName (this, "Open File", |
0 | 197 | "", "LDraw files (*.dat *.ldr)").toStdString().c_str(); |
198 | ||
199 | if (g_LoadedFiles.size()) | |
200 | closeModel (); | |
201 | ||
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
202 | IO_OpenLDrawFile (name); |
0 | 203 | } |
204 | ||
205 | void LDForgeWindow::slot_save () { | |
206 | printf ("save file\n"); | |
207 | } | |
208 | ||
209 | void LDForgeWindow::slot_saveAs () { | |
210 | printf ("save as file\n"); | |
211 | } | |
212 | ||
213 | void LDForgeWindow::slot_exit () { | |
214 | printf ("exit\n"); | |
215 | exit (0); | |
216 | } | |
217 | ||
218 | void LDForgeWindow::slot_newSubfile () { | |
219 | ||
220 | } | |
221 | ||
222 | void LDForgeWindow::slot_newLine () { | |
223 | ||
224 | } | |
225 | ||
226 | void LDForgeWindow::slot_newTriangle () { | |
227 | ||
228 | } | |
229 | ||
230 | void LDForgeWindow::slot_newQuad () { | |
231 | ||
232 | } | |
233 | ||
234 | void LDForgeWindow::slot_newCondLine () { | |
235 | ||
236 | } | |
237 | ||
238 | void LDForgeWindow::slot_newComment () { | |
239 | ||
240 | } | |
241 | ||
242 | void LDForgeWindow::slot_about () { | |
243 | ||
244 | } | |
245 | ||
246 | void LDForgeWindow::slot_aboutQt () { | |
247 | QMessageBox::aboutQt (this); | |
248 | } | |
249 | ||
250 | void LDForgeWindow::slot_cut () { | |
251 | ||
252 | } | |
253 | ||
254 | void LDForgeWindow::slot_copy () { | |
255 | ||
256 | } | |
257 | ||
258 | void LDForgeWindow::slot_paste () { | |
259 | ||
260 | } | |
261 | ||
262 | void LDForgeWindow::slot_newVector () { | |
263 | ||
264 | } | |
265 | ||
266 | void LDForgeWindow::slot_newVertex () { | |
267 | ||
268 | } | |
269 | ||
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
270 | void LDForgeWindow::slot_setContents () { |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
271 | if (qObjList->selectedItems().size() != 1) |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
272 | return; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
273 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
274 | ulong ulIndex; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
275 | LDObject* obj = nullptr; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
276 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
277 | QTreeWidgetItem* item = qObjList->selectedItems()[0]; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
278 | for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) { |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
279 | obj = g_CurrentFile->objects[ulIndex]; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
280 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
281 | if (obj->qObjListEntry == item) |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
282 | break; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
283 | } |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
284 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
285 | if (ulIndex >= g_CurrentFile->objects.size()) |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
286 | return; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
287 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
288 | Dialog_SetContents::staticDialog (obj, this); |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
289 | } |
0 | 290 | |
291 | static QIcon IconForObjectType (LDObject* obj) { | |
292 | switch (obj->getType ()) { | |
293 | case OBJ_Empty: | |
294 | return QIcon ("icons/empty.png"); | |
295 | ||
296 | case OBJ_Line: | |
297 | return QIcon ("icons/line.png"); | |
298 | ||
299 | case OBJ_Quad: | |
300 | return QIcon ("icons/quad.png"); | |
301 | ||
302 | case OBJ_Subfile: | |
303 | return QIcon ("icons/subfile.png"); | |
304 | ||
305 | case OBJ_Triangle: | |
306 | return QIcon ("icons/triangle.png"); | |
307 | ||
308 | case OBJ_CondLine: | |
309 | return QIcon ("icons/condline.png"); | |
310 | ||
311 | case OBJ_Comment: | |
312 | return QIcon ("icons/comment.png"); | |
313 | ||
314 | case OBJ_Vector: | |
315 | return QIcon ("icons/vector.png"); | |
316 | ||
317 | case OBJ_Vertex: | |
318 | return QIcon ("icons/vertex.png"); | |
319 | ||
320 | case OBJ_Gibberish: | |
321 | case OBJ_Unidentified: | |
322 | return QIcon ("icons/error.png"); | |
323 | } | |
324 | ||
325 | return QIcon (); | |
326 | } | |
327 | ||
328 | void LDForgeWindow::buildObjList () { | |
3
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
329 | if (!g_CurrentFile) |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
330 | return; |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
331 | |
0 | 332 | QList<QTreeWidgetItem*> qaItems; |
3
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
333 | |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
334 | qObjList->clear (); |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
335 | |
0 | 336 | for (ushort i = 0; i < g_CurrentFile->objects.size(); ++i) { |
337 | LDObject* obj = g_CurrentFile->objects[i]; | |
338 | ||
339 | str zText; | |
340 | switch (obj->getType ()) { | |
341 | case OBJ_Comment: | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
342 | zText = static_cast<LDComment*> (obj)->zText.chars(); |
10
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
343 | |
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
344 | // Remove leading whitespace |
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
345 | while (~zText && zText[0] == ' ') |
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
346 | zText -= -1; |
0 | 347 | break; |
348 | ||
349 | case OBJ_Empty: | |
350 | break; // leave it empty | |
351 | ||
352 | case OBJ_Line: | |
353 | case OBJ_CondLine: | |
354 | { | |
355 | LDLine* line = static_cast<LDLine*> (obj); | |
356 | zText.format ("%s, %s", | |
357 | line->vaCoords[0].getStringRep ().chars(), | |
358 | line->vaCoords[1].getStringRep ().chars()); | |
359 | } | |
360 | break; | |
361 | ||
362 | case OBJ_Triangle: | |
363 | { | |
364 | LDTriangle* triangle = static_cast<LDTriangle*> (obj); | |
365 | zText.format ("%s, %s, %s", | |
366 | triangle->vaCoords[0].getStringRep ().chars(), | |
367 | triangle->vaCoords[1].getStringRep ().chars(), | |
368 | triangle->vaCoords[2].getStringRep ().chars()); | |
369 | } | |
370 | break; | |
371 | ||
372 | case OBJ_Quad: | |
373 | { | |
374 | LDQuad* quad = static_cast<LDQuad*> (obj); | |
10
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
375 | zText.format ("%s, %s, %s, %s", |
0 | 376 | quad->vaCoords[0].getStringRep ().chars(), |
377 | quad->vaCoords[1].getStringRep ().chars(), | |
378 | quad->vaCoords[2].getStringRep ().chars(), | |
379 | quad->vaCoords[3].getStringRep ().chars()); | |
380 | } | |
381 | break; | |
382 | ||
383 | case OBJ_Gibberish: | |
384 | zText.format ("ERROR: %s", | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
385 | static_cast<LDGibberish*> (obj)->zContents.chars()); |
0 | 386 | break; |
387 | ||
388 | case OBJ_Vector: | |
389 | zText.format ("%s", static_cast<LDVector*> (obj)->vPos.getStringRep().chars()); | |
390 | break; | |
391 | ||
392 | case OBJ_Vertex: | |
393 | zText.format ("%s", static_cast<LDVertex*> (obj)->vPosition.getStringRep().chars()); | |
394 | break; | |
395 | ||
396 | default: | |
397 | zText = g_saObjTypeNames[obj->getType ()]; | |
398 | break; | |
399 | } | |
400 | ||
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
401 | QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*) (nullptr), |
0 | 402 | QStringList (zText.chars()), 0); |
403 | item->setIcon (0, IconForObjectType (obj)); | |
404 | ||
11
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
405 | // Color gibberish red |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
406 | if (obj->getType() == OBJ_Gibberish) { |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
407 | item->setBackgroundColor (0, "#AA0000"); |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
408 | item->setForeground (0, QColor ("#FFAA00")); |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
409 | } |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
410 | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
411 | obj->qObjListEntry = item; |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
412 | |
0 | 413 | qaItems.append (item); |
414 | } | |
415 | ||
416 | qObjList->insertTopLevelItems (0, qaItems); | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
417 | } |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
418 | |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
419 | void LDForgeWindow::slot_selectionChanged () { |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
420 | |
0 | 421 | } |