2015-07-13 12:48:29 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialognewmeasurements.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 12 7, 2015
|
|
|
|
**
|
|
|
|
** @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) 2015 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 "dialognewmeasurements.h"
|
|
|
|
#include "ui_dialognewmeasurements.h"
|
|
|
|
|
|
|
|
#include "../vpatterndb/variables/vmeasurement.h"
|
2015-12-12 12:11:39 +01:00
|
|
|
#include "../vmisc/vtapesettings.h"
|
|
|
|
#include "../mapplication.h"
|
2015-07-13 12:48:29 +02:00
|
|
|
|
2015-11-05 14:01:33 +01:00
|
|
|
#include <QShowEvent>
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogNewMeasurements::DialogNewMeasurements(QWidget *parent)
|
|
|
|
:QDialog(parent),
|
2015-11-05 14:01:33 +01:00
|
|
|
ui(new Ui::DialogNewMeasurements),
|
|
|
|
isInitialized(false)
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
InitMTypes();
|
|
|
|
InitUnits(MeasurementsType::Individual);
|
|
|
|
InitHeightsList();
|
|
|
|
InitSizesList();
|
|
|
|
|
2015-12-12 12:11:39 +01:00
|
|
|
const VTapeSettings *settings = qApp->TapeSettings();
|
|
|
|
|
|
|
|
const int height = static_cast<int>(UnitConvertor(settings->GetDefHeight(), Unit::Cm, MUnit()));
|
|
|
|
int index = ui->comboBoxBaseHeight->findText(QString().setNum(height));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxBaseHeight->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int size = static_cast<int>(UnitConvertor(settings->GetDefSize(), Unit::Cm, MUnit()));
|
|
|
|
index = ui->comboBoxBaseSize->findText(QString().setNum(size));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxBaseSize->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
connect(ui->comboBoxMType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogNewMeasurements::CurrentTypeChanged);
|
|
|
|
|
|
|
|
connect(ui->comboBoxUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogNewMeasurements::CurrentUnitChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogNewMeasurements::~DialogNewMeasurements()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementsType DialogNewMeasurements::Type() const
|
|
|
|
{
|
2017-05-30 18:52:38 +02:00
|
|
|
return static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt());
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Unit DialogNewMeasurements::MUnit() const
|
|
|
|
{
|
2017-05-30 18:52:38 +02:00
|
|
|
return static_cast<Unit>(ui->comboBoxUnit->currentData().toInt());
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int DialogNewMeasurements::BaseSize() const
|
|
|
|
{
|
2015-07-18 13:08:44 +02:00
|
|
|
return ui->comboBoxBaseSize->currentText().toInt();
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int DialogNewMeasurements::BaseHeight() const
|
|
|
|
{
|
2015-07-18 13:08:44 +02:00
|
|
|
return ui->comboBoxBaseHeight->currentText().toInt();
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogNewMeasurements::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
{
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
InitMTypes();
|
2017-05-30 18:52:38 +02:00
|
|
|
InitUnits(static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt()));
|
2015-08-08 16:33:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// remember to call base class implementation
|
|
|
|
QDialog::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-11-05 14:01:33 +01:00
|
|
|
void DialogNewMeasurements::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QDialog::showEvent( event );
|
|
|
|
if ( event->spontaneous() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInitialized)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// do your init stuff here
|
|
|
|
|
|
|
|
setMaximumSize(size());
|
|
|
|
setMinimumSize(size());
|
|
|
|
|
|
|
|
isInitialized = true;//first show windows are held
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-13 12:48:29 +02:00
|
|
|
void DialogNewMeasurements::CurrentTypeChanged(int index)
|
|
|
|
{
|
|
|
|
const MeasurementsType type = static_cast<MeasurementsType>(ui->comboBoxMType->itemData(index).toInt());
|
|
|
|
if (type == MeasurementsType::Standard)
|
|
|
|
{
|
|
|
|
ui->comboBoxBaseSize->setEnabled(true);
|
|
|
|
ui->comboBoxBaseHeight->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->comboBoxBaseSize->setEnabled(false);
|
|
|
|
ui->comboBoxBaseHeight->setEnabled(false);
|
|
|
|
}
|
|
|
|
InitUnits(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogNewMeasurements::CurrentUnitChanged(int index)
|
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(index)
|
2015-12-12 12:11:39 +01:00
|
|
|
|
|
|
|
if (MUnit() != Unit::Inch)
|
|
|
|
{
|
|
|
|
int i = ui->comboBoxBaseHeight->currentIndex();
|
|
|
|
InitHeightsList();
|
|
|
|
ui->comboBoxBaseHeight->setCurrentIndex(i);
|
|
|
|
|
|
|
|
i = ui->comboBoxBaseSize->currentIndex();
|
|
|
|
InitSizesList();
|
|
|
|
ui->comboBoxBaseSize->setCurrentIndex(i);
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogNewMeasurements::InitMTypes()
|
|
|
|
{
|
2015-10-09 19:26:53 +02:00
|
|
|
int val = static_cast<int>(MeasurementsType::Unknown);
|
2015-08-08 16:33:37 +02:00
|
|
|
if (ui->comboBoxMType->currentIndex() != -1)
|
|
|
|
{
|
2017-05-30 18:52:38 +02:00
|
|
|
val = ui->comboBoxMType->currentData().toInt();
|
2015-08-08 16:33:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
ui->comboBoxMType->blockSignals(true);
|
|
|
|
ui->comboBoxMType->clear();
|
|
|
|
ui->comboBoxMType->addItem(tr("Individual"), static_cast<int>(MeasurementsType::Individual));
|
|
|
|
ui->comboBoxMType->addItem(tr("Standard"), static_cast<int>(MeasurementsType::Standard));
|
|
|
|
ui->comboBoxMType->blockSignals(false);
|
2015-08-08 16:33:37 +02:00
|
|
|
|
|
|
|
int index = ui->comboBoxMType->findData(val);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxMType->setCurrentIndex(index);
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogNewMeasurements::InitHeightsList()
|
|
|
|
{
|
|
|
|
const QStringList list = VMeasurement::WholeListHeights(MUnit());
|
|
|
|
ui->comboBoxBaseHeight->clear();
|
|
|
|
ui->comboBoxBaseHeight->addItems(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogNewMeasurements::InitSizesList()
|
|
|
|
{
|
|
|
|
const QStringList list = VMeasurement::WholeListSizes(MUnit());
|
|
|
|
ui->comboBoxBaseSize->clear();
|
|
|
|
ui->comboBoxBaseSize->addItems(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogNewMeasurements::InitUnits(const MeasurementsType &type)
|
|
|
|
{
|
2015-10-09 19:26:53 +02:00
|
|
|
int val = static_cast<int>(Unit::Cm);
|
2015-08-08 16:33:37 +02:00
|
|
|
if (ui->comboBoxUnit->currentIndex() != -1)
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2017-05-30 18:52:38 +02:00
|
|
|
val = ui->comboBoxUnit->currentData().toInt();
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
ui->comboBoxUnit->blockSignals(true);
|
2015-07-13 12:48:29 +02:00
|
|
|
ui->comboBoxUnit->clear();
|
|
|
|
ui->comboBoxUnit->addItem(tr("Centimeters"), static_cast<int>(Unit::Cm));
|
|
|
|
ui->comboBoxUnit->addItem(tr("Millimiters"), static_cast<int>(Unit::Mm));
|
|
|
|
if (type == MeasurementsType::Individual)
|
|
|
|
{
|
|
|
|
ui->comboBoxUnit->addItem(tr("Inches"), static_cast<int>(Unit::Inch));
|
|
|
|
}
|
2015-12-12 12:11:39 +01:00
|
|
|
ui->comboBoxUnit->setCurrentIndex(-1);
|
2015-08-08 16:33:37 +02:00
|
|
|
ui->comboBoxUnit->blockSignals(false);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
|
|
int index = ui->comboBoxUnit->findData(val);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxUnit->setCurrentIndex(index);
|
|
|
|
}
|
2015-12-12 12:11:39 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
index = ui->comboBoxUnit->findData(static_cast<int>(Unit::Cm));
|
|
|
|
ui->comboBoxUnit->setCurrentIndex(index);
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|