src/dialogs/ldrawpathdialog.cpp

Wed, 10 Jan 2018 22:54:09 +0200

author
Santeri Piippo
date
Wed, 10 Jan 2018 22:54:09 +0200
changeset 1226
d1199d965235
parent 1222
34def2630300
permissions
-rw-r--r--

drop Qt4 support

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
1222
34def2630300 happy new year 2018
Santeri Piippo
parents: 1217
diff changeset
3 * Copyright (C) 2013 - 2018 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
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
26 LDrawPathDialog::LDrawPathDialog(const QString& defaultPath, bool validDefault, QWidget* parent, Qt::WindowFlags f) :
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
27 QDialog(parent, f),
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
28 m_hasValidDefault(validDefault),
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
29 ui(*new Ui_LDrawPathDialog)
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
31 ui.setupUi(this);
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
32 ui.status->setText("---");
953
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 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
38 cancelButton()->setText("Exit");
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
39 cancelButton()->setIcon(GetIcon("exit"));
953
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
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
42 okButton()->setEnabled(false);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
44 connect(ui.path, SIGNAL(textChanged(QString)), this, SIGNAL(pathChanged(QString)));
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
45 connect(ui.searchButton, SIGNAL(clicked()), this, SLOT(searchButtonClicked()));
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
46 connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
47 connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
48 setPath(defaultPath);
953
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 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
58 return ui.buttonBox->button(QDialogButtonBox::Ok);
953
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 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
63 return ui.buttonBox->button(QDialogButtonBox::Cancel);
953
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
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
66 void LDrawPathDialog::setPath(QString path)
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
68 ui.path->setText(path);
953
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 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
78 QString newpath = QFileDialog::getExistingDirectory(this, "Find LDraw Path");
953
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())
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
81 setPath(newpath);
953
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
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
84 void LDrawPathDialog::setStatusText(const QString& statusText, bool ok)
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
86 okButton()->setEnabled(ok);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 if (statusText.isEmpty() && ok == false)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
89 ui.status->setText("---");
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 else
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
92 ui.status->setText(QString("<span style=\"color: %1\">%2</span>")
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
93 .arg(ok ? "#270" : "#700")
314e12e23c3a fix paren style
Santeri Piippo
parents: 999
diff changeset
94 .arg(statusText));
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 }

mercurial