# HG changeset patch # User Santeri Piippo # Date 1387789074 -7200 # Node ID 507e5d5c348cd99c4b09a0dd29bb2cb6d134fa06 # Parent 89d1161197d3fca7bc8e36db26eee73508a68ac8 - removed the horrible actions.h hack in favor of usage of Qt's meta object system diff -r 89d1161197d3 -r 507e5d5c348c src/actions.h --- a/src/actions.h Sun Dec 22 20:46:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 Santeri Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -act (New) -act (NewFile) -act (Open) -act (DownloadFrom) -act (Save) -act (SaveAs) -act (SaveAll) -act (Close) -act (CloseAll) -act (InsertFrom) -act (ExportTo) -act (Settings) -act (SetLDrawPath) -act (ScanPrimitives) -act (Exit) -act (ResetView) -act (Axes) -act (Wireframe) -act (BFCView) -act (SetOverlay) -act (ClearOverlay) -act (Screenshot) -act (InsertRaw) -act (NewSubfile) -act (NewLine) -act (NewTriangle) -act (NewQuad) -act (NewCLine) -act (NewComment) -act (NewBFC) -act (NewVertex) -act (Undo) -act (Redo) -act (Cut) -act (Copy) -act (Paste) -act (Delete) -act (SelectAll) -act (SelectByColor) -act (SelectByType) -act (ModeDraw) -act (ModeSelect) -act (ModeCircle) -act (SetDrawDepth) -act (SetColor) -act (Autocolor) -act (Uncolorize) -act (Inline) -act (InlineDeep) -act (Invert) -act (MakePrimitive) -act (SplitQuads) -act (EditRaw) -act (Borders) -act (CornerVerts) -act (RoundCoordinates) -act (VisibilityHide) -act (VisibilityReveal) -act (VisibilityToggle) -act (ReplaceCoords) -act (Flip) -act (Demote) -act (Ytruder) -act (Rectifier) -act (Intersector) -act (Isecalc) -act (Coverer) -act (Edger2) -act (Help) -act (About) -act (AboutQt) -act (GridCoarse) -act (GridMedium) -act (GridFine) -act (Edit) -act (MoveUp) -act (MoveDown) -act (MoveXNeg) -act (MoveXPos) -act (MoveYNeg) -act (MoveYPos) -act (MoveZNeg) -act (MoveZPos) -act (RotateXNeg) -act (RotateXPos) -act (RotateYNeg) -act (RotateYPos) -act (RotateZNeg) -act (RotateZPos) -act (RotationPoint) -act (AddHistoryLine) -act (JumpTo) -act (SubfileSelection) -act (DrawAngles) - -#undef act \ No newline at end of file diff -r 89d1161197d3 -r 507e5d5c348c src/config.cc --- a/src/config.cc Sun Dec 22 20:46:46 2013 +0200 +++ b/src/config.cc Mon Dec 23 10:57:54 2013 +0200 @@ -138,3 +138,31 @@ assert (g_cfgPointerCursor < MAX_CONFIG); g_configPointers[g_cfgPointerCursor++] = ptr; } + +// ============================================================================= +// ----------------------------------------------------------------------------- +template T& getConfigByName (str name, Config::Type type) +{ for (Config* cfg : g_configPointers) + { if (!cfg) + break; + + if (cfg->name == name) + { assert (cfg->getType() == type); + return *(reinterpret_cast (cfg)); + } + } + + qFatal ("couldn't find a configuration element with name %s", name.toLocal8Bit().constData()); + abort(); +} + +#undef IMPLEMENT_CONFIG +#define IMPLEMENT_CONFIG(NAME) \ + NAME##Config& NAME##Config::getByName (str name) { return getConfigByName (name, NAME); } + +IMPLEMENT_CONFIG (Int) +IMPLEMENT_CONFIG (String) +IMPLEMENT_CONFIG (Bool) +IMPLEMENT_CONFIG (Float) +IMPLEMENT_CONFIG (List) +IMPLEMENT_CONFIG (KeySequence) \ No newline at end of file diff -r 89d1161197d3 -r 507e5d5c348c src/config.h --- a/src/config.h Sun Dec 22 20:46:46 2013 +0200 +++ b/src/config.h Mon Dec 23 10:57:54 2013 +0200 @@ -98,6 +98,7 @@ virtual QVariant toVariant() const override { return QVariant::fromValue (value); } \ virtual QVariant defaultVariant() const override { return QVariant::fromValue (defval); } \ virtual void loadFromVariant (const QVariant& val) override { value = val.value(); } \ + static NAME##Config& getByName (str name); #define DEFINE_UNARY_OPERATOR(T, OP) \ T operator OP() { \ diff -r 89d1161197d3 -r 507e5d5c348c src/configDialog.cc --- a/src/configDialog.cc Sun Dec 22 20:46:46 2013 +0200 +++ b/src/configDialog.cc Mon Dec 23 10:57:54 2013 +0200 @@ -72,9 +72,6 @@ extern_cfg (Bool, prog_isecalc_wine); extern_cfg (Bool, prog_edger2_wine); -#define act(N) extern_cfg (KeySequence, key_##N); -#include "actions.h" - const char* g_extProgPathFilter = #ifdef _WIN32 "Applications (*.exe)(*.exe);;All files (*.*)(*.*)"; @@ -111,8 +108,10 @@ ui->linelengths->setChecked (gl_linelengths); int i = 0; -#define act(N) addShortcut (key_##N, ACTION(N), i); -#include "actions.h" + + for (QAction* act : g_win->findChildren()) + if (!act->objectName().isEmpty()) + addShortcut (g_win->shortcutForAction (act), act, i); ui->shortcutsList->setSortingEnabled (true); ui->shortcutsList->sortItems(); @@ -328,8 +327,7 @@ g_GridInfo[i].confs[j]->value = dsb_gridData[i][j]->value(); // Apply key shortcuts -#define act(N) ACTION(N)->setShortcut (key_##N); -#include "actions.h" + g_win->updateActionShortcuts(); // Ext program settings for (const LDExtProgInfo& info : g_LDExtProgInfo) diff -r 89d1161197d3 -r 507e5d5c348c src/gldraw.cc --- a/src/gldraw.cc Sun Dec 22 20:46:46 2013 +0200 +++ b/src/gldraw.cc Mon Dec 23 10:57:54 2013 +0200 @@ -1526,9 +1526,7 @@ } if (objs.size() > 0) - { g_win->beginAction (null); - - for (LDObject* obj : objs) + { for (LDObject* obj : objs) { getFile()->addObject (obj); compileObject (obj); } @@ -1901,7 +1899,6 @@ if (selection().isEmpty()) return; - g_win->beginAction (null); LDObject* obj = selection().first(); AddObjectDialog::staticDialog (obj->getType(), obj); g_win->endAction(); diff -r 89d1161197d3 -r 507e5d5c348c src/gui.cc --- a/src/gui.cc Sun Dec 22 20:46:46 2013 +0200 +++ b/src/gui.cc Mon Dec 23 10:57:54 2013 +0200 @@ -34,6 +34,7 @@ #include #include #include +#include #include "main.h" #include "gldraw.h" @@ -63,9 +64,6 @@ extern_cfg (Bool, gl_colorbfc); extern_cfg (Bool, gl_drawangles); -#define act(N) extern_cfg (KeySequence, key_##N); -#include "actions.h" - // ============================================================================= // ----------------------------------------------------------------------------- ForgeWindow::ForgeWindow() @@ -109,37 +107,57 @@ updateRecentFilesMenu(); updateToolBars(); updateTitle(); + updateActionShortcuts(); setMinimumSize (300, 200); connect (qApp, SIGNAL (aboutToQuit()), this, SLOT (slot_lastSecondCleanup())); - // Connect all actions and set shortcuts -#define act(N) \ - connect (ui->action##N, SIGNAL (triggered()), this, SLOT (slot_action())); \ - ui->action##N->setShortcut (key_##N); -#include "actions.h" + // Connect all actions + for (QAction* act : findChildren()) + if (!act->objectName().isEmpty()) + connect (act, SIGNAL (triggered()), this, SLOT (slot_action())); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +KeySequenceConfig& ForgeWindow::shortcutForAction (QAction* act) +{ str keycfgname = fmt ("key_%1", act->objectName()); + return KeySequenceConfig::getByName (keycfgname); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void ForgeWindow::updateActionShortcuts() +{ for (QAction* act : findChildren()) + if (!act->objectName().isEmpty()) + act->setShortcut (shortcutForAction (act)); } // ============================================================================= // ----------------------------------------------------------------------------- void ForgeWindow::slot_action() -{ // Find out which action triggered this -#define act(N) if (sender() == ui->action##N) invokeAction (ui->action##N, &actiondef_##N); -#include "actions.h" +{ // Get the name of the sender object and use it to compose the slot name. + str methodName = fmt ("slot_%1", sender()->objectName()); + +#ifdef DEBUG + log ("Action %1 triggered", sender()->objectName()); +#endif + + // Now invoke this slot to call the action. + QMetaObject::invokeMethod (this, methodName.toAscii().constData(), Qt::DirectConnection); + endAction(); } // ============================================================================= // ----------------------------------------------------------------------------- -void ForgeWindow::invokeAction (QAction* act, void (*func)()) -{ -#ifdef DEBUG - log ("Action %1 triggered", act->iconText()); -#endif +void ForgeWindow::endAction() +{ // Add a step in the history now. + getCurrentDocument()->addHistoryStep(); - beginAction (act); - (*func) (); - endAction(); + // Update the list item of the current file - we may need to draw an icon + // now that marks it as having unsaved changes. + updateDocumentListItem (getCurrentDocument()); } // ============================================================================= @@ -442,8 +460,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void ForgeWindow::slot_quickColor() -{ beginAction (null); - QToolButton* button = static_cast (sender()); +{ QToolButton* button = static_cast (sender()); LDColor* col = null; for (const LDQuickColor & entry : m_quickColors) @@ -466,8 +483,8 @@ R()->compileObject (obj); } + endAction(); refresh(); - endAction(); } // ============================================================================= @@ -827,13 +844,10 @@ { statusBar()->showMessage (text); } -Ui_LDForgeUI* ForgeWindow::interface() const +Ui_LDForgeUI* ForgeWindow::getInterface() const { return ui; } -#define act(N) QAction* ForgeWindow::action##N() { return ui->action##N; } -#include "actions.h" - void ForgeWindow::updateDocumentList() { ui->fileList->clear(); @@ -875,17 +889,6 @@ f->getListItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); } -void ForgeWindow::beginAction (QAction* act) {} - -void ForgeWindow::endAction() -{ // Close the history now. - getCurrentDocument()->addHistoryStep(); - - // Update the list item of the current file - we may need to draw an icon - // now that marks it as having unsaved changes. - updateDocumentListItem (getCurrentDocument()); -} - // ============================================================================= // A file is selected from the list of files on the left of the screen. Find out // which file was picked and change to it. diff -r 89d1161197d3 -r 507e5d5c348c src/gui.h --- a/src/gui.h Sun Dec 22 20:46:46 2013 +0200 +++ b/src/gui.h Mon Dec 23 10:57:54 2013 +0200 @@ -25,6 +25,7 @@ #include #include "config.h" #include "ldtypes.h" +#include "ui_ldforge.h" class MessageManager; class ForgeWindow; @@ -41,15 +42,13 @@ bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \ connect (bbx_buttons, SIGNAL (accepted()), this, SLOT (accept())); \ connect (bbx_buttons, SIGNAL (rejected()), this, SLOT (reject())); \ - + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= #define DEFINE_ACTION(NAME, DEFSHORTCUT) \ - cfg (KeySequence, key_##NAME, DEFSHORTCUT); \ - void actiondef_##NAME() - -#define ACTION(N) g_win->action##N() + cfg (KeySequence, key_action##NAME, DEFSHORTCUT); \ + void ForgeWindow::slot_action##NAME() // Convenience macros for key sequences. #define KEY(N) (Qt::Key_##N) @@ -91,6 +90,9 @@ class ForgeWindow : public QMainWindow { Q_OBJECT + typedefs: + using ActionMethodType = void (ForgeWindow::*)(); + public: ForgeWindow(); void buildObjList(); @@ -125,22 +127,114 @@ void setStatusBarText (str text); void addMessage (str msg); - Ui_LDForgeUI* interface() const; + Ui_LDForgeUI* getInterface() const; void refreshObjectList(); - void beginAction (QAction* act); + void updateActionShortcuts(); + KeySequenceConfig& shortcutForAction (QAction* act); void endAction(); -#define act(N) QAction* action##N(); -#include "actions.h" - public slots: #if 0 void primitiveLoaderStart (int max); void primitiveLoaderUpdate (int prog); void primitiveLoaderEnd(); #endif // 0 + void changeCurrentFile(); void slot_action(); - void changeCurrentFile(); + void slot_actionNew(); + void slot_actionNewFile(); + void slot_actionOpen(); + void slot_actionDownloadFrom(); + void slot_actionSave(); + void slot_actionSaveAs(); + void slot_actionSaveAll(); + void slot_actionClose(); + void slot_actionCloseAll(); + void slot_actionInsertFrom(); + void slot_actionExportTo(); + void slot_actionSettings(); + void slot_actionSetLDrawPath(); + void slot_actionScanPrimitives(); + void slot_actionExit(); + void slot_actionResetView(); + void slot_actionAxes(); + void slot_actionWireframe(); + void slot_actionBFCView(); + void slot_actionSetOverlay(); + void slot_actionClearOverlay(); + void slot_actionScreenshot(); + void slot_actionInsertRaw(); + void slot_actionNewSubfile(); + void slot_actionNewLine(); + void slot_actionNewTriangle(); + void slot_actionNewQuad(); + void slot_actionNewCLine(); + void slot_actionNewComment(); + void slot_actionNewBFC(); + void slot_actionNewVertex(); + void slot_actionUndo(); + void slot_actionRedo(); + void slot_actionCut(); + void slot_actionCopy(); + void slot_actionPaste(); + void slot_actionDelete(); + void slot_actionSelectAll(); + void slot_actionSelectByColor(); + void slot_actionSelectByType(); + void slot_actionModeDraw(); + void slot_actionModeSelect(); + void slot_actionModeCircle(); + void slot_actionSetDrawDepth(); + void slot_actionSetColor(); + void slot_actionAutocolor(); + void slot_actionUncolorize(); + void slot_actionInline(); + void slot_actionInlineDeep(); + void slot_actionInvert(); + void slot_actionMakePrimitive(); + void slot_actionSplitQuads(); + void slot_actionEditRaw(); + void slot_actionBorders(); + void slot_actionCornerVerts(); + void slot_actionRoundCoordinates(); + void slot_actionVisibilityHide(); + void slot_actionVisibilityReveal(); + void slot_actionVisibilityToggle(); + void slot_actionReplaceCoords(); + void slot_actionFlip(); + void slot_actionDemote(); + void slot_actionYtruder(); + void slot_actionRectifier(); + void slot_actionIntersector(); + void slot_actionIsecalc(); + void slot_actionCoverer(); + void slot_actionEdger2(); + void slot_actionHelp(); + void slot_actionAbout(); + void slot_actionAboutQt(); + void slot_actionGridCoarse(); + void slot_actionGridMedium(); + void slot_actionGridFine(); + void slot_actionEdit(); + void slot_actionMoveUp(); + void slot_actionMoveDown(); + void slot_actionMoveXNeg(); + void slot_actionMoveXPos(); + void slot_actionMoveYNeg(); + void slot_actionMoveYPos(); + void slot_actionMoveZNeg(); + void slot_actionMoveZPos(); + void slot_actionRotateXNeg(); + void slot_actionRotateXPos(); + void slot_actionRotateYNeg(); + void slot_actionRotateYPos(); + void slot_actionRotateZNeg(); + void slot_actionRotateZPos(); + void slot_actionRotationPoint(); + void slot_actionAddHistoryLine(); + void slot_actionJumpTo(); + void slot_actionSubfileSelection(); + void slot_actionDrawAngles(); protected: void closeEvent (QCloseEvent* ev); @@ -156,9 +250,6 @@ MessageManager* m_msglog; Ui_LDForgeUI* ui; - void invokeAction (QAction* act, void (*func)()); - - private slots: void slot_selectionChanged(); void slot_recentFile(); @@ -167,10 +258,6 @@ void slot_editObject (QListWidgetItem* listitem); }; -#define INVOKE_ACTION(N) actiondef_##N(); -#define act(N) void actiondef_##N(); -#include "actions.h" - // ----------------------------------------------------------------------------- // Pointer to the instance of ForgeWindow. extern ForgeWindow* g_win; diff -r 89d1161197d3 -r 507e5d5c348c src/gui_actions.cc --- a/src/gui_actions.cc Sun Dec 22 20:46:46 2013 +0200 +++ b/src/gui_actions.cc Mon Dec 23 10:57:54 2013 +0200 @@ -101,7 +101,7 @@ new LDEmpty, }); - g_win->doFullRefresh(); + doFullRefresh(); } // ============================================================================= @@ -124,13 +124,13 @@ // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (Save, CTRL (S)) -{ g_win->save (getCurrentDocument(), false); +{ save (getCurrentDocument(), false); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) -{ g_win->save (getCurrentDocument(), true); +{ save (getCurrentDocument(), true); } // ============================================================================= @@ -140,7 +140,7 @@ { if (file->isImplicit()) continue; - g_win->save (file, false); + save (file, false); } } @@ -262,13 +262,13 @@ { for (LDObject* obj : getCurrentDocument()->getObjects()) obj->select(); - g_win->updateSelection(); + updateSelection(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) -{ int colnum = g_win->getSelectedColor(); +{ int colnum = getSelectedColor(); if (colnum == -1) return; // no consensus on color @@ -279,7 +279,7 @@ if (obj->getColor() == colnum) obj->select(); - g_win->updateSelection(); + updateSelection(); } // ============================================================================= @@ -288,7 +288,7 @@ { if (selection().isEmpty()) return; - LDObject::Type type = g_win->getUniformSelectedType(); + LDObject::Type type = getUniformSelectedType(); if (type == LDObject::Unidentified) return; @@ -317,38 +317,38 @@ obj->select(); } - g_win->updateSelection(); + updateSelection(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (GridCoarse, 0) { grid = Grid::Coarse; - g_win->updateGridToolBar(); + updateGridToolBar(); } DEFINE_ACTION (GridMedium, 0) { grid = Grid::Medium; - g_win->updateGridToolBar(); + updateGridToolBar(); } DEFINE_ACTION (GridFine, 0) { grid = Grid::Fine; - g_win->updateGridToolBar(); + updateGridToolBar(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ResetView, CTRL (0)) -{ g_win->R()->resetAngles(); - g_win->R()->update(); +{ R()->resetAngles(); + R()->update(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (InsertFrom, 0) { str fname = QFileDialog::getOpenFileName(); - int idx = g_win->getInsertionPoint(); + int idx = getInsertionPoint(); if (!fname.length()) return; @@ -367,13 +367,13 @@ for (LDObject* obj : objs) { getCurrentDocument()->insertObj (idx, obj); obj->select(); - g_win->R()->compileObject (obj); + R()->compileObject (obj); idx++; } - g_win->refresh(); - g_win->scrollToSelection(); + refresh(); + scrollToSelection(); } // ============================================================================= @@ -405,7 +405,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (InsertRaw, 0) -{ int idx = g_win->getInsertionPoint(); +{ int idx = getInsertionPoint(); QDialog* const dlg = new QDialog; QVBoxLayout* const layout = new QVBoxLayout; @@ -429,12 +429,12 @@ getCurrentDocument()->insertObj (idx, obj); obj->select(); - g_win->R()->compileObject (obj); + R()->compileObject (obj); idx++; } - g_win->refresh(); - g_win->scrollToSelection(); + refresh(); + scrollToSelection(); } // ============================================================================= @@ -443,7 +443,7 @@ { setlocale (LC_ALL, "C"); int w, h; - uchar* imgdata = g_win->R()->getScreencap (w, h); + uchar* imgdata = R()->getScreencap (w, h); QImage img = imageFromScreencap (imgdata, w, h); str root = basename (getCurrentDocument()->getName()); @@ -466,8 +466,8 @@ extern_cfg (Bool, gl_axes); DEFINE_ACTION (Axes, 0) { gl_axes = !gl_axes; - g_win->updateActions(); - g_win->R()->update(); + updateActions(); + R()->update(); } // ============================================================================= @@ -476,7 +476,7 @@ { for (LDObject* obj : selection()) obj->toggleHidden(); - g_win->refresh(); + refresh(); } // ============================================================================= @@ -485,7 +485,7 @@ { for (LDObject* obj : selection()) obj->setHidden (true); - g_win->refresh(); + refresh(); } // ============================================================================= @@ -493,14 +493,14 @@ DEFINE_ACTION (VisibilityReveal, 0) { for (LDObject* obj : selection()) obj->setHidden (false); - g_win->refresh(); + refresh(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (Wireframe, 0) { gl_wireframe = !gl_wireframe; - g_win->R()->refresh(); + R()->refresh(); } // ============================================================================= @@ -511,54 +511,54 @@ if (!dlg.exec()) return; - g_win->R()->setupOverlay ((GL::EFixedCamera) dlg.camera(), dlg.fpath(), dlg.ofsx(), + R()->setupOverlay ((GL::EFixedCamera) dlg.camera(), dlg.fpath(), dlg.ofsx(), dlg.ofsy(), dlg.lwidth(), dlg.lheight()); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ClearOverlay, 0) -{ g_win->R()->clearOverlay(); +{ R()->clearOverlay(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ModeSelect, CTRL (1)) -{ g_win->R()->setEditMode (ESelectMode); +{ R()->setEditMode (ESelectMode); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ModeDraw, CTRL (2)) -{ g_win->R()->setEditMode (EDrawMode); +{ R()->setEditMode (EDrawMode); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ModeCircle, CTRL (3)) -{ g_win->R()->setEditMode (ECircleMode); +{ R()->setEditMode (ECircleMode); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (DrawAngles, 0) { gl_drawangles = !gl_drawangles; - g_win->R()->refresh(); + R()->refresh(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (SetDrawDepth, 0) -{ if (g_win->R()->camera() == GL::EFreeCamera) +{ if (R()->camera() == GL::EFreeCamera) return; bool ok; double depth = QInputDialog::getDouble (g_win, "Set Draw Depth", - fmt ("Depth value for %1 Camera:", g_win->R()->getCameraName()), - g_win->R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); + fmt ("Depth value for %1 Camera:", R()->getCameraName()), + R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); if (ok) - g_win->R()->setDepthValue (depth); + R()->setDepthValue (depth); } #if 0 @@ -616,8 +616,8 @@ // ----------------------------------------------------------------------------- DEFINE_ACTION (BFCView, SHIFT (B)) { gl_colorbfc = !gl_colorbfc; - g_win->updateActions(); - g_win->R()->refresh(); + updateActions(); + R()->refresh(); } // ============================================================================= @@ -638,7 +638,7 @@ getCurrentDocument()->clearSelection(); obj->select(); - g_win->updateSelection(); + updateSelection(); } // ============================================================================= @@ -689,8 +689,8 @@ if (topdirname != "s") { str desiredPath = subdirname + "/s"; - str title = ForgeWindow::tr ("Create subfile directory?"); - str text = fmt (ForgeWindow::tr ("The directory %1 is suggested for " + str title = tr ("Create subfile directory?"); + str text = fmt (tr ("The directory %1 is suggested for " "subfiles. This directory does not exist, create it?"), desiredPath); if (QDir (desiredPath).exists() || confirm (title, text)) @@ -769,14 +769,14 @@ } // Try save it - if (g_win->save (doc, true)) + if (save (doc, true)) { // Remove the selection now for (LDObject* obj : selection()) obj->deleteSelf(); // Compile all objects in the new subfile for (LDObject* obj : doc->getObjects()) - g_win->R()->compileObject (obj); + R()->compileObject (obj); g_loadedFiles << doc; @@ -787,11 +787,11 @@ ref->setPosition (g_origin); ref->setTransform (g_identity); getCurrentDocument()->insertObj (refidx, ref); - g_win->R()->compileObject (ref); + R()->compileObject (ref); // Refresh stuff - g_win->updateDocumentList(); - g_win->doFullRefresh(); + updateDocumentList(); + doFullRefresh(); } else { // Failed to save. diff -r 89d1161197d3 -r 507e5d5c348c src/gui_editactions.cc --- a/src/gui_editactions.cc Sun Dec 22 20:46:46 2013 +0200 +++ b/src/gui_editactions.cc Mon Dec 23 10:57:54 2013 +0200 @@ -66,22 +66,22 @@ // ----------------------------------------------------------------------------- DEFINE_ACTION (Cut, CTRL (X)) { int num = copyToClipboard(); - g_win->deleteSelection(); - log (ForgeWindow::tr ("%1 objects cut"), num); + deleteSelection(); + log (tr ("%1 objects cut"), num); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (Copy, CTRL (C)) { int num = copyToClipboard(); - log (ForgeWindow::tr ("%1 objects copied"), num); + log (tr ("%1 objects copied"), num); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (Paste, CTRL (V)) { const str clipboardText = qApp->clipboard()->text(); - int idx = g_win->getInsertionPoint(); + int idx = getInsertionPoint(); getCurrentDocument()->clearSelection(); int num = 0; @@ -89,20 +89,20 @@ { LDObject* pasted = parseLine (line); getCurrentDocument()->insertObj (idx++, pasted); pasted->select(); - g_win->R()->compileObject (pasted); + R()->compileObject (pasted); ++num; } - log (ForgeWindow::tr ("%1 objects pasted"), num); - g_win->refresh(); - g_win->scrollToSelection(); + log (tr ("%1 objects pasted"), num); + refresh(); + scrollToSelection(); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (Delete, KEY (Delete)) -{ int num = g_win->deleteSelection(); - log (ForgeWindow::tr ("%1 objects deleted"), num); +{ int num = deleteSelection(); + log (tr ("%1 objects deleted"), num); } // ============================================================================= @@ -178,7 +178,7 @@ getCurrentDocument()->insertObj (index + 1, triangles[1]); for (LDTriangle* t : triangles) - g_win->R()->compileObject (t); + R()->compileObject (t); // Delete this quad now, it has been split. obj->deleteSelf(); @@ -187,7 +187,7 @@ } log ("%1 quadrilaterals split", num); - g_win->refresh(); + refresh(); } // ============================================================================= @@ -220,8 +220,8 @@ oldobj->replace (obj); // Refresh - g_win->R()->compileObject (obj); - g_win->refresh(); + R()->compileObject (obj); + refresh(); } // ============================================================================= @@ -237,7 +237,7 @@ // If all selected objects have the same color, said color is our default // value to the color selection dialog. - defcol = g_win->getSelectedColor(); + defcol = getSelectedColor(); // Show the dialog to the user now and ask for a color. if (ColorSelector::selectColor (colnum, defcol, g_win)) @@ -246,10 +246,10 @@ continue; obj->setColor (colnum); - g_win->R()->compileObject (obj); + R()->compileObject (obj); } - g_win->refresh(); + refresh(); } } @@ -290,14 +290,14 @@ lines[i]->setColor (edgecolor); getCurrentDocument()->insertObj (idx, lines[i]); - g_win->R()->compileObject (lines[i]); + R()->compileObject (lines[i]); } num += numLines; } - log (ForgeWindow::tr ("Added %1 border lines"), num); - g_win->refresh(); + log (tr ("Added %1 border lines"), num); + refresh(); } // ============================================================================= @@ -317,13 +317,13 @@ vert->setColor (obj->getColor()); getCurrentDocument()->insertObj (++idx, vert); - g_win->R()->compileObject (vert); + R()->compileObject (vert); ++num; } } - log (ForgeWindow::tr ("Added %1 vertices"), num); - g_win->refresh(); + log (tr ("Added %1 vertices"), num); + refresh(); } // ============================================================================= @@ -403,10 +403,10 @@ for (LDObject* obj : sel) { obj->invert(); - g_win->R()->compileObject (obj); + R()->compileObject (obj); } - g_win->refresh(); + refresh(); } // ============================================================================= @@ -533,15 +533,15 @@ roundToDecimals (v[ax], 3); obj->setVertex (i, v); - g_win->R()->compileObject (obj); + R()->compileObject (obj); num += 3; } } } - log (ForgeWindow::tr ("Rounded %1 values"), num); - g_win->refreshObjectList(); - g_win->refresh(); + log (tr ("Rounded %1 values"), num); + refreshObjectList(); + refresh(); } // ============================================================================= @@ -559,12 +559,12 @@ col = edgecolor; obj->setColor (col); - g_win->R()->compileObject (obj); + R()->compileObject (obj); num++; } - log (ForgeWindow::tr ("%1 objects uncolored"), num); - g_win->refresh(); + log (tr ("%1 objects uncolored"), num); + refresh(); } // ============================================================================= @@ -606,12 +606,12 @@ } obj->setVertex (i, v); - g_win->R()->compileObject (obj); + R()->compileObject (obj); } } - log (ForgeWindow::tr ("Altered %1 values"), num); - g_win->refresh(); + log (tr ("Altered %1 values"), num); + refresh(); } // ============================================================================= @@ -638,11 +638,11 @@ v[ax] *= -1; obj->setVertex (i, v); - g_win->R()->compileObject (obj); + R()->compileObject (obj); } } - g_win->refresh(); + refresh(); } // ============================================================================= @@ -656,12 +656,12 @@ continue; LDLine* repl = static_cast (obj)->demote(); - g_win->R()->compileObject (repl); + R()->compileObject (repl); ++num; } - log (ForgeWindow::tr ("Demoted %1 conditional lines"), num); - g_win->refresh(); + log (tr ("Demoted %1 conditional lines"), num); + refresh(); } // ============================================================================= @@ -683,7 +683,7 @@ colnum++; if (colnum >= MAX_COLORS) - { log (ForgeWindow::tr ("Cannot auto-color: all colors are in use!")); + { log (tr ("Cannot auto-color: all colors are in use!")); return; } @@ -692,11 +692,11 @@ continue; obj->setColor (colnum); - g_win->R()->compileObject (obj); + R()->compileObject (obj); } - log (ForgeWindow::tr ("Auto-colored: new color is [%1] %2"), colnum, getColor (colnum)->name); - g_win->refresh(); + log (tr ("Auto-colored: new color is [%1] %2"), colnum, getColor (colnum)->name); + refresh(); } // ============================================================================= @@ -752,6 +752,6 @@ if (obj && obj->next() && obj->next()->isScemantic()) getCurrentDocument()->insertObj (idx, new LDEmpty); - g_win->buildObjList(); + buildObjList(); delete ui; } diff -r 89d1161197d3 -r 507e5d5c348c src/main.h --- a/src/main.h Sun Dec 22 20:46:46 2013 +0200 +++ b/src/main.h Mon Dec 23 10:57:54 2013 +0200 @@ -127,6 +127,12 @@ #define methods #define for_axes(AX) for (const Axis AX : std::initializer_list ({X, Y, Z})) +#ifndef IN_IDE_PARSER +#define NORETURN [noreturn] +#else +#define NORETURN +#endif + // ----------------------------------------------------------------------------- #ifdef IN_IDE_PARSER // KDevelop workarounds: # error IN_IDE_PARSER is defined (this code is only for KDevelop workarounds)