Sat, 29 Aug 2015 19:18:40 +0300
Refactor the new part dialog into a new class
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/actions.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs/ldrawpathdialog.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs/ldrawpathdialog.h | file | annotate | diff | comparison | revisions | |
src/dialogs/newpartdialog.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs/newpartdialog.h | file | annotate | diff | comparison | revisions | |
src/dialogs/newpartdialog.ui | file | annotate | diff | comparison | revisions | |
src/ldDocument.cpp | file | annotate | diff | comparison | revisions | |
ui/newpart.ui | file | annotate | diff | comparison | revisions |
--- 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
--- 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<LDComment> (ui.le_title->text()); - objs << LDSpawn<LDComment> ("Name: <untitled>.dat"); - objs << LDSpawn<LDComment> (format ("Author: %1", ui.le_author->text())); - objs << LDSpawn<LDComment> (format ("!LDRAW_ORG Unofficial_Part")); - - if (not license.isEmpty()) - objs << LDSpawn<LDComment> (license); - - objs << LDSpawn<LDEmpty>(); - objs << LDSpawn<LDBFC> (bfctype); - objs << LDSpawn<LDEmpty>(); - 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);
--- 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 <http://www.gnu.org/licenses/>. + */ + #include <QFileDialog> #include <QPushButton> #include <QLabel>
--- 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 <http://www.gnu.org/licenses/>. + */ + #pragma once #include <QDialog> #include "../main.h"
--- /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 <http://www.gnu.org/licenses/>. + */ + +#include <QLineEdit> +#include <QRadioButton> +#include <QCheckBox> +#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: <untitled>.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); +}
--- /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 <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include <QDialog> +#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; +};
--- /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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>NewPart</class> + <widget class="QDialog" name="NewPart"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>491</width> + <height>254</height> + </rect> + </property> + <property name="windowTitle"> + <string>New Part</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string/> + </property> + <property name="pixmap"> + <pixmap resource="../../ldforge.qrc">:/icons/brick.png</pixmap> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="1"> + <widget class="QLineEdit" name="author"> + <property name="placeholderText"> + <string/> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="title"> + <property name="placeholderText"> + <string/> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Author:</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Title:</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>BFC winding</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QRadioButton" name="windingCcw"> + <property name="text"> + <string>CCW</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="windingCw"> + <property name="text"> + <string>CW</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="windingNone"> + <property name="text"> + <string>None</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QCheckBox" name="useCaLicense"> + <property name="text"> + <string>Use CA license</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <tabstops> + <tabstop>title</tabstop> + <tabstop>author</tabstop> + <tabstop>windingCcw</tabstop> + <tabstop>windingCw</tabstop> + <tabstop>windingNone</tabstop> + <tabstop>useCaLicense</tabstop> + </tabstops> + <resources> + <include location="../../ldforge.qrc"/> + </resources> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>NewPart</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>NewPart</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>
--- 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;
--- 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 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>NewPartUI</class> - <widget class="QDialog" name="NewPartUI"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>491</width> - <height>233</height> - </rect> - </property> - <property name="windowTitle"> - <string>New Part</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string/> - </property> - <property name="pixmap"> - <pixmap resource="../ldforge.qrc">:/icons/brick.png</pixmap> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="1"> - <widget class="QLineEdit" name="le_author"> - <property name="placeholderText"> - <string/> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="le_title"> - <property name="placeholderText"> - <string/> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Author:</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Title:</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>BFC winding</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_4"> - <item> - <widget class="QRadioButton" name="rb_bfc_ccw"> - <property name="text"> - <string>CCW</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QRadioButton" name="rb_bfc_cw"> - <property name="text"> - <string>CW</string> - </property> - </widget> - </item> - <item> - <widget class="QRadioButton" name="rb_bfc_none"> - <property name="text"> - <string>None</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QCheckBox" name="caLicense"> - <property name="text"> - <string>Use CA license</string> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - </layout> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources> - <include location="../ldforge.qrc"/> - <include location="../../ldforge.qrc"/> - </resources> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>NewPartUI</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>NewPartUI</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui>