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