Tue, 29 Apr 2014 02:06:09 +0300
- overhauled configuration setup a bit: configuration entries renamed and are now in a cfg:: namespace
--- a/src/actions.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/actions.cc Tue Apr 29 02:06:09 2014 +0300 @@ -38,13 +38,13 @@ #include "glCompiler.h" #include "ui_newpart.h" -extern_cfg (Bool, gl_wireframe); -extern_cfg (Bool, gl_colorbfc); -extern_cfg (String, ld_defaultname); -extern_cfg (String, ld_defaultuser); -extern_cfg (Int, ld_defaultlicense); -extern_cfg (Bool, gl_drawangles); -extern_cfg (Bool, gl_randomcolors) +EXTERN_CFGENTRY (Bool, drawWireframe); +EXTERN_CFGENTRY (Bool, bfcRedGreenView); +EXTERN_CFGENTRY (String, defaultName); +EXTERN_CFGENTRY (String, defaultUser); +EXTERN_CFGENTRY (Int, defaultLicense); +EXTERN_CFGENTRY (Bool, drawAngles); +EXTERN_CFGENTRY (Bool, randomColors) // ============================================================================= // @@ -54,14 +54,14 @@ Ui::NewPartUI ui; ui.setupUi (dlg); - String authortext = ld_defaultname; + String authortext = cfg::defaultName; - if (not ld_defaultuser.isEmpty()) - authortext.append (format (" [%1]", ld_defaultuser)); + if (not cfg::defaultUser.isEmpty()) + authortext.append (format (" [%1]", cfg::defaultUser)); ui.le_author->setText (authortext); - switch (ld_defaultlicense) + switch (cfg::defaultLicense) { case 0: ui.rb_license_ca->setChecked (true); @@ -77,7 +77,7 @@ default: QMessageBox::warning (null, "Warning", - format ("Unknown ld_defaultlicense value %1!", ld_defaultlicense)); + format ("Unknown ld_defaultlicense value %1!", cfg::defaultLicense)); break; } @@ -356,19 +356,19 @@ // DEFINE_ACTION (GridCoarse, 0) { - grid = Grid::Coarse; + cfg::grid = Grid::Coarse; updateGridToolBar(); } DEFINE_ACTION (GridMedium, 0) { - grid = Grid::Medium; + cfg::grid = Grid::Medium; updateGridToolBar(); } DEFINE_ACTION (GridFine, 0) { - grid = Grid::Fine; + cfg::grid = Grid::Fine; updateGridToolBar(); } @@ -507,10 +507,10 @@ // ============================================================================= // -extern_cfg (Bool, gl_axes); +EXTERN_CFGENTRY (Bool, drawAxes); DEFINE_ACTION (Axes, 0) { - gl_axes = not gl_axes; + cfg::drawAxes = not cfg::drawAxes; updateActions(); R()->update(); } @@ -548,7 +548,7 @@ // DEFINE_ACTION (Wireframe, 0) { - gl_wireframe = not gl_wireframe; + cfg::drawWireframe = not cfg::drawWireframe; R()->refresh(); } @@ -597,7 +597,7 @@ // DEFINE_ACTION (DrawAngles, 0) { - gl_drawangles = not gl_drawangles; + cfg::drawAngles = not cfg::drawAngles; R()->refresh(); } @@ -677,7 +677,7 @@ // DEFINE_ACTION (BFCView, SHIFT (B)) { - gl_colorbfc = not gl_colorbfc; + cfg::bfcRedGreenView = not cfg::bfcRedGreenView; updateActions(); R()->refresh(); } @@ -726,7 +726,7 @@ LDComment* titleobj = dynamic_cast<LDComment*> (getCurrentDocument()->getObject (0)); // License text for the subfile - String license = getLicenseText (ld_defaultlicense); + String license = getLicenseText (cfg::defaultLicense); // LDraw code body of the new subfile (i.e. code of the selection) QStringList code; @@ -825,7 +825,7 @@ { new LDComment (subtitle), new LDComment ("Name: "), - new LDComment (format ("Author: %1 [%2]", ld_defaultname, ld_defaultuser)), + new LDComment (format ("Author: %1 [%2]", cfg::defaultName, cfg::defaultUser)), new LDComment (format ("!LDRAW_ORG Unofficial_Subpart")), (license != "" ? new LDComment (license) : null), new LDEmpty, @@ -872,6 +872,6 @@ DEFINE_ACTION (RandomColors, CTRL_SHIFT (R)) { - gl_randomcolors = not gl_randomcolors; + cfg::randomColors = not cfg::randomColors; R()->refresh(); } \ No newline at end of file
--- a/src/actionsEdit.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/actionsEdit.cc Tue Apr 29 02:06:09 2014 +0300 @@ -34,8 +34,7 @@ #include "ui_flip.h" #include "ui_addhistoryline.h" -cfg (Bool, edit_schemanticinline, false); -extern_cfg (String, ld_defaultuser); +EXTERN_CFGENTRY (String, defaultUser); // ============================================================================= // @@ -742,7 +741,7 @@ QDialog* dlg = new QDialog; Ui_AddHistoryLine* ui = new Ui_AddHistoryLine; ui->setupUi (dlg); - ui->m_username->setText (ld_defaultuser); + ui->m_username->setText (cfg::defaultUser); ui->m_date->setDate (QDate::currentDate()); ui->m_comment->setFocus();
--- a/src/colorSelector.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/colorSelector.cc Tue Apr 29 02:06:09 2014 +0300 @@ -35,8 +35,8 @@ static const int g_numColumns = 16; static const int g_squareSize = 32; -extern_cfg (String, gl_maincolor); -extern_cfg (Float, gl_maincolor_alpha); +EXTERN_CFGENTRY (String, mainColor); +EXTERN_CFGENTRY (Float, mainColorAlpha); // ============================================================================= // ============================================================================= @@ -105,8 +105,8 @@ if (i == maincolor) { // Use the user preferences for main color here - col = QColor (gl_maincolor); - col.setAlpha (gl_maincolor_alpha * 255.0f); + col = QColor (cfg::mainColor); + col.setAlpha (cfg::mainColorAlpha * 255.0f); } QPen pen (info->edgeColor, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
--- a/src/configDialog.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/configDialog.cc Tue Apr 29 02:06:09 2014 +0300 @@ -39,44 +39,43 @@ #include "glRenderer.h" #include "ui_config.h" -extern_cfg (String, gl_bgcolor); -extern_cfg (String, gl_maincolor); -extern_cfg (Bool, lv_colorize); -extern_cfg (Bool, gl_colorbfc); -extern_cfg (Float, gl_maincolor_alpha); -extern_cfg (Int, gl_linethickness); -extern_cfg (String, gui_colortoolbar); -extern_cfg (Bool, edit_schemanticinline); -extern_cfg (Bool, gl_blackedges); -extern_cfg (Bool, gl_aa); -extern_cfg (Bool, gui_implicitfiles); -extern_cfg (String, net_downloadpath); -extern_cfg (Bool, net_guesspaths); -extern_cfg (Bool, net_autoclose); -extern_cfg (Bool, gl_logostuds); -extern_cfg (Bool, gl_linelengths); -extern_cfg (String, ld_defaultname); -extern_cfg (String, ld_defaultuser); -extern_cfg (Int, ld_defaultlicense); -extern_cfg (String, gl_selectcolor); -extern_cfg (String, prog_ytruder); -extern_cfg (String, prog_rectifier); -extern_cfg (String, prog_intersector); -extern_cfg (String, prog_coverer); -extern_cfg (String, prog_isecalc); -extern_cfg (String, prog_edger2); -extern_cfg (Bool, prog_ytruder_wine); -extern_cfg (Bool, prog_rectifier_wine); -extern_cfg (Bool, prog_intersector_wine); -extern_cfg (Bool, prog_coverer_wine); -extern_cfg (Bool, prog_isecalc_wine); -extern_cfg (Bool, prog_edger2_wine); -extern_cfg (Float, grid_coarse_snap); -extern_cfg (Float, grid_coarse_angle); -extern_cfg (Float, grid_medium_snap); -extern_cfg (Float, grid_medium_angle); -extern_cfg (Float, grid_fine_snap); -extern_cfg (Float, grid_fine_angle); +EXTERN_CFGENTRY (String, backgroundColor); +EXTERN_CFGENTRY (String, mainColor); +EXTERN_CFGENTRY (Bool, colorizeObjectsList); +EXTERN_CFGENTRY (Bool, bfcRedGreenView); +EXTERN_CFGENTRY (Float, mainColorAlpha); +EXTERN_CFGENTRY (Int, lineThickness); +EXTERN_CFGENTRY (String, quickColorToolbar); +EXTERN_CFGENTRY (Bool, blackEdges); +EXTERN_CFGENTRY (Bool, antiAliasedLines); +EXTERN_CFGENTRY (Bool, listImplicitFiles); +EXTERN_CFGENTRY (String, downloadFilePath); +EXTERN_CFGENTRY (Bool, guessDownloadPaths); +EXTERN_CFGENTRY (Bool, autoCloseDownloadDialog); +EXTERN_CFGENTRY (Bool, useLogoStuds); +EXTERN_CFGENTRY (Bool, drawLineLengths); +EXTERN_CFGENTRY (String, defaultName); +EXTERN_CFGENTRY (String, defaultUser); +EXTERN_CFGENTRY (Int, defaultLicense); +EXTERN_CFGENTRY (String, selectColorBlend); +EXTERN_CFGENTRY (String, ytruderPath); +EXTERN_CFGENTRY (String, rectifierPath); +EXTERN_CFGENTRY (String, intersectorPath); +EXTERN_CFGENTRY (String, covererPath); +EXTERN_CFGENTRY (String, isecalcPath); +EXTERN_CFGENTRY (String, edger2Path); +EXTERN_CFGENTRY (Bool, ytruderUsesWine); +EXTERN_CFGENTRY (Bool, rectifierUsesWine); +EXTERN_CFGENTRY (Bool, intersectorUsesWine); +EXTERN_CFGENTRY (Bool, covererUsesWine); +EXTERN_CFGENTRY (Bool, isecalcUsesWine); +EXTERN_CFGENTRY (Bool, edger2UsesWine); +EXTERN_CFGENTRY (Float, gridCoarseCoordinateSnap); +EXTERN_CFGENTRY (Float, gridCoarseAngleSnap); +EXTERN_CFGENTRY (Float, gridMediumCoordinateSnap); +EXTERN_CFGENTRY (Float, gridMediumAngleSnap); +EXTERN_CFGENTRY (Float, gridFineCoordinateSnap); +EXTERN_CFGENTRY (Float, gridFineAngleSnap); const char* g_extProgPathFilter = #ifdef _WIN32 @@ -95,33 +94,33 @@ ui->setupUi (this); // Interface tab - setButtonBackground (ui->backgroundColorButton, gl_bgcolor); + setButtonBackground (ui->backgroundColorButton, cfg::backgroundColor); connect (ui->backgroundColorButton, SIGNAL (clicked()), this, SLOT (slot_setGLBackground())); - setButtonBackground (ui->mainColorButton, gl_maincolor); + setButtonBackground (ui->mainColorButton, cfg::mainColor); connect (ui->mainColorButton, SIGNAL (clicked()), this, SLOT (slot_setGLForeground())); - setButtonBackground (ui->selColorButton, gl_selectcolor); + setButtonBackground (ui->selColorButton, cfg::selectColorBlend); connect (ui->selColorButton, SIGNAL (clicked()), this, SLOT (slot_setGLSelectColor())); - ui->mainColorAlpha->setValue (gl_maincolor_alpha * 10.0f); - ui->lineThickness->setValue (gl_linethickness); - ui->colorizeObjects->setChecked (lv_colorize); - ui->colorBFC->setChecked (gl_colorbfc); - ui->blackEdges->setChecked (gl_blackedges); - ui->m_aa->setChecked (gl_aa); - ui->implicitFiles->setChecked (gui_implicitfiles); - ui->m_logostuds->setChecked (gl_logostuds); - ui->linelengths->setChecked (gl_linelengths); + ui->mainColorAlpha->setValue (cfg::mainColorAlpha * 10.0f); + ui->lineThickness->setValue (cfg::lineThickness); + ui->colorizeObjects->setChecked (cfg::colorizeObjectsList); + ui->colorBFC->setChecked (cfg::bfcRedGreenView); + ui->blackEdges->setChecked (cfg::blackEdges); + ui->m_aa->setChecked (cfg::antiAliasedLines); + ui->implicitFiles->setChecked (cfg::listImplicitFiles); + ui->m_logostuds->setChecked (cfg::useLogoStuds); + ui->linelengths->setChecked (cfg::drawLineLengths); int i = 0; for (QAction* act : g_win->findChildren<QAction*>()) { - KeySequenceConfig* cfg = g_win->shortcutForAction (act); + KeySequenceConfigEntry* cfg = g_win->shortcutForAction (act); if (cfg) addShortcut (*cfg, act, i); @@ -145,20 +144,20 @@ connect (ui->quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor())); connect (ui->quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors())); - ui->downloadPath->setText (net_downloadpath); - ui->guessNetPaths->setChecked (net_guesspaths); - ui->autoCloseNetPrompt->setChecked (net_autoclose); + ui->downloadPath->setText (cfg::downloadFilePath); + ui->guessNetPaths->setChecked (cfg::guessDownloadPaths); + ui->autoCloseNetPrompt->setChecked (cfg::autoCloseDownloadDialog); connect (ui->findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder())); - ui->m_profileName->setText (ld_defaultname); - ui->m_profileUsername->setText (ld_defaultuser); - ui->m_profileLicense->setCurrentIndex (ld_defaultlicense); - ui->gridCoarseCoordinateSnap->setValue (grid_coarse_snap); - ui->gridCoarseAngleSnap->setValue (grid_coarse_angle); - ui->gridMediumCoordinateSnap->setValue (grid_medium_snap); - ui->gridMediumAngleSnap->setValue (grid_medium_angle); - ui->gridFineCoordinateSnap->setValue (grid_fine_snap); - ui->gridFineAngleSnap->setValue (grid_fine_angle); + ui->m_profileName->setText (cfg::defaultName); + ui->m_profileUsername->setText (cfg::defaultUser); + ui->m_profileLicense->setCurrentIndex (cfg::defaultLicense); + ui->gridCoarseCoordinateSnap->setValue (cfg::gridCoarseCoordinateSnap); + ui->gridCoarseAngleSnap->setValue (cfg::gridCoarseAngleSnap); + ui->gridMediumCoordinateSnap->setValue (cfg::gridMediumCoordinateSnap); + ui->gridMediumAngleSnap->setValue (cfg::gridMediumAngleSnap); + ui->gridFineCoordinateSnap->setValue (cfg::gridFineCoordinateSnap); + ui->gridFineAngleSnap->setValue (cfg::gridFineAngleSnap); initExtProgs(); selectPage (deftab); @@ -191,7 +190,7 @@ // ============================================================================= // Adds a shortcut entry to the list of shortcuts. // ============================================================================= -void ConfigDialog::addShortcut (KeySequenceConfig& cfg, QAction* act, int& i) +void ConfigDialog::addShortcut (KeySequenceConfigEntry& cfg, QAction* act, int& i) { ShortcutListItem* item = new ShortcutListItem; item->setIcon (act->icon()); @@ -211,9 +210,9 @@ // ============================================================================= static struct LDExtProgInfo { - const String name, - iconname; - String* const path; + const String name, + iconname; + String* const path; QLineEdit* input; QPushButton* setPathButton; #ifndef _WIN32 @@ -223,9 +222,9 @@ } g_LDExtProgInfo[] = { #ifndef _WIN32 -# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null, &prog_##LOWNAME##_wine, null }, +# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::LOWNAME##Path, null, null, &cfg::LOWNAME##UsesWine, null }, #else -# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null }, +# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::LOWNAME##Path, null, null }, #endif EXTPROG (Ytruder, ytruder) EXTPROG (Rectifier, rectifier) @@ -283,33 +282,33 @@ void ConfigDialog::applySettings() { // Apply configuration - lv_colorize = ui->colorizeObjects->isChecked(); - gl_colorbfc = ui->colorBFC->isChecked(); - gl_blackedges = ui->blackEdges->isChecked(); - gl_maincolor_alpha = ( (double) ui->mainColorAlpha->value()) / 10.0f; - gl_linethickness = ui->lineThickness->value(); - gui_implicitfiles = ui->implicitFiles->isChecked(); - net_downloadpath = ui->downloadPath->text(); - net_guesspaths = ui->guessNetPaths->isChecked(); - net_autoclose = ui->autoCloseNetPrompt->isChecked(); - gl_logostuds = ui->m_logostuds->isChecked(); - gl_linelengths = ui->linelengths->isChecked(); - ld_defaultuser = ui->m_profileUsername->text(); - ld_defaultname = ui->m_profileName->text(); - ld_defaultlicense = ui->m_profileLicense->currentIndex(); - gl_aa = ui->m_aa->isChecked(); + cfg::colorizeObjectsList = ui->colorizeObjects->isChecked(); + cfg::bfcRedGreenView = ui->colorBFC->isChecked(); + cfg::blackEdges = ui->blackEdges->isChecked(); + cfg::mainColorAlpha = ((double) ui->mainColorAlpha->value()) / 10.0; + cfg::lineThickness = ui->lineThickness->value(); + cfg::listImplicitFiles = ui->implicitFiles->isChecked(); + cfg::downloadFilePath = ui->downloadPath->text(); + cfg::guessDownloadPaths = ui->guessNetPaths->isChecked(); + cfg::autoCloseDownloadDialog = ui->autoCloseNetPrompt->isChecked(); + cfg::useLogoStuds = ui->m_logostuds->isChecked(); + cfg::drawLineLengths = ui->linelengths->isChecked(); + cfg::defaultUser = ui->m_profileUsername->text(); + cfg::defaultName = ui->m_profileName->text(); + cfg::defaultLicense = ui->m_profileLicense->currentIndex(); + cfg::antiAliasedLines = ui->m_aa->isChecked(); // Rebuild the quick color toolbar g_win->setQuickColors (quickColors); - gui_colortoolbar = quickColorString(); + cfg::quickColorToolbar = quickColorString(); // Set the grid settings - grid_coarse_snap = ui->gridCoarseCoordinateSnap->value(); - grid_coarse_angle = ui->gridCoarseAngleSnap->value(); - grid_medium_snap = ui->gridMediumCoordinateSnap->value(); - grid_medium_angle = ui->gridMediumAngleSnap->value(); - grid_fine_snap = ui->gridFineCoordinateSnap->value(); - grid_fine_angle = ui->gridFineAngleSnap->value(); + cfg::gridCoarseCoordinateSnap = ui->gridCoarseCoordinateSnap->value(); + cfg::gridCoarseAngleSnap = ui->gridCoarseAngleSnap->value(); + cfg::gridMediumCoordinateSnap = ui->gridMediumCoordinateSnap->value(); + cfg::gridMediumAngleSnap = ui->gridMediumAngleSnap->value(); + cfg::gridFineCoordinateSnap = ui->gridFineCoordinateSnap->value(); + cfg::gridFineAngleSnap = ui->gridFineAngleSnap->value(); // Apply key shortcuts g_win->updateActionShortcuts(); @@ -527,21 +526,21 @@ // ============================================================================= void ConfigDialog::slot_setGLBackground() { - pickColor (gl_bgcolor, ui->backgroundColorButton); + pickColor (cfg::backgroundColor, ui->backgroundColorButton); } // ============================================================================= // ============================================================================= void ConfigDialog::slot_setGLForeground() { - pickColor (gl_maincolor, ui->mainColorButton); + pickColor (cfg::mainColor, ui->mainColorButton); } // ============================================================================= // ============================================================================= void ConfigDialog::slot_setGLSelectColor() { - pickColor (gl_selectcolor, ui->selColorButton); + pickColor (cfg::selectColorBlend, ui->selColorButton); } // ============================================================================= @@ -621,7 +620,7 @@ for (ShortcutListItem* item : sel) { - item->keyConfig()->reset(); + item->keyConfig()->resetValue(); setShortcutText (item); } } @@ -735,7 +734,7 @@ // ============================================================================= // ============================================================================= -bool KeySequenceDialog::staticDialog (KeySequenceConfig* cfg, QWidget* parent) +bool KeySequenceDialog::staticDialog (KeySequenceConfigEntry* cfg, QWidget* parent) { KeySequenceDialog dlg (cfg->getValue(), parent);
--- a/src/configDialog.h Tue Apr 29 00:15:56 2014 +0300 +++ b/src/configDialog.h Tue Apr 29 02:06:09 2014 +0300 @@ -27,8 +27,8 @@ // ============================================================================= class ShortcutListItem : public QListWidgetItem { - PROPERTY (public, KeySequenceConfig*, keyConfig, setKeyConfig, STOCK_WRITE) - PROPERTY (public, QAction*, action, setAction, STOCK_WRITE) + PROPERTY (public, KeySequenceConfigEntry*, keyConfig, setKeyConfig, STOCK_WRITE) + PROPERTY (public, QAction*, action, setAction, STOCK_WRITE) public: explicit ShortcutListItem (QListWidget* view = null, int type = Type) : @@ -62,7 +62,7 @@ QList<QListWidgetItem*> quickColorItems; void applySettings(); - void addShortcut (KeySequenceConfig& cfg, QAction* act, int& i); + void addShortcut (KeySequenceConfigEntry& cfg, QAction* act, int& i); void setButtonBackground (QPushButton* button, String value); void pickColor (String& conf, QPushButton* button); void updateQuickColorList (LDQuickColor* sel = null); @@ -100,7 +100,7 @@ public: explicit KeySequenceDialog (QKeySequence seq, QWidget* parent = null, Qt::WindowFlags f = 0); - static bool staticDialog (KeySequenceConfig* cfg, QWidget* parent = null); + static bool staticDialog (KeySequenceConfigEntry* cfg, QWidget* parent = null); QLabel* lb_output; QDialogButtonBox* bbx_buttons;
--- a/src/configuration.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/configuration.cc Tue Apr 29 02:06:09 2014 +0300 @@ -38,32 +38,34 @@ # define EXTENSION ".cfg" #endif // _WIN32 -Config* g_configPointers[MAX_CONFIG]; -static int g_cfgPointerCursor = 0; -static QMap<String, Config*> g_configsByName; -static QList<Config*> g_configs; +#define MAX_CONFIG 512 -// ============================================================================= +ConfigEntry* g_configPointers[MAX_CONFIG]; +static int g_cfgPointerCursor = 0; +static QMap<String, ConfigEntry*> g_configsByName; +static QList<ConfigEntry*> g_configs; + +// // Get the QSettings object. -// ============================================================================= +// static QSettings* getSettingsObject() { String path = qApp->applicationDirPath() + "/" UNIXNAME EXTENSION; return new QSettings (path, QSettings::IniFormat); } -Config::Config (String name) : +ConfigEntry::ConfigEntry (String name) : m_name (name) {} -// ============================================================================= +// // Load the configuration from file -// ============================================================================= +// bool Config::load() { QSettings* settings = getSettingsObject(); print ("config::load: Loading configuration file from %1\n", settings->fileName()); - for (Config* cfg : g_configPointers) + for (ConfigEntry* cfg : g_configPointers) { if (not cfg) break; @@ -78,7 +80,6 @@ return true; } -// ============================================================================= // // Save the configuration to disk // @@ -86,7 +87,7 @@ { QSettings* settings = getSettingsObject(); - for (Config* cfg : g_configs) + for (ConfigEntry* cfg : g_configs) { if (not cfg->isDefault()) settings->setValue (cfg->name(), cfg->toVariant()); @@ -100,38 +101,38 @@ return true; } -// ============================================================================= +// // Reset configuration to defaults. -// ============================================================================= +// void Config::reset() { - for (Config* cfg : g_configs) + for (ConfigEntry* cfg : g_configs) cfg->resetValue(); } -// ============================================================================= +// // Where is the configuration file located at? -// ============================================================================= +// String Config::filepath (String file) { return Config::dirpath() + DIRSLASH + file; } -// ============================================================================= +// // Directory of the configuration file. -// ============================================================================= +// String Config::dirpath() { QSettings* cfg = getSettingsObject(); return dirname (cfg->fileName()); } -// ============================================================================= +// // We cannot just add config objects to a list or vector because that would rely // on the vector's c-tor being called before the configs' c-tors. With global // variables we cannot assume that, therefore we need to use a C-style array here. -// ============================================================================= -void Config::addToArray (Config* ptr) +// +void ConfigEntry::addToArray (ConfigEntry* ptr) { if (g_cfgPointerCursor == 0) memset (g_configPointers, 0, sizeof g_configPointers); @@ -140,16 +141,15 @@ g_configPointers[g_cfgPointerCursor++] = ptr; } -// ============================================================================= -// ============================================================================= -template<class T> T* getConfigByName (String name, Config::Type type) +template<typename T> +T* getConfigByName (String name, ConfigEntry::Type type) { auto it = g_configsByName.find (name); if (it == g_configsByName.end()) return null; - Config* cfg = it.value(); + ConfigEntry* cfg = it.value(); if (cfg->getType() != type) { @@ -160,14 +160,12 @@ return reinterpret_cast<T*> (cfg); } -// ============================================================================= -// ============================================================================= #undef IMPLEMENT_CONFIG -#define IMPLEMENT_CONFIG(NAME) \ - NAME##Config* NAME##Config::getByName (String name) \ - { \ - return getConfigByName<NAME##Config> (name, E##NAME##Type); \ +#define IMPLEMENT_CONFIG(NAME) \ + NAME##ConfigEntry* NAME##ConfigEntry::getByName (String name) \ + { \ + return getConfigByName<NAME##ConfigEntry> (name, E##NAME##Type); \ } IMPLEMENT_CONFIG (Int)
--- a/src/configuration.h Tue Apr 29 00:15:56 2014 +0300 +++ b/src/configuration.h Tue Apr 29 02:06:09 2014 +0300 @@ -25,170 +25,176 @@ class QSettings; -#define MAX_INI_LINE 512 -#define MAX_CONFIG 512 +#define CFGENTRY(T, NAME, DEFAULT) \ + namespace cfg \ + { \ + ConfigEntry::T##Type NAME; \ + T##ConfigEntry config_##NAME (&NAME, #NAME, DEFAULT); \ + } -#define cfg(T, NAME, DEFAULT) \ - Config::T##Type NAME; \ - T##Config config_##NAME (&NAME, #NAME, DEFAULT); +#define EXTERN_CFGENTRY(T, NAME) \ + namespace cfg \ + { \ + extern ConfigEntry::T##Type NAME; \ + } -#define extern_cfg(T, NAME) extern Config::T##Type NAME; +namespace Config +{ + bool load(); + bool save(); + void reset(); + String dirpath(); + String filepath (String file); +} // ========================================================= -class Config +class ConfigEntry { PROPERTY (private, String, name, setName, STOCK_WRITE) - public: - enum Type - { - EIntType, - EStringType, - EFloatType, - EBoolType, - EKeySequenceType, - EListType, - EVertexType, - }; +public: + enum Type + { + EIntType, + EStringType, + EFloatType, + EBoolType, + EKeySequenceType, + EListType, + EVertexType, + }; - using IntType = int; - using StringType = String; - using FloatType = float; - using BoolType = bool; - using KeySequenceType = QKeySequence; - using ListType = QList<QVariant>; - using VertexType = Vertex; + using IntType = int; + using StringType = String; + using FloatType = float; + using BoolType = bool; + using KeySequenceType = QKeySequence; + using ListType = QList<QVariant>; + using VertexType = Vertex; - Config (String name); + ConfigEntry (String name); - virtual QVariant getDefaultAsVariant() const = 0; - virtual Type getType() const = 0; - virtual bool isDefault() const = 0; - virtual void loadFromVariant (const QVariant& val) = 0; - virtual void resetValue() = 0; - virtual QVariant toVariant() const = 0; + virtual QVariant getDefaultAsVariant() const = 0; + virtual Type getType() const = 0; + virtual bool isDefault() const = 0; + virtual void loadFromVariant (const QVariant& val) = 0; + virtual void resetValue() = 0; + virtual QVariant toVariant() const = 0; - // ------------------------------------------ - static bool load(); - static bool save(); - static void reset(); - static String dirpath(); - static String filepath (String file); - - protected: - static void addToArray (Config* ptr); +protected: + static void addToArray (ConfigEntry* ptr); }; // ============================================================================= -#define IMPLEMENT_CONFIG(NAME) \ -public: \ - using ValueType = Config::NAME##Type; \ - \ - NAME##Config (ValueType* valueptr, String name, ValueType def) : \ - Config (name), \ - m_valueptr (valueptr), \ - m_default (def) \ - { \ - Config::addToArray (this); \ - *m_valueptr = def; \ - } \ - \ - inline ValueType getValue() const \ - { \ - return *m_valueptr; \ - } \ - \ - inline void setValue (ValueType val) \ - { \ - *m_valueptr = val; \ - } \ - \ - virtual Config::Type getType() const \ - { \ - return Config::E##NAME##Type; \ - } \ - \ - virtual void resetValue() \ - { \ - *m_valueptr = m_default; \ - } \ - \ - virtual const ValueType& getDefault() const \ - { \ - return m_default; \ - } \ - \ - virtual bool isDefault() const \ - { \ - return *m_valueptr == m_default; \ - } \ - \ - virtual void loadFromVariant (const QVariant& val) \ - { \ - *m_valueptr = val.value<ValueType>(); \ - } \ - \ - virtual QVariant toVariant() const \ - { \ - return QVariant::fromValue<ValueType> (*m_valueptr); \ - } \ - \ - virtual QVariant getDefaultAsVariant() const \ - { \ - return QVariant::fromValue<ValueType> (m_default); \ - } \ - \ - static NAME##Config* getByName (String name); \ - \ -private: \ - ValueType* m_valueptr; \ +#define IMPLEMENT_CONFIG(NAME) \ +public: \ + using ValueType = ConfigEntry::NAME##Type; \ + \ + NAME##ConfigEntry (ValueType* valueptr, String name, ValueType def) : \ + ConfigEntry (name), \ + m_valueptr (valueptr), \ + m_default (def) \ + { \ + ConfigEntry::addToArray (this); \ + *m_valueptr = def; \ + } \ + \ + inline ValueType getValue() const \ + { \ + return *m_valueptr; \ + } \ + \ + inline void setValue (ValueType val) \ + { \ + *m_valueptr = val; \ + } \ + \ + virtual ConfigEntry::Type getType() const \ + { \ + return ConfigEntry::E##NAME##Type; \ + } \ + \ + virtual void resetValue() \ + { \ + *m_valueptr = m_default; \ + } \ + \ + virtual const ValueType& getDefault() const \ + { \ + return m_default; \ + } \ + \ + virtual bool isDefault() const \ + { \ + return *m_valueptr == m_default; \ + } \ + \ + virtual void loadFromVariant (const QVariant& val) \ + { \ + *m_valueptr = val.value<ValueType>(); \ + } \ + \ + virtual QVariant toVariant() const \ + { \ + return QVariant::fromValue<ValueType> (*m_valueptr); \ + } \ + \ + virtual QVariant getDefaultAsVariant() const \ + { \ + return QVariant::fromValue<ValueType> (m_default); \ + } \ + \ + static NAME##ConfigEntry* getByName (String name); \ + \ +private: \ + ValueType* m_valueptr; \ ValueType m_default; // ============================================================================= // -class IntConfig : public Config +class IntConfigEntry : public ConfigEntry { IMPLEMENT_CONFIG (Int) }; // ============================================================================= // -class StringConfig : public Config +class StringConfigEntry : public ConfigEntry { IMPLEMENT_CONFIG (String) }; // ============================================================================= // -class FloatConfig : public Config +class FloatConfigEntry : public ConfigEntry { IMPLEMENT_CONFIG (Float) }; // ============================================================================= // -class BoolConfig : public Config +class BoolConfigEntry : public ConfigEntry { IMPLEMENT_CONFIG (Bool) }; // ============================================================================= // -class KeySequenceConfig : public Config +class KeySequenceConfigEntry : public ConfigEntry { IMPLEMENT_CONFIG (KeySequence) }; // ============================================================================= // -class ListConfig : public Config +class ListConfigEntry : public ConfigEntry { IMPLEMENT_CONFIG (List) }; // ============================================================================= // -class VertexConfig : public Config +class VertexConfigEntry : public ConfigEntry { IMPLEMENT_CONFIG (Vertex) };
--- a/src/dialogs.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/dialogs.cc Tue Apr 29 02:06:09 2014 +0300 @@ -45,7 +45,7 @@ #include "ui_bombbox.h" extern const char* g_extProgPathFilter; -extern_cfg (String, io_ldpath); +EXTERN_CFGENTRY (String, ldrawPath); // ============================================================================= // ============================================================================= @@ -178,12 +178,12 @@ okButton()->setEnabled (false); - connect (ui->path, SIGNAL (textEdited (String)), this, SLOT (slot_tryConfigure())); + connect (ui->path, SIGNAL (textEdited (QString)), this, SLOT (slot_tryConfigure())); connect (ui->searchButton, SIGNAL (clicked()), this, SLOT (slot_findPath())); connect (ui->buttonBox, SIGNAL (rejected()), this, validDefault ? SLOT (reject()) : SLOT (slot_exit())); connect (ui->buttonBox, SIGNAL (accepted()), this, SLOT (slot_accept())); - setPath (io_ldpath); + setPath (cfg::ldrawPath); if (validDefault) slot_tryConfigure();
--- a/src/extPrograms.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/extPrograms.cc Tue Apr 29 02:06:09 2014 +0300 @@ -51,39 +51,39 @@ // ============================================================================= // -cfg (String, prog_isecalc, ""); -cfg (String, prog_intersector, ""); -cfg (String, prog_coverer, ""); -cfg (String, prog_ytruder, ""); -cfg (String, prog_rectifier, ""); -cfg (String, prog_edger2, ""); +CFGENTRY (String, isecalcPath, ""); +CFGENTRY (String, intersectorPath, ""); +CFGENTRY (String, covererPath, ""); +CFGENTRY (String, ytruderPath, ""); +CFGENTRY (String, rectifierPath, ""); +CFGENTRY (String, edger2Path, ""); String* const g_extProgPaths[] = { - &prog_isecalc, - &prog_intersector, - &prog_coverer, - &prog_ytruder, - &prog_rectifier, - &prog_edger2, + &cfg::isecalcPath, + &cfg::intersectorPath, + &cfg::covererPath, + &cfg::ytruderPath, + &cfg::rectifierPath, + &cfg::edger2Path, }; #ifndef _WIN32 -cfg (Bool, prog_isecalc_wine, false); -cfg (Bool, prog_intersector_wine, false); -cfg (Bool, prog_coverer_wine, false); -cfg (Bool, prog_ytruder_wine, false); -cfg (Bool, prog_rectifier_wine, false); -cfg (Bool, prog_edger2_wine, false); +CFGENTRY (Bool, isecalcUsesWine, false); +CFGENTRY (Bool, intersectorUsesWine, false); +CFGENTRY (Bool, covererUsesWine, false); +CFGENTRY (Bool, ytruderUsesWine, false); +CFGENTRY (Bool, rectifierUsesWine, false); +CFGENTRY (Bool, edger2UsesWine, false); bool* const g_extProgWine[] = { - &prog_isecalc_wine, - &prog_intersector_wine, - &prog_coverer_wine, - &prog_ytruder_wine, - &prog_rectifier_wine, - &prog_edger2_wine, + &cfg::isecalcUsesWine, + &cfg::intersectorUsesWine, + &cfg::covererUsesWine, + &cfg::ytruderUsesWine, + &cfg::rectifierUsesWine, + &cfg::edger2UsesWine, }; #endif // _WIN32 @@ -381,7 +381,7 @@ writeSelection (inDATName); - if (not runUtilityProcess (Ytruder, prog_ytruder, argv)) + if (not runUtilityProcess (Ytruder, cfg::ytruderPath, argv)) return; insertOutput (outDATName, false, {}); @@ -426,7 +426,7 @@ writeSelection (inDATName); - if (not runUtilityProcess (Rectifier, prog_rectifier, argv)) + if (not runUtilityProcess (Rectifier, cfg::rectifierPath, argv)) return; insertOutput (outDATName, true, {}); @@ -517,20 +517,19 @@ writeColorGroup (inCol, inDATName); writeColorGroup (cutCol, cutDATName); - if (not runUtilityProcess (Intersector, prog_intersector, argv_normal)) + if (not runUtilityProcess (Intersector, cfg::intersectorPath, argv_normal)) return; insertOutput (outDATName, false, {inCol}); - if (repeatInverse && runUtilityProcess (Intersector, prog_intersector, argv_inverse)) + if (repeatInverse && runUtilityProcess (Intersector, cfg::intersectorPath, argv_inverse)) insertOutput (outDAT2Name, false, {cutCol}); - if ( - ui.cb_edges->isChecked() && - checkProgPath (Isecalc) && - runUtilityProcess (Isecalc, prog_isecalc, join ( {inDATName, cutDATName, edgesDATName})) - ) + if (ui.cb_edges->isChecked() && checkProgPath (Isecalc) && + runUtilityProcess (Isecalc, cfg::isecalcPath, join ( {inDATName, cutDATName, edgesDATName}))) + { insertOutput (edgesDATName, false, {}); + } } // ============================================================================= @@ -591,7 +590,7 @@ writeColorGroup (in1Col, in1DATName); writeColorGroup (in2Col, in2DATName); - if (not runUtilityProcess (Coverer, prog_coverer, argv)) + if (not runUtilityProcess (Coverer, cfg::covererPath, argv)) return; insertOutput (outDATName, false, {}); @@ -652,7 +651,7 @@ writeColorGroup (in1Col, in1DATName); writeColorGroup (in2Col, in2DATName); - runUtilityProcess (Isecalc, prog_isecalc, argv); + runUtilityProcess (Isecalc, cfg::isecalcPath, argv); insertOutput (outDATName, false, {}); } @@ -699,7 +698,7 @@ writeSelection (inName); - if (not runUtilityProcess (Edger2, prog_edger2, argv)) + if (not runUtilityProcess (Edger2, cfg::edger2Path, argv)) return; insertOutput (outName, true, {});
--- a/src/glCompiler.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/glCompiler.cc Tue Apr 29 02:06:09 2014 +0300 @@ -45,9 +45,9 @@ { GL_STACK_OVERFLOW, "The operation would have caused an overflow" }, }; -cfg (String, gl_selectcolor, "#0080FF") -extern_cfg (Bool, gl_blackedges); -extern_cfg (String, gl_bgcolor); +CFGENTRY (String, selectColorBlend, "#0080FF") +EXTERN_CFGENTRY (Bool, blackEdges); +EXTERN_CFGENTRY (String, backgroundColor); static QList<int> g_warnedColors; static const QColor g_BFCFrontColor (64, 192, 80); @@ -163,7 +163,7 @@ } elif (poly.color == edgecolor) { - qcol = luma (QColor (gl_bgcolor)) > 40 ? Qt::black : Qt::white; + qcol = luma (QColor (cfg::backgroundColor)) > 40 ? Qt::black : Qt::white; } else { @@ -197,7 +197,7 @@ if (topobj->isSelected()) { // Brighten it up for the select list. - QColor selcolor (gl_selectcolor); + QColor selcolor (cfg::selectColorBlend); qcol.setRed ((qcol.red() + selcolor.red()) / 2); qcol.setGreen ((qcol.green() + selcolor.green()) / 2); qcol.setBlue ((qcol.blue() + selcolor.blue()) / 2);
--- a/src/glRenderer.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/glRenderer.cc Tue Apr 29 02:06:09 2014 +0300 @@ -63,20 +63,20 @@ { 0, 1, 0, 2, 0, 0, 0, 0, 2 }, }; -cfg (String, gl_bgcolor, "#FFFFFF") -cfg (String, gl_maincolor, "#A0A0A0") -cfg (Float, gl_maincolor_alpha, 1.0) -cfg (Int, gl_linethickness, 2) -cfg (Bool, gl_colorbfc, false) -cfg (Int, gl_camera, GLRenderer::EFreeCamera) -cfg (Bool, gl_blackedges, false) -cfg (Bool, gl_axes, false) -cfg (Bool, gl_wireframe, false) -cfg (Bool, gl_logostuds, false) -cfg (Bool, gl_aa, true) -cfg (Bool, gl_linelengths, true) -cfg (Bool, gl_drawangles, false) -cfg (Bool, gl_randomcolors, false) +CFGENTRY (String, backgroundColor, "#FFFFFF") +CFGENTRY (String, mainColor, "#A0A0A0") +CFGENTRY (Float, mainColorAlpha, 1.0) +CFGENTRY (Int, lineThickness, 2) +CFGENTRY (Bool, bfcRedGreenView, false) +CFGENTRY (Int, camera, GLRenderer::EFreeCamera) +CFGENTRY (Bool, blackEdges, false) +CFGENTRY (Bool, drawAxes, false) +CFGENTRY (Bool, drawWireframe, false) +CFGENTRY (Bool, useLogoStuds, false) +CFGENTRY (Bool, antiAliasedLines, true) +CFGENTRY (Bool, drawLineLengths, true) +CFGENTRY (Bool, drawAngles, false) +CFGENTRY (Bool, randomColors, false) // argh const char* g_CameraNames[7] = @@ -123,7 +123,7 @@ GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) { m_isPicking = m_rangepick = false; - m_camera = (EFixedCamera) gl_camera; + m_camera = (EFixedCamera) cfg::camera; m_drawToolTip = false; m_editMode = ESelectMode; m_rectdraw = false; @@ -209,7 +209,7 @@ glShadeModel (GL_SMOOTH); glEnable (GL_MULTISAMPLE); - if (gl_aa) + if (cfg::antiAliasedLines) { glEnable (GL_LINE_SMOOTH); glEnable (GL_POLYGON_SMOOTH); @@ -260,7 +260,7 @@ void GLRenderer::initializeGL() { setBackground(); - glLineWidth (gl_linethickness); + glLineWidth (cfg::lineThickness); glLineStipple (1, 0x6666); setAutoFillBackground (false); setMouseTracking (true); @@ -306,12 +306,12 @@ // QColor GLRenderer::getMainColor() { - QColor col (gl_maincolor); + QColor col (cfg::mainColor); if (not col.isValid()) return QColor (0, 0, 0); - col.setAlpha (gl_maincolor_alpha * 255.f); + col.setAlpha (cfg::mainColorAlpha * 255.f); return col; } @@ -319,7 +319,7 @@ // void GLRenderer::setBackground() { - QColor col (gl_bgcolor); + QColor col (cfg::backgroundColor); if (not col.isValid()) return; @@ -345,7 +345,7 @@ { compiler()->compileDocument (getCurrentDocument()); refresh(); - glLineWidth (gl_linethickness); // TODO: ...? + glLineWidth (cfg::lineThickness); // TODO: ...? } // ============================================================================= @@ -377,7 +377,7 @@ zoomAllToFit(); } - if (gl_wireframe && not isPicking()) + if (cfg::drawWireframe && not isPicking()) glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -431,7 +431,7 @@ } else { - if (gl_colorbfc) + if (cfg::bfcRedGreenView) { glEnable (GL_CULL_FACE); glCullFace (GL_BACK); @@ -444,7 +444,7 @@ } else { - if (gl_randomcolors) + if (cfg::randomColors) { drawVBOs (VBOSF_Triangles, VBOCM_RandomColors, GL_TRIANGLES); drawVBOs (VBOSF_Quads, VBOCM_RandomColors, GL_QUADS); @@ -461,7 +461,7 @@ drawVBOs (VBOSF_CondLines, VBOCM_NormalColors, GL_LINES); glDisable (GL_LINE_STIPPLE); - if (gl_axes) + if (cfg::drawAxes) { glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO); glVertexPointer (3, GL_FLOAT, 0, NULL); @@ -703,14 +703,14 @@ const int j = (i + 1 < numverts) ? i + 1 : 0; const int h = (i - 1 >= 0) ? i - 1 : numverts - 1; - if (gl_linelengths) + if (cfg::drawLineLengths) { const String label = String::number ((poly3d[j] - poly3d[i]).length()); QPoint origin = QLineF (poly[i], poly[j]).pointAt (0.5).toPoint(); paint.drawText (origin, label); } - if (gl_drawangles) + if (cfg::drawAngles) { QLineF l0 (poly[h], poly[i]), l1 (poly[i], poly[j]); @@ -1210,7 +1210,7 @@ void GLRenderer::setCamera (const GLRenderer::EFixedCamera cam) { m_camera = cam; - gl_camera = (int) cam; + cfg::camera = (int) cam; g_win->updateEditModeActions(); } @@ -1221,7 +1221,7 @@ makeCurrent(); // Use particularly thick lines while picking ease up selecting lines. - glLineWidth (max<double> (gl_linethickness, 6.5f)); + glLineWidth (max<double> (cfg::lineThickness, 6.5f)); // Clear the selection if we do not wish to add to it. if (not m_addpick) @@ -1332,7 +1332,7 @@ compileObject (removedObj); // Restore line thickness - glLineWidth (gl_linethickness); + glLineWidth (cfg::lineThickness); setPicking (false); m_rangepick = false;
--- a/src/ldDocument.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/ldDocument.cc Tue Apr 29 02:06:09 2014 +0300 @@ -33,10 +33,10 @@ #include "misc/invokeLater.h" #include "glCompiler.h" -cfg (String, io_ldpath, ""); -cfg (List, io_recentfiles, {}); -extern_cfg (String, net_downloadpath); -extern_cfg (Bool, gl_logostuds); +CFGENTRY (String, ldrawPath, "") +CFGENTRY (List, recentFiles, {}) +EXTERN_CFGENTRY (String, downloadFilePath) +EXTERN_CFGENTRY (Bool, useLogoStuds) static bool g_loadingMainFile = false; static const int g_maxRecentFiles = 10; @@ -62,14 +62,14 @@ void initPaths() { - if (not tryConfigure (io_ldpath)) + if (not tryConfigure (cfg::ldrawPath)) { LDrawPathDialog dlg (false); if (not dlg.exec()) exit (0); - io_ldpath = dlg.filename(); + cfg::ldrawPath = dlg.filename(); } } @@ -273,7 +273,7 @@ return relpath; // Try with just the LDraw path first - fullPath = format ("%1" DIRSLASH "%2", io_ldpath, relpath); + fullPath = format ("%1" DIRSLASH "%2", cfg::ldrawPath, relpath); if (QFile::exists (fullPath)) return fullPath; @@ -282,7 +282,7 @@ { // Look in sub-directories: parts and p. Also look in net_downloadpath, since that's // where we download parts from the PT to. - for (const String& topdir : QList<String> ({ io_ldpath, net_downloadpath })) + for (const String& topdir : QList<String> ({ cfg::ldrawPath, cfg::downloadFilePath })) { for (const String& subdir : QList<String> ({ "parts", "p" })) { @@ -621,7 +621,7 @@ // void addRecentFile (String path) { - auto& rfiles = io_recentfiles; + auto& rfiles = cfg::recentFiles; int idx = rfiles.indexOf (path); // If this file already is in the list, pop it out. @@ -1330,7 +1330,7 @@ // Possibly substitute with logoed studs: // stud.dat -> stud-logo.dat // stud2.dat -> stud-logo2.dat - if (gl_logostuds && renderinline) + if (cfg::useLogoStuds && renderinline) { // Ensure logoed studs are loaded first loadLogoedStuds();
--- a/src/ldObject.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/ldObject.cc Tue Apr 29 02:06:09 2014 +0300 @@ -27,9 +27,9 @@ #include "colors.h" #include "glCompiler.h" -cfg (String, ld_defaultname, ""); -cfg (String, ld_defaultuser, ""); -cfg (Int, ld_defaultlicense, 0); +CFGENTRY (String, defaultName, ""); +CFGENTRY (String, defaultUser, ""); +CFGENTRY (Int, defaultLicense, 0); // List of all LDObjects static LDObjectList g_LDObjects;
--- a/src/main.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/main.cc Tue Apr 29 02:06:09 2014 +0300 @@ -41,7 +41,7 @@ const Vertex g_origin (0.0f, 0.0f, 0.0f); const Matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); -cfg (Bool, firststart, true); +CFGENTRY (Bool, firstStart, true); // ============================================================================= // @@ -72,10 +72,10 @@ // If this is the first start, get the user to configuration. Especially point // them to the profile tab, it's the most important form to fill in. - if (firststart) + if (cfg::firstStart) { (new ConfigDialog (ConfigDialog::ProfileTab))->exec(); - firststart = false; + cfg::firstStart = false; Config::save(); }
--- a/src/mainWindow.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/mainWindow.cc Tue Apr 29 02:06:09 2014 +0300 @@ -51,17 +51,17 @@ static bool g_isSelectionLocked = false; -cfg (Bool, lv_colorize, true); -cfg (String, gui_colortoolbar, "4:25:14:27:2:3:11:1:22:|:0:72:71:15"); -cfg (Bool, gui_implicitfiles, false); -extern_cfg (List, io_recentfiles); -extern_cfg (Bool, gl_axes); -extern_cfg (String, gl_maincolor); -extern_cfg (Float, gl_maincolor_alpha); -extern_cfg (Bool, gl_wireframe); -extern_cfg (Bool, gl_colorbfc); -extern_cfg (Bool, gl_drawangles); -extern_cfg (Bool, gl_randomcolors); +CFGENTRY (Bool, colorizeObjectsList, true); +CFGENTRY (String, quickColorToolbar, "4:25:14:27:2:3:11:1:22:|:0:72:71:15"); +CFGENTRY (Bool, listImplicitFiles, false); +EXTERN_CFGENTRY (List, recentFiles); +EXTERN_CFGENTRY (Bool, drawAxes); +EXTERN_CFGENTRY (String, mainColor); +EXTERN_CFGENTRY (Float, mainColorAlpha); +EXTERN_CFGENTRY (Bool, drawWireframe); +EXTERN_CFGENTRY (Bool, bfcRedGreenView); +EXTERN_CFGENTRY (Bool, drawAngles); +EXTERN_CFGENTRY (Bool, randomColors); // ============================================================================= // @@ -90,10 +90,10 @@ m_quickColors = quickColorsFromConfig(); slot_selectionChanged(); setStatusBar (new QStatusBar); - ui->actionAxes->setChecked (gl_axes); - ui->actionWireframe->setChecked (gl_wireframe); - ui->actionBFCView->setChecked (gl_colorbfc); - ui->actionRandomColors->setChecked (gl_randomcolors); + ui->actionAxes->setChecked (cfg::drawAxes); + ui->actionWireframe->setChecked (cfg::drawWireframe); + ui->actionBFCView->setChecked (cfg::bfcRedGreenView); + ui->actionRandomColors->setChecked (cfg::randomColors); updateGridToolBar(); updateEditModeActions(); updateRecentFilesMenu(); @@ -111,10 +111,10 @@ // ============================================================================= // -KeySequenceConfig* MainWindow::shortcutForAction (QAction* action) +KeySequenceConfigEntry* MainWindow::shortcutForAction (QAction* action) { - String keycfgname = format ("key_%1", action->objectName()); - return KeySequenceConfig::getByName (keycfgname); + String keycfgname = action->objectName() + "Shortcut"; + return KeySequenceConfigEntry::getByName (keycfgname); } // ============================================================================= @@ -123,7 +123,7 @@ { for (QAction* act : findChildren<QAction*>()) { - KeySequenceConfig* cfg = shortcutForAction (act); + KeySequenceConfigEntry* cfg = shortcutForAction (act); if (cfg) act->setShortcut (cfg->getValue()); @@ -173,7 +173,7 @@ QAction* first = null; - for (const QVariant& it : io_recentfiles) + for (const QVariant& it : cfg::recentFiles) { String file = it.toString(); QAction* recent = new QAction (getIcon ("open-recent"), file, this); @@ -191,7 +191,7 @@ { QList<LDQuickColor> colors; - for (String colorname : gui_colortoolbar.split (":")) + for (String colorname : cfg::quickColorToolbar.split (":")) { if (colorname == "|") colors << LDQuickColor::getSeparator(); @@ -243,9 +243,9 @@ void MainWindow::updateGridToolBar() { // Ensure that the current grid - and only the current grid - is selected. - ui->actionGridCoarse->setChecked (grid == Grid::Coarse); - ui->actionGridMedium->setChecked (grid == Grid::Medium); - ui->actionGridFine->setChecked (grid == Grid::Fine); + ui->actionGridCoarse->setChecked (cfg::grid == Grid::Coarse); + ui->actionGridMedium->setChecked (cfg::grid == Grid::Medium); + ui->actionGridFine->setChecked (cfg::grid == Grid::Fine); } // ============================================================================= @@ -417,7 +417,8 @@ item->setBackground (QColor ("#AA0000")); item->setForeground (QColor ("#FFAA00")); } - elif (lv_colorize && obj->isColored() && obj->color() != maincolor && obj->color() != edgecolor) + elif (cfg::colorizeObjectsList && obj->isColored() && + obj->color() != maincolor && obj->color() != edgecolor) { // If the object isn't in the main or edge color, draw this // list entry in said color. @@ -841,8 +842,8 @@ if (colinfo->index == maincolor) { // Use the user preferences for main color here - col = gl_maincolor; - col.setAlphaF (gl_maincolor_alpha); + col = cfg::mainColor; + col.setAlphaF (cfg::mainColorAlpha); } // Paint the icon border @@ -902,7 +903,7 @@ for (LDDocument* f : g_loadedFiles) { // Don't list implicit files unless explicitly desired. - if (f->isImplicit() && not gui_implicitfiles) + if (f->isImplicit() && not cfg::listImplicitFiles) continue; // Add an item to the list for this file and store the tab index @@ -996,9 +997,9 @@ int pos = his->position(); ui->actionUndo->setEnabled (pos != -1); ui->actionRedo->setEnabled (pos < (long) his->getSize() - 1); - ui->actionAxes->setChecked (gl_axes); - ui->actionBFCView->setChecked (gl_colorbfc); - ui->actionDrawAngles->setChecked (gl_drawangles); + ui->actionAxes->setChecked (cfg::drawAxes); + ui->actionBFCView->setChecked (cfg::bfcRedGreenView); + ui->actionDrawAngles->setChecked (cfg::drawAngles); } // =============================================================================
--- a/src/mainWindow.h Tue Apr 29 00:15:56 2014 +0300 +++ b/src/mainWindow.h Tue Apr 29 02:06:09 2014 +0300 @@ -45,7 +45,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= #define DEFINE_ACTION(NAME, DEFSHORTCUT) \ - cfg (KeySequence, key_action##NAME, DEFSHORTCUT); \ + CFGENTRY (KeySequence, action##NAME##Shortcut, DEFSHORTCUT); \ void MainWindow::slot_action##NAME() // Convenience macros for key sequences. @@ -189,7 +189,7 @@ void updateActionShortcuts(); //! Gets the shortcut configuration for the given \c action - KeySequenceConfig* shortcutForAction (QAction* action); + KeySequenceConfigEntry* shortcutForAction (QAction* action); void endAction();
--- a/src/miscallenous.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/miscallenous.cc Tue Apr 29 02:06:09 2014 +0300 @@ -102,21 +102,21 @@ // // Grid stuff // -cfg (Int, grid, Grid::Medium); -cfg (Float, grid_coarse_snap, 5.0f); -cfg (Float, grid_coarse_angle, 45.0f); -cfg (Float, grid_medium_snap, 1.0f); -cfg (Float, grid_medium_angle, 22.5f); -cfg (Float, grid_fine_snap, 0.1f); -cfg (Float, grid_fine_angle, 7.5f); -cfg (Int, edit_rotpoint, 0); -cfg (Vertex, edit_customrotpoint, g_origin); +CFGENTRY (Int, grid, Grid::Medium); +CFGENTRY (Float, gridCoarseCoordinateSnap, 5.0f); +CFGENTRY (Float, gridCoarseAngleSnap, 45.0f); +CFGENTRY (Float, gridMediumCoordinateSnap, 1.0f); +CFGENTRY (Float, gridMediumAngleSnap, 22.5f); +CFGENTRY (Float, gridFineCoordinateSnap, 0.1f); +CFGENTRY (Float, gridFineAngleSnap, 7.5f); +CFGENTRY (Int, edit_rotpoint, 0); +CFGENTRY (Vertex, edit_customrotpoint, g_origin); const gridinfo g_gridInfo[3] = { - { "Coarse", &grid_coarse_snap, &grid_coarse_angle }, - { "Medium", &grid_medium_snap, &grid_medium_angle }, - { "Fine", &grid_fine_snap, &grid_fine_angle }, + { "Coarse", &cfg::gridCoarseCoordinateSnap, &cfg::gridCoarseAngleSnap }, + { "Medium", &cfg::gridMediumCoordinateSnap, &cfg::gridMediumAngleSnap }, + { "Fine", &cfg::gridFineCoordinateSnap, &cfg::gridFineAngleSnap }, }; // ============================================================================= @@ -203,7 +203,7 @@ // Vertex rotPoint (const LDObjectList& objs) { - switch ((ERotationPoint) edit_rotpoint) + switch ((ERotationPoint) cfg::edit_rotpoint) { case EObjectOrigin: { @@ -228,7 +228,7 @@ case ECustomPoint: { - return edit_customrotpoint; + return cfg::edit_customrotpoint; } } @@ -243,7 +243,7 @@ Ui::RotPointUI ui; ui.setupUi (dlg); - switch ((ERotationPoint) edit_rotpoint) + switch ((ERotationPoint) cfg::edit_rotpoint) { case EObjectOrigin: ui.objectPoint->setChecked (true); @@ -258,21 +258,21 @@ break; } - ui.customX->setValue (edit_customrotpoint.x()); - ui.customY->setValue (edit_customrotpoint.y()); - ui.customZ->setValue (edit_customrotpoint.z()); + ui.customX->setValue (cfg::edit_customrotpoint.x()); + ui.customY->setValue (cfg::edit_customrotpoint.y()); + ui.customZ->setValue (cfg::edit_customrotpoint.z()); if (not dlg->exec()) return; - edit_rotpoint = + cfg::edit_rotpoint = (ui.objectPoint->isChecked()) ? EObjectOrigin : (ui.worldPoint->isChecked()) ? EWorldOrigin : ECustomPoint; - edit_customrotpoint.setX (ui.customX->value()); - edit_customrotpoint.setY (ui.customY->value()); - edit_customrotpoint.setZ (ui.customZ->value()); + cfg::edit_customrotpoint.setX (ui.customX->value()); + cfg::edit_customrotpoint.setY (ui.customY->value()); + cfg::edit_customrotpoint.setZ (ui.customZ->value()); } // =============================================================================
--- a/src/miscallenous.h Tue Apr 29 00:15:56 2014 +0300 +++ b/src/miscallenous.h Tue Apr 29 02:06:09 2014 +0300 @@ -52,17 +52,17 @@ struct gridinfo { const char* const name; - Config::FloatType* const coordsnap; - Config::FloatType* const anglesnap; + ConfigEntry::FloatType* const coordsnap; + ConfigEntry::FloatType* const anglesnap; }; -extern_cfg (Int, grid); +EXTERN_CFGENTRY (Int, grid); static const int g_numGrids = 3; extern const gridinfo g_gridInfo[3]; inline const gridinfo& currentGrid() { - return g_gridInfo[grid]; + return g_gridInfo[cfg::grid]; } // =============================================================================
--- a/src/partDownloader.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/partDownloader.cc Tue Apr 29 02:06:09 2014 +0300 @@ -30,9 +30,9 @@ #include "glRenderer.h" #include "configDialog.h" -cfg (String, net_downloadpath, ""); -cfg (Bool, net_guesspaths, true); -cfg (Bool, net_autoclose, true); +CFGENTRY (String, downloadFilePath, ""); +CFGENTRY (Bool, guessDownloadPaths, true); +CFGENTRY (Bool, autoCloseDownloadDialog, true); const QString g_unofficialLibraryURL ("http://ldraw.org/library/unofficial/"); @@ -59,7 +59,7 @@ // QString PartDownloader::getDownloadPath() { - QString path = net_downloadpath; + QString path = cfg::downloadFilePath; #if DIRSLASH_CHAR != '/' path.replace (DIRSLASH, "/"); @@ -123,7 +123,7 @@ dest = dest.simplified(); // If the user doesn't want us to guess, stop right here. - if (not net_guesspaths) + if (not cfg::guessDownloadPaths) return; // Ensure .dat extension @@ -288,7 +288,7 @@ g_win->R()->resetAngles(); } - if (net_autoclose && not failed) + if (cfg::autoCloseDownloadDialog && not failed) { // Close automatically if desired. accept();
--- a/src/primitives.cc Tue Apr 29 00:15:56 2014 +0300 +++ b/src/primitives.cc Tue Apr 29 02:06:09 2014 +0300 @@ -31,9 +31,9 @@ static PrimitiveScanner* g_activeScanner = null; PrimitiveCategory* g_unmatched = null; -extern_cfg (String, ld_defaultname); -extern_cfg (String, ld_defaultuser); -extern_cfg (Int, ld_defaultlicense); +EXTERN_CFGENTRY (String, defaultName); +EXTERN_CFGENTRY (String, defaultUser); +EXTERN_CFGENTRY (Int, defaultLicense); static const QStringList g_radialNameRoots = { @@ -613,10 +613,10 @@ QString author = APPNAME; QString license = ""; - if (not ld_defaultname.isEmpty()) + if (not cfg::defaultName.isEmpty()) { - license = getLicenseText (ld_defaultlicense); - author = format ("%1 [%2]", ld_defaultname, ld_defaultuser); + license = getLicenseText (cfg::defaultLicense); + author = format ("%1 [%2]", cfg::defaultName, cfg::defaultUser); } f->addObjects (