src/dialogs.cc

branch
projects
changeset 935
8d98ee0dc917
parent 930
ab77deb851fa
parent 934
be8128aff739
child 936
aee883858c90
equal deleted inserted replaced
930:ab77deb851fa 935:8d98ee0dc917
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 - 2015 Teemu 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 <QDialog>
20 #include <QLineEdit>
21 #include <QSpinBox>
22 #include <QDialogButtonBox>
23 #include <QFileDialog>
24 #include <QLabel>
25 #include <QPushButton>
26 #include <QBoxLayout>
27 #include <QGridLayout>
28 #include <QProgressBar>
29 #include <QCheckBox>
30 #include <QDesktopServices>
31 #include <QMessageBox>
32 #include <QUrl>
33 #include "dialogs.h"
34 #include "radioGroup.h"
35 #include "mainWindow.h"
36 #include "glRenderer.h"
37 #include "documentation.h"
38 #include "ldDocument.h"
39 #include "dialogs.h"
40 #include "ui_overlay.h"
41 #include "ui_ldrawpath.h"
42 #include "ui_openprogress.h"
43 #include "ui_extprogpath.h"
44 #include "ui_about.h"
45 #include "ui_bombbox.h"
46
47 extern const char* g_extProgPathFilter;
48 EXTERN_CFGENTRY (String, LDrawPath)
49
50 // =============================================================================
51 // =============================================================================
52 OverlayDialog::OverlayDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f)
53 {
54 ui = new Ui_OverlayUI;
55 ui->setupUi (this);
56
57 m_cameraArgs =
58 {
59 { ui->top, ETopCamera },
60 { ui->bottom, EBottomCamera },
61 { ui->front, EFrontCamera },
62 { ui->back, EBackCamera },
63 { ui->left, ELeftCamera },
64 { ui->right, ERightCamera }
65 };
66
67 ECamera cam = g_win->R()->camera();
68
69 if (cam == EFreeCamera)
70 cam = ETopCamera;
71
72 connect (ui->width, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged()));
73 connect (ui->height, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged()));
74 connect (ui->buttonBox, SIGNAL (helpRequested()), this, SLOT (slot_help()));
75 connect (ui->fileSearchButton, SIGNAL (clicked (bool)), this, SLOT (slot_fpath()));
76
77 slot_dimensionsChanged();
78 fillDefaults (cam);
79 }
80
81 // =============================================================================
82 // =============================================================================
83 OverlayDialog::~OverlayDialog()
84 {
85 delete ui;
86 }
87
88 // =============================================================================
89 // =============================================================================
90 void OverlayDialog::fillDefaults (int newcam)
91 {
92 LDGLOverlay& info = g_win->R()->getOverlay (newcam);
93 RadioDefault<int> (newcam, m_cameraArgs);
94
95 if (info.img != null)
96 {
97 ui->filename->setText (info.fname);
98 ui->originX->setValue (info.ox);
99 ui->originY->setValue (info.oy);
100 ui->width->setValue (info.lw);
101 ui->height->setValue (info.lh);
102 }
103 else
104 {
105 ui->filename->setText ("");
106 ui->originX->setValue (0);
107 ui->originY->setValue (0);
108 ui->width->setValue (0.0f);
109 ui->height->setValue (0.0f);
110 }
111 }
112
113 // =============================================================================
114 // =============================================================================
115 QString OverlayDialog::fpath() const
116 {
117 return ui->filename->text();
118 }
119
120 int OverlayDialog::ofsx() const
121 {
122 return ui->originX->value();
123 }
124
125 int OverlayDialog::ofsy() const
126 {
127 return ui->originY->value();
128 }
129
130 double OverlayDialog::lwidth() const
131 {
132 return ui->width->value();
133 }
134
135 double OverlayDialog::lheight() const
136 {
137 return ui->height->value();
138 }
139
140 int OverlayDialog::camera() const
141 {
142 return RadioSwitch<int> (ETopCamera, m_cameraArgs);
143 }
144
145 void OverlayDialog::slot_fpath()
146 {
147 ui->filename->setText (QFileDialog::getOpenFileName (null, "Overlay image"));
148 }
149
150 void OverlayDialog::slot_help()
151 {
152 showDocumentation (g_docs_overlays);
153 }
154
155 void OverlayDialog::slot_dimensionsChanged()
156 {
157 bool enable = (ui->width->value() != 0) or (ui->height->value() != 0);
158 ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (enable);
159 }
160
161 // =============================================================================
162 // =============================================================================
163 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f) :
164 QDialog (parent, f),
165 m_validDefault (validDefault)
166 {
167 ui = new Ui_LDPathUI;
168 ui->setupUi (this);
169 ui->status->setText ("---");
170
171 if (validDefault)
172 ui->heading->hide();
173 else
174 {
175 cancelButton()->setText ("Exit");
176 cancelButton()->setIcon (GetIcon ("exit"));
177 }
178
179 okButton()->setEnabled (false);
180
181 connect (ui->path, SIGNAL (textEdited (QString)), this, SLOT (slot_tryConfigure()));
182 connect (ui->searchButton, SIGNAL (clicked()), this, SLOT (slot_findPath()));
183 connect (ui->buttonBox, SIGNAL (rejected()), this, validDefault ? SLOT (reject()) : SLOT (slot_exit()));
184 connect (ui->buttonBox, SIGNAL (accepted()), this, SLOT (slot_accept()));
185
186 setPath (cfg::LDrawPath);
187
188 if (validDefault)
189 slot_tryConfigure();
190 }
191
192 // =============================================================================
193 // =============================================================================
194 LDrawPathDialog::~LDrawPathDialog()
195 {
196 delete ui;
197 }
198
199 QPushButton* LDrawPathDialog::okButton()
200 {
201 return ui->buttonBox->button (QDialogButtonBox::Ok);
202 }
203
204 QPushButton* LDrawPathDialog::cancelButton()
205 {
206 return ui->buttonBox->button (QDialogButtonBox::Cancel);
207 }
208
209 void LDrawPathDialog::setPath (QString path)
210 {
211 ui->path->setText (path);
212 }
213
214 QString LDrawPathDialog::filename() const
215 {
216 return ui->path->text();
217 }
218
219 // =============================================================================
220 // =============================================================================
221 void LDrawPathDialog::slot_findPath()
222 {
223 QString newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path");
224
225 if (not newpath.isEmpty())
226 {
227 setPath (newpath);
228 slot_tryConfigure();
229 }
230 }
231
232 // =============================================================================
233 // =============================================================================
234 void LDrawPathDialog::slot_exit()
235 {
236 Exit();
237 }
238
239 // =============================================================================
240 // =============================================================================
241 void LDrawPathDialog::slot_tryConfigure()
242 {
243 if (not LDPaths::tryConfigure (filename()))
244 {
245 ui->status->setText (format ("<span style=\"color:#700; \">%1</span>", LDPaths::getError()));
246 okButton()->setEnabled (false);
247 return;
248 }
249
250 ui->status->setText ("<span style=\"color: #270; \">OK!</span>");
251 okButton()->setEnabled (true);
252 }
253
254 // =============================================================================
255 // =============================================================================
256 void LDrawPathDialog::slot_accept()
257 {
258 Config::Save();
259 accept();
260 }
261
262 // =============================================================================
263 // =============================================================================
264 OpenProgressDialog::OpenProgressDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f)
265 {
266 ui = new Ui_OpenProgressUI;
267 ui->setupUi (this);
268 ui->progressText->setText ("Parsing...");
269 setNumLines (0);
270 m_progress = 0;
271 }
272
273 // =============================================================================
274 // =============================================================================
275 OpenProgressDialog::~OpenProgressDialog()
276 {
277 delete ui;
278 }
279
280 // =============================================================================
281 // =============================================================================
282 void OpenProgressDialog::setNumLines (int const& a)
283 {
284 m_numLines = a;
285 ui->progressBar->setRange (0, numLines());
286 updateValues();
287 }
288
289 // =============================================================================
290 // =============================================================================
291 void OpenProgressDialog::updateValues()
292 {
293 ui->progressText->setText (format ("Parsing... %1 / %2", progress(), numLines()));
294 ui->progressBar->setValue (progress());
295 }
296
297 // =============================================================================
298 // =============================================================================
299 void OpenProgressDialog::updateProgress (int progress)
300 {
301 setProgress (progress);
302 updateValues();
303 }
304
305 // =============================================================================
306 // =============================================================================
307 ExtProgPathPrompt::ExtProgPathPrompt (QString progName, QWidget* parent, Qt::WindowFlags f) :
308 QDialog (parent, f),
309 ui (new Ui_ExtProgPath)
310 {
311 ui->setupUi (this);
312 QString labelText = ui->m_label->text();
313 labelText.replace ("<PROGRAM>", progName);
314 ui->m_label->setText (labelText);
315 connect (ui->m_findPath, SIGNAL (clicked (bool)), this, SLOT (findPath()));
316 }
317
318 // =============================================================================
319 // =============================================================================
320 ExtProgPathPrompt::~ExtProgPathPrompt()
321 {
322 delete ui;
323 }
324
325 // =============================================================================
326 // =============================================================================
327 void ExtProgPathPrompt::findPath()
328 {
329 QString path = QFileDialog::getOpenFileName (null, "", "", g_extProgPathFilter);
330
331 if (not path.isEmpty())
332 ui->m_path->setText (path);
333 }
334
335 // =============================================================================
336 // =============================================================================
337 QString ExtProgPathPrompt::getPath() const
338 {
339 return ui->m_path->text();
340 }
341
342 // =============================================================================
343 // =============================================================================
344 AboutDialog::AboutDialog (QWidget* parent, Qt::WindowFlags f) :
345 QDialog (parent, f)
346 {
347 Ui::AboutUI ui;
348 ui.setupUi (this);
349 ui.versionInfo->setText (APPNAME " " + QString (FullVersionString()));
350
351 QPushButton* mailButton = new QPushButton;
352 mailButton->setText (tr ("Contact"));
353 mailButton->setIcon (GetIcon ("mail"));
354 ui.buttonBox->addButton (static_cast<QAbstractButton*> (mailButton), QDialogButtonBox::HelpRole);
355 connect (ui.buttonBox, SIGNAL (helpRequested()), this, SLOT (slot_mail()));
356
357 setWindowTitle (format (tr ("About %1"), APPNAME));
358 }
359
360 // =============================================================================
361 // =============================================================================
362 void AboutDialog::slot_mail()
363 {
364 QDesktopServices::openUrl (QUrl ("mailto:Teemu Piippo <arezey@gmail.com>?subject=LDForge"));
365 }
366
367 // =============================================================================
368 // =============================================================================
369 void DisplayBombBox (const QString& message)
370 {
371 QDialog dlg (g_win);
372 Ui_BombBox ui;
373
374 ui.setupUi (&dlg);
375 ui.m_text->setText (message);
376 ui.buttonBox->button (QDialogButtonBox::Close)->setText (QObject::tr ("Damn it"));
377 dlg.exec();
378 }

mercurial