Tue, 14 May 2013 03:49:15 +0300
Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
src/addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
src/colorSelectDialog.cpp | file | annotate | diff | comparison | revisions | |
src/config.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs.h | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui.h | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/ldrawPathDialog.cpp | file | annotate | diff | comparison | revisions | |
src/radiobox.cpp | file | annotate | diff | comparison | revisions | |
src/setContentsDialog.cpp | file | annotate | diff | comparison | revisions | |
src/setContentsDialog.h | file | annotate | diff | comparison | revisions |
--- 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
--- 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 <http://www.gnu.org/licenses/>. */ +#include <QGraphicsScene> +#include <QGraphicsView> +#include <QBoxLayout> +#include <QGraphicsItem> +#include <QMouseEvent> +#include <QScrollBar> +#include <QEvent> #include "common.h" #include "gui.h" -#include <qgraphicsscene.h> -#include <qgraphicsview.h> -#include <qicon.h> -#include <qboxlayout.h> -#include <qgraphicsitem.h> -#include <qevent.h> -#include <qscrollbar.h> #include "colorSelectDialog.h" #include "colors.h" #include "config.h"
--- 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 <http://www.gnu.org/licenses/>. */ -#include <stdio.h> -#include <stdlib.h> #include <errno.h> #include <time.h> #include <QDir>
--- 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<Axis> 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 " + "<a href=\"http://www.ldraw.org/article/218.html\">official file format " + "standard</a> 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 ("<span style=\"color: #900\">%s</span>", + static_cast<LDGibberish*> (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
--- 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 T> 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<Axis> axes () const; + double searchValue () const; + double replacementValue () const; + +private: + CheckBoxGroup<Axis>* 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
--- 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 <http://www.gnu.org/licenses/>. */ -#include <vector> -#include <stdio.h> -#include <qmessagebox.h> +#include <QMessageBox> #include <QDir> #include "common.h" #include "config.h"
--- 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 <http://www.gnu.org/licenses/>. */ -#include <qgridlayout.h> -#include <qmessagebox.h> -#include <qevent.h> -#include <qmenubar.h> -#include <qstatusbar.h> -#include <qsplitter.h> -#include <qlistwidget.h> -#include <qtoolbutton.h> -#include <qcombobox.h> -#include <qdialogbuttonbox.h> +#include <QGridLayout> +#include <QMessageBox> +#include <QEvent> +#include <QContextMenuEvent> +#include <QMenuBar> +#include <QStatusBar> +#include <QSplitter> +#include <QListWidget> +#include <QToolButton> +#include <QComboBox> +#include <QDialogButtonBox> #include <QToolBar> -#include <qcoreapplication.h> +#include <QCoreApplication> + #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<actionmeta> 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<Axis>* makeAxesBox () { + CheckBoxGroup<Axis>* cbg_axes = new CheckBoxGroup<Axis> ("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
--- 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 T> 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<Axis>* makeAxesBox (); // ----------------------------------------------------------------------------- // Pointer to the instance of ForgeWindow.
--- 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 <http://www.gnu.org/licenses/>. */ -#include <qfiledialog.h> -#include <qmessagebox.h> +#include <QFileDialog> +#include <QMessageBox> #include <QTextEdit> #include <QBoxLayout> + #include "gui.h" #include "file.h" #include "history.h"
--- 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 <http://www.gnu.org/licenses/>. */ +#include <QSpinBox> +#include <QCheckBox> + #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 <qspinbox.h> -#include <qcheckbox.h> #include "gldraw.h" +#include "dialogs.h" vector<LDObject*> 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<Axis>* makeAxesBox () { - CheckBoxGroup<Axis>* cbg_axes = new CheckBoxGroup<Axis> ("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<Axis> axes () const { - return cbg_axes->checkedValues (); - } - - double searchValue () { return dsb_search->value (); } - double replacementValue () { return dsb_replacement->value (); } - -private: - CheckBoxGroup<Axis>* 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;
--- 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 <http://www.gnu.org/licenses/>. */ -#include <qlineedit.h> -#include <qpushbutton.h> -#include <qdialogbuttonbox.h> +#include <QLineEdit> +#include <QPushButton> +#include <QDialogButtonBox> #include <QFileDialog> #include <QBoxLayout> #include <QLabel>
--- 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 <http://www.gnu.org/licenses/>. */ -#include <qboxlayout.h> -#include <qradiobutton.h> +#include <QBoxLayout> +#include <QRadioButton> #include "radiobox.h" QBoxLayout::Direction makeDirection (Qt::Orientation orient, bool invert = false) {
--- 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 <http://www.gnu.org/licenses/>. - */ - -#include <qboxlayout.h> -#include <QLineEdit> -#include <QLabel> -#include <QDialogButtonBox> -#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 " - "<a href=\"http://www.ldraw.org/article/218.html\">official file format " - "standard</a> for further information."); - le_contents->setMinimumWidth (384); - - if (obj->getType() == LDObject::Gibberish) { - lb_error = new QLabel; - lb_error->setText (fmt ("<span style=\"color: #900\">%s</span>", - static_cast<LDGibberish*> (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
--- 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 <http://www.gnu.org/licenses/>. - */ - -#ifndef SETCONTENTSDIALOG_H - -#include <QDialog> -#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