| 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 <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 "widgets.h" |
|
| 35 #include "gui.h" |
|
| 36 #include "gldraw.h" |
|
| 37 #include "docs.h" |
|
| 38 #include "document.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 #include "moc_dialogs.cpp" |
|
| 47 |
|
| 48 extern const char* g_extProgPathFilter; |
|
| 49 extern_cfg (String, io_ldpath); |
|
| 50 |
|
| 51 // ============================================================================= |
|
| 52 // ----------------------------------------------------------------------------- |
|
| 53 OverlayDialog::OverlayDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) |
|
| 54 { ui = new Ui_OverlayUI; |
|
| 55 ui->setupUi (this); |
|
| 56 |
|
| 57 m_cameraArgs = |
|
| 58 { { ui->top, GL::ETopCamera }, |
|
| 59 { ui->bottom, GL::EBottomCamera }, |
|
| 60 { ui->front, GL::EFrontCamera }, |
|
| 61 { ui->back, GL::EBackCamera }, |
|
| 62 { ui->left, GL::ELeftCamera }, |
|
| 63 { ui->right, GL::ERightCamera } |
|
| 64 }; |
|
| 65 |
|
| 66 GL::EFixedCamera cam = g_win->R()->camera(); |
|
| 67 |
|
| 68 if (cam == GL::EFreeCamera) |
|
| 69 cam = GL::ETopCamera; |
|
| 70 |
|
| 71 connect (ui->width, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged())); |
|
| 72 connect (ui->height, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged())); |
|
| 73 connect (ui->buttonBox, SIGNAL (helpRequested()), this, SLOT (slot_help())); |
|
| 74 connect (ui->fileSearchButton, SIGNAL (clicked (bool)), this, SLOT (slot_fpath())); |
|
| 75 |
|
| 76 slot_dimensionsChanged(); |
|
| 77 fillDefaults (cam); |
|
| 78 } |
|
| 79 |
|
| 80 // ============================================================================= |
|
| 81 // ----------------------------------------------------------------------------- |
|
| 82 OverlayDialog::~OverlayDialog() |
|
| 83 { delete ui; |
|
| 84 } |
|
| 85 |
|
| 86 // ============================================================================= |
|
| 87 // ----------------------------------------------------------------------------- |
|
| 88 void OverlayDialog::fillDefaults (int newcam) |
|
| 89 { LDGLOverlay& info = g_win->R()->getOverlay (newcam); |
|
| 90 radioDefault<int> (newcam, m_cameraArgs); |
|
| 91 |
|
| 92 if (info.img != null) |
|
| 93 { ui->filename->setText (info.fname); |
|
| 94 ui->originX->setValue (info.ox); |
|
| 95 ui->originY->setValue (info.oy); |
|
| 96 ui->width->setValue (info.lw); |
|
| 97 ui->height->setValue (info.lh); |
|
| 98 } |
|
| 99 else |
|
| 100 { ui->filename->setText (""); |
|
| 101 ui->originX->setValue (0); |
|
| 102 ui->originY->setValue (0); |
|
| 103 ui->width->setValue (0.0f); |
|
| 104 ui->height->setValue (0.0f); |
|
| 105 } |
|
| 106 } |
|
| 107 |
|
| 108 // ============================================================================= |
|
| 109 // ----------------------------------------------------------------------------- |
|
| 110 str OverlayDialog::fpath() const |
|
| 111 { return ui->filename->text(); |
|
| 112 } |
|
| 113 |
|
| 114 int OverlayDialog::ofsx() const |
|
| 115 { return ui->originX->value(); |
|
| 116 } |
|
| 117 |
|
| 118 int OverlayDialog::ofsy() const |
|
| 119 { return ui->originY->value(); |
|
| 120 } |
|
| 121 |
|
| 122 double OverlayDialog::lwidth() const |
|
| 123 { return ui->width->value(); |
|
| 124 } |
|
| 125 |
|
| 126 double OverlayDialog::lheight() const |
|
| 127 { return ui->height->value(); |
|
| 128 } |
|
| 129 |
|
| 130 int OverlayDialog::camera() const |
|
| 131 { return radioSwitch<int> (GL::ETopCamera, m_cameraArgs); |
|
| 132 } |
|
| 133 |
|
| 134 void OverlayDialog::slot_fpath() |
|
| 135 { ui->filename->setText (QFileDialog::getOpenFileName (null, "Overlay image")); |
|
| 136 } |
|
| 137 |
|
| 138 void OverlayDialog::slot_help() |
|
| 139 { showDocumentation (g_docs_overlays); |
|
| 140 } |
|
| 141 |
|
| 142 void OverlayDialog::slot_dimensionsChanged() |
|
| 143 { bool enable = (ui->width->value() != 0) || (ui->height->value() != 0); |
|
| 144 ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (enable); |
|
| 145 } |
|
| 146 |
|
| 147 // ============================================================================= |
|
| 148 // ----------------------------------------------------------------------------- |
|
| 149 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f) : |
|
| 150 QDialog (parent, f), |
|
| 151 m_validDefault (validDefault) |
|
| 152 { ui = new Ui_LDPathUI; |
|
| 153 ui->setupUi (this); |
|
| 154 ui->status->setText ("---"); |
|
| 155 |
|
| 156 if (validDefault) |
|
| 157 ui->heading->hide(); |
|
| 158 else |
|
| 159 { cancelButton()->setText ("Exit"); |
|
| 160 cancelButton()->setIcon (getIcon ("exit")); |
|
| 161 } |
|
| 162 |
|
| 163 okButton()->setEnabled (false); |
|
| 164 |
|
| 165 connect (ui->path, SIGNAL (textEdited (QString)), this, SLOT (slot_tryConfigure())); |
|
| 166 connect (ui->searchButton, SIGNAL (clicked()), this, SLOT (slot_findPath())); |
|
| 167 connect (ui->buttonBox, SIGNAL (rejected()), this, validDefault ? SLOT (reject()) : SLOT (slot_exit())); |
|
| 168 connect (ui->buttonBox, SIGNAL (accepted()), this, SLOT (slot_accept())); |
|
| 169 |
|
| 170 setPath (io_ldpath); |
|
| 171 |
|
| 172 if (validDefault) |
|
| 173 slot_tryConfigure(); |
|
| 174 } |
|
| 175 |
|
| 176 // ============================================================================= |
|
| 177 // ----------------------------------------------------------------------------- |
|
| 178 LDrawPathDialog::~LDrawPathDialog() |
|
| 179 { delete ui; |
|
| 180 } |
|
| 181 |
|
| 182 QPushButton* LDrawPathDialog::okButton() |
|
| 183 { return ui->buttonBox->button (QDialogButtonBox::Ok); |
|
| 184 } |
|
| 185 |
|
| 186 QPushButton* LDrawPathDialog::cancelButton() |
|
| 187 { return ui->buttonBox->button (QDialogButtonBox::Cancel); |
|
| 188 } |
|
| 189 |
|
| 190 void LDrawPathDialog::setPath (str path) |
|
| 191 { ui->path->setText (path); |
|
| 192 } |
|
| 193 |
|
| 194 str LDrawPathDialog::filename() const |
|
| 195 { return ui->path->text(); |
|
| 196 } |
|
| 197 |
|
| 198 // ============================================================================= |
|
| 199 // ----------------------------------------------------------------------------- |
|
| 200 void LDrawPathDialog::slot_findPath() |
|
| 201 { str newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path"); |
|
| 202 |
|
| 203 if (newpath.length() > 0 && newpath != filename()) |
|
| 204 { setPath (newpath); |
|
| 205 slot_tryConfigure(); |
|
| 206 } |
|
| 207 } |
|
| 208 |
|
| 209 // ============================================================================= |
|
| 210 // ----------------------------------------------------------------------------- |
|
| 211 void LDrawPathDialog::slot_exit() |
|
| 212 { exit (0); |
|
| 213 } |
|
| 214 |
|
| 215 // ============================================================================= |
|
| 216 // ----------------------------------------------------------------------------- |
|
| 217 void LDrawPathDialog::slot_tryConfigure() |
|
| 218 { if (LDPaths::tryConfigure (filename()) == false) |
|
| 219 { ui->status->setText (fmt ("<span style=\"color:#700; \">%1</span>", LDPaths::getError())); |
|
| 220 okButton()->setEnabled (false); |
|
| 221 return; |
|
| 222 } |
|
| 223 |
|
| 224 ui->status->setText ("<span style=\"color: #270; \">OK!</span>"); |
|
| 225 okButton()->setEnabled (true); |
|
| 226 } |
|
| 227 |
|
| 228 // ============================================================================= |
|
| 229 // ----------------------------------------------------------------------------- |
|
| 230 void LDrawPathDialog::slot_accept() |
|
| 231 { Config::save(); |
|
| 232 accept(); |
|
| 233 } |
|
| 234 |
|
| 235 // ============================================================================= |
|
| 236 // ----------------------------------------------------------------------------- |
|
| 237 OpenProgressDialog::OpenProgressDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) |
|
| 238 { ui = new Ui_OpenProgressUI; |
|
| 239 ui->setupUi (this); |
|
| 240 ui->progressText->setText ("Parsing..."); |
|
| 241 setNumLines (0); |
|
| 242 m_Progress = 0; |
|
| 243 } |
|
| 244 |
|
| 245 // ============================================================================= |
|
| 246 // ----------------------------------------------------------------------------- |
|
| 247 OpenProgressDialog::~OpenProgressDialog() |
|
| 248 { delete ui; |
|
| 249 } |
|
| 250 |
|
| 251 // ============================================================================= |
|
| 252 // ----------------------------------------------------------------------------- |
|
| 253 void OpenProgressDialog::setNumLines (int const& a) |
|
| 254 { m_NumLines = a; |
|
| 255 ui->progressBar->setRange (0, getNumLines()); |
|
| 256 updateValues(); |
|
| 257 } |
|
| 258 |
|
| 259 // ============================================================================= |
|
| 260 // ----------------------------------------------------------------------------- |
|
| 261 void OpenProgressDialog::updateValues() |
|
| 262 { ui->progressText->setText (fmt ("Parsing... %1 / %2", getProgress(), getNumLines())); |
|
| 263 ui->progressBar->setValue (getProgress()); |
|
| 264 } |
|
| 265 |
|
| 266 // ============================================================================= |
|
| 267 // ----------------------------------------------------------------------------- |
|
| 268 void OpenProgressDialog::updateProgress (int progress) |
|
| 269 { setProgress (progress); |
|
| 270 updateValues(); |
|
| 271 } |
|
| 272 |
|
| 273 // ============================================================================= |
|
| 274 // ----------------------------------------------------------------------------- |
|
| 275 ExtProgPathPrompt::ExtProgPathPrompt (str progName, QWidget* parent, Qt::WindowFlags f) : |
|
| 276 QDialog (parent, f), |
|
| 277 ui (new Ui_ExtProgPath) |
|
| 278 { |
|
| 279 ui->setupUi (this); |
|
| 280 str labelText = ui->m_label->text(); |
|
| 281 labelText.replace ("<PROGRAM>", progName); |
|
| 282 ui->m_label->setText (labelText); |
|
| 283 connect (ui->m_findPath, SIGNAL (clicked (bool)), this, SLOT (findPath())); |
|
| 284 } |
|
| 285 |
|
| 286 // ============================================================================= |
|
| 287 // ----------------------------------------------------------------------------- |
|
| 288 ExtProgPathPrompt::~ExtProgPathPrompt() |
|
| 289 { delete ui; |
|
| 290 } |
|
| 291 |
|
| 292 // ============================================================================= |
|
| 293 // ----------------------------------------------------------------------------- |
|
| 294 void ExtProgPathPrompt::findPath() |
|
| 295 { str path = QFileDialog::getOpenFileName (null, "", "", g_extProgPathFilter); |
|
| 296 |
|
| 297 if (!path.isEmpty()) |
|
| 298 ui->m_path->setText (path); |
|
| 299 } |
|
| 300 |
|
| 301 // ============================================================================= |
|
| 302 // ----------------------------------------------------------------------------- |
|
| 303 str ExtProgPathPrompt::getPath() const |
|
| 304 { return ui->m_path->text(); |
|
| 305 } |
|
| 306 |
|
| 307 // ============================================================================= |
|
| 308 // ----------------------------------------------------------------------------- |
|
| 309 AboutDialog::AboutDialog (QWidget* parent, Qt::WindowFlags f) : |
|
| 310 QDialog (parent, f) |
|
| 311 { Ui::AboutUI ui; |
|
| 312 ui.setupUi (this); |
|
| 313 ui.versionInfo->setText (fmt (tr ("LDForge %1"), fullVersionString())); |
|
| 314 |
|
| 315 QPushButton* mailButton = new QPushButton; |
|
| 316 mailButton->setText ("Contact"); |
|
| 317 mailButton->setIcon (getIcon ("mail")); |
|
| 318 ui.buttonBox->addButton (static_cast<QAbstractButton*> (mailButton), QDialogButtonBox::HelpRole); |
|
| 319 connect (ui.buttonBox, SIGNAL (helpRequested()), this, SLOT (slot_mail())); |
|
| 320 |
|
| 321 setWindowTitle ("About " APPNAME); |
|
| 322 } |
|
| 323 |
|
| 324 // ============================================================================= |
|
| 325 // ----------------------------------------------------------------------------- |
|
| 326 void AboutDialog::slot_mail() |
|
| 327 { QDesktopServices::openUrl (QUrl ("mailto:Santeri Piippo <slatenails64@gmail.com>?subject=LDForge")); |
|
| 328 } |
|
| 329 |
|
| 330 // ============================================================================= |
|
| 331 // ----------------------------------------------------------------------------- |
|
| 332 void bombBox (const str& message) |
|
| 333 { QDialog dlg (g_win); |
|
| 334 Ui_BombBox ui; |
|
| 335 |
|
| 336 ui.setupUi (&dlg); |
|
| 337 ui.m_text->setText (message); |
|
| 338 ui.buttonBox->button (QDialogButtonBox::Close)->setText (QObject::tr ("Damn it")); |
|
| 339 dlg.exec(); |
|
| 340 } |
|