Tue, 19 Mar 2013 21:52:38 +0200
Begin work on dialogs for adding objects. Comments functional!
file.cpp | file | annotate | diff | comparison | revisions | |
file.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
ldforge.pro | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.h | file | annotate | diff | comparison | revisions | |
zz_addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_addObjectDialog.h | file | annotate | diff | comparison | revisions | |
zz_configDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_configDialog.h | file | annotate | diff | comparison | revisions | |
zz_setContentsDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_setContentsDialog.h | file | annotate | diff | comparison | revisions |
--- a/file.cpp Tue Mar 19 18:25:08 2013 +0200 +++ b/file.cpp Tue Mar 19 21:52:38 2013 +0200 @@ -391,6 +391,11 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void OpenFile::addObject (LDObject* obj) { + if (this != g_CurrentFile) { + objects.insert (objects.end (), obj); + return; + } + const ulong ulSpot = g_qWindow->getInsertionPoint (); objects.insert (objects.begin() + ulSpot, obj); } \ No newline at end of file
--- a/file.h Tue Mar 19 18:25:08 2013 +0200 +++ b/file.h Tue Mar 19 21:52:38 2013 +0200 @@ -39,6 +39,8 @@ // Saves this file to disk. bool save (str zPath = ""); + + // Adds an object to this file at the appropriate location. void addObject (LDObject* obj); };
--- a/gui.cpp Tue Mar 19 18:25:08 2013 +0200 +++ b/gui.cpp Tue Mar 19 21:52:38 2013 +0200 @@ -25,6 +25,7 @@ #include "zz_setContentsDialog.h" #include "zz_configDialog.h" +#include "zz_addObjectDialog.h" #define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ @@ -314,9 +315,7 @@ } void ForgeWindow::slot_newComment () { - LDComment* comm = new LDComment; - g_CurrentFile->addObject (comm); - refresh (); + AddObjectDialog::staticDialog (OBJ_Comment, this); } void ForgeWindow::slot_help () {
--- a/gui.h Tue Mar 19 18:25:08 2013 +0200 +++ b/gui.h Tue Mar 19 21:52:38 2013 +0200 @@ -28,6 +28,13 @@ #include <QTextEdit> #include "gldraw.h" +// Stuff for dialogs +#define IMPLEMENT_DIALOG_BUTTONS \ + qButtons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \ + connect (qButtons, SIGNAL (accepted ()), this, SLOT (accept ())); \ + connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ())); \ + + class ForgeWindow : public QMainWindow { Q_OBJECT
--- a/ldforge.pro Tue Mar 19 18:25:08 2013 +0200 +++ b/ldforge.pro Tue Mar 19 21:52:38 2013 +0200 @@ -21,7 +21,8 @@ config.h \ cfgdef.h \ zz_setContentsDialog.h \ - zz_configDialog.h + zz_configDialog.h \ + zz_addObjectDialog.h SOURCES += bbox.cpp \ gldraw.cpp \ @@ -33,7 +34,8 @@ str.cpp \ config.cpp \ zz_setContentsDialog.cpp \ - zz_configDialog.cpp + zz_configDialog.cpp \ + zz_addObjectDialog.cpp QMAKE_CXXFLAGS += -std=c++0x QT += opengl \ No newline at end of file
--- a/ldtypes.cpp Tue Mar 19 18:25:08 2013 +0200 +++ b/ldtypes.cpp Tue Mar 19 21:52:38 2013 +0200 @@ -35,6 +35,20 @@ "vertex", }; +char const* g_saObjTypeIcons[] = { + "icons/error.png", + "icons/error.png", + "icons/empty.png", + "icons/comment.png", + "icons/subfile.png", + "icons/line.png", + "icons/triangle.png", + "icons/quad.png", + "icons/condline.png", + "icons/vector.png", + "icons/vertex.png" +}; + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // =============================================================================
--- a/ldtypes.h Tue Mar 19 18:25:08 2013 +0200 +++ b/ldtypes.h Tue Mar 19 21:52:38 2013 +0200 @@ -254,4 +254,7 @@ // string representation of the object's type. extern const char* g_saObjTypeNames[]; +// Icons for these types +extern const char* g_saObjTypeIcons[]; + #endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zz_addObjectDialog.cpp Tue Mar 19 21:52:38 2013 +0200 @@ -0,0 +1,69 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` 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 "gui.h" +#include "zz_addObjectDialog.h" +#include "file.h" + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +AddObjectDialog::AddObjectDialog (const LDObjectType_e type, QWidget* parent) : + QDialog (parent) +{ + qTypeIcon = new QLabel; + qTypeIcon->setPixmap (QPixmap (g_saObjTypeIcons[type])); + + qCommentLine = new QLineEdit; + + IMPLEMENT_DIALOG_BUTTONS + + QGridLayout* layout = new QGridLayout; + layout->addWidget (qTypeIcon, 0, 0); + layout->addWidget (qCommentLine, 0, 1); + layout->addWidget (qButtons, 1, 1); + + setLayout (layout); + setWindowTitle (str::mkfmt (APPNAME_DISPLAY " - new %s", + g_saObjTypeNames[type]).chars()); + + setWindowIcon (QIcon (g_saObjTypeIcons[type])); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void AddObjectDialog::staticDialog (const LDObjectType_e type, ForgeWindow* window) { + AddObjectDialog dlg (type, window); + + if (dlg.exec ()) { + switch (type) { + case OBJ_Comment: + { + LDComment* comm = new LDComment; + comm->zText = dlg.qCommentLine->text (); + g_CurrentFile->addObject (comm); + window->refresh (); + break; + } + default: + break; + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zz_addObjectDialog.h Tue Mar 19 21:52:38 2013 +0200 @@ -0,0 +1,41 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` 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 __ZZ_ADDOBJECTDIALOG_H__ +#define __ZZ_ADDOBJECTDIALOG_H__ + +#include "gui.h" +#include <qdialog.h> +#include <qlineedit.h> +#include <qdialogbuttonbox.h> +#include <qlabel.h> + +class AddObjectDialog : public QDialog { +public: + AddObjectDialog (const LDObjectType_e type, QWidget* parent = nullptr); + static void staticDialog (const LDObjectType_e type, ForgeWindow* window); + + QLabel* qTypeIcon; + + // -- COMMENT -- + QLineEdit* qCommentLine; + + QDialogButtonBox* qButtons; +}; + +#endif // __ZZ_ADDOBJECTDIALOG_H__ \ No newline at end of file
--- a/zz_configDialog.cpp Tue Mar 19 18:25:08 2013 +0200 +++ b/zz_configDialog.cpp Tue Mar 19 21:52:38 2013 +0200 @@ -53,9 +53,7 @@ connect (qGLForegroundButton, SIGNAL (clicked ()), this, SLOT (slot_setGLForeground ())); - qButtons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect (qButtons, SIGNAL (accepted ()), this, SLOT (accept ())); - connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ())); + IMPLEMENT_DIALOG_BUTTONS QGridLayout* layout = new QGridLayout; layout->addWidget (qLDrawPathLabel, 0, 0);
--- a/zz_configDialog.h Tue Mar 19 18:25:08 2013 +0200 +++ b/zz_configDialog.h Tue Mar 19 21:52:38 2013 +0200 @@ -17,7 +17,7 @@ */ #include "gui.h" -#include <QDialog> +#include <qdialog.h> #include <qlabel.h> #include <qlineedit.h> #include <qdialogbuttonbox.h>
--- a/zz_setContentsDialog.cpp Tue Mar 19 18:25:08 2013 +0200 +++ b/zz_setContentsDialog.cpp Tue Mar 19 21:52:38 2013 +0200 @@ -39,19 +39,12 @@ "standard</a> for further information."); qContents->setMinimumWidth (384); - qOKCancel = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, - Qt::Horizontal, parent); - - connect (qOKCancel, SIGNAL (accepted ()), this, SLOT (accept ())); - connect (qOKCancel, SIGNAL (rejected ()), this, SLOT (reject ())); - /* - connect (qOKCancel, SIGNAL (clicked (QAbstractButton*)), this, SLOT (slot_handleButtons (QAbstractButton*))); - */ + IMPLEMENT_DIALOG_BUTTONS QVBoxLayout* layout = new QVBoxLayout; layout->addWidget (qContentsLabel); layout->addWidget (qContents); - layout->addWidget (qOKCancel); + layout->addWidget (qButtons); setLayout (layout); setWindowTitle (APPNAME_DISPLAY " - setting contents");
--- a/zz_setContentsDialog.h Tue Mar 19 18:25:08 2013 +0200 +++ b/zz_setContentsDialog.h Tue Mar 19 21:52:38 2013 +0200 @@ -33,7 +33,7 @@ public: QLabel* qContentsLabel; QLineEdit* qContents; - QDialogButtonBox* qOKCancel; + QDialogButtonBox* qButtons; SetContentsDialog (LDObject* obj, QWidget* parent = nullptr); static void staticDialog (LDObject* obj, ForgeWindow* parent);