gui.cpp

changeset 14
6d9d8efae2f8
parent 11
323390a03294
child 17
5606eebd0b90
equal deleted inserted replaced
13:3955ff2a7d72 14:6d9d8efae2f8
4 #include "draw.h" 4 #include "draw.h"
5 #include "gui.h" 5 #include "gui.h"
6 #include "model.h" 6 #include "model.h"
7 #include "io.h" 7 #include "io.h"
8 8
9 #include "zz_setContentsDialog.h"
10
9 LDForgeWindow::LDForgeWindow () { 11 LDForgeWindow::LDForgeWindow () {
10 R = new renderer; 12 R = new renderer;
11 13
12 qObjList = new QTreeWidget; 14 qObjList = new QTreeWidget;
13 qObjList->setHeaderHidden (true); 15 qObjList->setHeaderHidden (true);
14 qObjList->setMaximumWidth (256); 16 qObjList->setMaximumWidth (256);
17 qObjList->setSelectionMode (QTreeWidget::MultiSelection);
15 18
16 qMessageLog = new QTextEdit; 19 qMessageLog = new QTextEdit;
17 qMessageLog->setReadOnly (true); 20 qMessageLog->setReadOnly (true);
18 qMessageLog->setMaximumHeight (96); 21 qMessageLog->setMaximumHeight (96);
19 22
56 MAKE_ACTION (cut, "Cut", "cut", "Cut the current selection to clipboard.") 59 MAKE_ACTION (cut, "Cut", "cut", "Cut the current selection to clipboard.")
57 MAKE_ACTION (copy, "Copy", "copy", "Copy the current selection to clipboard.") 60 MAKE_ACTION (copy, "Copy", "copy", "Copy the current selection to clipboard.")
58 MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.") 61 MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.")
59 MAKE_ACTION (about, sAboutText, "about", "Shows information about " APPNAME_DISPLAY ".") 62 MAKE_ACTION (about, sAboutText, "about", "Shows information about " APPNAME_DISPLAY ".")
60 MAKE_ACTION (aboutQt, "About Qt", "aboutQt", "Shows information about Qt.") 63 MAKE_ACTION (aboutQt, "About Qt", "aboutQt", "Shows information about Qt.")
64
65 MAKE_ACTION (setContents, "Set Contents", "set-contents", "Set the raw code of this object.")
61 66
62 MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.") 67 MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.")
63 MAKE_ACTION (newLine, "New Line", "add-line", "Creates a new line.") 68 MAKE_ACTION (newLine, "New Line", "add-line", "Creates a new line.")
64 MAKE_ACTION (newTriangle, "New Triangle", "add-triangle", "Creates a new triangle.") 69 MAKE_ACTION (newTriangle, "New Triangle", "add-triangle", "Creates a new triangle.")
65 MAKE_ACTION (newQuad, sNewQuadText, "add-quad", "Creates a new quadrilateral.") 70 MAKE_ACTION (newQuad, sNewQuadText, "add-quad", "Creates a new quadrilateral.")
123 128
124 qEditMenu = menuBar ()->addMenu (tr ("&Edit")); 129 qEditMenu = menuBar ()->addMenu (tr ("&Edit"));
125 qEditMenu->addAction (qAct_cut); // Cut 130 qEditMenu->addAction (qAct_cut); // Cut
126 qEditMenu->addAction (qAct_copy); // Copy 131 qEditMenu->addAction (qAct_copy); // Copy
127 qEditMenu->addAction (qAct_paste); // Paste 132 qEditMenu->addAction (qAct_paste); // Paste
133 qEditMenu->addSeparator (); // -----
134 qEditMenu->addAction (qAct_setContents); // Set Contents
128 135
129 // Help menu 136 // Help menu
130 qHelpMenu = menuBar ()->addMenu (tr ("&Help")); 137 qHelpMenu = menuBar ()->addMenu (tr ("&Help"));
131 qHelpMenu->addAction (qAct_about); // About 138 qHelpMenu->addAction (qAct_about); // About
132 qHelpMenu->addAction (qAct_aboutQt); // About Qt 139 qHelpMenu->addAction (qAct_aboutQt); // About Qt
153 160
154 qEditToolBar = new QToolBar ("Edit"); 161 qEditToolBar = new QToolBar ("Edit");
155 qEditToolBar->addAction (qAct_cut); 162 qEditToolBar->addAction (qAct_cut);
156 qEditToolBar->addAction (qAct_copy); 163 qEditToolBar->addAction (qAct_copy);
157 qEditToolBar->addAction (qAct_paste); 164 qEditToolBar->addAction (qAct_paste);
165 qEditToolBar->addAction (qAct_setContents);
158 addToolBar (qEditToolBar); 166 addToolBar (qEditToolBar);
159 } 167 }
160 168
161 void LDForgeWindow::setTitle () { 169 void LDForgeWindow::setTitle () {
162 str zTitle = APPNAME_DISPLAY " v" VERSION_STRING; 170 str zTitle = APPNAME_DISPLAY " v" VERSION_STRING;
257 265
258 void LDForgeWindow::slot_newVertex () { 266 void LDForgeWindow::slot_newVertex () {
259 267
260 } 268 }
261 269
270 void LDForgeWindow::slot_setContents () {
271 if (qObjList->selectedItems().size() != 1)
272 return;
273
274 ulong ulIndex;
275 LDObject* obj = nullptr;
276
277 QTreeWidgetItem* item = qObjList->selectedItems()[0];
278 for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) {
279 obj = g_CurrentFile->objects[ulIndex];
280
281 if (obj->qObjListEntry == item)
282 break;
283 }
284
285 if (ulIndex >= g_CurrentFile->objects.size())
286 return;
287
288 Dialog_SetContents::staticDialog (obj, this);
289 }
262 290
263 static QIcon IconForObjectType (LDObject* obj) { 291 static QIcon IconForObjectType (LDObject* obj) {
264 switch (obj->getType ()) { 292 switch (obj->getType ()) {
265 case OBJ_Empty: 293 case OBJ_Empty:
266 return QIcon ("icons/empty.png"); 294 return QIcon ("icons/empty.png");
309 LDObject* obj = g_CurrentFile->objects[i]; 337 LDObject* obj = g_CurrentFile->objects[i];
310 338
311 str zText; 339 str zText;
312 switch (obj->getType ()) { 340 switch (obj->getType ()) {
313 case OBJ_Comment: 341 case OBJ_Comment:
314 zText = static_cast<LDComment*> (obj)->zText; 342 zText = static_cast<LDComment*> (obj)->zText.chars();
315 343
316 // Remove leading whitespace 344 // Remove leading whitespace
317 while (~zText && zText[0] == ' ') 345 while (~zText && zText[0] == ' ')
318 zText -= -1; 346 zText -= -1;
319 break; 347 break;
352 } 380 }
353 break; 381 break;
354 382
355 case OBJ_Gibberish: 383 case OBJ_Gibberish:
356 zText.format ("ERROR: %s", 384 zText.format ("ERROR: %s",
357 static_cast<LDGibberish*> (obj)->zContent.chars()); 385 static_cast<LDGibberish*> (obj)->zContents.chars());
358 break; 386 break;
359 387
360 case OBJ_Vector: 388 case OBJ_Vector:
361 zText.format ("%s", static_cast<LDVector*> (obj)->vPos.getStringRep().chars()); 389 zText.format ("%s", static_cast<LDVector*> (obj)->vPos.getStringRep().chars());
362 break; 390 break;
368 default: 396 default:
369 zText = g_saObjTypeNames[obj->getType ()]; 397 zText = g_saObjTypeNames[obj->getType ()];
370 break; 398 break;
371 } 399 }
372 400
373 QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*)nullptr, 401 QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*) (nullptr),
374 QStringList (zText.chars()), 0); 402 QStringList (zText.chars()), 0);
375 item->setIcon (0, IconForObjectType (obj)); 403 item->setIcon (0, IconForObjectType (obj));
376 404
377 // Color gibberish red 405 // Color gibberish red
378 if (obj->getType() == OBJ_Gibberish) { 406 if (obj->getType() == OBJ_Gibberish) {
379 item->setBackgroundColor (0, "#AA0000"); 407 item->setBackgroundColor (0, "#AA0000");
380 item->setForeground (0, QColor ("#FFAA00")); 408 item->setForeground (0, QColor ("#FFAA00"));
381 } 409 }
382 410
411 obj->qObjListEntry = item;
412
383 qaItems.append (item); 413 qaItems.append (item);
384 } 414 }
385 415
386 qObjList->insertTopLevelItems (0, qaItems); 416 qObjList->insertTopLevelItems (0, qaItems);
387 } 417 }
418
419 void LDForgeWindow::slot_selectionChanged () {
420
421 }

mercurial