2017-04-12 12:31:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file preferencespatternpage.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 12 4, 2017
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2017-04-12 12:31:11 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2017 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2017-04-12 12:31:11 +02:00
|
|
|
**
|
|
|
|
** Valentina 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.
|
|
|
|
**
|
|
|
|
** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "preferencespatternpage.h"
|
|
|
|
#include "ui_preferencespatternpage.h"
|
|
|
|
#include "../../core/vapplication.h"
|
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
2017-08-19 18:10:57 +02:00
|
|
|
#include "../dialogdatetimeformats.h"
|
2017-08-30 06:26:18 +02:00
|
|
|
#include "../dialogknownmaterials.h"
|
2021-01-23 19:27:51 +01:00
|
|
|
#include "../vmisc/vsettings.h"
|
2017-04-12 12:31:11 +02:00
|
|
|
|
|
|
|
#include <QMessageBox>
|
2017-08-19 18:10:57 +02:00
|
|
|
#include <QDate>
|
|
|
|
#include <QTime>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
QStringList ComboBoxAllStrings(QComboBox *combo)
|
|
|
|
{
|
|
|
|
SCASSERT(combo != nullptr)
|
|
|
|
|
|
|
|
QStringList itemsInComboBox;
|
|
|
|
for (int index = 0; index < combo->count(); ++index)
|
|
|
|
{
|
|
|
|
itemsInComboBox << combo->itemText(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemsInComboBox;
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 12:31:11 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PreferencesPatternPage::PreferencesPatternPage(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
2017-08-30 06:26:18 +02:00
|
|
|
ui(new Ui::PreferencesPatternPage),
|
2018-02-06 18:30:27 +01:00
|
|
|
m_knownMaterials(),
|
|
|
|
m_oldLineUnit(Unit::Mm)
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2018-05-18 12:51:35 +02:00
|
|
|
RetranslateUi();
|
2017-08-30 06:26:18 +02:00
|
|
|
|
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
ui->graphOutputCheck->setChecked(settings->GetGraphicalOutput());
|
2018-03-10 15:39:37 +01:00
|
|
|
ui->checkBoxOpenGLRender->setChecked(settings->IsOpenGLRender());
|
2017-10-11 12:51:06 +02:00
|
|
|
ui->doubleSpinBoxCurveApproximation->setValue(settings->GetCurveApproximationScale());
|
|
|
|
ui->doubleSpinBoxCurveApproximation->setMinimum(minCurveApproximationScale);
|
|
|
|
ui->doubleSpinBoxCurveApproximation->setMaximum(maxCurveApproximationScale);
|
2017-08-30 06:26:18 +02:00
|
|
|
ui->undoCount->setValue(settings->GetUndoCount());
|
2017-04-12 12:31:11 +02:00
|
|
|
|
2018-02-06 18:30:27 +01:00
|
|
|
//----------------------- Unit setup
|
2018-05-18 12:51:35 +02:00
|
|
|
// set default unit
|
|
|
|
const Unit defUnit = QLocale().measurementSystem() == QLocale::MetricSystem ? Unit::Mm : Unit::Inch;
|
|
|
|
const qint32 indexUnit = ui->comboBoxLineWidthUnit->findData(static_cast<int>(defUnit));
|
|
|
|
if (indexUnit != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxLineWidthUnit->setCurrentIndex(indexUnit);
|
|
|
|
}
|
|
|
|
|
2018-02-06 18:30:27 +01:00
|
|
|
connect(ui->comboBoxLineWidthUnit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
|
|
|
|
{
|
|
|
|
const Unit lineUnit = static_cast<Unit>(ui->comboBoxLineWidthUnit->currentData().toInt());
|
|
|
|
const qreal value = UnitConvertor(ui->doubleSpinBoxLineWidth->value(), m_oldLineUnit, lineUnit);
|
|
|
|
ui->doubleSpinBoxLineWidth->setDecimals(lineUnit == Unit::Mm ? 1 : 6);
|
|
|
|
ui->doubleSpinBoxLineWidth->setMinimum(UnitConvertor(ui->doubleSpinBoxLineWidth->minimum(), m_oldLineUnit,
|
|
|
|
lineUnit));
|
|
|
|
ui->doubleSpinBoxLineWidth->setMaximum(UnitConvertor(ui->doubleSpinBoxLineWidth->maximum(), m_oldLineUnit,
|
|
|
|
lineUnit));
|
|
|
|
ui->doubleSpinBoxLineWidth->setValue(value);
|
|
|
|
m_oldLineUnit = lineUnit;
|
|
|
|
});
|
|
|
|
|
|
|
|
m_oldLineUnit = static_cast<Unit>(ui->comboBoxLineWidthUnit->currentData().toInt());
|
|
|
|
ui->doubleSpinBoxLineWidth->setDecimals(m_oldLineUnit == Unit::Mm ? 1 : 6);
|
|
|
|
ui->doubleSpinBoxLineWidth->setMinimum(UnitConvertor(VCommonSettings::MinimalLineWidth(), Unit::Mm, m_oldLineUnit));
|
|
|
|
ui->doubleSpinBoxLineWidth->setMaximum(UnitConvertor(VCommonSettings::MaximalLineWidth(), Unit::Mm, m_oldLineUnit));
|
|
|
|
ui->doubleSpinBoxLineWidth->setValue(UnitConvertor(settings->GetLineWidth(), Unit::Mm, m_oldLineUnit));
|
|
|
|
|
2017-07-03 10:23:34 +02:00
|
|
|
InitDefaultSeamAllowance();
|
2017-08-19 18:10:57 +02:00
|
|
|
InitLabelDateTimeFormats();
|
2017-07-02 10:14:01 +02:00
|
|
|
|
2017-08-30 06:26:18 +02:00
|
|
|
ui->forbidFlippingCheck->setChecked(settings->GetForbidWorkpieceFlipping());
|
|
|
|
ui->doublePassmarkCheck->setChecked(settings->IsDoublePassmark());
|
|
|
|
ui->checkBoxHideMainPath->setChecked(settings->IsHideMainPath());
|
|
|
|
ui->fontComboBoxLabelFont->setCurrentFont(settings->GetLabelFont());
|
|
|
|
|
|
|
|
ui->checkBoxRemeberPatternMaterials->setChecked(settings->IsRememberPatternMaterials());
|
|
|
|
m_knownMaterials = settings->GetKnownMaterials();
|
|
|
|
|
|
|
|
connect(ui->pushButtonKnownMaterials, &QPushButton::clicked, this, &PreferencesPatternPage::ManageKnownMaterials);
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PreferencesPatternPage::~PreferencesPatternPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-03-12 10:56:47 +01:00
|
|
|
QStringList PreferencesPatternPage::Apply()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
2018-03-12 10:56:47 +01:00
|
|
|
QStringList preferences;
|
|
|
|
|
2017-04-12 12:31:11 +02:00
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
// Scene antialiasing
|
2018-03-12 10:56:47 +01:00
|
|
|
if (settings->GetGraphicalOutput() != ui->graphOutputCheck->isChecked())
|
|
|
|
{
|
|
|
|
if (qApp->getSceneView()->IsOpenGLRender())
|
|
|
|
{
|
|
|
|
preferences.append(tr("antialiasing"));
|
|
|
|
}
|
|
|
|
|
|
|
|
settings->SetGraphicalOutput(ui->graphOutputCheck->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings->IsOpenGLRender() != ui->checkBoxOpenGLRender->isChecked())
|
|
|
|
{
|
|
|
|
preferences.append(tr("scene render"));
|
|
|
|
settings->SetOpenGLRender(ui->checkBoxOpenGLRender->isChecked());
|
|
|
|
}
|
|
|
|
|
2017-10-11 12:51:06 +02:00
|
|
|
settings->SetCurveApproximationScale(ui->doubleSpinBoxCurveApproximation->value());
|
2018-02-06 18:30:27 +01:00
|
|
|
settings->SetLineWidth(UnitConvertor(ui->doubleSpinBoxLineWidth->value(), m_oldLineUnit, Unit::Mm));
|
2018-03-10 15:39:37 +01:00
|
|
|
qApp->getSceneView()->SetAntialiasing(ui->graphOutputCheck->isChecked());
|
2017-04-12 12:31:11 +02:00
|
|
|
|
|
|
|
/* Maximum number of commands in undo stack may only be set when the undo stack is empty, since setting it on a
|
|
|
|
* non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack
|
|
|
|
* prints a warning and does nothing.*/
|
|
|
|
settings->SetUndoCount(ui->undoCount->value());
|
|
|
|
|
2017-07-02 10:14:01 +02:00
|
|
|
settings->SetDefaultSeamAllowance(ui->defaultSeamAllowance->value());
|
|
|
|
|
2017-04-12 12:31:11 +02:00
|
|
|
settings->SetForbidWorkpieceFlipping(ui->forbidFlippingCheck->isChecked());
|
2017-05-16 14:16:50 +02:00
|
|
|
settings->SetHideMainPath(ui->checkBoxHideMainPath->isChecked());
|
2017-08-19 18:10:57 +02:00
|
|
|
settings->SetLabelFont(ui->fontComboBoxLabelFont->currentFont());
|
2017-04-12 12:31:11 +02:00
|
|
|
|
|
|
|
if (settings->IsDoublePassmark() != ui->doublePassmarkCheck->isChecked())
|
|
|
|
{
|
|
|
|
settings->SetDoublePassmark(ui->doublePassmarkCheck->isChecked());
|
|
|
|
qApp->getCurrentDocument()->LiteParseTree(Document::LiteParse);
|
|
|
|
}
|
2017-08-19 18:10:57 +02:00
|
|
|
|
|
|
|
settings->SetLabelDateFormat(ui->comboBoxDateFormats->currentText());
|
|
|
|
settings->SetLabelTimeFormat(ui->comboBoxTimeFormats->currentText());
|
|
|
|
|
|
|
|
settings->SetUserDefinedDateFormats(ComboBoxAllStrings(ui->comboBoxDateFormats));
|
|
|
|
settings->SetUserDefinedTimeFormats(ComboBoxAllStrings(ui->comboBoxTimeFormats));
|
2017-08-30 06:26:18 +02:00
|
|
|
|
|
|
|
settings->SetKnownMaterials(m_knownMaterials);
|
|
|
|
settings->SetRememberPatternMaterials(ui->checkBoxRemeberPatternMaterials->isChecked());
|
2018-03-12 10:56:47 +01:00
|
|
|
|
|
|
|
return preferences;
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
2017-07-03 10:23:34 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::InitDefaultSeamAllowance()
|
|
|
|
{
|
|
|
|
ui->defaultSeamAllowance->setValue(qApp->ValentinaSettings()->GetDefaultSeamAllowance());
|
|
|
|
ui->defaultSeamAllowance->setSuffix(UnitsToStr(StrToUnits(qApp->ValentinaSettings()->GetUnit()), true));
|
|
|
|
}
|
2017-08-19 18:10:57 +02:00
|
|
|
|
2018-05-18 12:51:35 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
{
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
RetranslateUi();
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
// remember to call base class implementation
|
|
|
|
QWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:10:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::EditDateTimeFormats()
|
|
|
|
{
|
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
QPushButton *button = qobject_cast<QPushButton *>(sender());
|
|
|
|
if (button == ui->pushButtonEditDateFormats)
|
|
|
|
{
|
2017-09-13 10:52:41 +02:00
|
|
|
CallDateTimeFormatEditor(QDate::currentDate(), VCommonSettings::PredefinedDateFormats(),
|
2017-08-19 18:10:57 +02:00
|
|
|
settings->GetUserDefinedDateFormats(), ui->comboBoxDateFormats);
|
|
|
|
}
|
|
|
|
else if (button == ui->pushButtonEditTimeFormats)
|
|
|
|
{
|
2017-09-13 10:52:41 +02:00
|
|
|
CallDateTimeFormatEditor(QTime::currentTime(), VCommonSettings::PredefinedTimeFormats(),
|
2017-08-19 18:10:57 +02:00
|
|
|
settings->GetUserDefinedTimeFormats(), ui->comboBoxTimeFormats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 06:26:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::ManageKnownMaterials()
|
|
|
|
{
|
|
|
|
DialogKnownMaterials editor;
|
|
|
|
editor.SetList(m_knownMaterials);
|
|
|
|
|
|
|
|
if (QDialog::Accepted == editor.exec())
|
|
|
|
{
|
|
|
|
m_knownMaterials = editor.GetList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:10:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::InitLabelDateTimeFormats()
|
|
|
|
{
|
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
InitComboBoxFormats(ui->comboBoxDateFormats,
|
2017-09-13 10:52:41 +02:00
|
|
|
VCommonSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(),
|
2017-08-19 18:10:57 +02:00
|
|
|
settings->GetLabelDateFormat());
|
|
|
|
InitComboBoxFormats(ui->comboBoxTimeFormats,
|
2017-09-13 10:52:41 +02:00
|
|
|
VCommonSettings::PredefinedTimeFormats() + settings->GetUserDefinedTimeFormats(),
|
2017-08-19 18:10:57 +02:00
|
|
|
settings->GetLabelTimeFormat());
|
|
|
|
|
|
|
|
connect(ui->pushButtonEditDateFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats);
|
|
|
|
connect(ui->pushButtonEditTimeFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString ¤tFormat)
|
|
|
|
{
|
|
|
|
SCASSERT(box != nullptr)
|
|
|
|
|
|
|
|
box->addItems(items);
|
|
|
|
int index = box->findText(currentFormat);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
box->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
box->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 18:30:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::InitUnits()
|
|
|
|
{
|
|
|
|
ui->comboBoxLineWidthUnit->addItem(tr("Millimiters"), static_cast<int>(Unit::Mm));
|
|
|
|
ui->comboBoxLineWidthUnit->addItem(tr("Inches"), static_cast<int>(Unit::Inch));
|
2018-05-18 12:51:35 +02:00
|
|
|
}
|
2018-02-06 18:30:27 +01:00
|
|
|
|
2018-05-18 12:51:35 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::RetranslateUi()
|
|
|
|
{
|
|
|
|
ui->comboBoxLineWidthUnit->blockSignals(true);
|
|
|
|
const int unit = ui->comboBoxLineWidthUnit->currentData().toInt();
|
|
|
|
ui->comboBoxLineWidthUnit->clear();
|
|
|
|
InitUnits();
|
|
|
|
ui->comboBoxLineWidthUnit->setCurrentIndex(ui->comboBoxLineWidthUnit->findData(unit));
|
|
|
|
ui->comboBoxLineWidthUnit->blockSignals(false);
|
2018-02-06 18:30:27 +01:00
|
|
|
}
|
|
|
|
|
2017-08-19 18:10:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void PreferencesPatternPage::CallDateTimeFormatEditor(const T &type, const QStringList &predefinedFormats,
|
|
|
|
const QStringList &userDefinedFormats, QComboBox *box)
|
|
|
|
{
|
|
|
|
SCASSERT(box != nullptr)
|
|
|
|
|
|
|
|
DialogDateTimeFormats dialog(type, predefinedFormats, userDefinedFormats);
|
|
|
|
|
|
|
|
if (QDialog::Accepted == dialog.exec())
|
|
|
|
{
|
|
|
|
const QString currentFormat = box->currentText();
|
|
|
|
box->clear();
|
|
|
|
box->addItems(dialog.GetFormats());
|
|
|
|
|
|
|
|
int index = box->findText(currentFormat);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
box->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
box->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|