gui.cpp

changeset 50
7fd213c6b844
parent 49
242f6ea0f5e5
child 52
d71226763607
equal deleted inserted replaced
49:242f6ea0f5e5 50:7fd213c6b844
90 90
91 MAKE_ACTION (cut, "Cut", "cut", "Cut the current selection to clipboard.") 91 MAKE_ACTION (cut, "Cut", "cut", "Cut the current selection to clipboard.")
92 MAKE_ACTION (copy, "Copy", "copy", "Copy the current selection to clipboard.") 92 MAKE_ACTION (copy, "Copy", "copy", "Copy the current selection to clipboard.")
93 MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.") 93 MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.")
94 94
95 MAKE_ACTION (setColor, "Set Color", "palette", "Set the color on given objects.")
95 MAKE_ACTION (inline, "Inline", "inline", "Inline selected subfiles.") 96 MAKE_ACTION (inline, "Inline", "inline", "Inline selected subfiles.")
96 MAKE_ACTION (splitQuads, "Split Quads", "quad-split", "Split quads into triangles.") 97 MAKE_ACTION (splitQuads, "Split Quads", "quad-split", "Split quads into triangles.")
97 MAKE_ACTION (setContents, "Set Contents", "set-contents", "Set the raw code of this object.") 98 MAKE_ACTION (setContents, "Set Contents", "set-contents", "Set the raw code of this object.")
98 99
99 MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.") 100 MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.")
107 MAKE_ACTION (settings, "Settings", "settings", "Edit the settings of " APPNAME_DISPLAY ".") 108 MAKE_ACTION (settings, "Settings", "settings", "Edit the settings of " APPNAME_DISPLAY ".")
108 109
109 MAKE_ACTION (help, "Help", "help", "Shows the " APPNAME_DISPLAY " help manual.") 110 MAKE_ACTION (help, "Help", "help", "Shows the " APPNAME_DISPLAY " help manual.")
110 MAKE_ACTION (about, sAboutText, "ldforge", "Shows information about " APPNAME_DISPLAY ".") 111 MAKE_ACTION (about, sAboutText, "ldforge", "Shows information about " APPNAME_DISPLAY ".")
111 MAKE_ACTION (aboutQt, "About Qt", "aboutQt", "Shows information about Qt.") 112 MAKE_ACTION (aboutQt, "About Qt", "aboutQt", "Shows information about Qt.")
112
113 MAKE_ACTION (testColorSelect, "Test colors", "palette", "Test the color selection dialog")
114 113
115 // Keyboard shortcuts 114 // Keyboard shortcuts
116 qAct_new->setShortcut (Qt::CTRL | Qt::Key_N); 115 qAct_new->setShortcut (Qt::CTRL | Qt::Key_N);
117 qAct_open->setShortcut (Qt::CTRL | Qt::Key_O); 116 qAct_open->setShortcut (Qt::CTRL | Qt::Key_O);
118 qAct_save->setShortcut (Qt::CTRL | Qt::Key_S); 117 qAct_save->setShortcut (Qt::CTRL | Qt::Key_S);
165 qEditMenu = menuBar ()->addMenu (tr ("&Edit")); 164 qEditMenu = menuBar ()->addMenu (tr ("&Edit"));
166 qEditMenu->addAction (qAct_cut); // Cut 165 qEditMenu->addAction (qAct_cut); // Cut
167 qEditMenu->addAction (qAct_copy); // Copy 166 qEditMenu->addAction (qAct_copy); // Copy
168 qEditMenu->addAction (qAct_paste); // Paste 167 qEditMenu->addAction (qAct_paste); // Paste
169 qEditMenu->addSeparator (); // ----- 168 qEditMenu->addSeparator (); // -----
169 qEditMenu->addAction (qAct_setColor); // Set Color
170 qEditMenu->addSeparator (); // -----
170 qEditMenu->addAction (qAct_inline); // Inline 171 qEditMenu->addAction (qAct_inline); // Inline
171 qEditMenu->addAction (qAct_splitQuads); // Split Quads 172 qEditMenu->addAction (qAct_splitQuads); // Split Quads
172 qEditMenu->addAction (qAct_setContents); // Set Contents 173 qEditMenu->addAction (qAct_setContents); // Set Contents
173 174
174 // Help menu 175 // Help menu
202 203
203 qEditToolBar = new QToolBar ("Edit"); 204 qEditToolBar = new QToolBar ("Edit");
204 qEditToolBar->addAction (qAct_cut); 205 qEditToolBar->addAction (qAct_cut);
205 qEditToolBar->addAction (qAct_copy); 206 qEditToolBar->addAction (qAct_copy);
206 qEditToolBar->addAction (qAct_paste); 207 qEditToolBar->addAction (qAct_paste);
208 qEditToolBar->addAction (qAct_setColor);
207 qEditToolBar->addAction (qAct_inline); 209 qEditToolBar->addAction (qAct_inline);
208 qEditToolBar->addAction (qAct_splitQuads); 210 qEditToolBar->addAction (qAct_splitQuads);
209 qEditToolBar->addAction (qAct_setContents); 211 qEditToolBar->addAction (qAct_setContents);
210 qEditToolBar->addAction (qAct_testColorSelect);
211 addToolBar (qEditToolBar); 212 addToolBar (qEditToolBar);
212 } 213 }
213 214
214 // ============================================================================= 215 // =============================================================================
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
389 390
390 if (ulIndex >= g_CurrentFile->objects.size()) 391 if (ulIndex >= g_CurrentFile->objects.size())
391 return; 392 return;
392 393
393 SetContentsDialog::staticDialog (obj, this); 394 SetContentsDialog::staticDialog (obj, this);
395 }
396
397 // =============================================================================
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
399 // =============================================================================
400 void ForgeWindow::slot_setColor () {
401 if (qObjList->selectedItems().size() <= 0)
402 return;
403
404 short dColor;
405 short dDefault = -1;
406
407 std::vector<LDObject*> objs = getSelectedObjects ();
408
409 // Try to get a consensus on the color used for use as a default.
410 for (ulong i = 0; i < objs.size(); ++i) {
411 LDObject* obj = objs[i];
412
413 if (obj->dColor == -1)
414 continue; // doesn't use colors
415
416 if (dDefault != -1 && obj->dColor != dDefault) {
417 // No unanimosity in object color, therefore we don't have a
418 // proper default value to use.
419 dDefault = -1;
420 break;
421 }
422
423 if (dDefault == -1)
424 dDefault = obj->dColor;
425 }
426
427 // Show the dialog to the user now and ask him for a color.
428 if (ColorSelectDialog::staticDialog (dColor, dDefault, this)) {
429 for (ulong i = 0; i < objs.size(); ++i) {
430 LDObject* obj = objs[i];
431 if (obj->dColor != -1)
432 obj->dColor = dColor;
433 }
434
435 refresh ();
436 }
394 } 437 }
395 438
396 // ============================================================================= 439 // =============================================================================
397 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
398 // ============================================================================= 441 // =============================================================================
546 void ForgeWindow::refresh () { 589 void ForgeWindow::refresh () {
547 buildObjList (); 590 buildObjList ();
548 R->hardRefresh (); 591 R->hardRefresh ();
549 } 592 }
550 593
551 void ForgeWindow::slot_testColorSelect () { 594 // =============================================================================
552 short dColor; 595 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
553 if (ColorSelectDialog::staticDialog (dColor, -1, this)) { 596 // =============================================================================
554 printf ("you selected %s!\n", g_LDColors[dColor]->zName.chars()); 597 std::vector<LDObject*> ForgeWindow::getSelectedObjects () {
555 } 598 std::vector<LDObject*> objs;
556 } 599
600 QList<QTreeWidgetItem*> const qaItems = qObjList->selectedItems();
601 for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) {
602 LDObject* obj = g_CurrentFile->objects[i];
603
604 for (long j = 0; j < qaItems.size(); ++j) {
605 if (qaItems[j] == obj->qObjListEntry) {
606 objs.push_back (obj);
607 break;
608 }
609 }
610 }
611
612 return objs;
613 }

mercurial