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