Tue, 19 Mar 2013 21:52:38 +0200
Begin work on dialogs for adding objects. Comments functional!
/* * LDForge: LDraw parts authoring CAD * Copyright (C) 2013 Santeri `arezey` Piippo * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "common.h" #include "zz_configDialog.h" #include "file.h" #include <qgridlayout.h> #include <qfiledialog.h> #include <qcolordialog.h> ConfigDialog* g_ConfigDialog = nullptr; // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ConfigDialog::ConfigDialog (ForgeWindow* parent) : QDialog (parent) { g_ConfigDialog = this; qLDrawPath = new QLineEdit; qLDrawPath->setText (io_ldpath.value.chars()); qLDrawPathLabel = new QLabel ("LDraw path:"); qLDrawPathFindButton = new QPushButton; qLDrawPathFindButton->setIcon (QIcon ("icons/folder.png")); connect (qLDrawPathFindButton, SIGNAL (clicked ()), this, SLOT (slot_findLDrawPath ())); qGLBackgroundLabel = new QLabel ("Background color:"); qGLBackgroundButton = new QPushButton; setButtonBackground (qGLBackgroundButton, gl_bgcolor.value); connect (qGLBackgroundButton, SIGNAL (clicked ()), this, SLOT (slot_setGLBackground ())); qGLForegroundLabel = new QLabel ("Foreground color:"); qGLForegroundButton = new QPushButton; setButtonBackground (qGLForegroundButton, gl_maincolor.value); connect (qGLForegroundButton, SIGNAL (clicked ()), this, SLOT (slot_setGLForeground ())); IMPLEMENT_DIALOG_BUTTONS QGridLayout* layout = new QGridLayout; layout->addWidget (qLDrawPathLabel, 0, 0); layout->addWidget (qLDrawPath, 0, 1, 1, 2); layout->addWidget (qLDrawPathFindButton, 0, 3); layout->addWidget (qGLBackgroundLabel, 1, 0); layout->addWidget (qGLBackgroundButton, 1, 1); layout->addWidget (qGLForegroundLabel, 1, 2); layout->addWidget (qGLForegroundButton, 1, 3); layout->addWidget (qButtons, 2, 2, 1, 2); setLayout (layout); setWindowTitle (APPNAME_DISPLAY " - editing settings"); setWindowIcon (QIcon ("icons/settings.png")); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ConfigDialog::~ConfigDialog() { g_ConfigDialog = nullptr; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ConfigDialog::slot_findLDrawPath () { str zDir = QFileDialog::getExistingDirectory (this, "Choose LDraw directory", qLDrawPath->text()); if (~zDir) qLDrawPath->setText (zDir.chars()); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ConfigDialog::pickColor (strconfig& cfg, QPushButton* qButton) { QColorDialog dlg (QColor (cfg.value.chars())); dlg.setWindowIcon (QIcon ("icons/colorselect.png")); if (dlg.exec ()) { uchar r = dlg.currentColor ().red (), g = dlg.currentColor ().green (), b = dlg.currentColor ().blue (); cfg.value.format ("#%.2X%.2X%.2X", r, g, b); setButtonBackground (qButton, cfg.value); } } void ConfigDialog::slot_setGLBackground () { pickColor (gl_bgcolor, qGLBackgroundButton); } void ConfigDialog::slot_setGLForeground () { pickColor (gl_maincolor, qGLForegroundButton); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ConfigDialog::setButtonBackground (QPushButton* qButton, str zValue) { qButton->setIcon (QIcon ("icons/colorselect.png")); qButton->setAutoFillBackground (true); qButton->setStyleSheet ( str::mkfmt ("background-color: %s", zValue.chars()).chars() ); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ConfigDialog::staticDialog (ForgeWindow* window) { ConfigDialog dlg (window); if (dlg.exec ()) { io_ldpath = dlg.qLDrawPath->text(); // Save the config config::save (); // Reload all subfiles reloadAllSubfiles (); window->R->setBackground (); } }