# HG changeset patch # User Santeri Piippo # Date 1363722758 -7200 # Node ID 110669124cafbe28602d0ad8006f5fe8167cf056 # Parent 20f5eaae84252aec03a0b2351911ee6d1c6ff40f Begin work on dialogs for adding objects. Comments functional! diff -r 20f5eaae8425 -r 110669124caf file.cpp --- 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 diff -r 20f5eaae8425 -r 110669124caf file.h --- 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); }; diff -r 20f5eaae8425 -r 110669124caf gui.cpp --- 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 () { diff -r 20f5eaae8425 -r 110669124caf gui.h --- 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 #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 diff -r 20f5eaae8425 -r 110669124caf ldforge.pro --- 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 diff -r 20f5eaae8425 -r 110669124caf ldtypes.cpp --- 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" +}; + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= diff -r 20f5eaae8425 -r 110669124caf ldtypes.h --- 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 diff -r 20f5eaae8425 -r 110669124caf zz_addObjectDialog.cpp --- /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 . + */ + +#include +#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 diff -r 20f5eaae8425 -r 110669124caf zz_addObjectDialog.h --- /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 . + */ + +#ifndef __ZZ_ADDOBJECTDIALOG_H__ +#define __ZZ_ADDOBJECTDIALOG_H__ + +#include "gui.h" +#include +#include +#include +#include + +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 diff -r 20f5eaae8425 -r 110669124caf zz_configDialog.cpp --- 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); diff -r 20f5eaae8425 -r 110669124caf zz_configDialog.h --- 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 +#include #include #include #include diff -r 20f5eaae8425 -r 110669124caf zz_setContentsDialog.cpp --- 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 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"); diff -r 20f5eaae8425 -r 110669124caf zz_setContentsDialog.h --- 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);