Sun, 18 Aug 2013 15:33:00 +0300
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
--- a/mkqrc.sh Sat Aug 17 11:48:27 2013 +0300 +++ b/mkqrc.sh Sun Aug 18 15:33:00 2013 +0300 @@ -4,7 +4,6 @@ FILES=$(echo ./icons/*.* data/*.* LICENSE LICENSE.icons) printf "" > $QRCFILE - printf "<!DOCTYPE RCC>\n<RCC version=\"1.0\">\n<qresource>\n" >> $QRCFILE for f in $FILES; do
--- a/src/aboutDialog.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/aboutDialog.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -19,10 +19,13 @@ #include <QDesktopServices> #include <QPushButton> #include <QUrl> +#include "build/moc_aboutDialog.cpp" #include "aboutDialog.h" #include "ui_about.h" #include "gui.h" +// ============================================================================= +// ----------------------------------------------------------------------------- AboutDialog::AboutDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { @@ -39,8 +42,8 @@ setWindowTitle ("About " APPNAME); } +// ============================================================================= +// ----------------------------------------------------------------------------- void AboutDialog::slot_mail() { QDesktopServices::openUrl (QUrl ("mailto:Santeri Piippo <arezey@gmail.com>?subject=LDForge")); -} - -#include "build/moc_aboutDialog.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/actions.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/actions.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,3 +1,21 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ + act (New) act (NewFile) act (Open)
--- a/src/addObjectDialog.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/addObjectDialog.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,30 +1,30 @@ /* * 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 <http://www.gnu.org/licenses/>. */ -#include <qgridlayout.h> -#include <qcheckbox.h> -#include <qdialogbuttonbox.h> -#include <qspinbox.h> -#include <qlabel.h> -#include <qlistwidget.h> -#include <qtreewidget.h> -#include <qlineedit.h> -#include <qpushbutton.h> +#include <QGridLayout> +#include <QCheckBox> +#include <QDialogButtonBox> +#include <QSpinBox> +#include <QLabel> +#include <QListWidget> +#include <QTreeWidget> +#include <QLineEdit> +#include <QPushButton> #include "gui.h" #include "addObjectDialog.h" #include "file.h" @@ -34,7 +34,10 @@ #include "widgets.h" #include "misc.h" #include "primitives.h" +#include "build/moc_addObjectDialog.cpp" +// ============================================================================= +// ----------------------------------------------------------------------------- class SubfileListItem : public QTreeWidgetItem { PROPERTY (Primitive*, primInfo, setPrimInfo) @@ -46,8 +49,7 @@ }; // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- AddObjectDialog::AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent) : QDialog (parent) { setlocale (LC_ALL, "C"); @@ -96,47 +98,45 @@ break; case LDObject::Subfile: - { - coordCount = 3; - - // If the primitive lister is busy writing data, we have to wait - // for that to happen first. This should be quite considerably rare. - while (primitiveLoaderBusy()) - ; - - tw_subfileList = new QTreeWidget(); - tw_subfileList->setHeaderLabel (tr ("Primitives")); + coordCount = 3; + + // If the primitive lister is busy writing data, we have to wait + // for that to happen first. This should be quite considerably rare. + while (primitiveLoaderBusy()) + ; + + tw_subfileList = new QTreeWidget(); + tw_subfileList->setHeaderLabel (tr ("Primitives")); + + for (PrimitiveCategory& cat : g_PrimitiveCategories) { + SubfileListItem* parentItem = new SubfileListItem (tw_subfileList, null); + parentItem->setText (0, cat.name()); + QList<QTreeWidgetItem*> subfileItems; - for (PrimitiveCategory& cat : g_PrimitiveCategories) { - SubfileListItem* parentItem = new SubfileListItem (tw_subfileList, null); - parentItem->setText (0, cat.name()); - QList<QTreeWidgetItem*> subfileItems; + for (Primitive& prim : cat.prims) { + SubfileListItem* item = new SubfileListItem (parentItem, &prim); + item->setText (0, fmt ("%1 - %2", prim.name, prim.title)); + subfileItems << item; - for (Primitive& prim : cat.prims) { - SubfileListItem* item = new SubfileListItem (parentItem, &prim); - item->setText (0, fmt ("%1 - %2", prim.name, prim.title)); - subfileItems << item; - - // If this primitive is the one the current object points to, - // select it by default - if (obj && static_cast<LDSubfileObject*> (obj)->fileInfo()->name() == prim.name) - tw_subfileList->setCurrentItem (item); - } - - tw_subfileList->addTopLevelItem (parentItem); + // If this primitive is the one the current object points to, + // select it by default + if (obj && static_cast<LDSubfileObject*> (obj)->fileInfo()->name() == prim.name) + tw_subfileList->setCurrentItem (item); } - connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged())); - lb_subfileName = new QLabel ("File:"); - le_subfileName = new QLineEdit; - le_subfileName->setFocus(); - - if (obj) { - LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); - le_subfileName->setText (ref->fileInfo()->name()); - } - break; + tw_subfileList->addTopLevelItem (parentItem); } + + connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged())); + lb_subfileName = new QLabel ("File:"); + le_subfileName = new QLineEdit; + le_subfileName->setFocus(); + + if (obj) { + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); + le_subfileName->setText (ref->fileInfo()->name()); + } + break; default: critical (fmt ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, typeName)); @@ -246,8 +246,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void AddObjectDialog::setButtonBackground (QPushButton* button, short colnum) { LDColor* col = getColor (colnum); @@ -259,8 +258,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- str AddObjectDialog::currentSubfileName() { SubfileListItem* item = static_cast<SubfileListItem*> (tw_subfileList->currentItem()); @@ -271,16 +269,14 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void AddObjectDialog::slot_colorButtonClicked() { ColorSelector::getColor (colnum, colnum, this); setButtonBackground (pb_color, colnum); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void AddObjectDialog::slot_subfileTypeChanged() { str name = currentSubfileName(); @@ -289,7 +285,8 @@ } // ============================================================================= -template<class T> T* initObj (LDObject*& obj) { +// ----------------------------------------------------------------------------- +template<class T> static T* initObj (LDObject*& obj) { if (obj == null) obj = new T; @@ -297,8 +294,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void AddObjectDialog::staticDialog (const LDObject::Type type, LDObject* obj) { setlocale (LC_ALL, "C"); @@ -408,6 +404,4 @@ } g_win->fullRefresh(); -} - -#include "build/moc_addObjectDialog.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/addObjectDialog.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/addObjectDialog.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/colorSelectDialog.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/colorSelectDialog.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -28,6 +28,7 @@ #include "config.h" #include "misc.h" #include "ui_colorsel.h" +#include "build/moc_colorSelectDialog.cpp" static const int g_numColumns = 16; static const short g_squareSize = 32; @@ -36,43 +37,39 @@ extern_cfg (float, gl_maincolor_alpha); // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- ColorSelector::ColorSelector (short defval, QWidget* parent) : QDialog (parent) { // Remove the default color if it's invalid if (!::getColor (defval)) defval = -1; - + m_firstResize = true; ui = new Ui_ColorSelUI; ui->setupUi (this); - + m_scene = new QGraphicsScene; ui->viewport->setScene (m_scene); setSelection (::getColor (defval)); - + // not really an icon but eh m_scene->setBackgroundBrush (getIcon ("checkerboard")); - drawScene(); - + int width = viewportWidth(); ui->viewport->setMinimumWidth (width); ui->viewport->setMaximumWidth (width); - + drawColorInfo(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- ColorSelector::~ColorSelector() { delete ui; } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ColorSelector::drawScene() { const int numCols = g_numColumns; const int square = g_squareSize; @@ -119,22 +116,19 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- int ColorSelector::numRows() const { return (MAX_COLORS / g_numColumns); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- int ColorSelector::viewportWidth() const { return g_numColumns * g_squareSize + 21; } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ColorSelector::drawColorInfo() { if (!sel()) { ui->colorLabel->setText ("---"); @@ -145,8 +139,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ColorSelector::resizeEvent (QResizeEvent* ev) { // If this is the first resize, check if we need to scroll down to see the // currently selected color. We cannot do this in the constructor because the @@ -167,8 +160,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ColorSelector::mousePressEvent (QMouseEvent* event) { QPointF scenepos = ui->viewport->mapToScene (event->pos()); @@ -187,8 +179,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- bool ColorSelector::getColor (short& val, short int defval, QWidget* parent) { ColorSelector dlg (defval, parent); @@ -198,6 +189,4 @@ } return false; -} - -#include "build/moc_colorSelectDialog.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/colors.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/colors.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -26,6 +26,8 @@ static LDColor* g_LDColors[MAX_COLORS]; +// ============================================================================= +// ----------------------------------------------------------------------------- void initColors() { LDColor* col; print ("%1: initializing color information.\n", __func__); @@ -65,7 +67,8 @@ } // ============================================================================= -uchar luma (QColor& col) { +// ----------------------------------------------------------------------------- +int luma (QColor& col) { return (0.2126f * col.red()) + (0.7152f * col.green()) + (0.0722f * col.blue());
--- a/src/colors.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/colors.h Sun Aug 18 15:33:00 2013 +0300 @@ -19,7 +19,7 @@ #ifndef COLORS_H #define COLORS_H -#include <qcolor.h> +#include <QColor> #include "common.h" #define MAX_COLORS 512 @@ -32,7 +32,7 @@ }; void initColors(); -uchar luma (QColor& col); +int luma (QColor& col); // Safely gets a color with the given number or null if no such color. LDColor* getColor (short colnum);
--- a/src/common.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/common.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */ @@ -56,17 +56,9 @@ #define RELEASE #endif // BUILD_ID -#ifndef RELEASE -# define devf(...) doDevf (__func__, __VA_ARGS__); -#else -# define devf(...) -#endif // RELEASE - #define alias auto& #define elif else if -void doDevf (const char* func, const char* fmtstr, ...); - // Null pointer static const std::nullptr_t null = nullptr;
--- a/src/config.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/config.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -30,6 +30,7 @@ static ushort g_cfgPointerCursor = 0; // ============================================================================= +// ----------------------------------------------------------------------------- static QSettings* getSettingsObject() { #ifdef PORTABLE # ifdef _WIN32 @@ -44,6 +45,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- // Load the configuration from file bool config::load() { QSettings* settings = getSettingsObject(); @@ -61,32 +63,42 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void intconfig::loadFromConfig (const QSettings* cfg) { QVariant val = cfg->value (name, str::number (defval)); value = val.toInt(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void floatconfig::loadFromConfig (const QSettings* cfg) { QVariant val = cfg->value (name, str::number (defval)); value = val.toFloat(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void strconfig::loadFromConfig (const QSettings* cfg) { QVariant val = cfg->value (name, defval); value = val.toString(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void boolconfig::loadFromConfig (const QSettings* cfg) { QVariant val = cfg->value (name, str::number (defval)); value = val.toBool(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void keyseqconfig::loadFromConfig (const QSettings* cfg) { QVariant val = cfg->value (name, defval.toString()); value = keyseq (val.toString()); } // ============================================================================= +// ----------------------------------------------------------------------------- // TODO: make virtual str config::toString() const { switch (getType()) { @@ -118,6 +130,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- // Save the configuration to disk bool config::save() { QSettings* settings = getSettingsObject(); @@ -136,6 +149,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void config::reset() { for (config* cfg : g_configPointers) { if (!cfg) @@ -146,17 +160,20 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- str config::filepath (str file) { return config::dirpath() + DIRSLASH + file; } // ============================================================================= +// ----------------------------------------------------------------------------- str config::dirpath() { QSettings* cfg = getSettingsObject(); return dirname (cfg->fileName()); } // ============================================================================= +// ----------------------------------------------------------------------------- str config::defaultString() const { str defstring = m_defstring; @@ -171,6 +188,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void addConfig (config* ptr) { if (g_cfgPointerCursor == 0) memset (g_configPointers, 0, sizeof g_configPointers);
--- a/src/configDialog.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/configDialog.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */ @@ -35,6 +35,7 @@ #include "colorSelectDialog.h" #include "gldraw.h" #include "ui_config.h" +#include "build/moc_configDialog.cpp" extern_cfg (str, gl_bgcolor); extern_cfg (str, gl_maincolor); @@ -74,8 +75,7 @@ #include "actions.h" // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- ConfigDialog::ConfigDialog (ForgeWindow* parent) : QDialog (parent) { ui = new Ui_ConfigUI; ui->setupUi (this); @@ -93,15 +93,13 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- ConfigDialog::~ConfigDialog() { delete ui; } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::initMainTab() { // Init color stuff setButtonBackground (ui->backgroundColorButton, gl_bgcolor); @@ -125,8 +123,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::initShortcutsTab() { ulong i = 0; @@ -157,8 +154,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::initQuickColorTab() { quickColors = quickColorsFromConfig(); updateQuickColorList(); @@ -173,8 +169,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::initGridTab() { QGridLayout* gridlayout = new QGridLayout; QLabel* xlabel = new QLabel ("X"), @@ -213,8 +208,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static const struct extProgInfo { const str name, iconname; strconfig* const path; @@ -239,6 +233,8 @@ #undef EXTPROG }; +// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::initExtProgTab() { QGridLayout* pathsLayout = new QGridLayout; ulong row = 0; @@ -276,8 +272,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::updateQuickColorList (LDQuickColor* sel) { for (QListWidgetItem* item : quickColorItems) delete item; @@ -314,8 +309,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::slot_setColor() { LDQuickColor* entry = null; QListWidgetItem* item = null; @@ -361,8 +355,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::slot_delColor() { if (ui->quickColorList->selectedItems().size() == 0) return; @@ -373,6 +366,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::slot_moveColor() { const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp); @@ -394,20 +388,21 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::slot_addColorSeparator() { quickColors << LDQuickColor ({null, null, true}); updateQuickColorList (&quickColors[quickColors.size() - 1]); } // ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::slot_clearColors() { quickColors.clear(); updateQuickColorList(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::pickColor (strconfig& conf, QPushButton* button) { QColor col = QColorDialog::getColor (QColor (conf)); @@ -420,17 +415,20 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::slot_setGLBackground() { pickColor (gl_bgcolor, ui->backgroundColorButton); } +// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::slot_setGLForeground() { pickColor (gl_maincolor, ui->mainColorButton); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::setButtonBackground (QPushButton* button, str value) { button->setIcon (getIcon ("colorselect")); button->setAutoFillBackground (true); @@ -438,6 +436,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- int ConfigDialog::getItemRow (QListWidgetItem* item, List<QListWidgetItem*>& haystack) { int i = 0; @@ -451,6 +450,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- QListWidgetItem* ConfigDialog::getSelectedQuickColor() { if (ui->quickColorList->selectedItems().size() == 0) return null; @@ -459,8 +459,8 @@ } // ============================================================================= -QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() -{ +// ----------------------------------------------------------------------------- +QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() { QList<ShortcutListItem*> out; for (QListWidgetItem* entry : ui->shortcutsList->selectedItems()) @@ -470,8 +470,8 @@ } // ============================================================================= -void ConfigDialog::slot_setShortcut() -{ +// ----------------------------------------------------------------------------- +void ConfigDialog::slot_setShortcut() { QList<ShortcutListItem*> sel = getShortcutSelection(); if (sel.size() < 1) @@ -485,8 +485,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void ConfigDialog::slot_resetShortcut() -{ +void ConfigDialog::slot_resetShortcut() { QList<ShortcutListItem*> sel = getShortcutSelection(); for (ShortcutListItem* item : sel) { @@ -544,8 +543,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- str ConfigDialog::quickColorString() { str val; @@ -562,17 +560,20 @@ return val; } +// ============================================================================= +// ----------------------------------------------------------------------------- const Ui_ConfigUI* ConfigDialog::getUI() const { return ui; } +// ============================================================================= +// ----------------------------------------------------------------------------- float ConfigDialog::getGridValue (int i, int j) const { return dsb_gridData[i][j]->value(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ConfigDialog::staticDialog() { ConfigDialog dlg (g_win); @@ -648,8 +649,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- bool KeySequenceDialog::staticDialog (keyseqconfig* cfg, QWidget* parent) { KeySequenceDialog dlg (cfg->value, parent); @@ -661,8 +661,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void KeySequenceDialog::updateOutput() { str shortcut = seq.toString(); @@ -674,11 +673,8 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void KeySequenceDialog::keyPressEvent (QKeyEvent* ev) { seq = ev->key() + ev->modifiers(); updateOutput(); -} - -#include "build/moc_configDialog.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/dialogs.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/dialogs.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -45,6 +45,7 @@ extern_cfg (str, io_ldpath); // ============================================================================= +// ----------------------------------------------------------------------------- OverlayDialog::OverlayDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { ui = new Ui_OverlayUI; ui->setupUi (this); @@ -72,10 +73,14 @@ fillDefaults (cam); } +// ============================================================================= +// ----------------------------------------------------------------------------- OverlayDialog::~OverlayDialog() { delete ui; } +// ============================================================================= +// ----------------------------------------------------------------------------- void OverlayDialog::fillDefaults (int newcam) { overlayMeta& info = g_win->R()->getOverlay (newcam); radioDefault<int> (newcam, m_cameraArgs); @@ -95,6 +100,8 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- str OverlayDialog::fpath() const { return ui->filename->text(); } @@ -132,11 +139,12 @@ ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (enable); } -// ================================================================================================= +// ============================================================================= +// ----------------------------------------------------------------------------- LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f), - m_validDefault (validDefault) { - + m_validDefault (validDefault) +{ ui = new Ui_LDPathUI; ui->setupUi (this); ui->status->setText ("---"); @@ -161,6 +169,8 @@ slot_tryConfigure(); } +// ============================================================================= +// ----------------------------------------------------------------------------- LDrawPathDialog::~LDrawPathDialog() { delete ui; } @@ -181,6 +191,8 @@ return ui->path->text(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDrawPathDialog::slot_findPath() { str newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path"); @@ -190,29 +202,34 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDrawPathDialog::slot_exit() { exit (1); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDrawPathDialog::slot_tryConfigure() { if (LDPaths::tryConfigure (filename()) == false) { ui->status->setText (fmt ("<span style=\"color:#700; \">%1</span>", LDPaths::getError())); okButton()->setEnabled (false); return; } - + ui->status->setText ("<span style=\"color: #270; \">OK!</span>"); okButton()->setEnabled (true); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDrawPathDialog::slot_accept() { config::save(); accept(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- OpenProgressDialog::OpenProgressDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { ui = new Ui_OpenProgressUI; ui->setupUi (this); @@ -222,30 +239,42 @@ m_progress = 0; } +// ============================================================================= +// ----------------------------------------------------------------------------- OpenProgressDialog::~OpenProgressDialog() { delete ui; } +// ============================================================================= +// ----------------------------------------------------------------------------- READ_ACCESSOR (ulong, OpenProgressDialog::numLines) { return m_numLines; } +// ============================================================================= +// ----------------------------------------------------------------------------- SET_ACCESSOR (ulong, OpenProgressDialog::setNumLines) { m_numLines = val; ui->progressBar->setRange (0, numLines()); updateValues(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void OpenProgressDialog::updateValues() { ui->progressText->setText (fmt ("Parsing... %1 / %2", progress(), numLines())); ui->progressBar->setValue (progress()); } +// ============================================================================= +// ----------------------------------------------------------------------------- void OpenProgressDialog::updateProgress (int progress) { m_progress = progress; updateValues(); } +// ============================================================================= +// ----------------------------------------------------------------------------- ExtProgPathPrompt::ExtProgPathPrompt (str progName, QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f), ui (new Ui_ExtProgPath) @@ -259,10 +288,14 @@ connect (ui->m_findPath, SIGNAL (clicked (bool)), this, SLOT (findPath())); } +// ============================================================================= +// ----------------------------------------------------------------------------- ExtProgPathPrompt::~ExtProgPathPrompt() { delete ui; } +// ============================================================================= +// ----------------------------------------------------------------------------- void ExtProgPathPrompt::findPath() { str path = QFileDialog::getOpenFileName (null, "", "", g_extProgPathFilter); @@ -270,6 +303,8 @@ ui->m_path->setText (path); } +// ============================================================================= +// ----------------------------------------------------------------------------- str ExtProgPathPrompt::getPath() const { return ui->m_path->text(); } \ No newline at end of file
--- a/src/docs.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/docs.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */ @@ -23,6 +23,8 @@ #include "common.h" #include "types.h" +// ============================================================================= +// ----------------------------------------------------------------------------- class DocumentViewer : public QDialog { public: explicit DocumentViewer (QWidget* parent = null, Qt::WindowFlags f = 0) : QDialog (parent, f) { @@ -61,6 +63,8 @@ "<p>Finally, use the \"Set Overlay Image\" dialog and fill in the details. The " "overlay image should then be ready for use."; +// ============================================================================= +// ----------------------------------------------------------------------------- void showDocumentation (const char* text) { DocumentViewer dlg; dlg.setText (text);
--- a/src/docs.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/docs.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/download.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/download.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/download.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/download.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/extprogs.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/extprogs.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -50,6 +50,7 @@ }; // ============================================================================= +// ----------------------------------------------------------------------------- cfg (str, prog_isecalc, ""); cfg (str, prog_intersector, ""); cfg (str, prog_coverer, ""); @@ -94,6 +95,7 @@ }; // ============================================================================= +// ----------------------------------------------------------------------------- static bool checkProgPath (const extprog prog) { alias path = g_extProgPaths[prog]->value; @@ -110,6 +112,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- static str processErrorString (QProcess& proc) { switch (proc.error()) { case QProcess::FailedToStart: @@ -133,6 +136,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- static bool mkTempFile (QTemporaryFile& tmp, str& fname) { if (!tmp.open()) return false; @@ -143,6 +147,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void writeObjects (List<LDObject*>& objects, File& f) { for (LDObject* obj : objects) { if (obj->getType() == LDObject::Subfile) { @@ -157,6 +162,8 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- void writeObjects (List<LDObject*>& objects, str fname) { // Write the input file File f (fname, File::Write); @@ -171,11 +178,13 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void writeSelection (str fname) { writeObjects (g_win->sel(), fname); } // ============================================================================= +// ----------------------------------------------------------------------------- void writeColorGroup (const short colnum, str fname) { List<LDObject*> objects; @@ -190,6 +199,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- bool runUtilityProcess (extprog prog, str path, str argvstr) { QTemporaryFile input, output; str inputname, outputname; @@ -244,7 +254,8 @@ return true; } -// ================================================================================================ +// ============================================================================= +// ----------------------------------------------------------------------------- static void insertOutput (str fname, bool replace, List<short> colorsToReplace) { #ifndef RELEASE QFile::copy (fname, "./debug_lastOutput"); @@ -284,9 +295,8 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= // Interface for Ytruder +// ----------------------------------------------------------------------------- DEFINE_ACTION (Ytruder, 0) { setlocale (LC_ALL, "C"); @@ -340,9 +350,8 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= // Rectifier interface +// ----------------------------------------------------------------------------- DEFINE_ACTION (Rectifier, 0){ setlocale (LC_ALL, "C"); @@ -390,9 +399,8 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= // Intersector interface +// ----------------------------------------------------------------------------- DEFINE_ACTION (Intersector, 0) { setlocale (LC_ALL, "C"); @@ -483,8 +491,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Coverer, 0) { setlocale (LC_ALL, "C"); @@ -539,8 +546,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Isecalc, 0) { setlocale (LC_ALL, "C"); @@ -591,8 +597,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Edger2, 0) { setlocale (LC_ALL, "C");
--- a/src/file.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/file.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -30,6 +30,7 @@ #include "history.h" #include "dialogs.h" #include "gldraw.h" +#include "build/moc_file.cpp" cfg (str, io_ldpath, ""); cfg (str, io_recentfiles, ""); @@ -44,6 +45,7 @@ DEFINE_PROPERTY (QListWidgetItem*, LDFile, listItem, setListItem) // ============================================================================= +// ----------------------------------------------------------------------------- namespace LDPaths { static str pathError; @@ -94,6 +96,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- LDFile::LDFile() { setImplicit (true); setSavePos (-1); @@ -102,6 +105,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- LDFile::~LDFile() { // Clear everything from the model for (LDObject* obj : m_objs) @@ -133,6 +137,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- LDFile* findLoadedFile (str name) { for (LDFile* file : g_loadedFiles) if (file->name() == name) @@ -142,6 +147,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- str dirname (str path) { long lastpos = path.lastIndexOf (DIRSLASH); @@ -157,6 +163,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- str basename (str path) { long lastpos = path.lastIndexOf (DIRSLASH); @@ -167,6 +174,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- File* openLDrawFile (str relpath, bool subdirs) { print ("%1: Try to open %2\n", __func__, relpath); File* f = new File; @@ -213,8 +221,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void FileLoader::start() { setDone (false); setProgress (0); @@ -241,6 +248,8 @@ work (0); } +// ============================================================================= +// ----------------------------------------------------------------------------- void FileLoader::work (int i) { if (aborted()) { // We were flagged for abortion, so abort. @@ -294,6 +303,8 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- void FileLoader::abort() { setAborted (true); @@ -302,8 +313,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- List<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) { List<str> lines; List<LDObject*> objs; @@ -335,8 +345,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- LDFile* openDATFile (str path, bool search) { // Convert the file name to lowercase since some parts contain uppercase // file names. I'll assume here that the library will always use lowercase @@ -383,8 +392,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- bool LDFile::safeToClose() { typedef QMessageBox msgbox; setlocale (LC_ALL, "C"); @@ -433,8 +441,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void closeAll() { // Remove all loaded files and the objects they contain List<LDFile*> files = g_loadedFiles; @@ -443,8 +450,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void newFile() { // Create a new anonymous file and set it to our current LDFile* f = new LDFile; @@ -462,8 +468,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void addRecentFile (str path) { QStringList rfiles = io_recentfiles.value.split ('@'); int idx = rfiles.indexOf (path); @@ -492,9 +497,8 @@ } // ============================================================================= +// Open an LDraw file and set it as the main model // ----------------------------------------------------------------------------- -// Open an LDraw file and set it as the main model -// ============================================================================= void openMainFile (str path) { g_loadingMainFile = true; LDFile* file = openDATFile (path, false); @@ -530,8 +534,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- bool LDFile::save (str savepath) { if (!savepath.length()) savepath = name(); @@ -581,8 +584,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- #define CHECK_TOKEN_COUNT(N) \ if (tokens.size() != N) \ return new LDErrorObject (line, "Bad amount of tokens"); @@ -592,6 +594,8 @@ if (!isNumber (tokens[i])) \ return new LDErrorObject (line, fmt ("Token #%1 was `%2`, expected a number", (i + 1), tokens[i])); +// ============================================================================= +// ----------------------------------------------------------------------------- static vertex parseVertex (QStringList& s, const ushort n) { vertex v; @@ -602,11 +606,10 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- // This is the LDraw code parser function. It takes in a string containing LDraw // code and returns the object parsed from it. parseLine never returns null, // the object will be LDError if it could not be parsed properly. -// ============================================================================= +// ----------------------------------------------------------------------------- LDObject* parseLine (str line) { QStringList tokens = line.split (" ", str::SkipEmptyParts); @@ -775,8 +778,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- LDFile* getFile (str filename) { // Try find the file in the list of loaded files LDFile* load = findLoadedFile (filename); @@ -789,8 +791,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void reloadAllSubfiles() { if (!LDFile::current()) return; @@ -821,8 +822,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- ulong LDFile::addObject (LDObject* obj) { m_history.add (new AddHistory (m_objs.size(), obj)); m_objs << obj; @@ -835,8 +835,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDFile::insertObj (const ulong pos, LDObject* obj) { m_history.add (new AddHistory (pos, obj)); m_objs.insert (pos, obj); @@ -844,8 +843,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDFile::forgetObject (LDObject* obj) { ulong idx = obj->getIndex(); m_history.add (new DelHistory (idx, obj)); @@ -854,6 +852,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- bool safeToCloseAll() { for (LDFile* f : g_loadedFiles) if (!f->safeToClose()) @@ -863,6 +862,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void LDFile::setObject (ulong idx, LDObject* obj) { assert (idx < numObjs()); @@ -875,6 +875,8 @@ m_objs[idx] = obj; } +// ============================================================================= +// ----------------------------------------------------------------------------- static List<LDFile*> getFilesUsed (LDFile* node) { List<LDFile*> filesUsed; @@ -892,6 +894,7 @@ // ============================================================================= // Find out which files are unused and close them. +// ----------------------------------------------------------------------------- void LDFile::closeUnused() { List<LDFile*> filesUsed = getFilesUsed (LDFile::current()); @@ -922,6 +925,8 @@ g_loadedFiles << filesUsed; } +// ============================================================================= +// ----------------------------------------------------------------------------- LDObject* LDFile::object (ulong pos) const { if (m_objs.size() <= pos) return null; @@ -929,14 +934,20 @@ return m_objs[pos]; } +// ============================================================================= +// ----------------------------------------------------------------------------- LDObject* LDFile::obj (ulong pos) const { return object (pos); } +// ============================================================================= +// ----------------------------------------------------------------------------- ulong LDFile::numObjs() const { return m_objs.size(); } +// ============================================================================= +// ----------------------------------------------------------------------------- LDFile& LDFile::operator<< (List<LDObject*> objs) { for (LDObject* obj : objs) addObject (obj); @@ -944,10 +955,14 @@ return *this; } +// ============================================================================= +// ----------------------------------------------------------------------------- bool LDFile::hasUnsavedChanges() const { return !implicit() && history().pos() != savePos(); } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDFile::getShortName() { if (name().length() > 0) return basename (name()); @@ -956,19 +971,20 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- LDFile* LDFile::current() { return m_curfile; } // ============================================================================= -/* Sets the given file as the current one on display. At some point in time this - * was an operation completely unheard of. ;) - * - * FIXME: f can be temporarily null. This probably should not be the case. - */ +// Sets the given file as the current one on display. At some point in time this +// was an operation completely unheard of. ;) +// +// FIXME: f can be temporarily null. This probably should not be the case. +// ----------------------------------------------------------------------------- void LDFile::setCurrent (LDFile* f) { - /* Implicit files were loaded for caching purposes and must never be set - * current. */ + // Implicit files were loaded for caching purposes and must never be set + // current. if (f && f->implicit()) return; @@ -989,6 +1005,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- int LDFile::countExplicitFiles() { int count = 0; @@ -1002,12 +1019,12 @@ // ============================================================================= // This little beauty closes the initial file that was open at first when opening // a new file over it. +// ----------------------------------------------------------------------------- void LDFile::closeInitialFile() { - if (countExplicitFiles() == 2 && + if ( + countExplicitFiles() == 2 && g_loadedFiles[0]->name() == "" && - !g_loadedFiles[0]->hasUnsavedChanges()) { + !g_loadedFiles[0]->hasUnsavedChanges() + ) delete g_loadedFiles[0]; - } -} - -#include "build/moc_file.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/gldraw.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/gldraw.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */ @@ -21,7 +21,7 @@ #include <QMouseEvent> #include <QContextMenuEvent> #include <QInputDialog> -#include <qtooltip.h> +#include <QToolTip> #include <QTimer> #include <GL/glu.h> @@ -36,6 +36,7 @@ #include "dialogs.h" #include "addObjectDialog.h" #include "messagelog.h" +#include "build/moc_gldraw.cpp" static const struct staticCameraMeta { const char glrotate[3]; @@ -89,10 +90,12 @@ { QColor (80, 192, 0), vertex (0, 10000, 0) }, { QColor (0, 160, 192), vertex (0, 0, 10000) }, }; - + +static bool g_glInvert = false; +static List<short> g_warnedColors; + // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) { m_picking = m_rangepick = false; m_camera = (GL::Camera) gl_camera.value; @@ -131,6 +134,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- GLRenderer::~GLRenderer() { for (int i = 0; i < 6; ++i) delete m_overlays[i].img; @@ -140,8 +144,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::calcCameraIcons() { ushort i = 0; @@ -157,6 +160,8 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::initGLData() { glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -172,6 +177,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::resetAngles() { m_rotX = 30.0f; m_rotY = 325.f; @@ -180,8 +186,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::initializeGL() { setBackground(); @@ -194,8 +199,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- QColor GLRenderer::getMainColor() { QColor col (gl_maincolor); @@ -206,6 +210,7 @@ return col; } +// ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::setBackground() { QColor col (gl_bgcolor); @@ -221,9 +226,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -static List<short> g_warnedColors; +// ----------------------------------------------------------------------------- void GLRenderer::setObjectColor (LDObject* obj, const ListType list) { QColor qcol; @@ -313,14 +316,14 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::refresh() { update(); swapBuffers(); } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::hardRefresh() { compileAllObjects(); refresh(); @@ -329,8 +332,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::resizeGL (int w, int h) { m_width = w; m_height = h; @@ -344,6 +346,8 @@ glMatrixMode (GL_MODELVIEW); } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::drawGLScene() { if (file() == null) return; @@ -418,9 +422,10 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- // This converts a 2D point on the screen to a 3D point in the model. If 'snap' // is true, the 3D point will snap to the current grid. -// ============================================================================= +// ----------------------------------------------------------------------------- vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const { assert (camera() != Free); @@ -452,9 +457,10 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- // Inverse operation for the above - convert a 3D position to a 2D screen // position -// ============================================================================= +// ----------------------------------------------------------------------------- QPoint GLRenderer::coordconv3_2 (const vertex& pos3d) const { GLfloat m[16]; const staticCameraMeta* cam = &g_staticCameras[m_camera]; @@ -481,8 +487,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::paintEvent (QPaintEvent* ev) { Q_UNUSED (ev) @@ -634,7 +639,7 @@ const int margin = 2; QColor penColor = getTextPen(); - for (const MessageManager::Line& line : *msglog()) { + for (const MessageManager::Line& line : msglog()->getLines()) { penColor.setAlphaF (line.alpha); paint.setPen (penColor); paint.drawText (QPoint (margin, y + margin + metrics.ascent()), line.text); @@ -698,10 +703,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -static bool g_glInvert = false; - +// ----------------------------------------------------------------------------- void GLRenderer::compileSubObject (LDObject* obj, const GLenum gltype) { glBegin (gltype); @@ -718,8 +720,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::compileList (LDObject* obj, const GLRenderer::ListType list) { setObjectColor (obj, list); @@ -777,15 +778,13 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::compileVertex (const vertex& vrt) { glVertex3d (vrt[X], -vrt[Y], -vrt[Z]); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::clampAngle (double& angle) const { while (angle < 0) angle += 360.0; @@ -793,6 +792,8 @@ angle -= 360.0; } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::addDrawnVertex (vertex pos) { // If we picked an already-existing vertex, stop drawing for (vertex& vert : m_drawedVerts) { @@ -806,8 +807,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) { const bool wasLeft = (m_lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton), wasRight = (m_lastButtons & Qt::RightButton) && !(ev->buttons() & Qt::RightButton), @@ -916,8 +916,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::mousePressEvent (QMouseEvent* ev) { m_totalmove = 0; @@ -974,17 +973,19 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::keyPressEvent (QKeyEvent* ev) { m_keymods = ev->modifiers(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::keyReleaseEvent (QKeyEvent* ev) { m_keymods = ev->modifiers(); } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::wheelEvent (QWheelEvent* ev) { makeCurrent(); @@ -996,6 +997,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::leaveEvent (QEvent* ev) { (void) ev; m_drawToolTip = false; @@ -1004,11 +1006,13 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::contextMenuEvent (QContextMenuEvent* ev) { g_win->spawnContextMenu (ev->globalPos()); } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::setCamera (const GL::Camera cam) { m_camera = cam; gl_camera = (int) cam; @@ -1016,8 +1020,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::pick (uint mouseX, uint mouseY) { GLint viewport[4]; makeCurrent(); @@ -1149,10 +1152,13 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- READ_ACCESSOR (EditMode, GLRenderer::editMode) { return m_editMode; } +// ============================================================================= +// ----------------------------------------------------------------------------- SET_ACCESSOR (EditMode, GLRenderer::setEditMode) { m_editMode = val; @@ -1187,10 +1193,14 @@ update(); } +// ============================================================================= +// ----------------------------------------------------------------------------- READ_ACCESSOR (LDFile*, GLRenderer::file) { return m_file; } +// ============================================================================= +// ----------------------------------------------------------------------------- SET_ACCESSOR (LDFile*, GLRenderer::setFile) { m_file = val; @@ -1199,6 +1209,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::endDraw (bool accept) { (void) accept; @@ -1257,6 +1268,8 @@ m_rectdraw = false; } +// ============================================================================= +// ----------------------------------------------------------------------------- static List<vertex> getVertices (LDObject* obj) { List<vertex> verts; @@ -1276,8 +1289,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::compileObject (LDObject* obj) { deleteLists (obj); @@ -1303,6 +1315,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- uchar* GLRenderer::screencap (ushort& w, ushort& h) { w = m_width; h = m_height; @@ -1319,6 +1332,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::slot_toolTipTimer() { // We come here if the cursor has stayed in one place for longer than a // a second. Check if we're holding it over a camera icon - if so, draw @@ -1334,6 +1348,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::deleteLists (LDObject* obj) { // Delete the lists but only if they have been initialized if (!obj->m_glinit) @@ -1346,6 +1361,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- Axis GLRenderer::cameraAxis (bool y, GL::Camera camid) { if (camid == (GL::Camera) -1) camid = m_camera; @@ -1355,6 +1371,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- bool GLRenderer::setupOverlay (GL::Camera cam, str file, int x, int y, int w, int h) { QImage* img = new QImage (file); overlayMeta& info = getOverlay (cam); @@ -1381,27 +1398,29 @@ const Axis x2d = cameraAxis (false, cam), y2d = cameraAxis (true, cam); - + double negXFac = g_staticCameras[cam].negX ? -1 : 1, negYFac = g_staticCameras[cam].negY ? -1 : 1; - + info.v0 = info.v1 = g_origin; info.v0[x2d] = - (info.ox * info.lw * negXFac) / img->width(); info.v0[y2d] = (info.oy * info.lh * negYFac) / img->height(); info.v1[x2d] = info.v0[x2d] + info.lw; info.v1[y2d] = info.v0[y2d] + info.lh; - + // Set alpha of all pixels to 0.5 for (long i = 0; i < img->width(); ++i) for (long j = 0; j < img->height(); ++j) { uint32 pixel = img->pixel (i, j); img->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF)); } - + updateOverlayObjects(); return true; } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::clearOverlay() { if (camera() == Free) return; @@ -1413,24 +1432,34 @@ updateOverlayObjects(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::setDepthValue (double depth) { assert (camera() < Free); m_depthValues[camera()] = depth; } +// ============================================================================= +// ----------------------------------------------------------------------------- double GLRenderer::depthValue() const { assert (camera() < Free); return m_depthValues[camera()]; } +// ============================================================================= +// ----------------------------------------------------------------------------- const char* GLRenderer::cameraName() const { return g_CameraNames[camera()]; } +// ============================================================================= +// ----------------------------------------------------------------------------- overlayMeta& GLRenderer::getOverlay (int newcam) { return m_overlays[newcam]; } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::zoomNotch (bool inward) { if (zoom() > 15) setZoom (zoom() * (inward ? 0.833f : 1.2f)); @@ -1439,6 +1468,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::zoomToFit() { if (file() == null) { setZoom (30.0f); @@ -1517,6 +1547,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::updateRectVerts() { if (!m_rectdraw) return; @@ -1548,6 +1579,8 @@ m_rectverts[3][ay] = v1[ay]; } +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev) { if (!(ev->buttons() & Qt::LeftButton) || editMode() != Select) return; @@ -1564,6 +1597,8 @@ ev->accept(); } +// ============================================================================= +// ----------------------------------------------------------------------------- LDOverlayObject* GLRenderer::findOverlayObject (GLRenderer::Camera cam) { LDOverlayObject* ovlobj = null; @@ -1580,7 +1615,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- // Read in overlays from the current file and update overlay info accordingly. -// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::overlaysFromObjects() { for (Camera cam : g_Cameras) { if (cam == Free) @@ -1598,6 +1633,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::updateOverlayObjects() { for (Camera cam : g_Cameras) { if (cam == Free) @@ -1667,6 +1703,4 @@ if (g_win->R() == this) g_win->refresh(); -} - -#include "build/moc_gldraw.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/gldraw.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/gldraw.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/gui.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/gui.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */ @@ -70,8 +70,7 @@ }; // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- ForgeWindow::ForgeWindow() { g_win = this; m_renderer = new GLRenderer; @@ -125,12 +124,16 @@ #include "actions.h" } +// ============================================================================= +// ----------------------------------------------------------------------------- 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" } +// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::invokeAction (QAction* act, void (*func)()) { beginAction (act); (*func)(); @@ -138,14 +141,14 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::slot_lastSecondCleanup() { delete m_renderer; delete ui; } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::updateRecentFilesMenu() { QStringList files = io_recentfiles.value.split ("@", QString::SkipEmptyParts); QStringListIterator it (files); @@ -167,8 +170,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- List<LDQuickColor> quickColorsFromConfig() { List<LDQuickColor> colors; @@ -186,8 +188,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::updateToolBars() { m_colorButtons.clear(); ui->colorToolbar->clear(); @@ -213,8 +214,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::updateGridToolBar() { // Ensure that the current grid - and only the current grid - is selected. ui->actionGridCoarse->setChecked (grid == Grid::Coarse); @@ -223,8 +223,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::updateTitle() { str title = fmt (APPNAME " %1", fullVersionString()); @@ -251,10 +250,8 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -int ForgeWindow::deleteSelection() -{ +// ----------------------------------------------------------------------------- +int ForgeWindow::deleteSelection() { if (m_sel.size() == 0) return 0; @@ -273,8 +270,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::buildObjList() { if (!LDFile::current()) return; @@ -341,7 +337,7 @@ case LDObject::BFC: descr = LDBFCObject::statements[static_cast<LDBFCObject*> (obj)->type]; - break; + break; case LDObject::Overlay: { @@ -357,9 +353,8 @@ } // Put it into brackets if it's hidden - if (obj->hidden()) { + if (obj->hidden()) descr = fmt ("[[ %1 ]]", descr); - } QListWidgetItem* item = new QListWidgetItem (descr); item->setIcon (getIcon (obj->typeName())); @@ -388,8 +383,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::scrollToSelection() { if (m_sel.size() == 0) return; @@ -399,8 +393,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::slot_selectionChanged() { if (g_bSelectionLocked == true || LDFile::current() == null) return; @@ -440,14 +433,14 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::slot_recentFile() { QAction* qAct = static_cast<QAction*> (sender()); openMainFile (qAct->text()); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::slot_quickColor() { beginAction (null); QToolButton* button = static_cast<QToolButton*> (sender()); @@ -478,8 +471,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- ulong ForgeWindow::getInsertionPoint() { if (m_sel.size() > 0) { // If we have a selection, put the item after it. @@ -491,8 +483,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::fullRefresh() { buildObjList(); m_renderer->hardRefresh(); @@ -504,8 +495,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::updateSelection() { g_bSelectionLocked = true; @@ -526,8 +516,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- bool ForgeWindow::isSelected (LDObject* obj) { LDObject* needle = obj->topLevelParent(); @@ -556,8 +545,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- LDObject::Type ForgeWindow::uniformSelectedType() { LDObject::Type result = LDObject::Unidentified; @@ -573,8 +561,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::closeEvent (QCloseEvent* ev) { // Check whether it's safe to close all files. if (!safeToCloseAll()) { @@ -590,8 +577,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::spawnContextMenu (const QPoint pos) { const bool single = (g_win->sel().size() == 1); LDObject* singleObj = (single) ? g_win->sel()[0] : null; @@ -628,6 +614,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::deleteObjVector (List<LDObject*> objs) { for (LDObject* obj : objs) { LDFile::current()->forgetObject (obj); @@ -636,6 +623,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::deleteByColor (const short colnum) { List<LDObject*> objs; for (LDObject* obj : LDFile::current()->objs()) { @@ -649,12 +637,15 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::updateEditModeActions() { const EditMode mode = R()->editMode(); ACTION (ModeSelect)->setChecked (mode == Select); ACTION (ModeDraw)->setChecked (mode == Draw); } +// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::slot_editObject (QListWidgetItem* listitem) { LDObject* obj = null; for (LDObject* it : *LDFile::current()) { @@ -667,6 +658,8 @@ AddObjectDialog::staticDialog (obj->getType(), obj); } +// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::primitiveLoaderStart (ulong max) { m_primLoaderWidget->show(); m_primLoaderBar->setRange (0, max); @@ -674,10 +667,14 @@ m_primLoaderBar->setFormat ("%p%"); } +// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::primitiveLoaderUpdate (ulong prog) { m_primLoaderBar->setValue (prog); } +// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::primitiveLoaderEnd() { QTimer* hidetimer = new QTimer; connect (hidetimer, SIGNAL (timeout()), m_primLoaderWidget, SLOT (hide())); @@ -688,8 +685,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void ForgeWindow::save (LDFile* f, bool saveAs) { str path = f->name(); @@ -742,8 +738,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- QPixmap getIcon (str iconName) { return (QPixmap (fmt (":/icons/%1.png", iconName))); } @@ -832,12 +827,12 @@ ui->fileList->clear(); for (LDFile* f : g_loadedFiles) { - /* Don't list implicit files unless explicitly desired. */ + // Don't list implicit files unless explicitly desired. if (f->implicit() && !gui_implicitfiles) continue; - /* Add an item to the list for this file and store a pointer to it in - * the file, so we can find files by the list item. */ + // Add an item to the list for this file and store a pointer to it in + // the file, so we can find files by the list item. ui->fileList->addItem (""); QListWidgetItem* item = ui->fileList->item (ui->fileList->count() - 1); f->setListItem (item); @@ -848,25 +843,25 @@ void ForgeWindow::updateFileListItem (LDFile* f) { if (f->listItem() == null) { - /* We don't have a list item for this file, so the list either doesn't - * exist yet or is out of date. Build the list now. */ + // We don't have a list item for this file, so the list either doesn't + // exist yet or is out of date. Build the list now. updateFileList(); return; } - /* If this is the current file, it also needs to be the selected item on - * the list. */ + // If this is the current file, it also needs to be the selected item on + // the list. if (f == LDFile::current()) ui->fileList->setCurrentItem (f->listItem()); - /* If we list implicit files, draw them with a shade of gray to make them - * distinct. */ + // If we list implicit files, draw them with a shade of gray to make them + // distinct. if (f->implicit()) f->listItem()->setForeground (QColor (96, 96, 96)); f->listItem()->setText (f->getShortName()); - /* If the file has unsaved changes, draw a little icon next to it to mark that. */ + // If the file has unsaved changes, draw a little icon next to it to mark that. f->listItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); } @@ -880,20 +875,19 @@ // Close the history now. LDFile::current()->closeHistory(); - /* Update the list item of the current file - we may need to draw an icon - * now that marks it as having unsaved changes. */ + // Update the list item of the current file - we may need to draw an icon + // now that marks it as having unsaved changes. updateFileListItem (LDFile::current()); } // ============================================================================= -/* 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. - */ +// 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. void ForgeWindow::changeCurrentFile() { LDFile* f = null; QListWidgetItem* item = ui->fileList->currentItem(); - /* Find the file pointer of the item that was selected. */ + // Find the file pointer of the item that was selected. for (LDFile* it : g_loadedFiles) { if (it->listItem() == item) { f = it; @@ -901,8 +895,8 @@ } } - /* If we picked the same file we're currently on, we don't need to do - * anything. */ + // If we picked the same file we're currently on, we don't need to do + // anything. if (!f || f == LDFile::current()) return;
--- a/src/gui.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/gui.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/gui_actions.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/gui_actions.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */ @@ -41,8 +41,7 @@ extern_cfg (bool, gl_colorbfc); // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (New, CTRL_SHIFT (N)) { QDialog* dlg = new QDialog (g_win); Ui::NewPartUI ui; @@ -78,15 +77,13 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewFile, CTRL (N)) { newFile(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Open, CTRL (O)) { str name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)"); @@ -97,22 +94,19 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Save, CTRL (S)) { g_win->save (LDFile::current(), false); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) { g_win->save (LDFile::current(), true); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SaveAll, CTRL (L)) { for (LDFile* file : g_loadedFiles) { if (file->implicit()) @@ -123,8 +117,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Close, CTRL (W)) { if (!LDFile::current()->safeToClose()) return; @@ -133,8 +126,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (CloseAll, 0) { if (!safeToCloseAll()) return; @@ -143,63 +135,80 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Settings, 0) { ConfigDialog::staticDialog(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SetLDrawPath, 0) { LDrawPathDialog dlg (true); dlg.exec(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Exit, CTRL (Q)) { exit (0); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewSubfile, 0) { AddObjectDialog::staticDialog (LDObject::Subfile, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewLine, 0) { AddObjectDialog::staticDialog (LDObject::Line, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewTriangle, 0) { AddObjectDialog::staticDialog (LDObject::Triangle, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewQuad, 0) { AddObjectDialog::staticDialog (LDObject::Quad, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewCLine, 0) { AddObjectDialog::staticDialog (LDObject::CondLine, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewComment, 0) { AddObjectDialog::staticDialog (LDObject::Comment, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewBFC, 0) { AddObjectDialog::staticDialog (LDObject::BFC, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (NewVertex, 0) { AddObjectDialog::staticDialog (LDObject::Vertex, null); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (MakePrimitive, 0) { generatePrimitive(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Edit, 0) { if (g_win->sel().size() != 1) return; @@ -208,24 +217,26 @@ AddObjectDialog::staticDialog (obj->getType(), obj); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Help, KEY (F1)) { } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (About, 0) { AboutDialog().exec(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (AboutQt, 0) { QMessageBox::aboutQt (g_win); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SelectAll, CTRL (A)) { g_win->sel().clear(); @@ -236,6 +247,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) { short colnum = g_win->getSelectedColor(); @@ -251,6 +263,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SelectByType, 0) { if (g_win->sel().size() == 0) return; @@ -287,8 +300,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (GridCoarse, 0) { grid = Grid::Coarse; g_win->updateGridToolBar(); @@ -305,16 +317,14 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (ResetView, CTRL (0)) { g_win->R()->resetAngles(); g_win->R()->update(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (InsertFrom, 0) { str fname = QFileDialog::getOpenFileName(); ulong idx = g_win->getInsertionPoint(); @@ -345,8 +355,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (ExportTo, 0) { if (g_win->sel().size() == 0) return; @@ -370,8 +379,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (InsertRaw, 0) { ulong idx = g_win->getInsertionPoint(); @@ -405,6 +413,8 @@ g_win->scrollToSelection(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Screenshot, 0) { setlocale (LC_ALL, "C"); @@ -427,6 +437,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- extern_cfg (bool, gl_axes); DEFINE_ACTION (Axes, 0) { gl_axes = !gl_axes; @@ -435,6 +446,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Visibility, 0) { for (LDObject* obj : g_win->sel()) obj->setHidden (!obj->hidden()); @@ -442,13 +454,16 @@ g_win->refresh(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Wireframe, 0) { gl_wireframe = !gl_wireframe; g_win->R()->refresh(); } -DEFINE_ACTION (SetOverlay, 0) -{ +// ============================================================================= +// ----------------------------------------------------------------------------- +DEFINE_ACTION (SetOverlay, 0) { OverlayDialog dlg; if (!dlg.exec()) @@ -458,18 +473,26 @@ dlg.ofsy(), dlg.lwidth(), dlg.lheight() ); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (ClearOverlay, 0) { g_win->R()->clearOverlay(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (ModeSelect, CTRL (1)) { g_win->R()->setEditMode (Select); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (ModeDraw, CTRL (2)) { g_win->R()->setEditMode (Draw); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SetDrawDepth, 0) { if (g_win->R()->camera() == GL::Free) return; @@ -527,10 +550,14 @@ } #endif +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (ScanPrimitives, 0) { PrimitiveLister::start(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (BFCView, SHIFT (B)) { gl_colorbfc = !gl_colorbfc; ACTION (BFCView)->setChecked (gl_colorbfc);
--- a/src/gui_editactions.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/gui_editactions.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -38,8 +38,7 @@ cfg (bool, edit_schemanticinline, false); // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static int copyToClipboard() { List<LDObject*> objs = g_win->sel(); int num = 0; @@ -63,8 +62,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Cut, CTRL (X)) { int num = copyToClipboard(); g_win->deleteSelection(); @@ -72,16 +70,14 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Copy, CTRL (C)) { int num = copyToClipboard(); log (ForgeWindow::tr ("%1 objects copied"), num); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Paste, CTRL (V)) { const str clipboardText = qApp->clipboard()->text(); ulong idx = g_win->getInsertionPoint(); @@ -102,16 +98,14 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Delete, KEY (Delete)) { int num = g_win->deleteSelection(); log (ForgeWindow::tr ("%1 objects deleted"), num); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static void doInline (bool deep) { List<LDObject*> sel = g_win->sel(); @@ -157,9 +151,8 @@ doInline (true); } -// =============================================================================================== -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// =============================================================================================== +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SplitQuads, 0) { List<LDObject*> objs = g_win->sel(); int num = 0; @@ -195,8 +188,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (EditRaw, KEY (F9)) { if (g_win->sel().size() != 1) return; @@ -230,8 +222,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SetColor, KEY (C)) { if (g_win->sel().size() <= 0) return; @@ -260,8 +251,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Borders, CTRL_SHIFT (B)) { List<LDObject*> objs = g_win->sel(); int num = 0; @@ -306,8 +296,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (CornerVerts, 0) { int num = 0; @@ -333,14 +322,15 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static void doMoveSelection (const bool up) { List<LDObject*> objs = g_win->sel(); LDObject::moveObjects (objs, up); g_win->buildObjList(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (MoveUp, KEY (PageUp)) { doMoveSelection (true); } @@ -350,8 +340,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Undo, CTRL (Z)) { LDFile::current()->undo(); } @@ -361,8 +350,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void doMoveObjects (vertex vect) { // Apply the grid values vect[X] *= currentGrid().confs[Grid::X]->value; @@ -377,8 +365,10 @@ g_win->refresh(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (MoveXNeg, KEY (Left)) { - doMoveObjects ({ -1, 0, 0}); + doMoveObjects ({-1, 0, 0}); } DEFINE_ACTION (MoveYNeg, KEY (Home)) { @@ -402,6 +392,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Invert, CTRL_SHIFT (W)) { List<LDObject*> sel = g_win->sel(); @@ -414,12 +405,15 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- static void rotateVertex (vertex& v, const vertex& rotpoint, const matrix& transform) { v.move (-rotpoint); v.transform (transform, g_origin); v.move (rotpoint); } +// ============================================================================= +// ----------------------------------------------------------------------------- static void doRotate (const short l, const short m, const short n) { List<LDObject*> sel = g_win->sel(); List<vertex*> queue; @@ -471,6 +465,8 @@ g_win->refresh(); } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (RotateXPos, CTRL (Right)) { doRotate (1, 0, 0); } DEFINE_ACTION (RotateYPos, CTRL (End)) { doRotate (0, 1, 0); } DEFINE_ACTION (RotateZPos, CTRL (Up)) { doRotate (0, 0, 1); } @@ -483,8 +479,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (RoundCoordinates, 0) { setlocale (LC_ALL, "C"); int num = 0; @@ -510,8 +505,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Uncolorize, 0) { int num = 0; @@ -534,6 +528,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (ReplaceCoords, CTRL (R)) { QDialog* dlg = new QDialog (g_win); Ui::ReplaceCoordsUI ui; @@ -578,7 +573,8 @@ g_win->refresh(); } -// ================================================================================================ +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Flip, CTRL_SHIFT (F)) { QDialog* dlg = new QDialog; Ui::FlipUI ui; @@ -606,7 +602,8 @@ g_win->refresh(); } -// ================================================================================================ +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Demote, 0) { List<LDObject*> sel = g_win->sel(); int num = 0; @@ -624,7 +621,8 @@ g_win->refresh(); } -// ================================================================================================= +// ============================================================================= +// ----------------------------------------------------------------------------- static bool isColorUsed (short colnum) { for (LDObject* obj : LDFile::current()->objs()) if (obj->isColored() && obj->color() == colnum) @@ -633,6 +631,8 @@ return false; } +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (Autocolor, 0) { short colnum = 0;
--- a/src/history.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/history.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -25,10 +25,14 @@ bool g_fullRefresh = false; +// ============================================================================= +// ----------------------------------------------------------------------------- History::History() : m_pos (-1), m_opened (false) {} +// ============================================================================= +// ----------------------------------------------------------------------------- void History::undo() { if (m_changesets.size() == 0 || pos() == -1) return; @@ -50,6 +54,8 @@ updateActions(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void History::redo() { if (pos() == (long) m_changesets.size()) return; @@ -71,6 +77,8 @@ updateActions(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void History::clear() { for (List<AbstractHistoryEntry*> set : m_changesets) for (AbstractHistoryEntry * change : set) @@ -79,11 +87,15 @@ m_changesets.clear(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void History::updateActions() const { ACTION (Undo)->setEnabled (pos() != -1); ACTION (Redo)->setEnabled (pos() < (long) m_changesets.size() - 1); } +// ============================================================================= +// ----------------------------------------------------------------------------- void History::open() { if (opened()) return; @@ -91,6 +103,8 @@ setOpened (true); } +// ============================================================================= +// ----------------------------------------------------------------------------- void History::close() { if (!opened()) return; @@ -109,6 +123,8 @@ updateActions(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void History::add (AbstractHistoryEntry* entry) { if (!opened()) { delete entry; @@ -120,6 +136,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void AddHistory::undo() const { LDFile* f = parent()->file(); LDObject* obj = f->object (index()); @@ -129,6 +146,8 @@ g_fullRefresh = true; } +// ============================================================================= +// ----------------------------------------------------------------------------- void AddHistory::redo() const { LDFile* f = parent()->file(); LDObject* obj = parseLine (code()); @@ -140,6 +159,7 @@ // ============================================================================= // heh +// ----------------------------------------------------------------------------- void DelHistory::undo() const { LDFile* f = parent()->file(); LDObject* obj = parseLine (code()); @@ -147,6 +167,8 @@ g_win->R()->compileObject (obj); } +// ============================================================================= +// ----------------------------------------------------------------------------- void DelHistory::redo() const { LDFile* f = parent()->file(); LDObject* obj = f->object (index()); @@ -159,6 +181,7 @@ DelHistory::~DelHistory() {} // ============================================================================= +// ----------------------------------------------------------------------------- void EditHistory::undo() const { LDObject* obj = LDFile::current()->object (index()); LDObject* newobj = parseLine (oldCode()); @@ -166,6 +189,8 @@ g_win->R()->compileObject (newobj); } +// ============================================================================= +// ----------------------------------------------------------------------------- void EditHistory::redo() const { LDObject* obj = LDFile::current()->object (index()); LDObject* newobj = parseLine (newCode()); @@ -176,6 +201,7 @@ EditHistory::~EditHistory() {} // ============================================================================= +// ----------------------------------------------------------------------------- void SwapHistory::undo() const { LDObject::fromID (a)->swap (LDObject::fromID (b)); }
--- a/src/history.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/history.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/labeledwidget.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/labeledwidget.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/ldconfig.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/ldconfig.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -24,6 +24,7 @@ // ============================================================================= // Helper function for parseLDConfig +// ----------------------------------------------------------------------------- static bool parseLDConfigTag (LDConfigParser& pars, char const* tag, str& val) { short pos; @@ -36,6 +37,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void parseLDConfig() { File* f = openLDrawFile ("LDConfig.ldr", false); @@ -110,23 +112,25 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- LDConfigParser::LDConfigParser (str inText, char sep) { m_tokens = container_cast<QStringList, List<str>> (inText.split (sep, QString::SkipEmptyParts)); m_pos = -1; } +// ============================================================================= // ----------------------------------------------------------------------------- bool LDConfigParser::atBeginning() { return (m_pos == -1); } +// ============================================================================= // ----------------------------------------------------------------------------- bool LDConfigParser::atEnd() { return (m_pos == (signed) m_tokens.size() - 1); } +// ============================================================================= // ----------------------------------------------------------------------------- bool LDConfigParser::getToken (str& val, const ushort pos) { if (pos >= m_tokens.size()) @@ -136,16 +140,19 @@ return true; } +// ============================================================================= // ----------------------------------------------------------------------------- bool LDConfigParser::next (str& val) { return getToken (val, ++m_pos); } +// ============================================================================= // ----------------------------------------------------------------------------- bool LDConfigParser::peekNext (str& val) { return getToken (val, m_pos + 1); } +// ============================================================================= // ----------------------------------------------------------------------------- bool LDConfigParser::findToken (short& result, char const* needle, short args) { for (ushort i = 0; i < (m_tokens.size() - args); ++i) { @@ -158,21 +165,25 @@ return false; } +// ============================================================================= // ----------------------------------------------------------------------------- void LDConfigParser::rewind() { m_pos = -1; } +// ============================================================================= // ----------------------------------------------------------------------------- void LDConfigParser::seek (short amount, bool rel) { m_pos = (rel ? m_pos : 0) + amount; } +// ============================================================================= // ----------------------------------------------------------------------------- size_t LDConfigParser::size() { return m_tokens.size(); } +// ============================================================================= // ----------------------------------------------------------------------------- bool LDConfigParser::tokenCompare (short inPos, const char* sOther) { str tok;
--- a/src/ldtypes.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/ldtypes.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -29,17 +29,16 @@ List<LDObject*> g_LDObjects; // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= // LDObject constructors +// ----------------------------------------------------------------------------- LDObject::LDObject() : m_hidden (false), m_selected (false), m_parent (null), m_file (null), qObjListEntry (null), - m_glinit (false) { - + m_glinit (false) +{ // Determine ID int32 id = 1; // 0 is invalid @@ -51,9 +50,11 @@ g_LDObjects << this; } +// ============================================================================= // Default implementations for LDObject's virtual methods. These should never be // actually called, for a subclass-less LDObject should never come into existance. // These exist only to satisfy the linker. +// ----------------------------------------------------------------------------- LDObject::Type LDObject::getType() const { return LDObject::Unidentified; } @@ -79,6 +80,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void LDObject::setVertexCoord (int i, Axis ax, double value) { vertex v = getVertex (i); v[ax] = value; @@ -88,10 +90,13 @@ LDErrorObject::LDErrorObject() {} // ============================================================================= +// ----------------------------------------------------------------------------- str LDCommentObject::raw() { return fmt ("0 %1", text); } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDSubfileObject::raw() { str val = fmt ("1 %1 %2 ", color(), position()); val += transform().stringRep(); @@ -100,6 +105,8 @@ return val; } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDLineObject::raw() { str val = fmt ("2 %1", color()); @@ -109,6 +116,8 @@ return val; } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDTriangleObject::raw() { str val = fmt ("3 %1", color()); @@ -118,6 +127,8 @@ return val; } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDQuadObject::raw() { str val = fmt ("4 %1", color()); @@ -127,6 +138,8 @@ return val; } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDCondLineObject::raw() { str val = fmt ("5 %1", color()); @@ -137,21 +150,26 @@ return val; } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDErrorObject::raw() { return contents; } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDVertexObject::raw() { return fmt ("0 !LDFORGE VERTEX %1 %2", color(), pos); } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDEmptyObject::raw() { return ""; } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- const char* LDBFCObject::statements[] = { "CERTIFY CCW", "CCW", @@ -170,8 +188,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- List<LDTriangleObject*> LDQuadObject::splitToTriangles() { // Create the two triangles based on this quadrilateral: // 0---3 0---3 3 @@ -193,8 +210,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDObject::replace (LDObject* other) { long idx = getIndex(); assert (idx != -1); @@ -207,8 +223,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDObject::swap (LDObject* other) { for (LDObject*& obj : *file()) { if (obj == this) @@ -220,11 +235,15 @@ file()->addToHistory (new SwapHistory (id(), other->id())); } +// ============================================================================= +// ----------------------------------------------------------------------------- LDLineObject::LDLineObject (vertex v1, vertex v2) { setVertex (0, v1); setVertex (1, v2); } +// ============================================================================= +// ----------------------------------------------------------------------------- LDObject::~LDObject() { // Remove this object from the selection array if it is there. for (ulong i = 0; i < g_win->sel().size(); ++i) @@ -242,8 +261,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static void transformObject (LDObject* obj, matrix transform, vertex pos, short parentcolor) { switch (obj->getType()) { case LDObject::Line: @@ -279,8 +297,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- List<LDObject*> LDSubfileObject::inlineContents (bool deep, bool cache) { List<LDObject*> objs, objcache; @@ -335,8 +352,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- long LDObject::getIndex() const { #ifndef RELEASE assert (file() != null); @@ -350,8 +366,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDObject::moveObjects (List<LDObject*> objs, const bool up) { if (objs.size() == 0) return; @@ -391,6 +406,8 @@ g_win->R()->compileObject (obj); } +// ============================================================================= +// ----------------------------------------------------------------------------- str LDObject::typeName (LDObject::Type type) { LDObject* obj = LDObject::getDefault (type); str name = obj->typeName(); @@ -399,8 +416,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- str LDObject::objectListContents (const List<LDObject*>& objs) { bool firstDetails = true; str text = ""; @@ -436,6 +452,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- LDObject* LDObject::topLevelParent() { if (!parent()) return this; @@ -449,6 +466,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- LDObject* LDObject::next() const { long idx = getIndex(); assert (idx != -1); @@ -460,6 +478,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- LDObject* LDObject::prev() const { long idx = getIndex(); assert (idx != -1); @@ -471,45 +490,55 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDObject::move (vertex vect) { (void) vect; } void LDEmptyObject::move (vertex vect) { (void) vect; } void LDBFCObject::move (vertex vect) { (void) vect; } void LDCommentObject::move (vertex vect) { (void) vect; } void LDErrorObject::move (vertex vect) { (void) vect; } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDVertexObject::move (vertex vect) { pos += vect; } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDSubfileObject::move (vertex vect) { setPosition (position() + vect); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDLineObject::move (vertex vect) { for (short i = 0; i < 2; ++i) setVertex (i, getVertex (i) + vect); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDTriangleObject::move (vertex vect) { for (short i = 0; i < 3; ++i) setVertex (i, getVertex (i) + vect); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDQuadObject::move (vertex vect) { for (short i = 0; i < 4; ++i) setVertex (i, getVertex (i) + vect); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDCondLineObject::move (vertex vect) { for (short i = 0; i < 4; ++i) setVertex (i, getVertex (i) + vect); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- #define CHECK_FOR_OBJ(N) \ if (type == LDObject::N) \ return new LD##N##Object; @@ -531,14 +560,15 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDObject::invert() {} void LDBFCObject::invert() {} void LDEmptyObject::invert() {} void LDCommentObject::invert() {} void LDErrorObject::invert() {} +// ============================================================================= +// ----------------------------------------------------------------------------- void LDTriangleObject::invert() { // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. // Thus, we swap 1 and 2. @@ -549,6 +579,8 @@ return; } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDQuadObject::invert() { // Quad: 0 -> 1 -> 2 -> 3 // rev: 0 -> 3 -> 2 -> 1 @@ -558,6 +590,8 @@ setVertex (3, tmp); } +// ============================================================================= +// ----------------------------------------------------------------------------- void LDSubfileObject::invert() { // Subfiles are inverted when they're prefixed with // a BFC INVERTNEXT statement. Thus we need to toggle this status. @@ -583,6 +617,8 @@ file()->insertObj (idx, bfc); } +// ============================================================================= +// ----------------------------------------------------------------------------- static void invertLine (LDObject* line) { // For lines, we swap the vertices. I don't think that a // cond-line's control points need to be swapped, do they? @@ -602,6 +638,7 @@ void LDVertexObject::invert() {} // ============================================================================= +// ----------------------------------------------------------------------------- LDLineObject* LDCondLineObject::demote() { LDLineObject* repl = new LDLineObject; @@ -614,6 +651,8 @@ return repl; } +// ============================================================================= +// ----------------------------------------------------------------------------- LDObject* LDObject::fromID (int id) { for (LDObject* obj : g_LDObjects) if (obj->id() == id) @@ -623,6 +662,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- str LDOverlayObject::raw() { return fmt ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6", filename(), camera(), x(), y(), width(), height()); @@ -638,6 +678,7 @@ // Hook the set accessors of certain properties to this changeProperty function. // It takes care of history management so we can capture low-level changes, this // makes history stuff work out of the box. +// ----------------------------------------------------------------------------- template<class T> void changeProperty (LDObject* obj, T* ptr, const T& val) { if (obj->file()) { long idx = obj->getIndex(); @@ -650,6 +691,8 @@ *ptr = val; } +// ============================================================================= +// ----------------------------------------------------------------------------- READ_ACCESSOR (short, LDObject::color) { return m_color; } @@ -658,6 +701,8 @@ changeProperty (this, &m_color, val); } +// ============================================================================= +// ----------------------------------------------------------------------------- const vertex& LDObject::getVertex (int i) const { return m_coords[i]; } @@ -666,6 +711,8 @@ changeProperty (this, &m_coords[i], vert); } +// ============================================================================= +// ----------------------------------------------------------------------------- READ_ACCESSOR (vertex, LDMatrixObject::position) { return m_position; } @@ -674,6 +721,8 @@ changeProperty (linkPointer(), &m_position, val); } +// ============================================================================= +// ----------------------------------------------------------------------------- READ_ACCESSOR (matrix, LDMatrixObject::transform) { return m_transform; }
--- a/src/main.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/main.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */ @@ -19,7 +19,7 @@ #include <QApplication> #include <QMessageBox> #include <QAbstractButton> -#include <qfile.h> +#include <QFile> #include <QTextStream> #include "gui.h" #include "file.h" @@ -39,24 +39,8 @@ 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}); -void doPrint (File& f, initlist<StringFormatArg> args) { - str msg = DoFormat (args); - f.write (msg.toUtf8()); - f.flush(); -} - -void doPrint (FILE* fp, initlist<StringFormatArg> args) { - if (fp == stdout) - doPrint (g_file_stdout, args); - elif (fp == stderr) - doPrint (g_file_stderr, args); - else - fatal ("unknown FILE* argument"); -} - // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- int main (int argc, char* argv[]) { QApplication app (argc, argv); app.setOrganizationName (APPNAME); @@ -76,7 +60,7 @@ LDPaths::initPaths(); initColors(); - + ForgeWindow* win = new ForgeWindow; newFile(); @@ -86,16 +70,27 @@ return app.exec(); } -void doDevf (const char* func, const char* fmtstr, ...) { - va_list va; - - printf ("%s: ", func); - - va_start (va, fmtstr); - vprintf (fmtstr, va); - va_end (va); +// ============================================================================= +// ----------------------------------------------------------------------------- +void doPrint (File& f, initlist<StringFormatArg> args) { + str msg = DoFormat (args); + f.write (msg.toUtf8()); + f.flush(); } +// ============================================================================= +// ----------------------------------------------------------------------------- +void doPrint (FILE* fp, initlist<StringFormatArg> args) { + if (fp == stdout) + doPrint (g_file_stdout, args); + elif (fp == stderr) + doPrint (g_file_stderr, args); + else + fatal ("unknown FILE* argument"); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- str versionString() { if (g_versionString.length() == 0) { #if VERSION_PATCH == 0 @@ -108,6 +103,8 @@ return g_versionString; } +// ============================================================================= +// ----------------------------------------------------------------------------- str versionMoniker() { #if BUILD_ID == BUILD_INTERNAL return "Internal"; @@ -122,10 +119,14 @@ #endif // BUILD_ID } +// ============================================================================= +// ----------------------------------------------------------------------------- str fullVersionString() { return fmt ("v%1 %2", versionString(), versionMoniker()); } +// ============================================================================= +// ----------------------------------------------------------------------------- static void bombBox (str msg) { msg.replace ("\n", "<br />"); @@ -141,6 +142,8 @@ box.exec(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) { str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", file, line, funcname, expr); @@ -162,6 +165,8 @@ #endif } +// ============================================================================= +// ----------------------------------------------------------------------------- void fatalError (const char* file, const ulong line, const char* funcname, str msg) { str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4", file, line, funcname, msg);
--- a/src/messagelog.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/messagelog.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,26 +1,27 @@ /* * 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 <http://www.gnu.org/licenses/>. */ +#include <QTimer> +#include <QDate> #include "messagelog.h" #include "gldraw.h" #include "gui.h" -#include <QTimer> -#include <QDate> +#include "build/moc_messagelog.cpp" static const unsigned int g_maxMessages = 5; static const int g_expiry = 5; @@ -46,6 +47,7 @@ // Check this line's expiry and update alpha accordingly. Returns true if the // line is to still stick around, false if it expired. 'changed' is updated to // whether the line has somehow changed since the last update. +// ----------------------------------------------------------------------------- bool MessageManager::Line::update (bool& changed) { changed = false; QDateTime now = QDateTime::currentDateTime(); @@ -67,8 +69,8 @@ } // ============================================================================= +// Add a line to the message manager. // ----------------------------------------------------------------------------- -// Add a line to the message manager. void MessageManager::addLine (str line) { // If there's too many entries, pop the excess out while (m_lines.size() >= g_maxMessages) @@ -82,17 +84,9 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- -// Shortcut -MessageManager& MessageManager::operator<< (str line) { - addLine (line); - return *this; -} - -// ============================================================================= -// ----------------------------------------------------------------------------- // Ticks the message manager. All lines are ticked and the renderer scene is // redrawn if something changed. +// ----------------------------------------------------------------------------- void MessageManager::tick() { if (m_lines.size() == 0) return; @@ -114,27 +108,18 @@ // ============================================================================= // ----------------------------------------------------------------------------- -// C++11-for loop support -MessageManager::c_it MessageManager::begin() const { - return m_lines.begin(); +const List<MessageManager::Line>& MessageManager::getLines() const { + return m_lines; } // ============================================================================= -// ----------------------------------------------------------------------------- -MessageManager::c_it MessageManager::end() const { - return m_lines.end(); -} - -// ============================================================================= -// ----------------------------------------------------------------------------- // log() interface - format the argument list and add the resulting string to // the main message manager. +// ----------------------------------------------------------------------------- void DoLog (std::initializer_list<StringFormatArg> args) { const str msg = DoFormat (args); g_win->addMessage (msg); // Also print it to stdout print ("%1\n", msg); -} - -#include "build/moc_messagelog.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/messagelog.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/messagelog.h Sun Aug 18 15:33:00 2013 +0300 @@ -53,15 +53,9 @@ QDateTime expiry; }; - typedef List<Line>::it it; - typedef List<Line>::c_it c_it; - explicit MessageManager (QObject* parent = 0); void addLine (str line); - c_it begin() const; - c_it end() const; - - MessageManager& operator<< (str line); + const List<Line>& getLines() const; private: List<Line> m_lines;
--- a/src/misc.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/misc.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,24 +1,24 @@ /* * 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 <http://www.gnu.org/licenses/>. */ #include <math.h> #include <locale.h> -#include <qcolor.h> +#include <QColor> #include "common.h" #include "misc.h" #include "gui.h" @@ -80,8 +80,7 @@ }; // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- // Grid stuff cfg (int, grid, Grid::Medium); @@ -110,6 +109,7 @@ // ============================================================================= // Snap the given coordinate value on the current grid's given axis. +// ----------------------------------------------------------------------------- double Grid::snap (double in, const Grid::Config axis) { const double gridval = currentGrid().confs[axis]->value; const long mult = abs (in / gridval); @@ -126,9 +126,9 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= // Float to string. Removes trailing zeroes and is locale-independant. +// TODO: Replace with QString::number() +// ----------------------------------------------------------------------------- str ftoa (double num) { // Disable the locale first so that the decimal point will not // turn into anything weird (like commas) @@ -150,8 +150,8 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// TODO: I guess Qt must have something like this stashed somewhere? +// ----------------------------------------------------------------------------- bool isNumber (const str& tok) { bool gotDot = false; @@ -180,8 +180,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void simplify (short& numer, short& denom) { bool repeat; @@ -205,6 +204,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- vertex rotPoint (const List<LDObject*>& objs) { LDBoundingBox box; @@ -229,6 +229,8 @@ return vertex(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void configRotationPoint() { QDialog* dlg = new QDialog; Ui::RotPointUI ui; @@ -265,6 +267,8 @@ edit_rotpoint_z = ui.customZ->value(); } +// ============================================================================= +// ----------------------------------------------------------------------------- str join (initlist<StringFormatArg> vals, str delim) { QStringList list; for (const StringFormatArg& arg : vals) @@ -273,6 +277,9 @@ return list.join (delim); } +// ============================================================================= +// TODO: I'm quite sure Qt has this covered as well. +// ----------------------------------------------------------------------------- double atof (str val) { // Disable the locale while parsing the line or atof's behavior changes // between locales (i.e. fails to read decimals properly). That is
--- a/src/misc.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/misc.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/primitives.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/primitives.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -32,14 +32,22 @@ static bool g_primListerMutex = false; List<Primitive> g_primitives; -static const str g_Other = QObject::tr ("Other"); +static const str g_Other = PrimitiveLister::tr ("Other"); + +static const str g_radialNameRoots[] = { + "edge", + "cyli", + "disc", + "ndis", + "ring", + "con" +}; static void populateCategories(); static void loadPrimitiveCatgories(); // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void loadPrimitives() { print ("Loading primitives...\n"); loadPrimitiveCatgories(); @@ -69,8 +77,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static void recursiveGetFilenames (QDir dir, List<str>& fnames) { QFileInfoList flist = dir.entryInfoList(); @@ -86,8 +93,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void PrimitiveLister::work() { g_activePrimLister = this; m_prims.clear(); @@ -140,8 +146,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void PrimitiveLister::start() { if (g_activePrimLister) return; @@ -157,6 +162,8 @@ listerThread->start(); } +// ============================================================================= +// ----------------------------------------------------------------------------- static PrimitiveCategory* findCategory (str name) { for (PrimitiveCategory& cat : g_PrimitiveCategories) if (cat.name() == name) @@ -166,8 +173,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static void populateCategories() { for (PrimitiveCategory& cat : g_PrimitiveCategories) cat.prims.clear(); @@ -222,8 +228,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static void loadPrimitiveCatgories() { g_PrimitiveCategories.clear(); File f (config::dirpath() + "primregexps.cfg", File::Read); @@ -278,20 +283,19 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- bool primitiveLoaderBusy() { return g_primListerMutex; } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static double radialPoint (int i, int divs, double (*func) (double)) { return (*func) ((i * 2 * pi) / divs); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- List<LDObject*> makePrimitive (PrimitiveType type, int segs, int divs, int num) { List<LDObject*> objs; List<int> condLineSegs; @@ -436,8 +440,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- static str primitiveTypeName (PrimitiveType type) { // Not translated as primitives are in English. return type == Circle ? "Circle" : @@ -447,18 +450,8 @@ type == Ring ? "Ring" : "Cone"; } -static const str g_radialNameRoots[] = { - "edge", - "cyli", - "disc", - "ndis", - "ring", - "con" -}; - // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- str radialFileName (PrimitiveType type, int segs, int divs, int num) { short numer = segs, denom = divs; @@ -489,8 +482,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void generatePrimitive() { PrimitivePrompt* dlg = new PrimitivePrompt (g_win); @@ -546,6 +538,8 @@ delete f; } +// ============================================================================= +// ----------------------------------------------------------------------------- PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { @@ -554,10 +548,14 @@ connect (ui->cb_hires, SIGNAL (toggled(bool)), this, SLOT (hiResToggled (bool))); } +// ============================================================================= +// ----------------------------------------------------------------------------- PrimitivePrompt::~PrimitivePrompt() { delete ui; } +// ============================================================================= +// ----------------------------------------------------------------------------- void PrimitivePrompt::hiResToggled (bool on) { ui->sb_segs->setMaximum (on ? hires : lores);
--- a/src/primitives.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/primitives.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/types.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/types.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -27,6 +27,8 @@ #include "ldtypes.h" #include "file.h" +// ============================================================================= +// ----------------------------------------------------------------------------- str DoFormat (List<StringFormatArg> args) { assert (args.size() >= 1); str text = args[0].value(); @@ -37,6 +39,8 @@ return text; } +// ============================================================================= +// ----------------------------------------------------------------------------- vertex::vertex (double x, double y, double z) { m_coords[X] = x; m_coords[Y] = y; @@ -44,12 +48,14 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void vertex::move (const vertex& other) { for (const Axis ax : g_Axes) m_coords[ax] += other[ax]; } // ============================================================================= +// ----------------------------------------------------------------------------- vertex vertex::midpoint (const vertex& other) { vertex mid; @@ -60,6 +66,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- str vertex::stringRep (bool mangled) const { str fmtstr = "%1 %2 %3"; if (mangled) @@ -69,6 +76,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void vertex::transform (matrix matr, vertex pos) { double x2 = (matr[0] * x()) + (matr[1] * y()) + (matr[2] * z()) + pos[X]; double y2 = (matr[3] * x()) + (matr[4] * y()) + (matr[5] * z()) + pos[Y]; @@ -79,14 +87,20 @@ z() = z2; } +// ============================================================================= +// ----------------------------------------------------------------------------- vertex vertex::operator-() const { return vertex (-m_coords[X], -m_coords[Y], -m_coords[Z]); } +// ============================================================================= +// ----------------------------------------------------------------------------- bool vertex::operator!= (const vertex& other) const { return !operator== (other); } +// ============================================================================= +// ----------------------------------------------------------------------------- double& vertex::operator[] (const Axis ax) { return coord ((ushort) ax); } @@ -103,12 +117,16 @@ return coord (ax); } +// ============================================================================= +// ----------------------------------------------------------------------------- bool vertex::operator== (const vertex& other) const { return coord (X) == other[X] && coord (Y) == other[Y] && coord (Z) == other[Z]; } +// ============================================================================= +// ----------------------------------------------------------------------------- vertex& vertex::operator/= (const double d) { for (const Axis ax : g_Axes) m_coords[ax] /= d; @@ -116,22 +134,30 @@ return *this; } +// ============================================================================= +// ----------------------------------------------------------------------------- vertex vertex::operator/ (const double d) const { vertex other (*this); return other /= d; } +// ============================================================================= +// ----------------------------------------------------------------------------- vertex& vertex::operator+= (const vertex& other) { move (other); return *this; } +// ============================================================================= +// ----------------------------------------------------------------------------- vertex vertex::operator+ (const vertex& other) const { vertex newvert (*this); newvert.move (other); return newvert; } +// ============================================================================= +// ----------------------------------------------------------------------------- int vertex::operator< (const vertex& other) const { if (operator== (other)) return false; @@ -152,21 +178,28 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- matrix::matrix (double vals[]) { for (short i = 0; i < 9; ++i) m_vals[i] = vals[i]; } +// ============================================================================= +// ----------------------------------------------------------------------------- matrix::matrix (double fillval) { for (short i = 0; i < 9; ++i) m_vals[i] = fillval; } +// ============================================================================= +// ----------------------------------------------------------------------------- matrix::matrix (initlist<double> vals) { assert (vals.size() == 9); memcpy (&m_vals[0], & (*vals.begin()), sizeof m_vals); } +// ============================================================================= +// ----------------------------------------------------------------------------- void matrix::puts() const { for (short i = 0; i < 3; ++i) { for (short j = 0; j < 3; ++j) @@ -177,6 +210,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- str matrix::stringRep() const { str val; @@ -191,11 +225,13 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- void matrix::zero() { memset (&m_vals[0], 0, sizeof (double) * 9); } // ============================================================================= +// ----------------------------------------------------------------------------- matrix matrix::mult (matrix other) const { matrix val; val.zero(); @@ -209,12 +245,14 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- matrix& matrix::operator= (matrix other) { memcpy (&m_vals[0], &other.m_vals[0], sizeof (double) * 9); return *this; } // ============================================================================= +// ----------------------------------------------------------------------------- double matrix::determinant() const { return (val (0) * val (4) * val (8)) + (val (1) * val (5) * val (6)) + @@ -225,6 +263,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- StringFormatArg::StringFormatArg (const str& v) { m_val = v; } @@ -278,6 +317,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- File::File() { // Make a null file m_file = null; @@ -294,6 +334,8 @@ open (fp, rtype); } +// ============================================================================= +// ----------------------------------------------------------------------------- File::~File() { if (m_file) { m_file->close(); @@ -304,6 +346,8 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- bool File::open (FILE* fp, OpenType rtype) { return open ("", rtype, fp); } @@ -337,6 +381,8 @@ return false; } +// ============================================================================= +// ----------------------------------------------------------------------------- File::iterator File::begin() { return iterator (this); } @@ -345,10 +391,14 @@ return m_endIterator; } +// ============================================================================= +// ----------------------------------------------------------------------------- void File::write (str msg) { m_file->write (msg.toUtf8(), msg.length()); } +// ============================================================================= +// ----------------------------------------------------------------------------- bool File::readLine (str& line) { if (!m_textstream || m_textstream->atEnd()) return false; @@ -357,6 +407,8 @@ return true; } +// ============================================================================= +// ----------------------------------------------------------------------------- bool File::atEnd() const { if (!m_textstream) fatal ("cannot use atEnd on a null file"); @@ -364,6 +416,8 @@ return m_textstream->atEnd(); } +// ============================================================================= +// ----------------------------------------------------------------------------- bool File::isNull() const { return m_file == null; } @@ -372,6 +426,8 @@ return isNull(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void File::close() { if (!m_file) return; @@ -385,49 +441,63 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- bool File::flush() { return m_file->flush(); } +// ============================================================================= +// ----------------------------------------------------------------------------- File::operator bool() const { return !isNull(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void File::rewind() { m_file->seek (0); } +// ============================================================================= +// ----------------------------------------------------------------------------- File::iterator::iterator (File* f) : m_file (f) { operator++(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void File::iterator::operator++() { m_gotdata = m_file->readLine (m_text); } +// ============================================================================= +// ----------------------------------------------------------------------------- str File::iterator::operator*() { return m_text; } +// ============================================================================= // The prime contestant for the weirdest operator== 2013 award? +// ----------------------------------------------------------------------------- bool File::iterator::operator== (File::iterator& other) { return (other.m_file == null && !m_gotdata); } +// ============================================================================= +// ----------------------------------------------------------------------------- bool File::iterator::operator!= (File::iterator& other) { return !operator== (other); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- LDBoundingBox::LDBoundingBox() { reset(); } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDBoundingBox::calculate() { reset(); @@ -439,8 +509,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDBoundingBox::calcObject (LDObject* obj) { switch (obj->getType()) { case LDObject::Line: @@ -468,19 +537,22 @@ } } +// ============================================================================= +// ----------------------------------------------------------------------------- LDBoundingBox& LDBoundingBox::operator<< (const vertex& v) { calcVertex (v); return *this; } +// ============================================================================= +// ----------------------------------------------------------------------------- LDBoundingBox& LDBoundingBox::operator<< (LDObject* obj) { calcObject (obj); return *this; } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDBoundingBox::calcVertex (const vertex& v) { for (const Axis ax : g_Axes) { if (v[ax] < m_v0[ax]) @@ -494,8 +566,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- void LDBoundingBox::reset() { m_v0[X] = m_v0[Y] = m_v0[Z] = 0x7FFFFFFF; m_v1[X] = m_v1[Y] = m_v1[Z] = 0xFFFFFFFF; @@ -504,8 +575,7 @@ } // ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= +// ----------------------------------------------------------------------------- double LDBoundingBox::size() const { double xscale = (m_v0[X] - m_v1[X]); double yscale = (m_v0[Y] - m_v1[Y]); @@ -525,6 +595,7 @@ } // ============================================================================= +// ----------------------------------------------------------------------------- vertex LDBoundingBox::center() const { return vertex ( (m_v0[X] + m_v1[X]) / 2,
--- a/src/types.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/types.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */
--- a/src/widgets.cpp Sat Aug 17 11:48:27 2013 +0300 +++ b/src/widgets.cpp Sun Aug 18 15:33:00 2013 +0300 @@ -1,21 +1,28 @@ /* * 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 <http://www.gnu.org/licenses/>. */ +// I still find the radio box useful... find a way to use this in Designer. +// I probably need to look into how to make Designer plugins. +// +// The name is quite confusing too considering there's the check box and radio +// button around. This widget is a group of radio buttons. +// TODO: rename to RadioGroup, make this usable in Designer + #include <QBoxLayout> #include <QRadioButton> #include <QButtonGroup> @@ -23,19 +30,28 @@ #include <map> #include "widgets.h" +#include "build/moc_widgets.cpp" +// ============================================================================= +// ----------------------------------------------------------------------------- RadioBox::RadioBox (const QString& title, QWidget* parent) : QGroupBox (title, parent) { init (Qt::Vertical); } +// ============================================================================= +// ----------------------------------------------------------------------------- QBoxLayout::Direction makeDirection (Qt::Orientation orient, bool invert = false) { return (orient == (invert ? Qt::Vertical : Qt::Horizontal)) ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom; } +// ============================================================================= +// ----------------------------------------------------------------------------- bool RadioBox::isChecked (int n) const { return m_buttonGroup->checkedId() == n; } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::init (Qt::Orientation orient) { m_vert = orient == Qt::Vertical; @@ -53,6 +69,8 @@ connect (m_buttonGroup, SIGNAL (buttonReleased (int)), this, SLOT (slot_buttonReleased (int))); } +// ============================================================================= +// ----------------------------------------------------------------------------- RadioBox::RadioBox (const QString& title, initlist<char const*> entries, int const defaultId, const Qt::Orientation orient, QWidget* parent) : QGroupBox (title, parent), m_defId (defaultId) { @@ -63,6 +81,8 @@ addButton (entry); } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::rowBreak() { QBoxLayout* newLayout = new QBoxLayout (m_vert ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); m_currentLayout = newLayout; @@ -71,11 +91,15 @@ m_coreLayout->addLayout (newLayout); } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::addButton (const char* entry) { QRadioButton* button = new QRadioButton (entry); addButton (button); } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::addButton (QRadioButton* button) { bool const selectThis = (m_curId == m_defId); @@ -87,38 +111,54 @@ button->setChecked (true); } +// ============================================================================= +// ----------------------------------------------------------------------------- RadioBox& RadioBox::operator<< (QRadioButton* button) { addButton (button); return *this; } +// ============================================================================= +// ----------------------------------------------------------------------------- RadioBox& RadioBox::operator<< (const char* entry) { addButton (entry); return *this; } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::setCurrentRow (uint row) { m_currentLayout = m_layouts[row]; } +// ============================================================================= +// ----------------------------------------------------------------------------- int RadioBox::value() const { return m_buttonGroup->checkedId(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::setValue (int val) { m_buttonGroup->button (val)->setChecked (true); } +// ============================================================================= +// ----------------------------------------------------------------------------- QRadioButton* RadioBox::operator[] (uint n) const { return m_objects[n]; } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::slot_buttonPressed (int btn) { emit buttonPressed (btn); m_oldId = m_buttonGroup->checkedId(); } +// ============================================================================= +// ----------------------------------------------------------------------------- void RadioBox::slot_buttonReleased (int btn) { emit buttonReleased (btn); int newid = m_buttonGroup->checkedId(); @@ -127,12 +167,14 @@ emit valueChanged (newid); } +// ============================================================================= +// ----------------------------------------------------------------------------- RadioBox::it RadioBox::begin() { return m_objects.begin(); } +// ============================================================================= +// ----------------------------------------------------------------------------- RadioBox::it RadioBox::end() { return m_objects.end(); -} - -#include "build/moc_widgets.cpp" \ No newline at end of file +} \ No newline at end of file
--- a/src/widgets.h Sat Aug 17 11:48:27 2013 +0300 +++ b/src/widgets.h Sun Aug 18 15:33:00 2013 +0300 @@ -1,17 +1,17 @@ /* * 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 <http://www.gnu.org/licenses/>. */