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