zz_ldrawPathDialog.cpp

Wed, 08 May 2013 03:53:45 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 08 May 2013 03:53:45 +0300
changeset 179
f98391b179ab
child 180
16306e69a895
permissions
-rw-r--r--

Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...

179
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <qlineedit.h>
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <qpushbutton.h>
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <qdialogbuttonbox.h>
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QFileDialog>
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "zz_ldrawPathDialog.h"
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "gui.h"
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "file.h"
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 // ========================================================================================================================================
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 LDrawPathDialog::LDrawPathDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 lb_resolution = new QLabel ("---");
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 QLabel* lb_description = new QLabel ("Please input your LDraw directory");
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 QLabel* lb_path = new QLabel ("LDraw path:");
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 le_path = new QLineEdit;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 btn_findPath = new QPushButton;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 btn_findPath->setIcon (getIcon ("folder"));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 btn_tryConfigure = new QPushButton ("Configure");
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 btn_tryConfigure->setIcon (getIcon ("settings"));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 btn_exit = new QPushButton ("Exit");
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 btn_exit->setIcon (getIcon ("exit"));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 dbb_buttons = new QDialogButtonBox (QDialogButtonBox::Ok);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 dbb_buttons->addButton (btn_tryConfigure, QDialogButtonBox::ApplyRole);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 dbb_buttons->addButton (btn_exit, QDialogButtonBox::RejectRole);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 okButton ()->setEnabled (false);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 QHBoxLayout* inputLayout = new QHBoxLayout;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 inputLayout->addWidget (lb_path);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 inputLayout->addWidget (le_path);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 inputLayout->addWidget (btn_findPath);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 QVBoxLayout* mainLayout = new QVBoxLayout;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 mainLayout->addWidget (lb_description);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 mainLayout->addLayout (inputLayout);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 mainLayout->addWidget (lb_resolution);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 mainLayout->addWidget (dbb_buttons);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 setLayout (mainLayout);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 connect (btn_findPath, SIGNAL (clicked ()), this, SLOT (slot_findPath ()));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 connect (btn_tryConfigure, SIGNAL (clicked ()), this, SLOT (slot_tryConfigure ()));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 connect (dbb_buttons, SIGNAL (accepted ()), this, SLOT (accept ()));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 connect (dbb_buttons, SIGNAL (rejected ()), this, SLOT (slot_exit ()));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 // ========================================================================================================================================
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 QPushButton* LDrawPathDialog::okButton () {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 return dbb_buttons->button (QDialogButtonBox::Ok);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 // ========================================================================================================================================
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 void LDrawPathDialog::setPath (str path) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 le_path->setText (path);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 // ========================================================================================================================================
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 str LDrawPathDialog::path () const {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 return le_path->text ();
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 // ========================================================================================================================================
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 void LDrawPathDialog::slot_findPath () {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 str newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path");
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 if (~newpath > 0 && newpath != path ()) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 setPath (newpath);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 slot_tryConfigure ();
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 // ========================================================================================================================================
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 void LDrawPathDialog::slot_exit () {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 exit (1);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 // ========================================================================================================================================
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 void LDrawPathDialog::slot_tryConfigure () {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 if (LDPaths::tryConfigure (path ()) == false) {
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 lb_resolution->setText (fmt ("<span style=\"color:red; font-weight: bold;\">%s</span>", LDPaths::getError().chars ()));
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 okButton ()->setEnabled (false);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 return;
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 }
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 lb_resolution->setText ("<span style=\"color: #7A0; font-weight: bold;\">OK!</span>");
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 okButton ()->setEnabled (true);
f98391b179ab Added a dialog for inquering the user's LDraw directory, not having it set leads to crashing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 }

mercurial