2017-04-12 12:31:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file preferencespatternpage.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 12 4, 2017
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2017 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** 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"
|
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),
|
|
|
|
m_knownMaterials()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-08-30 06:26:18 +02:00
|
|
|
|
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
ui->graphOutputCheck->setChecked(settings->GetGraphicalOutput());
|
|
|
|
ui->undoCount->setValue(settings->GetUndoCount());
|
2017-04-12 12:31:11 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesPatternPage::Apply()
|
|
|
|
{
|
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
// Scene antialiasing
|
|
|
|
settings->SetGraphicalOutput(ui->graphOutputCheck->isChecked());
|
|
|
|
qApp->getSceneView()->setRenderHint(QPainter::Antialiasing, ui->graphOutputCheck->isChecked());
|
|
|
|
qApp->getSceneView()->setRenderHint(QPainter::SmoothPixmapTransform, ui->graphOutputCheck->isChecked());
|
|
|
|
|
|
|
|
/* 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());
|
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
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|