75 EXTERN_ACTION (rotateZNeg) |
75 EXTERN_ACTION (rotateZNeg) |
76 EXTERN_ACTION (rotateXPos) |
76 EXTERN_ACTION (rotateXPos) |
77 EXTERN_ACTION (rotateYPos) |
77 EXTERN_ACTION (rotateYPos) |
78 EXTERN_ACTION (rotateZPos) |
78 EXTERN_ACTION (rotateZPos) |
79 EXTERN_ACTION (roundCoords) |
79 EXTERN_ACTION (roundCoords) |
|
80 EXTERN_ACTION (gridCoarse) |
|
81 EXTERN_ACTION (gridMedium) |
|
82 EXTERN_ACTION (gridFine) |
80 |
83 |
81 #ifndef RELEASE |
84 #ifndef RELEASE |
82 EXTERN_ACTION (addTestQuad) |
85 EXTERN_ACTION (addTestQuad) |
83 EXTERN_ACTION (addTestRadial) |
86 EXTERN_ACTION (addTestRadial) |
84 #endif // RELEASE |
87 #endif // RELEASE |
90 cfg (bool, lv_colorize, true); |
93 cfg (bool, lv_colorize, true); |
91 cfg (int, gui_toolbar_iconsize, 24); |
94 cfg (int, gui_toolbar_iconsize, 24); |
92 cfg (str, gui_colortoolbar, "16:24:|:0:1:2:3:4:5:6:7"); |
95 cfg (str, gui_colortoolbar, "16:24:|:0:1:2:3:4:5:6:7"); |
93 extern_cfg (str, io_recentfiles); |
96 extern_cfg (str, io_recentfiles); |
94 |
97 |
95 // ========================================================================= // |
98 // ============================================================================= |
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
97 // ========================================================================= // |
100 // ============================================================================= |
98 ForgeWindow::ForgeWindow () { |
101 ForgeWindow::ForgeWindow () { |
99 g_ForgeWindow = this; |
102 g_ForgeWindow = this; |
100 R = new GLRenderer; |
103 R = new GLRenderer; |
101 |
104 |
102 qObjList = new QTreeWidget; |
105 qObjList = new QTreeWidget; |
134 setTitle (); |
137 setTitle (); |
135 setMinimumSize (320, 200); |
138 setMinimumSize (320, 200); |
136 resize (800, 600); |
139 resize (800, 600); |
137 } |
140 } |
138 |
141 |
139 // ========================================================================= // |
142 // ============================================================================= |
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
141 // ========================================================================= // |
144 // ============================================================================= |
142 void ForgeWindow::createMenuActions () { |
145 void ForgeWindow::createMenuActions () { |
143 // Create the actions based on stored meta. |
146 // Create the actions based on stored meta. |
144 for (actionmeta meta : g_ActionMeta) { |
147 for (actionmeta meta : g_ActionMeta) { |
145 QAction*& qAct = *meta.qAct; |
148 QAction*& qAct = *meta.qAct; |
146 qAct = new QAction (getIcon (meta.sIconName), meta.sDisplayName, this); |
149 qAct = new QAction (getIcon (meta.sIconName), meta.sDisplayName, this); |
148 qAct->setShortcut (*meta.conf); |
151 qAct->setShortcut (*meta.conf); |
149 |
152 |
150 connect (qAct, SIGNAL (triggered ()), this, SLOT (slot_action ())); |
153 connect (qAct, SIGNAL (triggered ()), this, SLOT (slot_action ())); |
151 } |
154 } |
152 |
155 |
|
156 // Grid actions are checkable |
|
157 ACTION_NAME (gridCoarse)->setCheckable (true); |
|
158 ACTION_NAME (gridMedium)->setCheckable (true); |
|
159 ACTION_NAME (gridFine)->setCheckable (true); |
|
160 |
153 // things not implemented yet |
161 // things not implemented yet |
154 QAction* const qaDisabledActions[] = { |
162 QAction* const qaDisabledActions[] = { |
155 ACTION_NAME (newSubfile), |
163 ACTION_NAME (newSubfile), |
156 ACTION_NAME (help), |
164 ACTION_NAME (help), |
157 }; |
165 }; |
160 act->setEnabled (false); |
168 act->setEnabled (false); |
161 |
169 |
162 History::updateActions (); |
170 History::updateActions (); |
163 } |
171 } |
164 |
172 |
165 // ========================================================================= // |
173 // ============================================================================= |
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
167 // ========================================================================= // |
175 // ============================================================================= |
168 void ForgeWindow::createMenus () { |
176 void ForgeWindow::createMenus () { |
169 qRecentFilesMenu = new QMenu (tr ("Open &Recent")); |
177 qRecentFilesMenu = new QMenu (tr ("Open &Recent")); |
170 qRecentFilesMenu->setIcon (getIcon ("open-recent")); |
178 qRecentFilesMenu->setIcon (getIcon ("open-recent")); |
171 updateRecentFilesMenu (); |
179 updateRecentFilesMenu (); |
172 |
180 |
219 // Move menu |
227 // Move menu |
220 qMoveMenu = menuBar ()->addMenu (tr ("&Move")); |
228 qMoveMenu = menuBar ()->addMenu (tr ("&Move")); |
221 qMoveMenu->addAction (ACTION_NAME (moveUp)); // Move Up |
229 qMoveMenu->addAction (ACTION_NAME (moveUp)); // Move Up |
222 qMoveMenu->addAction (ACTION_NAME (moveDown)); // Move Down |
230 qMoveMenu->addAction (ACTION_NAME (moveDown)); // Move Down |
223 qMoveMenu->addSeparator (); // ----- |
231 qMoveMenu->addSeparator (); // ----- |
|
232 qMoveMenu->addAction (ACTION_NAME (gridCoarse)); // Coarse Grid |
|
233 qMoveMenu->addAction (ACTION_NAME (gridMedium)); // Medium Grid |
|
234 qMoveMenu->addAction (ACTION_NAME (gridFine)); // Fine Grid |
|
235 qMoveMenu->addSeparator (); // ----- |
224 qMoveMenu->addAction (ACTION_NAME (moveXPos)); // Move +X |
236 qMoveMenu->addAction (ACTION_NAME (moveXPos)); // Move +X |
225 qMoveMenu->addAction (ACTION_NAME (moveXNeg)); // Move -X |
237 qMoveMenu->addAction (ACTION_NAME (moveXNeg)); // Move -X |
226 qMoveMenu->addAction (ACTION_NAME (moveYPos)); // Move +Y |
238 qMoveMenu->addAction (ACTION_NAME (moveYPos)); // Move +Y |
227 qMoveMenu->addAction (ACTION_NAME (moveYNeg)); // Move -Y |
239 qMoveMenu->addAction (ACTION_NAME (moveYNeg)); // Move -Y |
228 qMoveMenu->addAction (ACTION_NAME (moveZPos)); // Move +Z |
240 qMoveMenu->addAction (ACTION_NAME (moveZPos)); // Move +Z |
252 qHelpMenu->addSeparator (); // ----- |
264 qHelpMenu->addSeparator (); // ----- |
253 qHelpMenu->addAction (ACTION_NAME (about)); // About |
265 qHelpMenu->addAction (ACTION_NAME (about)); // About |
254 qHelpMenu->addAction (ACTION_NAME (aboutQt)); // About Qt |
266 qHelpMenu->addAction (ACTION_NAME (aboutQt)); // About Qt |
255 } |
267 } |
256 |
268 |
257 // ========================================================================= // |
269 // ============================================================================= |
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
259 // ========================================================================= // |
271 // ============================================================================= |
260 void ForgeWindow::updateRecentFilesMenu () { |
272 void ForgeWindow::updateRecentFilesMenu () { |
261 // First, clear any items in the recent files menu |
273 // First, clear any items in the recent files menu |
262 for (QAction* qRecent : qaRecentFiles) |
274 for (QAction* qRecent : qaRecentFiles) |
263 delete qRecent; |
275 delete qRecent; |
264 qaRecentFiles.clear (); |
276 qaRecentFiles.clear (); |
273 qRecentFilesMenu->addAction (qRecent); |
285 qRecentFilesMenu->addAction (qRecent); |
274 qaRecentFiles.push_back (qRecent); |
286 qaRecentFiles.push_back (qRecent); |
275 } |
287 } |
276 } |
288 } |
277 |
289 |
278 // ========================================================================= // |
290 // ============================================================================= |
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
280 // ========================================================================= // |
292 // ============================================================================= |
281 #define ADD_TOOLBAR_ITEM(ACT) g_CurrentToolBar->addAction (ACTION_NAME (ACT)); |
293 #define ADD_TOOLBAR_ITEM(ACT) g_CurrentToolBar->addAction (ACTION_NAME (ACT)); |
282 static QToolBar* g_CurrentToolBar; |
294 static QToolBar* g_CurrentToolBar; |
283 static Qt::ToolBarArea g_ToolBarArea = Qt::TopToolBarArea; |
295 static Qt::ToolBarArea g_ToolBarArea = Qt::TopToolBarArea; |
284 |
296 |
285 void ForgeWindow::initSingleToolBar (const char* sName) { |
297 void ForgeWindow::initSingleToolBar (const char* sName) { |
344 ADD_TOOLBAR_ITEM (rotateZPos) |
356 ADD_TOOLBAR_ITEM (rotateZPos) |
345 ADD_TOOLBAR_ITEM (rotateZNeg) |
357 ADD_TOOLBAR_ITEM (rotateZNeg) |
346 |
358 |
347 // ========================================== |
359 // ========================================== |
348 // Grid toolbar |
360 // Grid toolbar |
349 qGridToolBar = new QToolBar ("Grids"); |
361 initSingleToolBar ("Grids"); |
350 addToolBar (Qt::TopToolBarArea, qGridToolBar); |
362 ADD_TOOLBAR_ITEM (gridCoarse) |
351 |
363 ADD_TOOLBAR_ITEM (gridMedium) |
352 for (int i = 0; i < g_NumGrids; ++i) { |
364 ADD_TOOLBAR_ITEM (gridFine) |
353 QIcon icon = getIcon (format ("grid-%s", str (g_GridInfo[i].name).tolower ().chars ())); |
|
354 gridActions[i] = new QAction (icon, "", this); |
|
355 gridActions[i]->setCheckable (true); |
|
356 |
|
357 qGridToolBar->addAction (gridActions[i]); |
|
358 |
|
359 connect (gridActions[i], SIGNAL (triggered ()), this, SLOT (slot_setGrid ())); |
|
360 } |
|
361 |
365 |
362 // ========================================== |
366 // ========================================== |
363 // Color toolbar |
367 // Color toolbar |
364 qColorToolBar = new QToolBar ("Quick Colors"); |
368 qColorToolBar = new QToolBar ("Quick Colors"); |
365 addToolBar (Qt::RightToolBarArea, qColorToolBar); |
369 addToolBar (Qt::RightToolBarArea, qColorToolBar); |
379 ADD_TOOLBAR_ITEM (roundCoords) |
383 ADD_TOOLBAR_ITEM (roundCoords) |
380 |
384 |
381 updateToolBars (); |
385 updateToolBars (); |
382 } |
386 } |
383 |
387 |
384 // ========================================================================= // |
388 // ============================================================================= |
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
386 // ========================================================================= // |
390 // ============================================================================= |
387 std::vector<quickColorMetaEntry> parseQuickColorMeta () { |
391 std::vector<quickColorMetaEntry> parseQuickColorMeta () { |
388 std::vector<quickColorMetaEntry> meta; |
392 std::vector<quickColorMetaEntry> meta; |
389 |
393 |
390 for (str zColor : gui_colortoolbar.value / ":") { |
394 for (str zColor : gui_colortoolbar.value / ":") { |
391 if (zColor == "|") { |
395 if (zColor == "|") { |
397 } |
401 } |
398 |
402 |
399 return meta; |
403 return meta; |
400 } |
404 } |
401 |
405 |
402 // ========================================================================= // |
406 // ============================================================================= |
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
404 // ========================================================================= // |
408 // ============================================================================= |
405 void ForgeWindow::updateToolBars () { |
409 void ForgeWindow::updateToolBars () { |
406 for (QToolBar* qBar : qaToolBars) |
410 for (QToolBar* qBar : qaToolBars) |
407 qBar->setIconSize (QSize (gui_toolbar_iconsize, gui_toolbar_iconsize)); |
411 qBar->setIconSize (QSize (gui_toolbar_iconsize, gui_toolbar_iconsize)); |
408 |
412 |
409 // Update the quick color toolbar. |
413 // Update the quick color toolbar. |
430 |
434 |
431 entry.btn = qColorButton; |
435 entry.btn = qColorButton; |
432 } |
436 } |
433 } |
437 } |
434 |
438 |
435 for (short i = 0; i < g_NumGrids; ++i) |
439 updateGridToolBar (); |
436 gridActions[i]->setChecked (i == grid); |
440 } |
437 } |
441 |
438 |
442 // ============================================================================= |
439 // ========================================================================= // |
443 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
444 // ============================================================================= |
441 // ========================================================================= // |
445 void ForgeWindow::updateGridToolBar () { |
|
446 // Ensure that the current grid - and only the current grid - is selected. |
|
447 ACTION_NAME (gridCoarse)->setChecked (grid == Grid::Coarse); |
|
448 ACTION_NAME (gridMedium)->setChecked (grid == Grid::Medium); |
|
449 ACTION_NAME (gridFine)->setChecked (grid == Grid::Fine); |
|
450 } |
|
451 |
|
452 // ============================================================================= |
|
453 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
454 // ============================================================================= |
442 void ForgeWindow::setTitle () { |
455 void ForgeWindow::setTitle () { |
443 str zTitle = APPNAME_DISPLAY " v" VERSION_STRING; |
456 str zTitle = APPNAME_DISPLAY " v" VERSION_STRING; |
444 |
457 |
445 // Append our current file if we have one |
458 // Append our current file if we have one |
446 if (g_CurrentFile) { |
459 if (g_CurrentFile) { |
456 } |
469 } |
457 |
470 |
458 setWindowTitle (zTitle.chars()); |
471 setWindowTitle (zTitle.chars()); |
459 } |
472 } |
460 |
473 |
461 // ========================================================================= // |
474 // ============================================================================= |
462 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
475 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
463 // ========================================================================= // |
476 // ============================================================================= |
464 void ForgeWindow::slot_action () { |
477 void ForgeWindow::slot_action () { |
465 // Get the action that triggered this slot. |
478 // Get the action that triggered this slot. |
466 QAction* qAct = static_cast<QAction*> (sender ()); |
479 QAction* qAct = static_cast<QAction*> (sender ()); |
467 |
480 |
468 // Find the meta for the action. |
481 // Find the meta for the action. |
482 |
495 |
483 // We have the meta, now call the handler. |
496 // We have the meta, now call the handler. |
484 (*pMeta->handler) (); |
497 (*pMeta->handler) (); |
485 } |
498 } |
486 |
499 |
487 // ========================================================================= // |
500 // ============================================================================= |
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
489 // ========================================================================= // |
502 // ============================================================================= |
490 void ForgeWindow::deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects) { |
503 void ForgeWindow::deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects) { |
491 if (selection ().size () == 0) |
504 if (selection ().size () == 0) |
492 return; |
505 return; |
493 |
506 |
494 std::vector<LDObject*> sel = selection (); |
507 std::vector<LDObject*> sel = selection (); |
505 } |
518 } |
506 |
519 |
507 refresh (); |
520 refresh (); |
508 } |
521 } |
509 |
522 |
510 // ========================================================================= // |
523 // ============================================================================= |
511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
524 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
512 // ========================================================================= // |
525 // ============================================================================= |
513 void ForgeWindow::buildObjList () { |
526 void ForgeWindow::buildObjList () { |
514 if (!g_CurrentFile) |
527 if (!g_CurrentFile) |
515 return; |
528 return; |
516 |
529 |
517 // Lock the selection while we do this so that refreshing the object list |
530 // Lock the selection while we do this so that refreshing the object list |
734 } |
747 } |
735 |
748 |
736 // ============================================================================= |
749 // ============================================================================= |
737 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
750 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
738 // ============================================================================= |
751 // ============================================================================= |
739 void ForgeWindow::slot_setGrid () { |
|
740 short idx; |
|
741 for (idx = 0; idx < g_NumGrids; ++idx) |
|
742 if (sender () == gridActions[idx]) |
|
743 break; |
|
744 |
|
745 assert (idx < g_NumGrids); |
|
746 |
|
747 grid = idx; |
|
748 |
|
749 for (short i = 0; i < g_NumGrids; ++i) |
|
750 if (i != idx) |
|
751 gridActions[i]->setChecked (false); |
|
752 } |
|
753 |
|
754 // ============================================================================= |
|
755 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
756 // ============================================================================= |
|
757 ulong ForgeWindow::getInsertionPoint () { |
752 ulong ForgeWindow::getInsertionPoint () { |
758 ulong ulIndex; |
753 ulong ulIndex; |
759 |
754 |
760 if (qObjList->selectedItems().size() == 1) { |
755 if (qObjList->selectedItems().size() == 1) { |
761 // If we have a selection, put the item after it. |
756 // If we have a selection, put the item after it. |