# HG changeset patch # User Santeri Piippo # Date 1368492555 -10800 # Node ID 10dd5909a50ea282b7ffc65b35d5c04472183fd5 # Parent f246725199dc824566faaec2600764862857e0ae Made Qt file includes more proper ( instead of ), merged setContentsDialog.cpp into dialogs.cpp diff -r f246725199dc -r 10dd5909a50e src/addObjectDialog.cpp --- a/src/addObjectDialog.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/addObjectDialog.cpp Tue May 14 03:49:15 2013 +0300 @@ -31,7 +31,6 @@ #include "colors.h" #include "colorSelectDialog.h" #include "history.h" -#include "setContentsDialog.h" #include "radiobox.h" #define APPLY_COORDS(OBJ, N) \ @@ -368,11 +367,8 @@ void AddObjectDialog::staticDialog (const LDObject::Type type, LDObject* obj) { setlocale (LC_ALL, "C"); - // Redirect editing of gibberish to the set contents dialog - if (obj && obj->getType () == LDObject::Gibberish) { - SetContentsDialog::staticDialog (obj); + if (obj && obj->getType () == LDObject::Gibberish) return; - } if (type == LDObject::Empty) return; // Nothing to edit with empties diff -r f246725199dc -r 10dd5909a50e src/colorSelectDialog.cpp --- a/src/colorSelectDialog.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/colorSelectDialog.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,15 +16,15 @@ * along with this program. If not, see . */ +#include +#include +#include +#include +#include +#include +#include #include "common.h" #include "gui.h" -#include -#include -#include -#include -#include -#include -#include #include "colorSelectDialog.h" #include "colors.h" #include "config.h" diff -r f246725199dc -r 10dd5909a50e src/config.cpp --- a/src/config.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/config.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,8 +16,6 @@ * along with this program. If not, see . */ -#include -#include #include #include #include diff -r f246725199dc -r 10dd5909a50e src/dialogs.cpp --- a/src/dialogs.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/dialogs.cpp Tue May 14 03:49:15 2013 +0300 @@ -29,6 +29,7 @@ #include "gui.h" #include "gldraw.h" #include "docs.h" +#include "checkboxgroup.h" #include "dialogs.h" // ============================================================================= @@ -144,4 +145,90 @@ void OverlayDialog::slot_dimensionsChanged () { bool enable = (dsb_lwidth->value () != 0) || (dsb_lheight->value () != 0); dbb_buttons->button (QDialogButtonBox::Ok)->setEnabled (enable); +} + +ReplaceCoordsDialog::ReplaceCoordsDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { + cbg_axes = makeAxesBox (); + + lb_search = new QLabel ("Search:"); + lb_replacement = new QLabel ("Replacement:"); + + dsb_search = new QDoubleSpinBox; + dsb_search->setRange (-10000.0f, 10000.0f); + + dsb_replacement = new QDoubleSpinBox; + dsb_replacement->setRange (-10000.0f, 10000.0f); + + QGridLayout* valueLayout = new QGridLayout; + valueLayout->setColumnStretch (1, 1); + valueLayout->addWidget (lb_search, 0, 0); + valueLayout->addWidget (dsb_search, 0, 1); + valueLayout->addWidget (lb_replacement, 1, 0); + valueLayout->addWidget (dsb_replacement, 1, 1); + + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget (cbg_axes); + layout->addLayout (valueLayout); + layout->addWidget (makeButtonBox (*this)); + setLayout (layout); +} + +double ReplaceCoordsDialog::searchValue() const { + return dsb_search->value (); +} + +double ReplaceCoordsDialog::replacementValue() const { + return dsb_replacement->value (); +} + +vector ReplaceCoordsDialog::axes() const { + return cbg_axes->checkedValues (); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +SetContentsDialog::SetContentsDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { + setWindowTitle (APPNAME ": Set Contents"); + + lb_error = new QLabel; + lb_errorIcon = new QLabel; + lb_contents = new QLabel ("Set contents:", parent); + + le_contents = new QLineEdit (parent); + le_contents->setWhatsThis ("The LDraw code of this object. The code written " + "here is expected to be valid LDraw code, invalid code here results " + "the object being turned into an error object. Please do refer to the " + "official file format " + "standard for further information."); + le_contents->setMinimumWidth (384); + + QHBoxLayout* bottomRow = new QHBoxLayout; + bottomRow->addWidget (lb_errorIcon); + bottomRow->addWidget (lb_error); + bottomRow->addWidget (makeButtonBox (*this)); + + QVBoxLayout* layout = new QVBoxLayout (this); + layout->addWidget (lb_contents); + layout->addWidget (le_contents); + layout->addLayout (bottomRow); + + setWindowTitle ("Set Contents"); + setWindowIcon (getIcon ("set-contents")); +} + +void SetContentsDialog::setObject (LDObject* obj) { + le_contents->setText (obj->getContents ().chars()); + + if (obj->getType() == LDObject::Gibberish) { + lb_error->setText (fmt ("%s", + static_cast (obj)->reason.chars())); + + QPixmap errorPixmap = getIcon ("error").scaledToHeight (16); + lb_errorIcon->setPixmap (errorPixmap); + } +} + +str SetContentsDialog::text () const { + return le_contents->text (); } \ No newline at end of file diff -r f246725199dc -r 10dd5909a50e src/dialogs.h --- a/src/dialogs.h Tue May 14 03:23:01 2013 +0300 +++ b/src/dialogs.h Tue May 14 03:49:15 2013 +0300 @@ -10,6 +10,9 @@ class QLineEdit; class QSpinBox; class RadioBox; +template class CheckBoxGroup; +class QLabel; +class QAbstractButton; class OverlayDialog : public QDialog { Q_OBJECT @@ -39,4 +42,36 @@ void fillDefaults (int newcam); }; +class ReplaceCoordsDialog : public QDialog { +public: + explicit ReplaceCoordsDialog (QWidget* parent = null, Qt::WindowFlags f = 0); + + vector axes () const; + double searchValue () const; + double replacementValue () const; + +private: + CheckBoxGroup* cbg_axes; + QLabel* lb_search, *lb_replacement; + QDoubleSpinBox* dsb_search, *dsb_replacement; +}; + +// ============================================================================= +// SetContentsDialog +// +// Performs the Set Contents dialog on the given LDObject. Object's contents +// are exposed to the user and is reinterpreted if the user accepts the new +// contents. +// ============================================================================= +class SetContentsDialog : public QDialog { +public: + explicit SetContentsDialog (QWidget* parent = null, Qt::WindowFlags f = 0); + str text () const; + void setObject (LDObject* obj); + +private: + QLabel* lb_contents, *lb_errorIcon, *lb_error; + QLineEdit* le_contents; +}; + #endif // DIALOGS_H \ No newline at end of file diff -r f246725199dc -r 10dd5909a50e src/file.cpp --- a/src/file.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/file.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,9 +16,7 @@ * along with this program. If not, see . */ -#include -#include -#include +#include #include #include "common.h" #include "config.h" diff -r f246725199dc -r 10dd5909a50e src/gui.cpp --- a/src/gui.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/gui.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,18 +16,20 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include +#include + #include "common.h" #include "gldraw.h" #include "gui.h" @@ -36,6 +38,7 @@ #include "misc.h" #include "colors.h" #include "history.h" +#include "checkboxgroup.h" #include "config.h" vector g_ActionMeta; @@ -82,7 +85,7 @@ setMinimumSize (320, 200); resize (800, 600); - connect (QCoreApplication::instance (), SIGNAL (aboutToQuit ()), this, SLOT (slot_lastSecondCleanup ())); + connect (qApp, SIGNAL (aboutToQuit ()), this, SLOT (slot_lastSecondCleanup ())); } // ============================================================================= @@ -1038,4 +1041,12 @@ QWidget::connect (bbx_buttons, SIGNAL (accepted ()), &dlg, SLOT (accept ())); QWidget::connect (bbx_buttons, SIGNAL (rejected ()), &dlg, SLOT (reject ())); return bbx_buttons; +} + +CheckBoxGroup* makeAxesBox () { + CheckBoxGroup* cbg_axes = new CheckBoxGroup ("Axes", Qt::Horizontal); + cbg_axes->addCheckBox ("X", X); + cbg_axes->addCheckBox ("Y", Y); + cbg_axes->addCheckBox ("Z", Z); + return cbg_axes; } \ No newline at end of file diff -r f246725199dc -r 10dd5909a50e src/gui.h --- a/src/gui.h Tue May 14 03:23:01 2013 +0300 +++ b/src/gui.h Tue May 14 03:49:15 2013 +0300 @@ -33,6 +33,7 @@ class QToolButton; class QDialogButtonBox; class GLRenderer; +template class CheckBoxGroup; // Stuff for dialogs #define IMPLEMENT_DIALOG_BUTTONS \ @@ -192,6 +193,7 @@ QIcon makeColorIcon (color* colinfo, const ushort size); void makeColorSelector (QComboBox* box); QDialogButtonBox* makeButtonBox (QDialog& dlg); +CheckBoxGroup* makeAxesBox (); // ----------------------------------------------------------------------------- // Pointer to the instance of ForgeWindow. diff -r f246725199dc -r 10dd5909a50e src/gui_actions.cpp --- a/src/gui_actions.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/gui_actions.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,10 +16,11 @@ * along with this program. If not, see . */ -#include -#include +#include +#include #include #include + #include "gui.h" #include "file.h" #include "history.h" diff -r f246725199dc -r 10dd5909a50e src/gui_editactions.cpp --- a/src/gui_editactions.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/gui_editactions.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,21 +16,22 @@ * along with this program. If not, see . */ +#include +#include + #include "gui.h" #include "common.h" #include "file.h" #include "history.h" #include "colorSelectDialog.h" #include "historyDialog.h" -#include "setContentsDialog.h" #include "misc.h" #include "bbox.h" #include "radiobox.h" #include "extprogs.h" #include "checkboxgroup.h" -#include -#include #include "gldraw.h" +#include "dialogs.h" vector g_Clipboard; @@ -283,7 +284,27 @@ return; LDObject* obj = g_win->sel ()[0]; - SetContentsDialog::staticDialog (obj); + + SetContentsDialog dlg; + dlg.setObject (obj); + if (!dlg.exec ()) + return; + + LDObject* oldobj = obj; + + // Reinterpret it from the text of the input field + obj = parseLine (dlg.text ()); + + // Mark down the history now before we perform the replacement (which + // destroys the old object) + History::addEntry (new EditHistory ({(ulong) oldobj->getIndex (g_curfile)}, + {oldobj->clone ()}, {obj->clone ()})); + + oldobj->replace (obj); + + // Rebuild stuff after this + g_win->R ()->compileObject (obj); + g_win->refresh (); } // ============================================================================= @@ -660,58 +681,6 @@ } // ========================================================================================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ========================================================================================================================================= -static CheckBoxGroup* makeAxesBox () { - CheckBoxGroup* cbg_axes = new CheckBoxGroup ("Axes", Qt::Horizontal); - cbg_axes->addCheckBox ("X", X); - cbg_axes->addCheckBox ("Y", Y); - cbg_axes->addCheckBox ("Z", Z); - return cbg_axes; -} - -class ReplaceCoordsDialog : public QDialog { -public: - explicit ReplaceCoordsDialog (QWidget* parent = null, Qt::WindowFlags f = 0) : QDialog (parent, f) { - cbg_axes = makeAxesBox (); - - lb_search = new QLabel ("Search:"); - lb_replacement = new QLabel ("Replacement:"); - - dsb_search = new QDoubleSpinBox; - dsb_search->setRange (-10000.0f, 10000.0f); - - dsb_replacement = new QDoubleSpinBox; - dsb_replacement->setRange (-10000.0f, 10000.0f); - - QGridLayout* valueLayout = new QGridLayout; - valueLayout->setColumnStretch (1, 1); - valueLayout->addWidget (lb_search, 0, 0); - valueLayout->addWidget (dsb_search, 0, 1); - valueLayout->addWidget (lb_replacement, 1, 0); - valueLayout->addWidget (dsb_replacement, 1, 1); - - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget (cbg_axes); - layout->addLayout (valueLayout); - layout->addWidget (makeButtonBox (*this)); - setLayout (layout); - } - - std::vector axes () const { - return cbg_axes->checkedValues (); - } - - double searchValue () { return dsb_search->value (); } - double replacementValue () { return dsb_replacement->value (); } - -private: - CheckBoxGroup* cbg_axes; - QLabel* lb_search, *lb_replacement; - QDoubleSpinBox* dsb_search, *dsb_replacement; -}; - -// ========================================================================================================================================= MAKE_ACTION (replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL (R)) { ReplaceCoordsDialog dlg; diff -r f246725199dc -r 10dd5909a50e src/ldrawPathDialog.cpp --- a/src/ldrawPathDialog.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/ldrawPathDialog.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -#include -#include -#include +#include +#include +#include #include #include #include diff -r f246725199dc -r 10dd5909a50e src/radiobox.cpp --- a/src/radiobox.cpp Tue May 14 03:23:01 2013 +0300 +++ b/src/radiobox.cpp Tue May 14 03:49:15 2013 +0300 @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#include -#include +#include +#include #include "radiobox.h" QBoxLayout::Direction makeDirection (Qt::Orientation orient, bool invert = false) { diff -r f246725199dc -r 10dd5909a50e src/setContentsDialog.cpp --- a/src/setContentsDialog.cpp Tue May 14 03:23:01 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 Santeri Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include "setContentsDialog.h" -#include "file.h" -#include "gui.h" -#include "history.h" - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -SetContentsDialog::SetContentsDialog (LDObject* obj, QWidget* parent) : QDialog(parent) { - setWindowTitle (APPNAME ": Set Contents"); - - lb_contents = new QLabel ("Set contents:", parent); - - le_contents = new QLineEdit (parent); - le_contents->setText (obj->getContents ().chars()); - le_contents->setWhatsThis ("The LDraw code of this object. The code written " - "here is expected to be valid LDraw code, invalid code here results " - "the object being turned into an error object. Please do refer to the " - "official file format " - "standard for further information."); - le_contents->setMinimumWidth (384); - - if (obj->getType() == LDObject::Gibberish) { - lb_error = new QLabel; - lb_error->setText (fmt ("%s", - static_cast (obj)->reason.chars())); - - QPixmap qErrorPixmap = getIcon ("error").scaledToHeight (16); - - lb_errorIcon = new QLabel; - lb_errorIcon->setPixmap (qErrorPixmap); - } - - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget (lb_contents); - layout->addWidget (le_contents); - - QHBoxLayout* layout2 = new QHBoxLayout; - - if (obj->getType() == LDObject::Gibberish) { - layout2->addWidget (lb_errorIcon); - layout2->addWidget (lb_error); - } - - layout2->addWidget (makeButtonBox (*this)); - layout->addLayout (layout2); - setLayout (layout); - - setWindowTitle (APPNAME ": Set Contents"); - setWindowIcon (getIcon ("set-contents")); -} - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -void SetContentsDialog::slot_handleButtons (QAbstractButton* btn) { - btn = btn; -} - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -void SetContentsDialog::staticDialog (LDObject* obj) { - if (!obj) - return; - - SetContentsDialog dlg (obj, g_win); - if (dlg.exec () == false) - return; - - LDObject* oldobj = obj; - - // Reinterpret it from the text of the input field - obj = parseLine (dlg.le_contents->text ().toStdString ().c_str ()); - - // Mark down the history now before we perform the replacement (which - // destroys the old object) - History::addEntry (new EditHistory ({(ulong) oldobj->getIndex (g_curfile)}, - {oldobj->clone ()}, {obj->clone ()})); - - oldobj->replace (obj); - - // Rebuild stuff after this - g_win->fullRefresh (); -} \ No newline at end of file diff -r f246725199dc -r 10dd5909a50e src/setContentsDialog.h --- a/src/setContentsDialog.h Tue May 14 03:23:01 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 Santeri Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef SETCONTENTSDIALOG_H - -#include -#include "common.h" - -class QAbstractButton; -class QLabel; -class QLineEdit; - -// ============================================================================= -// SetContentsDialog -// -// Performs the Set Contents dialog on the given LDObject. Object's contents -// are exposed to the user and is reinterpreted if the user accepts the new -// contents. -// ============================================================================= -class SetContentsDialog : public QDialog { -public: - QLabel* lb_contents, *lb_errorIcon, *lb_error; - QLineEdit* le_contents; - - SetContentsDialog (LDObject* obj, QWidget* parent = null); - static void staticDialog (LDObject* obj); - -private slots: - void slot_handleButtons (QAbstractButton* btn); -}; - -#endif // SETCONTENTSDIALOG_H \ No newline at end of file