# HG changeset patch # User Teemu Piippo # Date 1440865120 -10800 # Node ID 7feaa1a3c438d44495e16b51049f61eb43a87864 # Parent 8349552ee5e9d5df70b84c621ef9ecf3b45f1f3c Refactor the new part dialog into a new class diff -r 8349552ee5e9 -r 7feaa1a3c438 CMakeLists.txt --- a/CMakeLists.txt Sat Aug 29 18:45:48 2015 +0300 +++ b/CMakeLists.txt Sat Aug 29 19:18:40 2015 +0300 @@ -62,6 +62,7 @@ src/version.cpp src/dialogs/colorselector.cpp src/dialogs/ldrawpathdialog.cpp + src/dialogs/newpartdialog.cpp src/editmodes/abstractEditMode.cpp src/editmodes/circleMode.cpp src/editmodes/drawMode.cpp @@ -99,6 +100,7 @@ src/ldpaths.h src/dialogs/colorselector.h src/dialogs/ldrawpathdialog.h + src/dialogs/newpartdialog.h src/editmodes/abstractEditMode.h src/editmodes/circleMode.h src/editmodes/drawMode.h @@ -123,7 +125,6 @@ ui/isecalc.ui ui/ldforge.ui ui/makeprim.ui - ui/newpart.ui ui/openprogress.ui ui/overlay.ui ui/rectifier.ui @@ -132,6 +133,7 @@ ui/ytruder.ui src/dialogs/colorselector.ui src/dialogs/ldrawpathdialog.ui + src/dialogs/newpartdialog.ui ) add_custom_target (codegeneration ALL diff -r 8349552ee5e9 -r 7feaa1a3c438 src/actions.cpp --- a/src/actions.cpp Sat Aug 29 18:45:48 2015 +0300 +++ b/src/actions.cpp Sat Aug 29 19:18:40 2015 +0300 @@ -38,13 +38,11 @@ #include "glCompiler.h" #include "ui_newpart.h" #include "dialogs/ldrawpathdialog.h" +#include "dialogs/newpartdialog.h" #include "editmodes/abstractEditMode.h" EXTERN_CFGENTRY (Bool, DrawWireframe) EXTERN_CFGENTRY (Bool, BFCRedGreenView) -EXTERN_CFGENTRY (String, DefaultName) -EXTERN_CFGENTRY (String, DefaultUser) -EXTERN_CFGENTRY (Bool, UseCALicense) EXTERN_CFGENTRY (Bool, DrawAngles) EXTERN_CFGENTRY (Bool, RandomColors) EXTERN_CFGENTRY (Bool, DrawSurfaces) @@ -52,47 +50,22 @@ EXTERN_CFGENTRY (Bool, DrawConditionalLines) EXTERN_CFGENTRY (Bool, DrawAxes) EXTERN_CFGENTRY (String, LDrawPath) +EXTERN_CFGENTRY (String, DefaultName) +EXTERN_CFGENTRY (String, DefaultUser) +EXTERN_CFGENTRY (Bool, UseCALicense) // ============================================================================= // void MainWindow::slot_actionNew() { - QDialog* dlg = new QDialog (g_win); - Ui::NewPartUI ui; - ui.setupUi (dlg); - - QString authortext = cfg::DefaultName; - - if (not cfg::DefaultUser.isEmpty()) - authortext.append (format (" [%1]", cfg::DefaultUser)); - - ui.le_author->setText (authortext); - ui.caLicense->setChecked (cfg::UseCALicense); - - if (dlg->exec() == QDialog::Rejected) - return; - - newFile(); + NewPartDialog* dlg = new NewPartDialog (this); - BFCStatement const bfctype = ui.rb_bfc_ccw->isChecked() ? BFCStatement::CertifyCCW - : ui.rb_bfc_cw->isChecked() ? BFCStatement::CertifyCW - : BFCStatement::NoCertify; - QString const license = ui.caLicense->isChecked() ? CALicenseText : ""; - - LDObjectList objs; - objs << LDSpawn (ui.le_title->text()); - objs << LDSpawn ("Name: .dat"); - objs << LDSpawn (format ("Author: %1", ui.le_author->text())); - objs << LDSpawn (format ("!LDRAW_ORG Unofficial_Part")); - - if (not license.isEmpty()) - objs << LDSpawn (license); - - objs << LDSpawn(); - objs << LDSpawn (bfctype); - objs << LDSpawn(); - CurrentDocument()->addObjects (objs); - doFullRefresh(); + if (dlg->exec() == QDialog::Accepted) + { + newFile(); + dlg->fillHeader (CurrentDocument()); + doFullRefresh(); + } } // ============================================================================= @@ -106,7 +79,7 @@ // void MainWindow::slot_actionOpen() { - QString name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)"); + QString name = QFileDialog::getOpenFileName (this, "Open File", "", "LDraw files (*.dat *.ldr)"); if (name.isEmpty()) return; @@ -240,7 +213,7 @@ if (Selection().size() != 1) return; - LDObject* obj = Selection() [0]; + LDObject* obj = Selection().first(); AddObjectDialog::staticDialog (obj->type(), obj); } @@ -261,7 +234,7 @@ // void MainWindow::slot_actionAboutQt() { - QMessageBox::aboutQt (g_win); + QMessageBox::aboutQt (this); } // ============================================================================= @@ -478,7 +451,7 @@ root.chop (4); QString defaultname = (root.length() > 0) ? format ("%1.png", root) : ""; - QString fname = QFileDialog::getSaveFileName (g_win, "Save Screencap", defaultname, + QString fname = QFileDialog::getSaveFileName (this, "Save Screencap", defaultname, "PNG images (*.png);;JPG images (*.jpg);;BMP images (*.bmp);;All Files (*.*)"); if (not fname.isEmpty() and not img.save (fname)) @@ -609,7 +582,7 @@ return; bool ok; - double depth = QInputDialog::getDouble (g_win, "Set Draw Depth", + double depth = QInputDialog::getDouble (this, "Set Draw Depth", format ("Depth value for %1 Camera:", R()->getCameraName()), R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); diff -r 8349552ee5e9 -r 7feaa1a3c438 src/dialogs/ldrawpathdialog.cpp --- a/src/dialogs/ldrawpathdialog.cpp Sat Aug 29 18:45:48 2015 +0300 +++ b/src/dialogs/ldrawpathdialog.cpp Sat Aug 29 19:18:40 2015 +0300 @@ -1,3 +1,21 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013, 2014 Teemu 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 diff -r 8349552ee5e9 -r 7feaa1a3c438 src/dialogs/ldrawpathdialog.h --- a/src/dialogs/ldrawpathdialog.h Sat Aug 29 18:45:48 2015 +0300 +++ b/src/dialogs/ldrawpathdialog.h Sat Aug 29 19:18:40 2015 +0300 @@ -1,3 +1,21 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013, 2014 Teemu 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 . + */ + #pragma once #include #include "../main.h" diff -r 8349552ee5e9 -r 7feaa1a3c438 src/dialogs/newpartdialog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dialogs/newpartdialog.cpp Sat Aug 29 19:18:40 2015 +0300 @@ -0,0 +1,86 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013, 2014 Teemu 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 "../ldDocument.h" +#include "newpartdialog.h" +#include "ui_newpartdialog.h" + +EXTERN_CFGENTRY (String, DefaultName) +EXTERN_CFGENTRY (String, DefaultUser) +EXTERN_CFGENTRY (Bool, UseCALicense) + +NewPartDialog::NewPartDialog (QWidget *parent) : + QDialog (parent), + ui (*new Ui_NewPart) +{ + ui.setupUi (this); + + QString authortext = cfg::DefaultName; + + if (not cfg::DefaultUser.isEmpty()) + authortext.append (format (" [%1]", cfg::DefaultUser)); + + ui.author->setText (authortext); + ui.useCaLicense->setChecked (cfg::UseCALicense); +} + +BFCStatement NewPartDialog::getWinding() const +{ + if (ui.windingCcw->isChecked()) + return BFCStatement::CertifyCCW; + + if (ui.windingCw->isChecked()) + return BFCStatement::CertifyCW; + + return BFCStatement::NoCertify; +} + +bool NewPartDialog::useCaLicense() const +{ + return ui.useCaLicense->isChecked(); +} + +QString NewPartDialog::author() const +{ + return ui.author->text(); +} + +QString NewPartDialog::title() const +{ + return ui.title->text(); +} + +void NewPartDialog::fillHeader (LDDocument* newdoc) const +{ + LDObjectList objs; + objs << new LDComment (title()); + objs << new LDComment ("Name: .dat"); + objs << new LDComment ("Author: " + author()); + objs << new LDComment ("!LDRAW_ORG Unofficial_Part"); + + if (useCaLicense()) + objs << new LDComment (CALicenseText); + + objs << new LDEmpty(); + objs << new LDBFC (getWinding()); + objs << new LDEmpty(); + newdoc->addObjects (objs); +} diff -r 8349552ee5e9 -r 7feaa1a3c438 src/dialogs/newpartdialog.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dialogs/newpartdialog.h Sat Aug 29 19:18:40 2015 +0300 @@ -0,0 +1,38 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013, 2014 Teemu 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 . + */ + +#pragma once +#include +#include "../main.h" +#include "../ldObject.h" + +class NewPartDialog : public QDialog +{ + Q_OBJECT +public: + NewPartDialog (QWidget *parent = nullptr); + + QString author() const; + void fillHeader (LDDocument* newdoc) const; + BFCStatement getWinding() const; + bool useCaLicense() const; + QString title() const; + +private: + class Ui_NewPart& ui; +}; diff -r 8349552ee5e9 -r 7feaa1a3c438 src/dialogs/newpartdialog.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dialogs/newpartdialog.ui Sat Aug 29 19:18:40 2015 +0300 @@ -0,0 +1,198 @@ + + + NewPart + + + + 0 + 0 + 491 + 254 + + + + New Part + + + + + + + + + + + + + :/icons/brick.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + + + + + + + + + Author: + + + + + + + Title: + + + + + + + + + + + + + BFC winding + + + + + + CCW + + + true + + + + + + + CW + + + + + + + None + + + + + + + + + + + + Use CA license + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + title + author + windingCcw + windingCw + windingNone + useCaLicense + + + + + + + buttonBox + accepted() + NewPart + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NewPart + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff -r 8349552ee5e9 -r 7feaa1a3c438 src/ldDocument.cpp --- a/src/ldDocument.cpp Sat Aug 29 18:45:48 2015 +0300 +++ b/src/ldDocument.cpp Sat Aug 29 19:18:40 2015 +0300 @@ -54,6 +54,7 @@ // ============================================================================= // LDDocument::LDDocument() : + m_history (new History), m_isImplicit (true), m_flags (0), m_verticesOutdated (true), @@ -62,7 +63,6 @@ { setSavePosition (-1); setTabIndex (-1); - m_history = new History; m_history->setDocument (this); m_needsReCache = true; g_allDocuments << this; diff -r 8349552ee5e9 -r 7feaa1a3c438 ui/newpart.ui --- a/ui/newpart.ui Sat Aug 29 18:45:48 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,191 +0,0 @@ - - - NewPartUI - - - - 0 - 0 - 491 - 233 - - - - New Part - - - - - - - - - - - - - :/icons/brick.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - - - - - - - - - - Author: - - - - - - - Title: - - - - - - - - - - - - - BFC winding - - - - - - CCW - - - true - - - - - - - CW - - - - - - - None - - - - - - - - - - - - Use CA license - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - - buttonBox - accepted() - NewPartUI - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - NewPartUI - reject() - - - 316 - 260 - - - 286 - 274 - - - - -