/* This file is part of moth. moth is a program for creating and editing textured 3D models. Copyright (C) 2004 Peter Uray. moth 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 2 of the License, or (at your option) any later version. moth 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 moth; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include MPreferencesDialog::MPreferencesDialog(void) : QDialog(0, "preferencesDialog", true, Qt::WStyle_DialogBorder | Qt::WStyle_Dialog | Qt::WStyle_StaysOnTop) { QGridLayout* gl; QGridLayout* gl2; resize(400, 100); setCaption("Preferences"); gl = new QGridLayout(this, 2, 1, 3); _tabWidget = new QTabWidget(this); gl->addMultiCellWidget(_tabWidget, 0, 0, 0, 1); _generalTab = new QWidget(this); _tabWidget->addTab(_generalTab, "General"); _gridandunitsTab = new QWidget(this); _tabWidget->addTab(_gridandunitsTab, "Grid / Units"); _cameraTab = new QWidget(this); _tabWidget->addTab(_cameraTab, "Camera"); // fill the general tab widget. gl2 = new QGridLayout(_generalTab, 3, 10, 3); gl2->addMultiCellWidget(new QLabel("Undo Steps:", _generalTab), 0, 0, 0, 3); _undoStepsBox = new QSpinBox(1, 100, 1, _generalTab); gl2->addMultiCellWidget(_undoStepsBox, 0, 0, 4, 9); // project location. gl2->addMultiCellWidget(new QLabel("Project Directory:", _generalTab), 1, 1, 0, 3); _projectLocationEdit = new QLineEdit(_generalTab); gl2->addMultiCellWidget(_projectLocationEdit, 1, 1, 4, 8); _projectLocationSelectButton = new QPushButton("...", _generalTab); connect(_projectLocationSelectButton, SIGNAL(released()), this, SLOT(onProjectLocationSelect())); gl2->addMultiCellWidget(_projectLocationSelectButton, 1, 1, 9, 9); gl2->setRowStretch(2, 100); // end general tab widget. // fill the grid / units tab widget. gl2 = new QGridLayout(_gridandunitsTab, 9, 6, 3); // grid position gl2->addMultiCellWidget(new QLabel("Grid Position:", _gridandunitsTab), 0, 0, 0, 2); _gridXEdit = new QLineEdit(_gridandunitsTab); _gridXEdit->setAlignment(AlignRight); _gridXEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _gridXEdit)); gl2->addWidget(_gridXEdit, 0, 3); _gridYEdit = new QLineEdit(_gridandunitsTab); _gridYEdit->setAlignment(AlignRight); _gridYEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _gridYEdit)); gl2->addWidget(_gridYEdit, 0, 4); _gridZEdit = new QLineEdit(_gridandunitsTab); _gridZEdit->setAlignment(AlignRight); _gridZEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _gridZEdit)); gl2->addWidget(_gridZEdit, 0, 5); // grid spacing gl2->addMultiCellWidget(new QLabel("Grid Spacing:", _gridandunitsTab), 1, 1, 0, 2); _gridDXEdit = new QLineEdit(_gridandunitsTab); _gridDXEdit->setAlignment(AlignRight); _gridDXEdit->setValidator(new QDoubleValidator(0.0, 9999999.0, 2, _gridDXEdit)); gl2->addWidget(_gridDXEdit, 1, 3); _gridDYEdit = new QLineEdit(_gridandunitsTab); _gridDYEdit->setAlignment(AlignRight); _gridDYEdit->setValidator(new QDoubleValidator(0.0, 9999999.0, 2, _gridDYEdit)); gl2->addWidget(_gridDYEdit, 1, 4); _gridDZEdit = new QLineEdit(_gridandunitsTab); _gridDZEdit->setAlignment(AlignRight); _gridDZEdit->setValidator(new QDoubleValidator(0.0, 9999999.0, 2, _gridDZEdit)); gl2->addWidget(_gridDZEdit, 1, 5); // snap spacing gl2->addMultiCellWidget(new QLabel("Snap Spacing:", _gridandunitsTab), 2, 2, 0, 2); _snapXEdit = new QLineEdit(_gridandunitsTab); _snapXEdit->setAlignment(AlignRight); _snapXEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _snapXEdit)); gl2->addWidget(_snapXEdit, 2, 3); _snapYEdit = new QLineEdit(_gridandunitsTab); _snapYEdit->setAlignment(AlignRight); _snapYEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _snapYEdit)); gl2->addWidget(_snapYEdit, 2, 4); _snapZEdit = new QLineEdit(_gridandunitsTab); _snapZEdit->setAlignment(AlignRight); _snapZEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _snapZEdit)); gl2->addWidget(_snapZEdit, 2, 5); // angle snap spacing gl2->addMultiCellWidget(new QLabel("Snap Angles:", _gridandunitsTab), 3, 3, 0, 2); _snapAngleXEdit = new QLineEdit(_gridandunitsTab); _snapAngleXEdit->setAlignment(AlignRight); _snapAngleXEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _snapXEdit)); gl2->addWidget(_snapAngleXEdit, 3, 3); _snapAngleYEdit = new QLineEdit(_gridandunitsTab); _snapAngleYEdit->setAlignment(AlignRight); _snapAngleYEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _snapYEdit)); gl2->addWidget(_snapAngleYEdit, 3, 4); _snapAngleZEdit = new QLineEdit(_gridandunitsTab); _snapAngleZEdit->setAlignment(AlignRight); _snapAngleZEdit->setValidator(new QDoubleValidator(-9999999.0, 9999999.0, 2, _snapZEdit)); gl2->addWidget(_snapAngleZEdit, 3, 5); // Grid display switches _displayXYBox = new QCheckBox("Show XY Grid", _gridandunitsTab); gl2->addMultiCellWidget(_displayXYBox, 4, 4, 0, 2); _displayYZBox = new QCheckBox("Show YZ Grid", _gridandunitsTab); gl2->addMultiCellWidget(_displayYZBox, 4, 4, 3, 5); _displayZXBox = new QCheckBox("Show ZX Grid", _gridandunitsTab); gl2->addMultiCellWidget(_displayZXBox, 5, 5, 0, 2); _displayAxesBox = new QCheckBox("Display Axes", _gridandunitsTab); gl2->addMultiCellWidget(_displayAxesBox, 5, 5, 3, 5); _snapBox = new QCheckBox("Snap Points", _gridandunitsTab); gl2->addMultiCellWidget(_snapBox, 6, 6, 0, 2); _snapAnglesBox = new QCheckBox("Snap Angles", _gridandunitsTab); gl2->addMultiCellWidget(_snapAnglesBox, 6, 6, 3, 5); // grid size gl2->addMultiCellWidget(new QLabel("Grid Size:", _gridandunitsTab), 7, 7, 0, 2); _sizeEdit = new QLineEdit(_gridandunitsTab); _sizeEdit->setAlignment(AlignRight); _sizeEdit->setValidator(new QDoubleValidator(1.0, 9999999.0, 2, _sizeEdit)); gl2->addMultiCellWidget(_sizeEdit, 7, 7, 3, 5); // texture grid size gl2->addMultiCellWidget(new QLabel("Texture Grid Size:", _gridandunitsTab), 8, 8, 0, 2); _texSizeEdit = new QLineEdit(_gridandunitsTab); _texSizeEdit->setAlignment(AlignRight); _texSizeEdit->setValidator(new QIntValidator(1, 1000, _texSizeEdit)); gl2->addMultiCellWidget(_texSizeEdit, 8, 8, 3, 5); // end grid / units tab widget. // fill the camera tab widget. gl2 = new QGridLayout(_cameraTab, 8, 2, 3); // opening angle. gl2->addWidget(new QLabel("Opening Angle:", _cameraTab), 0, 0); _angleEdit = new QLineEdit(_cameraTab); _angleEdit->setAlignment(AlignRight); _angleEdit->setValidator(new QDoubleValidator(5.0, 180.0, 2, _angleEdit)); gl2->addWidget(_angleEdit, 0, 1); // near clipping distance. gl2->addWidget(new QLabel("Near Clipping Distance:", _cameraTab), 1, 0); _ncdEdit = new QLineEdit(_cameraTab); _ncdEdit->setAlignment(AlignRight); _ncdEdit->setValidator(new QDoubleValidator(0.0, 1000000.0, 2, _ncdEdit)); gl2->addWidget(_ncdEdit, 1, 1); // far clipping distance. gl2->addWidget(new QLabel("Far Clipping Distance:", _cameraTab), 2, 0); _fcdEdit = new QLineEdit(_cameraTab); _fcdEdit->setAlignment(AlignRight); _fcdEdit->setValidator(new QDoubleValidator(0.0, 1000000.0, 2, _fcdEdit)); gl2->addWidget(_fcdEdit, 2, 1); // default radius. gl2->addWidget(new QLabel("Default Radius:", _cameraTab), 3, 0); _rDefaultEdit = new QLineEdit(_cameraTab); _rDefaultEdit->setAlignment(AlignRight); _rDefaultEdit->setValidator(new QDoubleValidator(0.01, 1000000.0, 2, _rDefaultEdit)); gl2->addWidget(_rDefaultEdit, 3, 1); // default phi. gl2->addWidget(new QLabel("Default Phi:", _cameraTab), 4, 0); _phiDefaultEdit = new QLineEdit(_cameraTab); _phiDefaultEdit->setAlignment(AlignRight); _phiDefaultEdit->setValidator(new QDoubleValidator(0.01, 1000000.0, 2, _phiDefaultEdit)); gl2->addWidget(_phiDefaultEdit, 4, 1); // default theta. gl2->addWidget(new QLabel("Default Theta:", _cameraTab), 5, 0); _thetaDefaultEdit = new QLineEdit(_cameraTab); _thetaDefaultEdit->setAlignment(AlignRight); _thetaDefaultEdit->setValidator(new QDoubleValidator(0.01, 1000000.0, 2, _thetaDefaultEdit)); gl2->addWidget(_thetaDefaultEdit, 5, 1); // end camera tab. _okButton = new QPushButton("OK", this); connect(_okButton, SIGNAL(released()), this, SLOT(onOKButtonPressed())); gl->addMultiCellWidget(_okButton, 1, 1, 0, 0); _cancelButton = new QPushButton("Cancel", this); connect(_cancelButton, SIGNAL(released()), this, SLOT(reject())); gl->addMultiCellWidget(_cancelButton, 1, 1, 1, 1); } MPreferencesDialog::~MPreferencesDialog(void) { } void MPreferencesDialog::show(void) { char buffer[80]; _undoStepsBox->setValue(MPreferences::get()->getUndoSteps()); _projectLocationEdit->setText(MPreferences::get()->getProjectLocation()); sprintf(buffer, "%8.3f", MPreferences::get()->getGridX()); _gridXEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getGridY()); _gridYEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getGridZ()); _gridZEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getGridDX()); _gridDXEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getGridDY()); _gridDYEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getGridDZ()); _gridDZEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getSnapX()); _snapXEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getSnapY()); _snapYEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getSnapZ()); _snapZEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getAngleSnapX()); _snapAngleXEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getAngleSnapY()); _snapAngleYEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getAngleSnapZ()); _snapAngleZEdit->setText(buffer); if(MPreferences::get()->getDisplayXY()) _displayXYBox->setChecked(true); else _displayXYBox->setChecked(false); if(MPreferences::get()->getDisplayYZ()) _displayYZBox->setChecked(true); else _displayYZBox->setChecked(false); if(MPreferences::get()->getDisplayZX()) _displayZXBox->setChecked(true); else _displayZXBox->setChecked(false); if(MPreferences::get()->getDisplayAxes()) _displayAxesBox->setChecked(true); else _displayAxesBox->setChecked(false); if(MPreferences::get()->getSnap()) _snapBox->setChecked(true); else _snapBox->setChecked(false); if(MPreferences::get()->getSnapAngles()) _snapAnglesBox->setChecked(true); else _snapAnglesBox->setChecked(false); sprintf(buffer, "%8.3f", MPreferences::get()->getSize()); _sizeEdit->setText(buffer); sprintf(buffer, "%i", MPreferences::get()->getTexSize()); _texSizeEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getCameraAngle()); _angleEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getNCD()); _ncdEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getFCD()); _fcdEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getRDefault()); _rDefaultEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getPhiDefault()); _phiDefaultEdit->setText(buffer); sprintf(buffer, "%8.3f", MPreferences::get()->getThetaDefault()); _thetaDefaultEdit->setText(buffer); _tabWidget->showPage(_gridandunitsTab); QDialog::show(); } void MPreferencesDialog::onProjectLocationSelect(void) { QString startDir; QString selDir; startDir = getenv("HOME"); selDir = QFileDialog::getExistingDirectory(startDir, this); if(selDir.isNull()) return; if((selDir[selDir.length() - 1] == '\\') || (selDir[selDir.length() - 1] == '/')) selDir.remove(selDir.length() - 1, selDir.length()); _projectLocationEdit->setText(selDir); } void MPreferencesDialog::onOKButtonPressed(void) { int intval; float x, y, z; // General tab sscanf(_undoStepsBox->text(), "%i", &intval); MPreferences::get()->setUndoSteps(intval); MPreferences::get()->setProjectLocation(_projectLocationEdit->text()); // Grid & units tab sscanf(_gridXEdit->text(), "%f", &x); sscanf(_gridYEdit->text(), "%f", &y); sscanf(_gridZEdit->text(), "%f", &z); MPreferences::get()->setGridPosition(x, y, z); sscanf(_gridDXEdit->text(), "%f", &x); sscanf(_gridDYEdit->text(), "%f", &y); sscanf(_gridDZEdit->text(), "%f", &z); MPreferences::get()->setGridDistances(x, y, z); sscanf(_snapXEdit->text(), "%f", &x); sscanf(_snapYEdit->text(), "%f", &y); sscanf(_snapZEdit->text(), "%f", &z); MPreferences::get()->setSnap(x, y, z); sscanf(_snapAngleXEdit->text(), "%f", &x); sscanf(_snapAngleYEdit->text(), "%f", &y); sscanf(_snapAngleZEdit->text(), "%f", &z); MPreferences::get()->setSnapAngles(x, y, z); MPreferences::get()->setDisplayXY(false); if(_displayXYBox->isChecked()) MPreferences::get()->setDisplayXY(true); MPreferences::get()->setDisplayYZ(false); if(_displayYZBox->isChecked()) MPreferences::get()->setDisplayYZ(true); MPreferences::get()->setDisplayZX(false); if(_displayZXBox->isChecked()) MPreferences::get()->setDisplayZX(true); MPreferences::get()->setDisplayAxes(false); if(_displayAxesBox->isChecked()) MPreferences::get()->setDisplayAxes(true); MPreferences::get()->setSnap(false); if(_snapBox->isChecked()) MPreferences::get()->setSnap(true); MPreferences::get()->setSnapAngles(false); if(_snapAnglesBox->isChecked()) MPreferences::get()->setSnapAngles(true); sscanf(_sizeEdit->text(), "%f", &x); MPreferences::get()->setSize(x); sscanf(_texSizeEdit->text(), "%i", &intval); MPreferences::get()->setTexSize(intval); // Camera tab. sscanf(_angleEdit->text(), "%f", &x); MPreferences::get()->setCameraAngle(x); sscanf(_ncdEdit->text(), "%f", &x); MPreferences::get()->setNCD(x); sscanf(_fcdEdit->text(), "%f", &x); MPreferences::get()->setFCD(x); sscanf(_rDefaultEdit->text(), "%f", &x); MPreferences::get()->setRDefault(x); sscanf(_phiDefaultEdit->text(), "%f", &x); MPreferences::get()->setPhiDefault(x); sscanf(_thetaDefaultEdit->text(), "%f", &x); MPreferences::get()->setThetaDefault(x); if(!MPreferences::get()->writePreferences()) { QMessageBox::critical(this, "Error", "The preferences file could not be written.", "OK"); } accept(); }