Wed, 21 Aug 2013 14:07:02 +0300
stuff
src/colorSelectDialog.cpp | file | annotate | diff | comparison | revisions | |
src/colors.cpp | file | annotate | diff | comparison | revisions | |
src/config.cpp | file | annotate | diff | comparison | revisions | |
src/config.h | file | annotate | diff | comparison | revisions | |
src/configDialog.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions |
--- a/src/colorSelectDialog.cpp Wed Aug 21 11:09:39 2013 +0300 +++ b/src/colorSelectDialog.cpp Wed Aug 21 14:07:02 2013 +0300 @@ -14,6 +14,9 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * ===================================================================== + * + * colorSelectDialog.cpp: Color selector box. */ #include <QGraphicsScene>
--- a/src/colors.cpp Wed Aug 21 11:09:39 2013 +0300 +++ b/src/colors.cpp Wed Aug 21 14:07:02 2013 +0300 @@ -14,6 +14,11 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * ===================================================================== + * + * colors.cpp: LDraw color management. LDConfig.ldr parsing is not here! + * TODO: Make LDColor more full-fledged, add support for direct colors. + * TODO: g_LDColors should probably be a map. */ #include "common.h" @@ -34,14 +39,15 @@ // Always make sure there's 16 and 24 available. They're special like that. col = new LDColor; + col->faceColor = col->hexcode = "#AAAAAA"; - col->faceColor = col->hexcode; col->edgeColor = Qt::black; g_LDColors[maincolor] = col; col = new LDColor; + col->faceColor = + col->edgeColor = col->hexcode = "#000000"; - col->edgeColor = col->faceColor = Qt::black; g_LDColors[edgecolor] = col; parseLDConfig();
--- a/src/config.cpp Wed Aug 21 11:09:39 2013 +0300 +++ b/src/config.cpp Wed Aug 21 14:07:02 2013 +0300 @@ -14,6 +14,12 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * ===================================================================== + * + * config.cpp: Configuration management. I don't like how unsafe QSettings + * is so this implements a type-safer and idenitifer-safer wrapping system of + * configuration variables. QSettings is used underlyingly, this is a matter + * of interface. */ #include <errno.h> @@ -30,6 +36,8 @@ static ushort g_cfgPointerCursor = 0; // ============================================================================= +// Get the QSettings object. A portable build refers to a file in the current +// directory, a non-portable build to ~/.config/LDForge or to registry. // ----------------------------------------------------------------------------- static QSettings* getSettingsObject() { #ifdef PORTABLE @@ -48,11 +56,11 @@ name (name), m_defstring (defstring) {} // ============================================================================= +// Load the configuration from file // ----------------------------------------------------------------------------- -// Load the configuration from file bool Config::load() { QSettings* settings = getSettingsObject(); - print ("config::load: Loading configuration file from %1...\n", settings->fileName()); + print ("config::load: Loading configuration file from %1\n", settings->fileName()); for (Config* cfg : g_configPointers) { if (!cfg) @@ -67,8 +75,8 @@ } // ============================================================================= +// Save the configuration to disk // ----------------------------------------------------------------------------- -// Save the configuration to disk bool Config::save() { QSettings* settings = getSettingsObject(); print ("Saving configuration to %1...\n", settings->fileName()); @@ -89,6 +97,7 @@ } // ============================================================================= +// Reset configuration defaults. // ----------------------------------------------------------------------------- void Config::reset() { for (Config* cfg : g_configPointers) { @@ -100,12 +109,15 @@ } // ============================================================================= +// Where is the configuration file located at? Note that the Windows build uses +// the registry so only use this with PORTABLE code. // ----------------------------------------------------------------------------- str Config::filepath (str file) { return Config::dirpath() + DIRSLASH + file; } // ============================================================================= +// Directory of the configuration file. PORTABLE code here as well. // ----------------------------------------------------------------------------- str Config::dirpath() { QSettings* cfg = getSettingsObject(); @@ -113,21 +125,6 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- -str Config::defaultString() const { - str defstring = m_defstring; - - // String types inevitably get extra quotes in their default string due to - // preprocessing stuff. We can only remove them now... - if (getType() == String) { - defstring.remove (0, 1); - defstring.chop (1); - } - - return defstring; -} - -// ============================================================================= // 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.
--- a/src/config.h Wed Aug 21 11:09:39 2013 +0300 +++ b/src/config.h Wed Aug 21 14:07:02 2013 +0300 @@ -55,7 +55,6 @@ return (Type) 0; } - str defaultString() const; virtual void resetValue() {} virtual void loadFromVariant (const QVariant& val) { (void) val; } virtual bool isDefault() const { return false; }
--- a/src/configDialog.cpp Wed Aug 21 11:09:39 2013 +0300 +++ b/src/configDialog.cpp Wed Aug 21 14:07:02 2013 +0300 @@ -14,6 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * ===================================================================== + * + * configDialog.cpp: Settings dialog and everything related to it. + * Actual configuration core is in config.cpp. */ #include <QGridLayout> @@ -25,7 +29,6 @@ #include <QDoubleSpinBox> #include <QLineEdit> #include <QCheckBox> - #include "common.h" #include "configDialog.h" #include "file.h" @@ -67,6 +70,9 @@ 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 (*.*)(*.*)"; @@ -74,9 +80,6 @@ ""; #endif -#define act(N) extern_cfg (KeySequence, key_##N); -#include "actions.h" - // ============================================================================= // ----------------------------------------------------------------------------- ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) : @@ -86,12 +89,12 @@ ui = new Ui_ConfigUI; ui->setupUi (this); - // Interface tab: + // Interface tab setButtonBackground (ui->backgroundColorButton, gl_bgcolor); connect (ui->backgroundColorButton, SIGNAL (clicked()), this, SLOT (slot_setGLBackground())); - setButtonBackground (ui->mainColorButton, gl_maincolor.value); + setButtonBackground (ui->mainColorButton, gl_maincolor); connect (ui->mainColorButton, SIGNAL (clicked()), this, SLOT (slot_setGLForeground())); @@ -149,6 +152,7 @@ } // ============================================================================= +// Adds a shortcut entry to the list of shortcuts. // ----------------------------------------------------------------------------- void ConfigDialog::addShortcut (KeySequenceConfig& cfg, QAction* act, ulong& i) { ShortcutListItem* item = new ShortcutListItem; @@ -166,6 +170,7 @@ } // ============================================================================= +// Initializes the table of grid stuff // ----------------------------------------------------------------------------- void ConfigDialog::initGrids() { QGridLayout* gridlayout = new QGridLayout; @@ -231,6 +236,7 @@ }; // ============================================================================= +// Initializes the stuff in the ext programs tab // ----------------------------------------------------------------------------- void ConfigDialog::initExtProgs() { QGridLayout* pathsLayout = new QGridLayout; @@ -269,12 +275,12 @@ } // ============================================================================= +// Set the settings based on widget data. // ----------------------------------------------------------------------------- void ConfigDialog::applySettings() { // Apply configuration lv_colorize = ui->colorizeObjects->isChecked(); gl_colorbfc = ui->colorBFC->isChecked(); - // edit_schemanticinline = ui->scemanticInlining->isChecked(); gl_blackedges = ui->blackEdges->isChecked(); gl_maincolor_alpha = ((double) ui->mainColorAlpha->value()) / 10.0f; gl_linethickness = ui->lineThickness->value(); @@ -287,6 +293,7 @@ ld_defaultname = ui->m_profileName->text(); ld_defaultlicense = ui->m_profileLicense->currentIndex(); + // Ensure '/' postfix to the download path if (net_downloadpath.value.right (1) != DIRSLASH) net_downloadpath += DIRSLASH; @@ -322,6 +329,7 @@ } // ============================================================================= +// A dialog button was clicked // ----------------------------------------------------------------------------- void ConfigDialog::buttonClicked (QAbstractButton* button) { typedef QDialogButtonBox QDDB; @@ -338,6 +346,7 @@ } // ============================================================================= +// Update the list of color toolbar items in the quick color tab. // ----------------------------------------------------------------------------- void ConfigDialog::updateQuickColorList (LDQuickColor* sel) { for (QListWidgetItem* item : quickColorItems) @@ -375,6 +384,7 @@ } // ============================================================================= +// Quick colors: add or edit button was clicked. // ----------------------------------------------------------------------------- void ConfigDialog::slot_setColor() { LDQuickColor* entry = null; @@ -421,6 +431,7 @@ } // ============================================================================= +// Remove a quick color // ----------------------------------------------------------------------------- void ConfigDialog::slot_delColor() { if (ui->quickColorList->selectedItems().size() == 0) @@ -432,6 +443,7 @@ } // ============================================================================= +// Move a quick color up/down // ----------------------------------------------------------------------------- void ConfigDialog::slot_moveColor() { const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp); @@ -454,6 +466,7 @@ } // ============================================================================= +// Add a separator to quick colors // ----------------------------------------------------------------------------- void ConfigDialog::slot_addColorSeparator() { quickColors << LDQuickColor ({null, null, true}); @@ -461,6 +474,7 @@ } // ============================================================================= +// Clear all quick colors // ----------------------------------------------------------------------------- void ConfigDialog::slot_clearColors() { quickColors.clear(); @@ -468,6 +482,7 @@ } // ============================================================================= +// Pick a color and set the appropriate configuration option. // ----------------------------------------------------------------------------- void ConfigDialog::pickColor (StringConfig& conf, QPushButton* button) { QColor col = QColorDialog::getColor (QColor (conf)); @@ -494,6 +509,7 @@ } // ============================================================================= +// Sets background color of a given button. // ----------------------------------------------------------------------------- void ConfigDialog::setButtonBackground (QPushButton* button, str value) { button->setIcon (getIcon ("colorselect")); @@ -502,6 +518,7 @@ } // ============================================================================= +// Finds the given list widget item in the list of widget items given. // ----------------------------------------------------------------------------- int ConfigDialog::getItemRow (QListWidgetItem* item, List<QListWidgetItem*>& haystack) { int i = 0; @@ -516,15 +533,17 @@ } // ============================================================================= +// Which quick color is currently selected? // ----------------------------------------------------------------------------- QListWidgetItem* ConfigDialog::getSelectedQuickColor() { if (ui->quickColorList->selectedItems().size() == 0) return null; - return ui->quickColorList->selectedItems() [0]; + return ui->quickColorList->selectedItems()[0]; } // ============================================================================= +// Get the list of shortcuts selected // ----------------------------------------------------------------------------- QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() { QList<ShortcutListItem*> out; @@ -536,6 +555,7 @@ } // ============================================================================= +// Edit the shortcut of a given action. // ----------------------------------------------------------------------------- void ConfigDialog::slot_setShortcut() { QList<ShortcutListItem*> sel = getShortcutSelection(); @@ -550,6 +570,7 @@ } // ============================================================================= +// Reset a shortcut to defaults // ----------------------------------------------------------------------------- void ConfigDialog::slot_resetShortcut() { QList<ShortcutListItem*> sel = getShortcutSelection(); @@ -561,6 +582,7 @@ } // ============================================================================= +// Remove the shortcut of an action. // ----------------------------------------------------------------------------- void ConfigDialog::slot_clearShortcut() { QList<ShortcutListItem*> sel = getShortcutSelection(); @@ -572,6 +594,7 @@ } // ============================================================================= +// Set the path of an external program // ----------------------------------------------------------------------------- void ConfigDialog::slot_setExtProgPath() { const extProgInfo* info = null; @@ -593,6 +616,7 @@ } // ============================================================================= +// '...' button pressed for the download path // ----------------------------------------------------------------------------- void ConfigDialog::slot_findDownloadFolder() { str dpath = QFileDialog::getExistingDirectory(); @@ -600,6 +624,7 @@ } // ============================================================================= +// Updates the text string for a given shortcut list item // ----------------------------------------------------------------------------- void ConfigDialog::setShortcutText (ShortcutListItem* item) { QAction* act = item->action(); @@ -609,6 +634,7 @@ } // ============================================================================= +// Gets the configuration string of the quick color toolbar // ----------------------------------------------------------------------------- str ConfigDialog::quickColorString() { str val;
--- a/src/file.cpp Wed Aug 21 11:09:39 2013 +0300 +++ b/src/file.cpp Wed Aug 21 14:07:02 2013 +0300 @@ -14,14 +14,17 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * ===================================================================== + * + * file.cpp: File I/O and management. + * - File loading, parsing, manipulation, saving, closing. + * - LDraw path verification. */ #include <QMessageBox> #include <QFileDialog> #include <QDir> #include <QApplication> - -#include <stdlib.h> #include "common.h" #include "config.h" #include "file.h" @@ -149,7 +152,7 @@ // ----------------------------------------------------------------------------- LDFile* findLoadedFile (str name) { for (LDFile* file : g_loadedFiles) - if (file->name() == name) + if (!file->name().isEmpty() && file->getShortName() == name) return file; return null;