2014-02-19 14:32:02 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogpatternproperties.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-02-19 14:32:02 +01:00
|
|
|
** @date 18 2, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-02-19 14:32:02 +01:00
|
|
|
** <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 "dialogpatternproperties.h"
|
|
|
|
#include "ui_dialogpatternproperties.h"
|
2016-03-09 20:01:37 +01:00
|
|
|
#include <QBuffer>
|
2014-06-17 11:50:11 +02:00
|
|
|
#include <QPushButton>
|
2016-03-09 20:01:37 +01:00
|
|
|
#include <QFileDialog>
|
2016-03-17 15:34:40 +01:00
|
|
|
#include <QMenu>
|
2015-06-19 13:21:46 +02:00
|
|
|
#include "../xml/vpattern.h"
|
2015-12-11 15:19:11 +01:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2015-06-19 13:21:46 +02:00
|
|
|
#include "../core/vapplication.h"
|
2014-02-19 14:32:02 +01:00
|
|
|
|
2014-08-07 21:06:36 +02:00
|
|
|
#define MAX_HEIGHTS 18
|
|
|
|
#define MAX_SIZES 18
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-12-11 15:19:11 +01:00
|
|
|
DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent) :
|
|
|
|
QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), pattern(pattern), heightsChecked(MAX_HEIGHTS),
|
2014-08-08 18:07:44 +02:00
|
|
|
sizesChecked(MAX_SIZES), heights (QMap<GHeights, bool>()), sizes(QMap<GSizes, bool>()),
|
2015-12-11 15:19:11 +01:00
|
|
|
data(QMap<QCheckBox *, int>()), descriptionChanged(false), gradationChanged(false), defaultChanged(false),
|
2016-01-22 11:45:18 +01:00
|
|
|
securityChanged(false), isInitialized(false)
|
2014-02-19 14:32:02 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2015-12-09 11:40:43 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
ui->lineEditAuthor->setClearButtonEnabled(true);
|
|
|
|
#endif
|
|
|
|
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(doc != nullptr);
|
2014-02-19 14:32:02 +01:00
|
|
|
|
2015-07-24 14:06:53 +02:00
|
|
|
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
|
2015-02-10 20:27:11 +01:00
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
ui->lineEditAuthor->setText(doc->GetAuthor());
|
|
|
|
connect(ui->lineEditAuthor, &QLineEdit::editingFinished, this, &DialogPatternProperties::DescEdited);
|
2014-02-19 14:32:02 +01:00
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
ui->plainTextEditDescription->setPlainText(doc->GetDescription());
|
|
|
|
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited);
|
2014-02-19 14:32:02 +01:00
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
ui->plainTextEditTechNotes->setPlainText(doc->GetNotes());
|
|
|
|
connect(ui->plainTextEditTechNotes, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited);
|
|
|
|
|
2016-03-09 20:01:37 +01:00
|
|
|
InitImage();
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &DialogPatternProperties::Ok);
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this,
|
|
|
|
&DialogPatternProperties::Apply);
|
2014-02-19 14:32:02 +01:00
|
|
|
|
2016-01-06 07:05:41 +01:00
|
|
|
QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
|
|
|
SCASSERT(bCancel != nullptr);
|
|
|
|
connect(bCancel, &QPushButton::clicked, this, &DialogPatternProperties::close);
|
2014-02-19 14:32:02 +01:00
|
|
|
|
2014-08-07 16:05:37 +02:00
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
2015-12-11 15:19:11 +01:00
|
|
|
if (qApp->patternType() != MeasurementsType::Standard)
|
2014-08-07 16:05:37 +02:00
|
|
|
{
|
|
|
|
ui->tabWidget->setTabEnabled(1, false);
|
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
|
|
|
|
InitHeights();
|
|
|
|
InitSizes();
|
|
|
|
|
|
|
|
heights = doc->GetGradationHeights();
|
|
|
|
sizes = doc->GetGradationSizes();
|
|
|
|
|
|
|
|
SetOptions(heights);
|
|
|
|
SetOptions(sizes);
|
|
|
|
|
2015-12-11 15:19:11 +01:00
|
|
|
InitComboBox(ui->comboBoxHeight, heights);
|
|
|
|
InitComboBox(ui->comboBoxSize, sizes);
|
|
|
|
|
2016-01-03 14:21:30 +01:00
|
|
|
const QString height = QString().setNum(doc->GetDefCustomHeight());
|
2015-12-11 15:19:11 +01:00
|
|
|
SetDefaultHeight(height);
|
|
|
|
|
2016-01-03 14:21:30 +01:00
|
|
|
const QString size = QString().setNum(doc->GetDefCustomSize());
|
2015-12-11 15:19:11 +01:00
|
|
|
SetDefaultSize(size);
|
|
|
|
|
|
|
|
connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, &DialogPatternProperties::ToggleComboBox);
|
|
|
|
connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, &DialogPatternProperties::DefValueChanged);
|
|
|
|
|
|
|
|
ui->radioButtonDefFromP->setChecked(doc->IsDefCustom());
|
|
|
|
|
|
|
|
connect(ui->comboBoxHeight, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogPatternProperties::DefValueChanged);
|
|
|
|
connect(ui->comboBoxSize, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogPatternProperties::DefValueChanged);
|
|
|
|
|
2016-01-22 11:45:18 +01:00
|
|
|
const bool readOnly = doc->IsReadOnly();
|
|
|
|
ui->checkBoxPatternReadOnly->setChecked(readOnly);
|
|
|
|
if (not readOnly)
|
|
|
|
{
|
|
|
|
connect(ui->checkBoxPatternReadOnly, &QRadioButton::toggled, this,
|
|
|
|
&DialogPatternProperties::SecurityValueChanged);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->checkBoxPatternReadOnly->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
2015-12-11 15:19:11 +01:00
|
|
|
//Initialization change value. Set to default value after initialization
|
|
|
|
gradationChanged = false;
|
|
|
|
defaultChanged = false;
|
2016-01-22 11:45:18 +01:00
|
|
|
securityChanged = false;
|
2014-02-19 14:32:02 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-19 14:32:02 +01:00
|
|
|
DialogPatternProperties::~DialogPatternProperties()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-19 14:32:02 +01:00
|
|
|
void DialogPatternProperties::Apply()
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
switch (ui->tabWidget->currentIndex())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
SaveDescription();
|
|
|
|
descriptionChanged = false;
|
2015-12-11 15:19:11 +01:00
|
|
|
emit doc->patternChanged(false);
|
2014-08-08 18:07:44 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
SaveGradation();
|
|
|
|
gradationChanged = false;
|
2015-12-11 15:19:11 +01:00
|
|
|
SaveDefValues();
|
|
|
|
defaultChanged = false;
|
|
|
|
emit doc->patternChanged(false);
|
2014-08-08 18:07:44 +02:00
|
|
|
break;
|
2016-01-22 11:45:18 +01:00
|
|
|
case 2:
|
|
|
|
doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked());
|
|
|
|
securityChanged = false;
|
|
|
|
emit doc->patternChanged(false);
|
|
|
|
break;
|
2014-08-08 18:07:44 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::Ok()
|
|
|
|
{
|
|
|
|
if (descriptionChanged)
|
|
|
|
{
|
|
|
|
SaveDescription();
|
|
|
|
descriptionChanged = false;
|
2016-01-08 12:22:48 +01:00
|
|
|
emit doc->patternChanged(false);
|
2014-08-08 18:07:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gradationChanged)
|
|
|
|
{
|
|
|
|
SaveGradation();
|
|
|
|
gradationChanged = false;
|
2016-01-08 12:22:48 +01:00
|
|
|
emit doc->patternChanged(false);
|
2014-08-08 18:07:44 +02:00
|
|
|
}
|
|
|
|
|
2015-12-11 15:19:11 +01:00
|
|
|
if (defaultChanged)
|
|
|
|
{
|
|
|
|
SaveDefValues();
|
|
|
|
defaultChanged = false;
|
2016-01-08 12:22:48 +01:00
|
|
|
emit doc->patternChanged(false);
|
2015-12-11 15:19:11 +01:00
|
|
|
}
|
|
|
|
|
2016-01-22 11:45:18 +01:00
|
|
|
if (securityChanged)
|
|
|
|
{
|
|
|
|
doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked());
|
|
|
|
securityChanged = false;
|
|
|
|
emit doc->patternChanged(false);
|
|
|
|
}
|
|
|
|
|
2014-02-19 14:32:02 +01:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2014-08-07 21:06:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SelectAll(int state)
|
|
|
|
{
|
|
|
|
QCheckBox* box = qobject_cast<QCheckBox*>(sender());
|
|
|
|
if (box)
|
|
|
|
{
|
|
|
|
if (box == ui->checkBoxAllHeights)
|
|
|
|
{
|
|
|
|
if (state == Qt::Checked)
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
SetHeightsChecked(true);
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
|
|
|
else if (state == Qt::Unchecked)
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
SetHeightsChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.contains(box))
|
|
|
|
{
|
|
|
|
heights.insert(static_cast<GHeights>(data.value(box)), box->isChecked());
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (box == ui->checkBoxAllSizes)
|
|
|
|
{
|
|
|
|
if (state == Qt::Checked)
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
SetSizesChecked(true);
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
|
|
|
else if (state == Qt::Unchecked)
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
SetSizesChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.contains(box))
|
|
|
|
{
|
|
|
|
sizes.insert(static_cast<GSizes>(data.value(box)), box->isChecked());
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-08 18:07:44 +02:00
|
|
|
void DialogPatternProperties::CheckStateHeight(int state)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
|
|
|
QCheckBox* box = qobject_cast<QCheckBox*>(sender());
|
|
|
|
if (box)
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
if (state == Qt::Checked)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
++heightsChecked;
|
|
|
|
if (heightsChecked == MAX_HEIGHTS)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
ui->checkBoxAllHeights->blockSignals(true);//don't touch anothers checkboxes
|
|
|
|
ui->checkBoxAllHeights->setCheckState(Qt::Checked);
|
|
|
|
heights.insert(GHeights::ALL, true);
|
|
|
|
ui->checkBoxAllHeights->blockSignals(false);
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
}
|
|
|
|
else if (state == Qt::Unchecked)
|
|
|
|
{
|
|
|
|
if (heightsChecked == MAX_HEIGHTS)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
ui->checkBoxAllHeights->blockSignals(true);//don't touch anothers checkboxes
|
|
|
|
ui->checkBoxAllHeights->setCheckState(Qt::Unchecked);
|
|
|
|
heights.insert(GHeights::ALL, false);
|
|
|
|
ui->checkBoxAllHeights->blockSignals(false);
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
--heightsChecked;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.contains(box))
|
|
|
|
{
|
|
|
|
heights.insert(static_cast<GHeights>(data.value(box)), box->isChecked());
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
|
2015-12-11 15:19:11 +01:00
|
|
|
UpdateDefHeight();
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
CheckApplyOk();
|
|
|
|
gradationChanged = true;
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-08 18:07:44 +02:00
|
|
|
void DialogPatternProperties::CheckStateSize(int state)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
|
|
|
QCheckBox* box = qobject_cast<QCheckBox*>(sender());
|
|
|
|
if (box)
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
|
|
|
|
if (state == Qt::Checked)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
++sizesChecked;
|
|
|
|
if (sizesChecked == MAX_SIZES)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
ui->checkBoxAllSizes->blockSignals(true);//don't touch anothers checkboxes
|
|
|
|
ui->checkBoxAllSizes->setCheckState(Qt::Checked);
|
|
|
|
sizes.insert(GSizes::ALL, true);
|
|
|
|
ui->checkBoxAllSizes->blockSignals(false);
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
}
|
|
|
|
else if (state == Qt::Unchecked)
|
|
|
|
{
|
|
|
|
if (sizesChecked == MAX_SIZES)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
ui->checkBoxAllSizes->blockSignals(true);//don't touch anothers checkboxes
|
|
|
|
ui->checkBoxAllSizes->setCheckState(Qt::Unchecked);
|
|
|
|
sizes.insert(GSizes::ALL, false);
|
|
|
|
ui->checkBoxAllSizes->blockSignals(false);
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
--sizesChecked;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.contains(box))
|
|
|
|
{
|
|
|
|
sizes.insert(static_cast<GSizes>(data.value(box)), box->isChecked());
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
2014-08-08 18:07:44 +02:00
|
|
|
|
2015-12-11 15:19:11 +01:00
|
|
|
UpdateDefSize();
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
CheckApplyOk();
|
|
|
|
gradationChanged = true;
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-08 18:07:44 +02:00
|
|
|
void DialogPatternProperties::DescEdited()
|
2014-02-19 14:32:02 +01:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
descriptionChanged = true;
|
|
|
|
}
|
2014-02-19 14:32:02 +01:00
|
|
|
|
2015-11-05 14:01:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::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-12-11 15:19:11 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::ToggleComboBox()
|
|
|
|
{
|
|
|
|
ui->comboBoxHeight->setEnabled(ui->radioButtonDefFromP->isChecked());
|
|
|
|
ui->comboBoxSize->setEnabled(ui->radioButtonDefFromP->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::DefValueChanged()
|
|
|
|
{
|
|
|
|
defaultChanged = true;
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:45:18 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SecurityValueChanged()
|
|
|
|
{
|
|
|
|
securityChanged = true;
|
|
|
|
}
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SetHeightsChecked(bool enabled)
|
|
|
|
{
|
|
|
|
ui->checkBoxH92->setChecked(enabled);
|
|
|
|
ui->checkBoxH98->setChecked(enabled);
|
|
|
|
ui->checkBoxH104->setChecked(enabled);
|
|
|
|
ui->checkBoxH110->setChecked(enabled);
|
|
|
|
ui->checkBoxH116->setChecked(enabled);
|
|
|
|
ui->checkBoxH122->setChecked(enabled);
|
|
|
|
ui->checkBoxH128->setChecked(enabled);
|
|
|
|
ui->checkBoxH134->setChecked(enabled);
|
|
|
|
ui->checkBoxH140->setChecked(enabled);
|
|
|
|
ui->checkBoxH146->setChecked(enabled);
|
|
|
|
ui->checkBoxH152->setChecked(enabled);
|
|
|
|
ui->checkBoxH158->setChecked(enabled);
|
|
|
|
ui->checkBoxH164->setChecked(enabled);
|
|
|
|
ui->checkBoxH170->setChecked(enabled);
|
|
|
|
ui->checkBoxH176->setChecked(enabled);
|
|
|
|
ui->checkBoxH182->setChecked(enabled);
|
|
|
|
ui->checkBoxH188->setChecked(enabled);
|
|
|
|
ui->checkBoxH194->setChecked(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SetSizesChecked(bool enabled)
|
|
|
|
{
|
|
|
|
ui->checkBoxS22->setChecked(enabled);
|
|
|
|
ui->checkBoxS24->setChecked(enabled);
|
|
|
|
ui->checkBoxS26->setChecked(enabled);
|
|
|
|
ui->checkBoxS28->setChecked(enabled);
|
|
|
|
ui->checkBoxS30->setChecked(enabled);
|
|
|
|
ui->checkBoxS32->setChecked(enabled);
|
|
|
|
ui->checkBoxS34->setChecked(enabled);
|
|
|
|
ui->checkBoxS36->setChecked(enabled);
|
|
|
|
ui->checkBoxS38->setChecked(enabled);
|
|
|
|
ui->checkBoxS40->setChecked(enabled);
|
|
|
|
ui->checkBoxS42->setChecked(enabled);
|
|
|
|
ui->checkBoxS44->setChecked(enabled);
|
|
|
|
ui->checkBoxS46->setChecked(enabled);
|
|
|
|
ui->checkBoxS48->setChecked(enabled);
|
|
|
|
ui->checkBoxS50->setChecked(enabled);
|
|
|
|
ui->checkBoxS52->setChecked(enabled);
|
|
|
|
ui->checkBoxS54->setChecked(enabled);
|
|
|
|
ui->checkBoxS56->setChecked(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::InitHeights()
|
|
|
|
{
|
|
|
|
Init(ui->checkBoxAllHeights, static_cast<int>(GHeights::ALL), &DialogPatternProperties::SelectAll);
|
|
|
|
|
|
|
|
Init(ui->checkBoxH92, static_cast<int>(GHeights::H92), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH98, static_cast<int>(GHeights::H98), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH104, static_cast<int>(GHeights::H104), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH110, static_cast<int>(GHeights::H110), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH116, static_cast<int>(GHeights::H116), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH122, static_cast<int>(GHeights::H122), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH128, static_cast<int>(GHeights::H128), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH134, static_cast<int>(GHeights::H134), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH140, static_cast<int>(GHeights::H140), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH146, static_cast<int>(GHeights::H146), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH152, static_cast<int>(GHeights::H152), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH158, static_cast<int>(GHeights::H158), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH164, static_cast<int>(GHeights::H164), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH170, static_cast<int>(GHeights::H170), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH176, static_cast<int>(GHeights::H176), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH182, static_cast<int>(GHeights::H182), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH188, static_cast<int>(GHeights::H188), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
Init(ui->checkBoxH194, static_cast<int>(GHeights::H194), &DialogPatternProperties::CheckStateHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::InitSizes()
|
|
|
|
{
|
|
|
|
Init(ui->checkBoxAllSizes, static_cast<int>(GSizes::ALL), &DialogPatternProperties::SelectAll);
|
|
|
|
|
|
|
|
Init(ui->checkBoxS22, static_cast<int>(GSizes::S22), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS24, static_cast<int>(GSizes::S24), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS26, static_cast<int>(GSizes::S26), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS28, static_cast<int>(GSizes::S28), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS30, static_cast<int>(GSizes::S30), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS32, static_cast<int>(GSizes::S32), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS34, static_cast<int>(GSizes::S34), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS36, static_cast<int>(GSizes::S36), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS38, static_cast<int>(GSizes::S38), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS40, static_cast<int>(GSizes::S40), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS42, static_cast<int>(GSizes::S42), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS44, static_cast<int>(GSizes::S44), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS46, static_cast<int>(GSizes::S46), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS48, static_cast<int>(GSizes::S48), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS50, static_cast<int>(GSizes::S50), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS52, static_cast<int>(GSizes::S52), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS54, static_cast<int>(GSizes::S54), &DialogPatternProperties::CheckStateSize);
|
|
|
|
Init(ui->checkBoxS56, static_cast<int>(GSizes::S56), &DialogPatternProperties::CheckStateSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::CheckApplyOk()
|
|
|
|
{
|
|
|
|
bool enable = !(heightsChecked == 0 || sizesChecked == 0);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SaveDescription()
|
|
|
|
{
|
|
|
|
doc->SetNotes(ui->plainTextEditTechNotes->document()->toPlainText());
|
2016-02-29 13:46:24 +01:00
|
|
|
doc->SetDescription(ui->plainTextEditDescription->document()->toPlainText());
|
2014-08-08 18:07:44 +02:00
|
|
|
doc->SetAuthor(ui->lineEditAuthor->text());
|
2014-02-19 14:32:02 +01:00
|
|
|
}
|
2014-08-07 21:06:36 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-08 18:07:44 +02:00
|
|
|
void DialogPatternProperties::SaveGradation()
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
doc->SetGradationHeights(heights);
|
|
|
|
doc->SetGradationSizes(sizes);
|
|
|
|
emit UpdateGradation();
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
|
|
|
|
2015-12-11 15:19:11 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SaveDefValues()
|
|
|
|
{
|
|
|
|
if (ui->radioButtonDefFromM->isChecked())
|
|
|
|
{
|
|
|
|
doc->SetDefCustom(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
doc->SetDefCustom(true);
|
2016-01-03 14:21:30 +01:00
|
|
|
doc->SetDefCustomHeight(ui->comboBoxHeight->currentText().toInt());
|
|
|
|
doc->SetDefCustomSize(ui->comboBoxSize->currentText().toInt());
|
2015-12-11 15:19:11 +01:00
|
|
|
}
|
|
|
|
defaultChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SetDefaultHeight(const QString &def)
|
|
|
|
{
|
|
|
|
int index = ui->comboBoxHeight->findText(def);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxHeight->setCurrentIndex(index);
|
|
|
|
defaultChanged = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-03 14:21:30 +01:00
|
|
|
const int height = static_cast<int>(pattern->height());
|
2015-12-11 15:19:11 +01:00
|
|
|
index = ui->comboBoxHeight->findText(QString().setNum(height));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxHeight->setCurrentIndex(index);
|
|
|
|
defaultChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SetDefaultSize(const QString &def)
|
|
|
|
{
|
|
|
|
int index = ui->comboBoxSize->findText(def);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxSize->setCurrentIndex(index);
|
|
|
|
defaultChanged = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-03 14:21:30 +01:00
|
|
|
const int size = static_cast<int>(pattern->size());
|
2015-12-11 15:19:11 +01:00
|
|
|
index = ui->comboBoxSize->findText(QString().setNum(size));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxSize->setCurrentIndex(index);
|
|
|
|
defaultChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::UpdateDefHeight()
|
|
|
|
{
|
|
|
|
const QString def = ui->comboBoxHeight->currentText();
|
|
|
|
InitComboBox(ui->comboBoxHeight, heights);
|
|
|
|
SetDefaultHeight(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::UpdateDefSize()
|
|
|
|
{
|
|
|
|
const QString def = ui->comboBoxSize->currentText();
|
|
|
|
InitComboBox(ui->comboBoxSize, sizes);
|
|
|
|
SetDefaultSize(def);
|
|
|
|
}
|
|
|
|
|
2014-08-07 21:06:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-08 18:07:44 +02:00
|
|
|
template<typename Func>
|
|
|
|
void DialogPatternProperties::Init(QCheckBox *check, int val, Func slot)
|
2014-08-07 21:06:36 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
connect(check, &QCheckBox::stateChanged, this, slot);
|
|
|
|
data.insert(check, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename GVal>
|
|
|
|
void DialogPatternProperties::SetOptions(const QMap<GVal, bool> &option)
|
|
|
|
{
|
|
|
|
if (option.value(GVal::ALL) == false)
|
|
|
|
{
|
|
|
|
QMapIterator<GVal, bool> i(option);
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
if (i.value() == false && i.key() != GVal::ALL)
|
|
|
|
{
|
|
|
|
QCheckBox *box = data.key(static_cast<int>(i.key()));
|
|
|
|
if (box != nullptr)
|
|
|
|
{
|
|
|
|
box->setCheckState(Qt::Unchecked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-07 21:06:36 +02:00
|
|
|
}
|
2015-12-11 15:19:11 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename GVal>
|
|
|
|
void DialogPatternProperties::InitComboBox(QComboBox *box, const QMap<GVal, bool> &option)
|
|
|
|
{
|
|
|
|
SCASSERT(box != nullptr);
|
|
|
|
|
|
|
|
box->clear();
|
|
|
|
|
|
|
|
QMapIterator<GVal, bool> i(option);
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
if (i.value() && i.key() != GVal::ALL)
|
|
|
|
{
|
2016-01-03 14:21:30 +01:00
|
|
|
box->addItem(QString().setNum(static_cast<int>(UnitConvertor(static_cast<int>(i.key()), Unit::Cm,
|
|
|
|
*pattern->GetPatternUnit()))));
|
2015-12-11 15:19:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 20:01:37 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::InitImage()
|
|
|
|
{
|
|
|
|
// we set an image from file.val
|
|
|
|
QImage image;
|
|
|
|
QByteArray byteArray;
|
|
|
|
byteArray.append(doc->GetImage().toUtf8());
|
|
|
|
QByteArray ba = QByteArray::fromBase64(byteArray);
|
|
|
|
QBuffer buffer(&ba);
|
|
|
|
buffer.open(QIODevice::ReadOnly);
|
2016-03-22 11:18:05 +01:00
|
|
|
QString extension = doc->GetImageExtension();
|
|
|
|
if (extension.isEmpty())
|
|
|
|
{
|
|
|
|
extension = "PNG";
|
|
|
|
}
|
|
|
|
image.load(&buffer, extension.toLatin1().data()); // writes image into ba in PNG format
|
2016-03-17 15:34:40 +01:00
|
|
|
|
2016-03-09 20:01:37 +01:00
|
|
|
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
|
2016-03-17 15:34:40 +01:00
|
|
|
ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
2016-03-18 19:23:42 +01:00
|
|
|
ui->imageLabel->setScaledContents(true);
|
2016-03-17 15:34:40 +01:00
|
|
|
|
2016-03-09 20:01:37 +01:00
|
|
|
connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::SetNewImage);
|
2016-03-17 15:34:40 +01:00
|
|
|
connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage);
|
|
|
|
connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, &DialogPatternProperties::ShowContextMenu);
|
|
|
|
|
2016-03-19 09:36:16 +01:00
|
|
|
deleteAction = new QAction(tr("Delete image"), this);
|
|
|
|
changeImageAction = new QAction(tr("Change image"), this);
|
|
|
|
saveImageAction = new QAction(tr("Save image to file"), this);
|
|
|
|
showImageAction = new QAction(tr("Show image"), this);
|
2016-03-17 15:34:40 +01:00
|
|
|
connect(deleteAction, &QAction::triggered, this, &DialogPatternProperties::DeleteImage);
|
|
|
|
connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::SetNewImage);
|
2016-03-18 19:23:19 +01:00
|
|
|
connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage);
|
2016-03-09 20:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SetNewImage()
|
|
|
|
{
|
2016-03-22 11:18:05 +01:00
|
|
|
const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(),
|
|
|
|
tr("Images (*.png *.jpg *.jpeg *.bmp)"));
|
2016-03-09 20:01:37 +01:00
|
|
|
QImage image;
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!image.load(fileName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
|
2016-03-22 11:18:05 +01:00
|
|
|
QFileInfo f(fileName);
|
|
|
|
QString extension = f.suffix().toUpper();
|
2016-03-09 20:01:37 +01:00
|
|
|
|
2016-03-22 11:18:05 +01:00
|
|
|
if (extension == "JPEG")
|
|
|
|
{
|
|
|
|
extension = "JPG";
|
|
|
|
}
|
|
|
|
if (extension == "PNG" || extension == "JPG" || extension == "BMP")
|
|
|
|
{
|
|
|
|
QByteArray byteArray;
|
|
|
|
QBuffer buffer(&byteArray);
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
image.save(&buffer, extension.toLatin1().data()); // writes the image in 'extension' format inside the buffer
|
|
|
|
QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());
|
|
|
|
|
|
|
|
// save our image to file.val
|
|
|
|
doc->SetImage(iconBase64, extension);
|
|
|
|
}
|
2016-03-09 20:01:37 +01:00
|
|
|
}
|
2016-03-15 19:32:52 +01:00
|
|
|
}
|
2016-03-09 20:01:37 +01:00
|
|
|
|
2016-03-15 19:32:52 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::DeleteImage()
|
|
|
|
{
|
|
|
|
doc->DeleteImage();
|
2016-03-19 09:36:16 +01:00
|
|
|
ui->imageLabel->setText(tr("Change image"));
|
2016-03-09 20:01:37 +01:00
|
|
|
}
|
2016-03-17 15:34:40 +01:00
|
|
|
|
2016-03-18 19:23:19 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::SaveImage()
|
|
|
|
{
|
|
|
|
QByteArray byteArray;
|
|
|
|
byteArray.append(doc->GetImage().toUtf8());
|
|
|
|
QByteArray ba = QByteArray::fromBase64(byteArray);
|
|
|
|
|
2016-03-22 11:18:05 +01:00
|
|
|
QString extension = "." + doc->GetImageExtension();
|
2016-03-18 19:23:19 +01:00
|
|
|
QString filename = QFileDialog::getSaveFileName(this, tr("Save File"));
|
|
|
|
QFile file(filename + extension);
|
|
|
|
if (file.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
file.write(ba);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 15:34:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPatternProperties::ShowContextMenu()
|
|
|
|
{
|
|
|
|
QMenu menu(this);
|
|
|
|
menu.addAction(deleteAction);
|
|
|
|
menu.addAction(changeImageAction);
|
|
|
|
menu.addAction(saveImageAction);
|
|
|
|
menu.addAction(showImageAction);
|
|
|
|
menu.exec(QCursor::pos());
|
|
|
|
menu.show();
|
|
|
|
}
|