| |
1 #include <QFileDialog> |
| |
2 #include <QPushButton> |
| |
3 #include <QLabel> |
| |
4 #include "ldrawpathdialog.h" |
| |
5 #include "ui_ldrawpathdialog.h" |
| |
6 #include "../mainWindow.h" |
| |
7 |
| |
8 LDrawPathDialog::LDrawPathDialog (const QString& defaultPath, bool validDefault, QWidget* parent, Qt::WindowFlags f) : |
| |
9 QDialog (parent, f), |
| |
10 m_hasValidDefault (validDefault), |
| |
11 ui (*new Ui_LDrawPathDialog) |
| |
12 { |
| |
13 ui.setupUi (this); |
| |
14 ui.status->setText ("---"); |
| |
15 |
| |
16 if (validDefault) |
| |
17 ui.heading->hide(); |
| |
18 else |
| |
19 { |
| |
20 cancelButton()->setText ("Exit"); |
| |
21 cancelButton()->setIcon (GetIcon ("exit")); |
| |
22 } |
| |
23 |
| |
24 okButton()->setEnabled (false); |
| |
25 |
| |
26 connect (ui.path, SIGNAL (textChanged (QString)), this, SIGNAL (pathChanged (QString))); |
| |
27 connect (ui.searchButton, SIGNAL (clicked()), this, SLOT (searchButtonClicked())); |
| |
28 connect (ui.buttonBox, SIGNAL (rejected()), this, validDefault ? SLOT (reject()) : SLOT (slot_exit())); |
| |
29 connect (ui.buttonBox, SIGNAL (accepted()), this, SLOT (slot_accept())); |
| |
30 setPath (defaultPath); |
| |
31 } |
| |
32 |
| |
33 LDrawPathDialog::~LDrawPathDialog() |
| |
34 { |
| |
35 delete &ui; |
| |
36 } |
| |
37 |
| |
38 QPushButton* LDrawPathDialog::okButton() |
| |
39 { |
| |
40 return ui.buttonBox->button (QDialogButtonBox::Ok); |
| |
41 } |
| |
42 |
| |
43 QPushButton* LDrawPathDialog::cancelButton() |
| |
44 { |
| |
45 return ui.buttonBox->button (QDialogButtonBox::Cancel); |
| |
46 } |
| |
47 |
| |
48 void LDrawPathDialog::setPath (QString path) |
| |
49 { |
| |
50 ui.path->setText (path); |
| |
51 } |
| |
52 |
| |
53 QString LDrawPathDialog::path() const |
| |
54 { |
| |
55 return ui.path->text(); |
| |
56 } |
| |
57 |
| |
58 void LDrawPathDialog::searchButtonClicked() |
| |
59 { |
| |
60 QString newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path"); |
| |
61 |
| |
62 if (not newpath.isEmpty()) |
| |
63 setPath (newpath); |
| |
64 } |
| |
65 |
| |
66 void LDrawPathDialog::slot_exit() |
| |
67 { |
| |
68 Exit(); |
| |
69 } |
| |
70 |
| |
71 void LDrawPathDialog::setStatusText (const QString& statusText, bool ok) |
| |
72 { |
| |
73 okButton()->setEnabled (ok); |
| |
74 |
| |
75 if (statusText.isEmpty() && ok == false) |
| |
76 ui.status->setText ("---"); |
| |
77 else |
| |
78 { |
| |
79 ui.status->setText (QString ("<span style=\"color: %1\">%2</span>") |
| |
80 .arg (ok ? "#700" : "#270") |
| |
81 .arg (statusText)); |
| |
82 } |
| |
83 } |
| |
84 |
| |
85 void LDrawPathDialog::slot_accept() |
| |
86 { |
| |
87 Config::Save(); |
| |
88 accept(); |
| |
89 } |