2014-05-30 10:32:40 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogeditwrongformula.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 29 5, 2014
|
|
|
|
**
|
|
|
|
** @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) 2014 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 "dialogeditwrongformula.h"
|
|
|
|
#include "ui_dialogeditwrongformula.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, QWidget *parent)
|
2014-06-19 11:29:56 +02:00
|
|
|
:DialogTool(data, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0)
|
2014-05-30 10:32:40 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
InitVariables(ui);
|
|
|
|
labelResultCalculation = ui->labelResult;
|
2014-06-19 11:29:56 +02:00
|
|
|
plainTextEditFormula = ui->plainTextEditFormula;
|
2014-05-30 10:32:40 +02:00
|
|
|
labelEditFormula = ui->labelFormula;
|
|
|
|
|
2014-05-30 16:52:12 +02:00
|
|
|
InitOkCancel(ui);
|
2014-05-30 10:32:40 +02:00
|
|
|
flagFormula = false;
|
|
|
|
CheckState();
|
|
|
|
|
2014-06-19 11:29:56 +02:00
|
|
|
this->formulaBaseHeight=ui->plainTextEditFormula->height();
|
2014-05-30 10:32:40 +02:00
|
|
|
|
|
|
|
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEditWrongFormula::PutHere);
|
|
|
|
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEditWrongFormula::PutVal);
|
|
|
|
|
|
|
|
connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEditWrongFormula::EvalFormula);
|
2014-06-19 11:29:56 +02:00
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEditWrongFormula::FormulaChanged);
|
|
|
|
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEditWrongFormula::DeployFormulaTextEdit);
|
2014-05-30 11:04:19 +02:00
|
|
|
|
|
|
|
//Disable Qt::WaitCursor
|
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
#endif
|
2014-05-30 10:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogEditWrongFormula::~DialogEditWrongFormula()
|
|
|
|
{
|
2014-05-30 11:04:19 +02:00
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
#endif
|
2014-05-30 10:32:40 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogEditWrongFormula::DialogAccepted()
|
|
|
|
{
|
2014-06-19 11:29:56 +02:00
|
|
|
formula = ui->plainTextEditFormula->toPlainText();
|
|
|
|
formula.replace("\n", " ");
|
2014-05-30 10:32:40 +02:00
|
|
|
emit DialogClosed(QDialog::Accepted);
|
|
|
|
accepted();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogEditWrongFormula::DialogRejected()
|
|
|
|
{
|
|
|
|
emit DialogClosed(QDialog::Rejected);
|
|
|
|
rejected();
|
|
|
|
}
|
|
|
|
|
2014-06-19 11:29:56 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogEditWrongFormula::DeployFormulaTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
|
|
|
|
}
|
|
|
|
|
2014-05-30 10:32:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogEditWrongFormula::CheckState()
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(bOk != nullptr);
|
2014-05-30 10:32:40 +02:00
|
|
|
bOk->setEnabled(flagFormula);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogEditWrongFormula::setFormula(const QString &value)
|
|
|
|
{
|
|
|
|
formula = qApp->FormulaToUser(value);
|
2014-06-19 11:29:56 +02:00
|
|
|
// increase height if needed. TODO : see if I can get the max number of caracters in one line
|
|
|
|
// of this PlainTextEdit to change 80 to this value
|
|
|
|
if (formula.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployFormulaTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditFormula->setPlainText(formula);
|
2014-05-30 10:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogEditWrongFormula::getFormula() const
|
|
|
|
{
|
|
|
|
return qApp->FormulaFromUser(formula);
|
|
|
|
}
|