zz_ldrawPathDialog.cpp

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

mercurial