src/ldrawPathDialog.cpp

changeset 200
5583af82087e
parent 199
10dd5909a50e
child 201
4d620d819f4f
equal deleted inserted replaced
199:10dd5909a50e 200:5583af82087e
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>
20 #include <QPushButton>
21 #include <QDialogButtonBox>
22 #include <QFileDialog>
23 #include <QBoxLayout>
24 #include <QLabel>
25 #include "ldrawPathDialog.h"
26 #include "gui.h"
27 #include "file.h"
28
29 extern_cfg (str, io_ldpath);
30
31 // ========================================================================================================================================
32 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f)
33 : QDialog (parent, f), m_validDefault (validDefault)
34 {
35 QLabel* lb_description = null;
36 lb_resolution = new QLabel ("---");
37
38 if (validDefault == false)
39 lb_description = new QLabel ("Please input your LDraw directory");
40
41 QLabel* lb_path = new QLabel ("LDraw path:");
42 le_path = new QLineEdit;
43 btn_findPath = new QPushButton;
44 btn_findPath->setIcon (getIcon ("folder"));
45
46 btn_tryConfigure = new QPushButton ("Configure");
47 btn_tryConfigure->setIcon (getIcon ("settings"));
48
49 btn_cancel = new QPushButton;
50
51 if (validDefault == false) {
52 btn_cancel->setText ("Exit");
53 btn_cancel->setIcon (getIcon ("exit"));
54 } else {
55 btn_cancel->setText ("Cancel");
56 btn_cancel->setIcon (getIcon ("cancel"));
57 }
58
59 dbb_buttons = new QDialogButtonBox (QDialogButtonBox::Ok);
60 dbb_buttons->addButton (btn_tryConfigure, QDialogButtonBox::ActionRole);
61 dbb_buttons->addButton (btn_cancel, QDialogButtonBox::RejectRole);
62 okButton ()->setEnabled (false);
63
64 QHBoxLayout* inputLayout = new QHBoxLayout;
65 inputLayout->addWidget (lb_path);
66 inputLayout->addWidget (le_path);
67 inputLayout->addWidget (btn_findPath);
68
69 QVBoxLayout* mainLayout = new QVBoxLayout;
70
71 if (validDefault == false)
72 mainLayout->addWidget (lb_description);
73
74 mainLayout->addLayout (inputLayout);
75 mainLayout->addWidget (lb_resolution);
76 mainLayout->addWidget (dbb_buttons);
77 setLayout (mainLayout);
78
79 connect (le_path, SIGNAL (textEdited ()), this, SLOT (slot_tryConfigure ()));
80 connect (btn_findPath, SIGNAL (clicked ()), this, SLOT (slot_findPath ()));
81 connect (btn_tryConfigure, SIGNAL (clicked ()), this, SLOT (slot_tryConfigure ()));
82 connect (dbb_buttons, SIGNAL (accepted ()), this, SLOT (accept ()));
83 connect (dbb_buttons, SIGNAL (rejected ()), this, (validDefault) ? SLOT (reject ()) : SLOT (slot_exit ()));
84
85 setPath (io_ldpath);
86 if (validDefault)
87 slot_tryConfigure ();
88 }
89
90 // ========================================================================================================================================
91 QPushButton* LDrawPathDialog::okButton () {
92 return dbb_buttons->button (QDialogButtonBox::Ok);
93 }
94
95 // ========================================================================================================================================
96 void LDrawPathDialog::setPath (str path) {
97 le_path->setText (path);
98 }
99
100 // ========================================================================================================================================
101 str LDrawPathDialog::path () const {
102 return le_path->text ();
103 }
104
105 // ========================================================================================================================================
106 void LDrawPathDialog::slot_findPath () {
107 str newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path");
108
109 if (~newpath > 0 && newpath != path ()) {
110 setPath (newpath);
111 slot_tryConfigure ();
112 }
113 }
114
115
116 // ========================================================================================================================================
117 void LDrawPathDialog::slot_exit () {
118 exit (1);
119 }
120
121 // ========================================================================================================================================
122 void LDrawPathDialog::slot_tryConfigure () {
123 if (LDPaths::tryConfigure (path ()) == false) {
124 lb_resolution->setText (fmt ("<span style=\"color:red; font-weight: bold;\">%s</span>", LDPaths::getError().chars ()));
125 okButton ()->setEnabled (false);
126 return;
127 }
128
129 lb_resolution->setText ("<span style=\"color: #7A0; font-weight: bold;\">OK!</span>");
130 okButton ()->setEnabled (true);
131 }

mercurial