2017-04-12 12:31:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file preferencesconfigurationpage.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 "preferencesconfigurationpage.h"
|
|
|
|
#include "ui_preferencesconfigurationpage.h"
|
|
|
|
#include "../../core/vapplication.h"
|
2017-06-01 12:04:25 +02:00
|
|
|
#include "../vpatterndb/pmsystems.h"
|
2017-04-12 12:31:11 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDirIterator>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
|
|
|
ui(new Ui::PreferencesConfigurationPage),
|
|
|
|
m_langChanged(false),
|
|
|
|
m_systemChanged(),
|
|
|
|
m_unitChanged(false),
|
|
|
|
m_labelLangChanged(false)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2018-05-18 12:51:35 +02:00
|
|
|
RetranslateUi();
|
2018-05-11 11:42:20 +02:00
|
|
|
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
|
|
|
|
// Tab General
|
2017-04-12 12:31:11 +02:00
|
|
|
ui->autoSaveCheck->setChecked(qApp->ValentinaSettings()->GetAutosaveState());
|
|
|
|
|
2017-04-12 14:50:48 +02:00
|
|
|
InitLanguages(ui->langCombo);
|
2018-01-12 14:25:20 +01:00
|
|
|
connect(ui->langCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
|
|
|
m_langChanged = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
//-------------------- Decimal separator setup
|
|
|
|
ui->osOptionCheck->setChecked(qApp->ValentinaSettings()->GetOsSeparator());
|
|
|
|
|
|
|
|
//----------------------- Unit setup
|
2018-05-18 12:51:35 +02:00
|
|
|
// set default unit
|
|
|
|
const qint32 indexUnit = ui->unitCombo->findData(qApp->ValentinaSettings()->GetUnit());
|
|
|
|
if (indexUnit != -1)
|
|
|
|
{
|
|
|
|
ui->unitCombo->setCurrentIndex(indexUnit);
|
|
|
|
}
|
|
|
|
|
2018-01-12 14:25:20 +01:00
|
|
|
connect(ui->unitCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
|
|
|
m_unitChanged = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
//----------------------- Label language
|
|
|
|
SetLabelComboBox(VApplication::LabelLanguages());
|
|
|
|
|
|
|
|
int index = ui->labelCombo->findData(qApp->ValentinaSettings()->GetLabelLanguage());
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->labelCombo->setCurrentIndex(index);
|
|
|
|
}
|
2018-01-12 14:25:20 +01:00
|
|
|
connect(ui->labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
|
|
|
m_labelLangChanged = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
//---------------------- Pattern making system
|
|
|
|
ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing());
|
2018-01-12 14:25:20 +01:00
|
|
|
connect(ui->systemCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
|
|
|
m_systemChanged = true;
|
2017-05-30 18:52:38 +02:00
|
|
|
QString text = qApp->TrVars()->PMSystemAuthor(ui->systemCombo->currentData().toString());
|
2017-04-12 12:31:11 +02:00
|
|
|
ui->systemAuthorValueLabel->setText(text);
|
|
|
|
ui->systemAuthorValueLabel->setToolTip(text);
|
|
|
|
|
2017-05-30 18:52:38 +02:00
|
|
|
text = qApp->TrVars()->PMSystemBook(ui->systemCombo->currentData().toString());
|
2017-04-12 12:31:11 +02:00
|
|
|
ui->systemBookValueLabel->setPlainText(text);
|
|
|
|
});
|
|
|
|
|
|
|
|
// set default pattern making system
|
|
|
|
index = ui->systemCombo->findData(qApp->ValentinaSettings()->GetPMSystemCode());
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->systemCombo->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------- Pattern Editing
|
2018-03-14 14:39:15 +01:00
|
|
|
connect(ui->resetWarningsButton, &QPushButton::released, this, []()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
settings->SetConfirmItemDelete(true);
|
|
|
|
settings->SetConfirmFormatRewriting(true);
|
|
|
|
});
|
|
|
|
|
2018-05-11 11:42:20 +02:00
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
|
|
|
|
ui->checkBoxFreeCurve->setChecked(settings->IsFreeCurveMode());
|
|
|
|
ui->checkBoxZoomFitBestCurrentPP->setChecked(settings->IsDoubleClickZoomFitBestCurrentPP());
|
2017-10-03 12:01:56 +02:00
|
|
|
|
2017-04-12 12:31:11 +02:00
|
|
|
//----------------------- Toolbar
|
2018-05-11 11:42:20 +02:00
|
|
|
ui->toolBarStyleCheck->setChecked(settings->GetToolBarStyle());
|
|
|
|
|
2018-10-29 13:05:49 +01:00
|
|
|
// Theme
|
|
|
|
ui->darkModeCheck->setChecked(settings->GetDarkMode());
|
|
|
|
|
2018-05-11 11:42:20 +02:00
|
|
|
// Tab Scrolling
|
|
|
|
ui->spinBoxDuration->setMinimum(VSettings::scrollingDurationMin);
|
|
|
|
ui->spinBoxDuration->setMaximum(VSettings::scrollingDurationMax);
|
|
|
|
ui->spinBoxDuration->setValue(settings->GetScrollingDuration());
|
|
|
|
|
|
|
|
ui->spinBoxUpdateInterval->setMinimum(VSettings::scrollingUpdateIntervalMin);
|
2018-05-15 13:01:26 +02:00
|
|
|
ui->spinBoxUpdateInterval->setMaximum(VSettings::scrollingUpdateIntervalMax);
|
2018-05-11 11:42:20 +02:00
|
|
|
ui->spinBoxUpdateInterval->setValue(settings->GetScrollingUpdateInterval());
|
|
|
|
|
|
|
|
ui->doubleSpinBoxSensor->setMinimum(VSettings::sensorMouseScaleMin);
|
|
|
|
ui->doubleSpinBoxSensor->setMaximum(VSettings::sensorMouseScaleMax);
|
|
|
|
ui->doubleSpinBoxSensor->setValue(settings->GetSensorMouseScale());
|
|
|
|
|
|
|
|
ui->doubleSpinBoxWheel->setMinimum(VSettings::wheelMouseScaleMin);
|
|
|
|
ui->doubleSpinBoxWheel->setMaximum(VSettings::wheelMouseScaleMax);
|
|
|
|
ui->doubleSpinBoxWheel->setValue(settings->GetWheelMouseScale());
|
|
|
|
|
|
|
|
ui->doubleSpinBoxAcceleration->setMinimum(VSettings::scrollingAccelerationMin);
|
|
|
|
ui->doubleSpinBoxAcceleration->setMaximum(VSettings::scrollingAccelerationMax);
|
|
|
|
ui->doubleSpinBoxAcceleration->setValue(settings->GetScrollingAcceleration());
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PreferencesConfigurationPage::~PreferencesConfigurationPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-03-12 10:56:47 +01:00
|
|
|
QStringList PreferencesConfigurationPage::Apply()
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
2018-05-11 11:42:20 +02:00
|
|
|
// Tab General
|
2018-03-12 10:56:47 +01:00
|
|
|
QStringList preferences;
|
2017-04-12 12:31:11 +02:00
|
|
|
VSettings *settings = qApp->ValentinaSettings();
|
|
|
|
settings->SetAutosaveState(ui->autoSaveCheck->isChecked());
|
|
|
|
settings->SetAutosaveTime(ui->autoTime->value());
|
|
|
|
|
|
|
|
QTimer *autoSaveTimer = qApp->getAutoSaveTimer();
|
|
|
|
SCASSERT(autoSaveTimer)
|
|
|
|
|
|
|
|
ui->autoSaveCheck->isChecked() ? autoSaveTimer->start(ui->autoTime->value()*60000) : autoSaveTimer->stop();
|
|
|
|
|
|
|
|
settings->SetOsSeparator(ui->osOptionCheck->isChecked());
|
|
|
|
settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked());
|
2018-10-29 18:56:39 +01:00
|
|
|
|
|
|
|
if (settings->GetDarkMode() != ui->darkModeCheck->isChecked())
|
|
|
|
{
|
|
|
|
settings->SetDarkMode(ui->darkModeCheck->isChecked());
|
|
|
|
preferences.append(tr("dark mode"));
|
|
|
|
}
|
|
|
|
|
2017-10-03 12:01:56 +02:00
|
|
|
settings->SetFreeCurveMode(ui->checkBoxFreeCurve->isChecked());
|
2018-05-10 13:12:41 +02:00
|
|
|
settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->isChecked());
|
2017-04-12 12:31:11 +02:00
|
|
|
|
|
|
|
if (m_langChanged || m_systemChanged)
|
|
|
|
{
|
|
|
|
const QString locale = qvariant_cast<QString>(ui->langCombo->currentData());
|
|
|
|
settings->SetLocale(locale);
|
|
|
|
m_langChanged = false;
|
|
|
|
|
|
|
|
const QString code = qvariant_cast<QString>(ui->systemCombo->currentData());
|
|
|
|
settings->SetPMSystemCode(code);
|
|
|
|
m_systemChanged = false;
|
|
|
|
|
|
|
|
qApp->LoadTranslation(locale);
|
|
|
|
}
|
|
|
|
if (m_unitChanged)
|
|
|
|
{
|
|
|
|
const QString unit = qvariant_cast<QString>(ui->unitCombo->currentData());
|
|
|
|
settings->SetUnit(unit);
|
|
|
|
m_unitChanged = false;
|
2018-03-12 10:56:47 +01:00
|
|
|
preferences.append(tr("default unit"));
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
|
|
|
if (m_labelLangChanged)
|
|
|
|
{
|
|
|
|
const QString locale = qvariant_cast<QString>(ui->labelCombo->currentData());
|
|
|
|
settings->SetLabelLanguage(locale);
|
|
|
|
m_labelLangChanged = false;
|
|
|
|
}
|
2018-05-11 11:42:20 +02:00
|
|
|
|
|
|
|
// Tab Scrolling
|
|
|
|
settings->SetScrollingDuration(ui->spinBoxDuration->value());
|
|
|
|
settings->SetScrollingUpdateInterval(ui->spinBoxUpdateInterval->value());
|
|
|
|
settings->SetSensorMouseScale(ui->doubleSpinBoxSensor->value());
|
|
|
|
settings->SetWheelMouseScale(ui->doubleSpinBoxWheel->value());
|
|
|
|
settings->SetScrollingAcceleration(ui->doubleSpinBoxAcceleration->value());
|
|
|
|
|
2018-03-12 10:56:47 +01:00
|
|
|
return preferences;
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesConfigurationPage::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
{
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
RetranslateUi();
|
2018-05-18 12:51:35 +02:00
|
|
|
ui->retranslateUi(this);
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
|
|
|
// remember to call base class implementation
|
|
|
|
QWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesConfigurationPage::SetLabelComboBox(const QStringList &list)
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &name : list)
|
2017-04-12 12:31:11 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
ui->labelCombo->addItem(QLocale(name).nativeLanguageName(), name);
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesConfigurationPage::InitUnits()
|
|
|
|
{
|
2017-06-16 15:01:09 +02:00
|
|
|
ui->unitCombo->addItem(tr("Centimeters"), unitCM);
|
|
|
|
ui->unitCombo->addItem(tr("Millimiters"), unitMM);
|
|
|
|
ui->unitCombo->addItem(tr("Inches"), unitINCH);
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PreferencesConfigurationPage::RetranslateUi()
|
|
|
|
{
|
2018-05-18 12:51:35 +02:00
|
|
|
ui->osOptionCheck->setText(tr("With OS options") + QStringLiteral(" (%1)").arg(QLocale().decimalPoint()));
|
|
|
|
|
|
|
|
{
|
|
|
|
ui->unitCombo->blockSignals(true);
|
|
|
|
const QString unit = qvariant_cast<QString>(ui->unitCombo->currentData());
|
|
|
|
ui->unitCombo->clear();
|
|
|
|
InitUnits();
|
|
|
|
ui->unitCombo->setCurrentIndex(ui->unitCombo->findData(unit));
|
|
|
|
ui->unitCombo->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const QString code = qvariant_cast<QString>(ui->systemCombo->currentData());
|
|
|
|
ui->systemCombo->blockSignals(true);
|
|
|
|
ui->systemCombo->clear();
|
|
|
|
InitPMSystems(ui->systemCombo);
|
|
|
|
ui->systemCombo->setCurrentIndex(-1);
|
|
|
|
ui->systemCombo->blockSignals(false);
|
|
|
|
ui->systemCombo->setCurrentIndex(ui->systemCombo->findData(code));
|
|
|
|
}
|
2017-04-12 12:31:11 +02:00
|
|
|
}
|