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