src/dialogs/ldrawpathdialog.cpp

Sun, 29 Jan 2017 15:18:40 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 29 Jan 2017 15:18:40 +0200
changeset 1074
a62f810ca26f
parent 1072
9ce9496427f2
child 1157
1d6d244bdabd
permissions
-rw-r--r--

Made the quad→triangles use emplacement. However, now it crashes because of problems in the underlying system (the LDObject constructor shouldn't do anything in regard to the model!)

954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
1 /*
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
2 * LDForge: LDraw parts authoring CAD
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1022
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
954
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
4 *
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
5 * This program is free software: you can redistribute it and/or modify
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
6 * it under the terms of the GNU General Public License as published by
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
8 * (at your option) any later version.
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
9 *
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
10 * This program is distributed in the hope that it will be useful,
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
13 * GNU General Public License for more details.
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
14 *
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
15 * You should have received a copy of the GNU General Public License
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
17 */
7feaa1a3c438 Refactor the new part dialog into a new class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
18
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QFileDialog>
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QPushButton>
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QLabel>
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "ldrawpathdialog.h"
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "ui_ldrawpathdialog.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 954
diff changeset
24 #include "../mainwindow.h"
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LDrawPathDialog::LDrawPathDialog (const QString& defaultPath, bool validDefault, QWidget* parent, Qt::WindowFlags f) :
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 QDialog (parent, f),
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 m_hasValidDefault (validDefault),
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 ui (*new Ui_LDrawPathDialog)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 ui.setupUi (this);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 ui.status->setText ("---");
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 if (validDefault)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 ui.heading->hide();
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 else
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 cancelButton()->setText ("Exit");
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 cancelButton()->setIcon (GetIcon ("exit"));
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 okButton()->setEnabled (false);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 connect (ui.path, SIGNAL (textChanged (QString)), this, SIGNAL (pathChanged (QString)));
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 connect (ui.searchButton, SIGNAL (clicked()), this, SLOT (searchButtonClicked()));
987
91281e39c50c Removed the exiting hacks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
46 connect (ui.buttonBox, SIGNAL (rejected()), this, SLOT (reject()));
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
47 connect (ui.buttonBox, SIGNAL (accepted()), this, SLOT (accept()));
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 setPath (defaultPath);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 LDrawPathDialog::~LDrawPathDialog()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 delete &ui;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 QPushButton* LDrawPathDialog::okButton()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 return ui.buttonBox->button (QDialogButtonBox::Ok);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 QPushButton* LDrawPathDialog::cancelButton()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 return ui.buttonBox->button (QDialogButtonBox::Cancel);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 void LDrawPathDialog::setPath (QString path)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 ui.path->setText (path);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 QString LDrawPathDialog::path() const
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 return ui.path->text();
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 void LDrawPathDialog::searchButtonClicked()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 QString newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path");
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 if (not newpath.isEmpty())
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 setPath (newpath);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 void LDrawPathDialog::setStatusText (const QString& statusText, bool ok)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 okButton()->setEnabled (ok);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
1022
a7f8ce5aa858 Use a better gcd algorithm, some style fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
88 if (statusText.isEmpty() and not ok)
a7f8ce5aa858 Use a better gcd algorithm, some style fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
89 {
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 ui.status->setText ("---");
1022
a7f8ce5aa858 Use a better gcd algorithm, some style fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
91 }
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 else
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 ui.status->setText (QString ("<span style=\"color: %1\">%2</span>")
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
95 .arg (ok ? "#270" : "#700")
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 .arg (statusText));
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }

mercurial