Merge with develop

--HG--
branch : DialogTools
This commit is contained in:
dismine 2014-05-27 21:39:54 +03:00
commit f14d21b7da
9 changed files with 560 additions and 430 deletions

View File

@ -1,10 +1,13 @@
[Desktop Entry] [Desktop Entry]
Type=Application Type=Application
Name=Valentina Name=Valentina
Exec=valentina %U
Version=1.0
Encoding=UTF-8
GenericName=Pattern making program GenericName=Pattern making program
Comment=Open source project of creating a pattern making program, whose allow create and modeling patterns of clothing Comment=Open source project of creating a pattern making program, whose allow create and modeling patterns of clothing
Icon=valentina Icon=valentina
Exec=valentina Terminal=false
MimeType=text/val;
Categories=Graphics;VectorGraphics;2DGraphics; Categories=Graphics;VectorGraphics;2DGraphics;
Version=1.0
Name[uk]=valentina Name[uk]=valentina

View File

@ -49,6 +49,9 @@ Calculator::Calculator(const VContainer *data)
DefinePostfixOprt(cm_Oprt, CmUnit); DefinePostfixOprt(cm_Oprt, CmUnit);
DefinePostfixOprt(mm_Oprt, MmUnit); DefinePostfixOprt(mm_Oprt, MmUnit);
DefinePostfixOprt(in_Oprt, InchUnit); DefinePostfixOprt(in_Oprt, InchUnit);
SetArgSep(',');
SetDecSep('.');
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -65,7 +68,7 @@ Calculator::Calculator(const QString &formula, bool fromUser)
DefinePostfixOprt(qApp->PostfixOperator(mm_Oprt), MmUnit); DefinePostfixOprt(qApp->PostfixOperator(mm_Oprt), MmUnit);
DefinePostfixOprt(qApp->PostfixOperator(in_Oprt), InchUnit); DefinePostfixOprt(qApp->PostfixOperator(in_Oprt), InchUnit);
QLocale loc = QLocale(); QLocale loc = QLocale::system();
SetDecSep(loc.decimalPoint().toLatin1()); SetDecSep(loc.decimalPoint().toLatin1());
SetThousandsSep(loc.groupSeparator().toLatin1()); SetThousandsSep(loc.groupSeparator().toLatin1());
SetArgSep(';'); SetArgSep(';');
@ -75,6 +78,9 @@ Calculator::Calculator(const QString &formula, bool fromUser)
DefinePostfixOprt(cm_Oprt, CmUnit); DefinePostfixOprt(cm_Oprt, CmUnit);
DefinePostfixOprt(mm_Oprt, MmUnit); DefinePostfixOprt(mm_Oprt, MmUnit);
DefinePostfixOprt(in_Oprt, InchUnit); DefinePostfixOprt(in_Oprt, InchUnit);
SetArgSep(',');
SetDecSep('.');
} }
SetExpr(formula); SetExpr(formula);

View File

@ -122,7 +122,7 @@ void DialogEndLine::setFormula(const QString &value)
{ {
this->DeployFormulaTextEdit(); this->DeployFormulaTextEdit();
} }
ui->plainTextEditFormula->setPlainText(value); ui->plainTextEditFormula->setPlainText(formula);
//QTextCursor cursor = ui->plainTextEditFormula->textCursor(); //QTextCursor cursor = ui->plainTextEditFormula->textCursor();
//cursor.insertText(value); //cursor.insertText(value);
//ui->plainTextEditFormula->setCursor(cursor); //ui->plainTextEditFormula->setCursor(cursor);

View File

@ -377,7 +377,8 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label)
Calculator cal(data); Calculator cal(data);
const qreal result = cal.EvalFormula(formula); const qreal result = cal.EvalFormula(formula);
label->setText(QString().setNum(result)); QLocale loc = QLocale::system();
label->setText(loc.toString(result));
flag = true; flag = true;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
emit ToolTip(""); emit ToolTip("");
@ -424,7 +425,8 @@ void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *l
Calculator cal(data); Calculator cal(data);
const qreal result = cal.EvalFormula(formula); const qreal result = cal.EvalFormula(formula);
label->setText(QString().setNum(result)); QLocale loc = QLocale::system();
label->setText(loc.toString(result));
flag = true; flag = true;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
emit ToolTip(""); emit ToolTip("");

View File

@ -47,6 +47,10 @@
#include <QSourceLocation> #include <QSourceLocation>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief MainWindow constructor.
* @param parent parent widget.
*/
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Valentina::ArrowTool), :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Valentina::ArrowTool),
currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr),
@ -67,6 +71,8 @@ MainWindow::MainWindow(QWidget *parent)
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
view = new VMainGraphicsView(); view = new VMainGraphicsView();
ui->LayoutView->addWidget(view); ui->LayoutView->addWidget(view);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
view->setScene(currentScene); view->setScene(currentScene);
sceneDraw->setTransform(view->transform()); sceneDraw->setTransform(view->transform());
@ -94,6 +100,9 @@ MainWindow::MainWindow(QWidget *parent)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionNewDraw add to scene new pattern peace.
*/
void MainWindow::ActionNewDraw() void MainWindow::ActionNewDraw()
{ {
QString patternPieceName = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1); QString patternPieceName = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1);
@ -183,6 +192,9 @@ void MainWindow::ActionNewDraw()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief OptionDraw help change name of pattern peace.
*/
void MainWindow::OptionDraw() void MainWindow::OptionDraw()
{ {
const QString activDraw = doc->GetNameActivDraw(); const QString activDraw = doc->GetNameActivDraw();
@ -202,6 +214,14 @@ void MainWindow::OptionDraw()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetToolButton set tool and show dialog.
* @param checked true if tool button checked.
* @param t tool type.
* @param cursor path tool cursor icon.
* @param toolTip first tooltipe.
* @param closeDialogSlot function what handle after close dialog.
*/
// TODO Issue 79 : remove function // TODO Issue 79 : remove function
template <typename Dialog, typename Func> template <typename Dialog, typename Func>
void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip,
@ -234,6 +254,15 @@ void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// TODO Issue 79 : rename to SetToolButton // TODO Issue 79 : rename to SetToolButton
template <typename Dialog, typename Func, typename Func2> template <typename Dialog, typename Func, typename Func2>
/**
* @brief SetToolButton set tool and show dialog.
* @param checked true if tool button checked.
* @param t tool type.
* @param cursor path tool cursor icon.
* @param toolTip first tooltipe.
* @param closeDialogSlot function to handle close of dialog.
* @param applyDialogSlot function to handle apply in dialog.
*/
void MainWindow::SetToolButton2(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, void MainWindow::SetToolButton2(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip,
Func closeDialogSlot, Func2 applyDialogSlot) Func closeDialogSlot, Func2 applyDialogSlot)
{ {
@ -262,6 +291,10 @@ void MainWindow::SetToolButton2(bool checked, Valentina::Tools t, const QString
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialog handle close dialog
* @param result result working dialog.
*/
template <typename DrawTool> template <typename DrawTool>
void MainWindow::ClosedDialog(int result) void MainWindow::ClosedDialog(int result)
{// TODO ISSUE 79 : delete {// TODO ISSUE 79 : delete
@ -274,9 +307,14 @@ void MainWindow::ClosedDialog(int result)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialog handle close dialog
* @param result result working dialog.
*/
// TODO ISSUE 79 : rename
template <typename DrawTool> template <typename DrawTool>
void MainWindow::ClosedDialog2(int result) void MainWindow::ClosedDialog2(int result)
{ // TODO ISSUE 79 : rename {
Q_CHECK_PTR(dialogTool); Q_CHECK_PTR(dialogTool);
if (result == QDialog::Accepted) if (result == QDialog::Accepted)
{ {
@ -301,6 +339,9 @@ void MainWindow::ClosedDialog2(int result)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ApplyDialog handle apply in dialog
*/
template <typename DrawTool> template <typename DrawTool>
void MainWindow::ApplyDialog() void MainWindow::ApplyDialog()
{// TODO ISSUE 79 : copy {// TODO ISSUE 79 : copy
@ -320,6 +361,10 @@ void MainWindow::ApplyDialog()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolEndLine handler tool endLine.
* @param checked true - button checked.
*/
void MainWindow::ToolEndLine(bool checked) void MainWindow::ToolEndLine(bool checked)
{// TODO ISSUE 79 : copy {// TODO ISSUE 79 : copy
// SetToolButton<DialogEndLine>(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), // SetToolButton<DialogEndLine>(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"),
@ -329,18 +374,29 @@ void MainWindow::ToolEndLine(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** // TODO ISSUE 79 : copy
* @brief ApplyDialogEndLine actions after apply in DialogEndLine.
*/
void MainWindow::ApplyDialogEndLine() void MainWindow::ApplyDialogEndLine()
{ // TODO ISSUE 79 : copy { // TODO ISSUE 79 : copy
ApplyDialog<VToolEndLine>(); ApplyDialog<VToolEndLine>();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogEndLine actions after closing DialogEndLine.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogEndLine(int result) void MainWindow::ClosedDialogEndLine(int result)
{ {
ClosedDialog2<VToolEndLine>(result); ClosedDialog2<VToolEndLine>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolLine handler tool line.
* @param checked true - button checked.
*/
void MainWindow::ToolLine(bool checked) void MainWindow::ToolLine(bool checked)
{ {
SetToolButton<DialogLine>(checked, Valentina::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), SetToolButton<DialogLine>(checked, Valentina::LineTool, ":/cursor/line_cursor.png", tr("Select first point"),
@ -348,12 +404,20 @@ void MainWindow::ToolLine(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogLine actions after closing DialogLine.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogLine(int result) void MainWindow::ClosedDialogLine(int result)
{ {
ClosedDialog<VToolLine>(result); ClosedDialog<VToolLine>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolAlongLine handler tool alongLine.
* @param checked true - button checked.
*/
void MainWindow::ToolAlongLine(bool checked) void MainWindow::ToolAlongLine(bool checked)
{ {
SetToolButton<DialogAlongLine>(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", SetToolButton<DialogAlongLine>(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png",
@ -361,12 +425,20 @@ void MainWindow::ToolAlongLine(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogAlongLine actions after closing DialogAlongLine.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogAlongLine(int result) void MainWindow::ClosedDialogAlongLine(int result)
{ {
ClosedDialog<VToolAlongLine>(result); ClosedDialog<VToolAlongLine>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolShoulderPoint handler tool shoulderPoint.
* @param checked true - button checked.
*/
void MainWindow::ToolShoulderPoint(bool checked) void MainWindow::ToolShoulderPoint(bool checked)
{ {
SetToolButton<DialogShoulderPoint>(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", SetToolButton<DialogShoulderPoint>(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png",
@ -374,12 +446,20 @@ void MainWindow::ToolShoulderPoint(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogShoulderPoint actions after closing DialogShoulderPoint.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogShoulderPoint(int result) void MainWindow::ClosedDialogShoulderPoint(int result)
{ {
ClosedDialog<VToolShoulderPoint>(result); ClosedDialog<VToolShoulderPoint>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolNormal handler tool normal.
* @param checked true - button checked.
*/
void MainWindow::ToolNormal(bool checked) void MainWindow::ToolNormal(bool checked)
{ {
SetToolButton<DialogNormal>(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png", SetToolButton<DialogNormal>(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png",
@ -387,12 +467,20 @@ void MainWindow::ToolNormal(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogNormal actions after closing DialogNormal.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogNormal(int result) void MainWindow::ClosedDialogNormal(int result)
{ {
ClosedDialog<VToolNormal>(result); ClosedDialog<VToolNormal>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolBisector handler tool bisector.
* @param checked true - button checked.
*/
void MainWindow::ToolBisector(bool checked) void MainWindow::ToolBisector(bool checked)
{ {
SetToolButton<DialogBisector>(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png", SetToolButton<DialogBisector>(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png",
@ -400,12 +488,20 @@ void MainWindow::ToolBisector(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogBisector actions after closing DialogBisector.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogBisector(int result) void MainWindow::ClosedDialogBisector(int result)
{ {
ClosedDialog<VToolBisector>(result); ClosedDialog<VToolBisector>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolLineIntersect handler tool lineIntersect.
* @param checked true - button checked.
*/
void MainWindow::ToolLineIntersect(bool checked) void MainWindow::ToolLineIntersect(bool checked)
{ {
SetToolButton<DialogLineIntersect>(checked, Valentina::LineIntersectTool, ":/cursor/intersect_cursor.png", SetToolButton<DialogLineIntersect>(checked, Valentina::LineIntersectTool, ":/cursor/intersect_cursor.png",
@ -413,12 +509,20 @@ void MainWindow::ToolLineIntersect(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogLineIntersect actions after closing DialogLineIntersect.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogLineIntersect(int result) void MainWindow::ClosedDialogLineIntersect(int result)
{ {
ClosedDialog<VToolLineIntersect>(result); ClosedDialog<VToolLineIntersect>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolSpline handler tool spline.
* @param checked true - button checked.
*/
void MainWindow::ToolSpline(bool checked) void MainWindow::ToolSpline(bool checked)
{ {
SetToolButton<DialogSpline>(checked, Valentina::SplineTool, ":/cursor/spline_cursor.png", SetToolButton<DialogSpline>(checked, Valentina::SplineTool, ":/cursor/spline_cursor.png",
@ -426,12 +530,20 @@ void MainWindow::ToolSpline(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogSpline actions after closing DialogSpline.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogSpline(int result) void MainWindow::ClosedDialogSpline(int result)
{ {
ClosedDialog<VToolSpline>(result); ClosedDialog<VToolSpline>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolCutSpline handler tool CutSpline.
* @param checked true - button is checked
*/
void MainWindow::ToolCutSpline(bool checked) void MainWindow::ToolCutSpline(bool checked)
{ {
SetToolButton<DialogCutSpline>(checked, Valentina::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", SetToolButton<DialogCutSpline>(checked, Valentina::CutSplineTool, ":/cursor/spline_cut_point_cursor.png",
@ -439,12 +551,20 @@ void MainWindow::ToolCutSpline(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogCutSpline actions after closing DialogCutSpline.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogCutSpline(int result) void MainWindow::ClosedDialogCutSpline(int result)
{ {
ClosedDialog<VToolCutSpline>(result); ClosedDialog<VToolCutSpline>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolArc handler tool arc.
* @param checked true - button checked.
*/
void MainWindow::ToolArc(bool checked) void MainWindow::ToolArc(bool checked)
{ {
SetToolButton<DialogArc>(checked, Valentina::ArcTool, ":/cursor/arc_cursor.png", SetToolButton<DialogArc>(checked, Valentina::ArcTool, ":/cursor/arc_cursor.png",
@ -452,12 +572,20 @@ void MainWindow::ToolArc(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogArc actions after closing DialogArc.
* @param result result of dialog working..
*/
void MainWindow::ClosedDialogArc(int result) void MainWindow::ClosedDialogArc(int result)
{ {
ClosedDialog<VToolArc>(result); ClosedDialog<VToolArc>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolSplinePath handler tool splinePath.
* @param checked true - button checked.
*/
void MainWindow::ToolSplinePath(bool checked) void MainWindow::ToolSplinePath(bool checked)
{ {
SetToolButton<DialogSplinePath>(checked, Valentina::SplinePathTool, ":/cursor/splinepath_cursor.png", SetToolButton<DialogSplinePath>(checked, Valentina::SplinePathTool, ":/cursor/splinepath_cursor.png",
@ -465,12 +593,20 @@ void MainWindow::ToolSplinePath(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogSplinePath actions after closing DialogSplinePath.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogSplinePath(int result) void MainWindow::ClosedDialogSplinePath(int result)
{ {
ClosedDialog<VToolSplinePath>(result); ClosedDialog<VToolSplinePath>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolCutSplinePath handler tool CutSplinePath.
* @param checked true - button is checked
*/
void MainWindow::ToolCutSplinePath(bool checked) void MainWindow::ToolCutSplinePath(bool checked)
{ {
SetToolButton<DialogCutSplinePath>(checked, Valentina::CutSplinePathTool, SetToolButton<DialogCutSplinePath>(checked, Valentina::CutSplinePathTool,
@ -479,12 +615,20 @@ void MainWindow::ToolCutSplinePath(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogCutSplinePath actions after closing DialogCutSplinePath.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogCutSplinePath(int result) void MainWindow::ClosedDialogCutSplinePath(int result)
{ {
ClosedDialog<VToolCutSplinePath>(result); ClosedDialog<VToolCutSplinePath>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolPointOfContact handler tool pointOfContact.
* @param checked true - button checked.
*/
void MainWindow::ToolPointOfContact(bool checked) void MainWindow::ToolPointOfContact(bool checked)
{ {
SetToolButton<DialogPointOfContact>(checked, Valentina::PointOfContact, ":/cursor/pointcontact_cursor.png", SetToolButton<DialogPointOfContact>(checked, Valentina::PointOfContact, ":/cursor/pointcontact_cursor.png",
@ -492,12 +636,20 @@ void MainWindow::ToolPointOfContact(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogPointOfContact actions after closing DialogPointOfContact.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogPointOfContact(int result) void MainWindow::ClosedDialogPointOfContact(int result)
{ {
ClosedDialog<VToolPointOfContact>(result); ClosedDialog<VToolPointOfContact>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolDetail handler tool detail.
* @param checked true - button checked.
*/
void MainWindow::ToolDetail(bool checked) void MainWindow::ToolDetail(bool checked)
{ {
SetToolButton<DialogDetail>(checked, Valentina::DetailTool, "://cursor/new_detail_cursor.png", SetToolButton<DialogDetail>(checked, Valentina::DetailTool, "://cursor/new_detail_cursor.png",
@ -505,6 +657,10 @@ void MainWindow::ToolDetail(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogDetail actions after closing DialogDetail.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogDetail(int result) void MainWindow::ClosedDialogDetail(int result)
{ {
if (result == QDialog::Accepted) if (result == QDialog::Accepted)
@ -516,6 +672,10 @@ void MainWindow::ClosedDialogDetail(int result)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolHeight handler tool height.
* @param checked true - button checked.
*/
void MainWindow::ToolHeight(bool checked) void MainWindow::ToolHeight(bool checked)
{ {
SetToolButton<DialogHeight>(checked, Valentina::Height, ":/cursor/height_cursor.png", tr("Select base point"), SetToolButton<DialogHeight>(checked, Valentina::Height, ":/cursor/height_cursor.png", tr("Select base point"),
@ -523,12 +683,20 @@ void MainWindow::ToolHeight(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogHeight actions after closing DialogHeight.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogHeight(int result) void MainWindow::ClosedDialogHeight(int result)
{ {
ClosedDialog<VToolHeight>(result); ClosedDialog<VToolHeight>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolTriangle handler tool triangle.
* @param checked true - button checked.
*/
void MainWindow::ToolTriangle(bool checked) void MainWindow::ToolTriangle(bool checked)
{ {
SetToolButton<DialogTriangle>(checked, Valentina::Triangle, ":/cursor/triangle_cursor.png", SetToolButton<DialogTriangle>(checked, Valentina::Triangle, ":/cursor/triangle_cursor.png",
@ -536,12 +704,20 @@ void MainWindow::ToolTriangle(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogTriangle actions after closing DialogTriangle.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogTriangle(int result) void MainWindow::ClosedDialogTriangle(int result)
{ {
ClosedDialog<VToolTriangle>(result); ClosedDialog<VToolTriangle>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolPointOfIntersection handler tool pointOfIntersection.
* @param checked true - button checked.
*/
void MainWindow::ToolPointOfIntersection(bool checked) void MainWindow::ToolPointOfIntersection(bool checked)
{ {
SetToolButton<DialogPointOfIntersection>(checked, Valentina::PointOfIntersection, SetToolButton<DialogPointOfIntersection>(checked, Valentina::PointOfIntersection,
@ -550,12 +726,20 @@ void MainWindow::ToolPointOfIntersection(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogPointOfIntersection actions after closing DialogPointOfIntersection.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogPointOfIntersection(int result) void MainWindow::ClosedDialogPointOfIntersection(int result)
{ {
ClosedDialog<VToolPointOfIntersection>(result); ClosedDialog<VToolPointOfIntersection>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolUnionDetails handler tool unionDetails.
* @param checked true - button checked.
*/
void MainWindow::ToolUnionDetails(bool checked) void MainWindow::ToolUnionDetails(bool checked)
{ {
SetToolButton<DialogUnionDetails>(checked, Valentina::UnionDetails, ":/cursor/union_cursor.png", SetToolButton<DialogUnionDetails>(checked, Valentina::UnionDetails, ":/cursor/union_cursor.png",
@ -565,6 +749,10 @@ void MainWindow::ToolUnionDetails(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogUnionDetails actions after closing DialogUnionDetails.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogUnionDetails(int result) void MainWindow::ClosedDialogUnionDetails(int result)
{ {
ClosedDialog<VToolUnionDetails>(result); ClosedDialog<VToolUnionDetails>(result);
@ -572,6 +760,10 @@ void MainWindow::ClosedDialogUnionDetails(int result)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolCutArc handler tool cutArc.
* @param checked true - button checked.
*/
void MainWindow::ToolCutArc(bool checked) void MainWindow::ToolCutArc(bool checked)
{ {
SetToolButton<DialogCutArc>(checked, Valentina::CutArcTool, ":/cursor/arc_cut_cursor.png", tr("Select arc"), SetToolButton<DialogCutArc>(checked, Valentina::CutArcTool, ":/cursor/arc_cut_cursor.png", tr("Select arc"),
@ -579,12 +771,19 @@ void MainWindow::ToolCutArc(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedDialogCutArc actions after closing DialogCutArc.
* @param result result of dialog working.
*/
void MainWindow::ClosedDialogCutArc(int result) void MainWindow::ClosedDialogCutArc(int result)
{ {
ClosedDialog<VToolCutArc>(result); ClosedDialog<VToolCutArc>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief About show widows about.
*/
void MainWindow::About() void MainWindow::About()
{ {
DialogAboutApp * about_dialog = new DialogAboutApp(this); DialogAboutApp * about_dialog = new DialogAboutApp(this);
@ -593,18 +792,28 @@ void MainWindow::About()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief AboutQt show widows aboutQt.
*/
void MainWindow::AboutQt() void MainWindow::AboutQt()
{ {
QMessageBox::aboutQt(this, tr("About Qt")); QMessageBox::aboutQt(this, tr("About Qt"));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowTool highlight tool.Tip show tools tooltip.
* @param toolTip tooltip text.
*/
void MainWindow::ShowToolTip(const QString &toolTip) void MainWindow::ShowToolTip(const QString &toolTip)
{ {
helpLabel->setText(toolTip); helpLabel->setText(toolTip);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief tableClosed handle after close layout window.
*/
void MainWindow::tableClosed() void MainWindow::tableClosed()
{ {
show(); show();
@ -629,6 +838,10 @@ void MainWindow::PatternProperties()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief showEvent handle after show window.
* @param event show event.
*/
void MainWindow::showEvent( QShowEvent *event ) void MainWindow::showEvent( QShowEvent *event )
{ {
QMainWindow::showEvent( event ); QMainWindow::showEvent( event );
@ -649,6 +862,10 @@ void MainWindow::showEvent( QShowEvent *event )
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief closeEvent handle after close window.
* @param event close event.
*/
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
if (MaybeSave()) if (MaybeSave())
@ -663,6 +880,9 @@ void MainWindow::closeEvent(QCloseEvent *event)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolBarOption enable option toolbar.
*/
void MainWindow::ToolBarOption() void MainWindow::ToolBarOption()
{ {
if (qApp->patternType() == Pattern::Standard) if (qApp->patternType() == Pattern::Standard)
@ -699,6 +919,9 @@ void MainWindow::ToolBarOption()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolBarDraws enable draw toolbar.
*/
void MainWindow::ToolBarDraws() void MainWindow::ToolBarDraws()
{ {
QLabel *labelPtternPieceName = new QLabel(tr("Pattern Piece: ")); QLabel *labelPtternPieceName = new QLabel(tr("Pattern Piece: "));
@ -750,6 +973,10 @@ void MainWindow::InitToolButtons()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief currentDrawChanged change active pattern peace.
* @param index index in combobox.
*/
void MainWindow::currentDrawChanged( int index ) void MainWindow::currentDrawChanged( int index )
{ {
if (index != -1) if (index != -1)
@ -770,6 +997,10 @@ void MainWindow::currentDrawChanged( int index )
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseMove save mouse position and show user.
* @param scenePos position mouse.
*/
void MainWindow::mouseMove(const QPointF &scenePos) void MainWindow::mouseMove(const QPointF &scenePos)
{ {
QString string = QString("%1, %2").arg(static_cast<qint32>(qApp->fromPixel(scenePos.x()))) QString string = QString("%1, %2").arg(static_cast<qint32>(qApp->fromPixel(scenePos.x())))
@ -781,6 +1012,9 @@ void MainWindow::mouseMove(const QPointF &scenePos)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief CanselTool cansel tool.
*/
void MainWindow::CancelTool() void MainWindow::CancelTool()
{ {
delete dialogTool; delete dialogTool;
@ -895,6 +1129,9 @@ void MainWindow::CancelTool()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowTool enable arrow tool.
*/
void MainWindow::ArrowTool() void MainWindow::ArrowTool()
{ {
CancelTool(); CancelTool();
@ -906,12 +1143,19 @@ void MainWindow::ArrowTool()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionAroowTool set arrow tool. Cansel tool what was before.
*/
void MainWindow::ActionAroowTool() void MainWindow::ActionAroowTool()
{ {
ArrowTool(); ArrowTool();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief keyPressEvent handle key press events.
* @param event key event.
*/
void MainWindow::keyPressEvent ( QKeyEvent * event ) void MainWindow::keyPressEvent ( QKeyEvent * event )
{ {
switch (event->key()) switch (event->key())
@ -926,6 +1170,9 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveCurrentScene save scene options before set another.
*/
void MainWindow::SaveCurrentScene() void MainWindow::SaveCurrentScene()
{ {
/*Save transform*/ /*Save transform*/
@ -938,6 +1185,9 @@ void MainWindow::SaveCurrentScene()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief RestoreCurrentScene restore scene options after change.
*/
void MainWindow::RestoreCurrentScene() void MainWindow::RestoreCurrentScene()
{ {
/*Set transform for current scene*/ /*Set transform for current scene*/
@ -950,6 +1200,10 @@ void MainWindow::RestoreCurrentScene()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionDraw show draw scene.
* @param checked true - button checked.
*/
void MainWindow::ActionDraw(bool checked) void MainWindow::ActionDraw(bool checked)
{ {
if (checked) if (checked)
@ -983,6 +1237,10 @@ void MainWindow::ActionDraw(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionDetails show details scene.
* @param checked true - button checked.
*/
void MainWindow::ActionDetails(bool checked) void MainWindow::ActionDetails(bool checked)
{ {
if (checked) if (checked)
@ -1018,6 +1276,10 @@ void MainWindow::ActionDetails(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveAs save as pattern file.
* @return true for successes saving.
*/
bool MainWindow::SaveAs() bool MainWindow::SaveAs()
{ {
QString filters(tr("Pattern files (*.val)")); QString filters(tr("Pattern files (*.val)"));
@ -1045,6 +1307,10 @@ bool MainWindow::SaveAs()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief Save save pattern file.
* @return true for successes saving.
*/
bool MainWindow::Save() bool MainWindow::Save()
{ {
if (curFile.isEmpty()) if (curFile.isEmpty())
@ -1065,19 +1331,27 @@ bool MainWindow::Save()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief Open ask user select pattern file.
*/
void MainWindow::Open() void MainWindow::Open()
{ {
if (MaybeSave()) if (MaybeSave())
{ {
QString filter(tr("Pattern files (*.val)")); QString filter(tr("Pattern files (*.val)"));
//Get list last open files
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QStringList files = settings.value("recentFileList").toStringList();
QString dir; QString dir;
if (curFile.isEmpty()) if (files.isEmpty())
{ {
dir = QDir::homePath(); dir = QDir::homePath();
} }
else else
{ {
dir = QFileInfo(curFile).absolutePath(); //Absolute path to last open file
dir = QFileInfo(files.first()).absolutePath();
} }
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter); QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter);
if (fileName.isEmpty() == false) if (fileName.isEmpty() == false)
@ -1091,6 +1365,9 @@ void MainWindow::Open()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief Options config dialog.
*/
void MainWindow::Options() void MainWindow::Options()
{ {
ConfigDialog dlg(this); ConfigDialog dlg(this);
@ -1101,6 +1378,9 @@ void MainWindow::Options()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief Clear reset to default window.
*/
void MainWindow::Clear() void MainWindow::Clear()
{ {
setCurrentFile(""); setCurrentFile("");
@ -1123,6 +1403,9 @@ void MainWindow::Clear()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief NewPattern create new empty pattern.
*/
void MainWindow::NewPattern() void MainWindow::NewPattern()
{ {
QProcess *v = new QProcess(this); QProcess *v = new QProcess(this);
@ -1131,6 +1414,9 @@ void MainWindow::NewPattern()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief haveChange enable action save if we have unsaved change.
*/
void MainWindow::PatternWasModified() void MainWindow::PatternWasModified()
{ {
setWindowModified(doc->isPatternModified()); setWindowModified(doc->isPatternModified());
@ -1138,6 +1424,10 @@ void MainWindow::PatternWasModified()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangedSize change new size value.
* @param text value size.
*/
void MainWindow::ChangedSize(const QString & text) void MainWindow::ChangedSize(const QString & text)
{ {
qint32 size = text.toInt(); qint32 size = text.toInt();
@ -1146,6 +1436,10 @@ void MainWindow::ChangedSize(const QString & text)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangedGrowth change new height value.
* @param text value height.
*/
void MainWindow::ChangedHeight(const QString &text) void MainWindow::ChangedHeight(const QString &text)
{ {
qint32 growth = text.toInt(); qint32 growth = text.toInt();
@ -1154,6 +1448,10 @@ void MainWindow::ChangedHeight(const QString &text)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetEnableWidgets enable action button.
* @param enable enable value.
*/
void MainWindow::SetEnableWidgets(bool enable) void MainWindow::SetEnableWidgets(bool enable)
{ {
ui->actionSaveAs->setEnabled(enable); ui->actionSaveAs->setEnabled(enable);
@ -1169,6 +1467,10 @@ void MainWindow::SetEnableWidgets(bool enable)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionTable show table with variables.
* @param checked true - button checked.
*/
void MainWindow::ActionTable(bool checked) void MainWindow::ActionTable(bool checked)
{ {
if (checked) if (checked)
@ -1185,6 +1487,9 @@ void MainWindow::ActionTable(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedActionTable actions after closing table with variables.
*/
void MainWindow::ClosedActionTable() void MainWindow::ClosedActionTable()
{ {
ui->actionTable->setChecked(false); ui->actionTable->setChecked(false);
@ -1193,6 +1498,10 @@ void MainWindow::ClosedActionTable()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionHistory show tool history.
* @param checked true - button checked.
*/
void MainWindow::ActionHistory(bool checked) void MainWindow::ActionHistory(bool checked)
{ {
if (checked) if (checked)
@ -1210,6 +1519,10 @@ void MainWindow::ActionHistory(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionLayout begin creation layout.
* @param checked true - button checked.
*/
void MainWindow::ActionLayout(bool checked) void MainWindow::ActionLayout(bool checked)
{ {
Q_UNUSED(checked); Q_UNUSED(checked);
@ -1228,6 +1541,9 @@ void MainWindow::ActionLayout(bool checked)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedActionHistory actions after closing history window with variables.
*/
void MainWindow::ClosedActionHistory() void MainWindow::ClosedActionHistory()
{ {
ui->actionHistory->setChecked(false); ui->actionHistory->setChecked(false);
@ -1235,6 +1551,10 @@ void MainWindow::ClosedActionHistory()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetEnableTool enable button.
* @param enable enable value.
*/
void MainWindow::SetEnableTool(bool enable) void MainWindow::SetEnableTool(bool enable)
{ {
bool drawTools = false; bool drawTools = false;
@ -1272,6 +1592,9 @@ void MainWindow::SetEnableTool(bool enable)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief MinimumScrollBar set scroll bar to minimum.
*/
void MainWindow::MinimumScrollBar() void MainWindow::MinimumScrollBar()
{ {
QScrollBar *horScrollBar = view->horizontalScrollBar(); QScrollBar *horScrollBar = view->horizontalScrollBar();
@ -1281,6 +1604,11 @@ void MainWindow::MinimumScrollBar()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief SavePattern save pattern file.
* @param fileName pattern file name.
* @return true if all is good.
*/
bool MainWindow::SavePattern(const QString &fileName) bool MainWindow::SavePattern(const QString &fileName)
{ {
QFileInfo tempInfo(fileName); QFileInfo tempInfo(fileName);
@ -1297,6 +1625,9 @@ bool MainWindow::SavePattern(const QString &fileName)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief AutoSavePattern start safe saving.
*/
void MainWindow::AutoSavePattern() void MainWindow::AutoSavePattern()
{ {
if (curFile.isEmpty() == false && doc->isPatternModified() == true) if (curFile.isEmpty() == false && doc->isPatternModified() == true)
@ -1310,6 +1641,11 @@ void MainWindow::AutoSavePattern()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief setCurrentFile the function is called to reset the state of a few variables when a file
* is loaded or saved, or when the user starts editing a new file (in which case fileName is empty).
* @param fileName file name.
*/
void MainWindow::setCurrentFile(const QString &fileName) void MainWindow::setCurrentFile(const QString &fileName)
{ {
curFile = fileName; curFile = fileName;
@ -1341,11 +1677,20 @@ void MainWindow::setCurrentFile(const QString &fileName)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief strippedName the function call around curFile to exclude the path to the file.
* @param fullFileName full path to the file.
* @return file name.
*/
QString MainWindow::strippedName(const QString &fullFileName) QString MainWindow::strippedName(const QString &fullFileName)
{ {
return QFileInfo(fullFileName).fileName(); return QFileInfo(fullFileName).fileName();
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ReadSettings read setting for app.
*/
void MainWindow::ReadSettings() void MainWindow::ReadSettings()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
@ -1357,6 +1702,9 @@ void MainWindow::ReadSettings()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief WriteSettings save setting for app.
*/
void MainWindow::WriteSettings() void MainWindow::WriteSettings()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
@ -1366,6 +1714,10 @@ void MainWindow::WriteSettings()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief MaybeSave The function is called to save pending changes.
* @return returns true in all cases, except when the user clicks Cancel.
*/
bool MainWindow::MaybeSave() bool MainWindow::MaybeSave()
{ {
if (doc->isPatternModified()) if (doc->isPatternModified())
@ -1522,6 +1874,10 @@ MainWindow::~MainWindow()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/**
* @brief LoadPattern open pattern file.
* @param fileName name of file.
*/
void MainWindow::LoadPattern(const QString &fileName) void MainWindow::LoadPattern(const QString &fileName)
{ {
try try

View File

@ -51,319 +51,72 @@ class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
/** explicit MainWindow(QWidget *parent = nullptr);
* @brief MainWindow constructor. ~MainWindow();
* @param parent parent widget.
*/
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
/**
* @brief LoadPattern open pattern file.
* @param fileName name of file.
*/
void LoadPattern(const QString &curFile); void LoadPattern(const QString &curFile);
public slots: public slots:
/**
* @brief mouseMove save mouse position and show user.
* @param scenePos position mouse.
*/
void mouseMove(const QPointF &scenePos); void mouseMove(const QPointF &scenePos);
/**
* @brief ActionAroowTool set arrow tool. Cansel tool what was before.
*/
void ActionAroowTool(); void ActionAroowTool();
/**
* @brief ActionDraw show draw scene.
* @param checked true - button checked.
*/
void ActionDraw(bool checked); void ActionDraw(bool checked);
/**
* @brief ActionDetails show details scene.
* @param checked true - button checked.
*/
void ActionDetails(bool checked); void ActionDetails(bool checked);
/**
* @brief ActionNewDraw add to scene new pattern peace.
*/
void ActionNewDraw(); void ActionNewDraw();
/**
* @brief SaveAs save as pattern file.
* @return true for successes saving.
*/
bool SaveAs(); bool SaveAs();
/**
* @brief Save save pattern file.
* @return true for successes saving.
*/
bool Save(); bool Save();
/**
* @brief Open ask user select pattern file.
*/
void Open(); void Open();
/**
* @brief Options config dialog.
*/
void Options(); void Options();
/**
* @brief NewPattern create new empty pattern.
*/
void NewPattern(); void NewPattern();
/**
* @brief ActionTable show table with variables.
* @param checked true - button checked.
*/
void ActionTable(bool checked); void ActionTable(bool checked);
/**
* @brief ActionHistory show tool history.
* @param checked true - button checked.
*/
void ActionHistory(bool checked); void ActionHistory(bool checked);
/**
* @brief ActionLayout begin creation layout.
* @param checked true - button checked.
*/
void ActionLayout(bool checked); void ActionLayout(bool checked);
/**
* @brief currentDrawChanged change active pattern peace.
* @param index index in combobox.
*/
void currentDrawChanged( int index ); void currentDrawChanged( int index );
/**
* @brief OptionDraw help change name of pattern peace.
*/
void OptionDraw(); void OptionDraw();
/**
* @brief haveChange enable action save if we have unsaved change.
*/
void PatternWasModified(); void PatternWasModified();
/**
* @brief ChangedSize change new size value.
* @param text value size.
*/
void ChangedSize(const QString &text); void ChangedSize(const QString &text);
/**
* @brief ChangedGrowth change new height value.
* @param text value height.
*/
void ChangedHeight(const QString & text); void ChangedHeight(const QString & text);
/**
* @brief ClosedActionTable actions after closing table with variables.
*/
void ClosedActionTable(); void ClosedActionTable();
/**
* @brief ClosedActionHistory actions after closing history window with variables.
*/
void ClosedActionHistory(); void ClosedActionHistory();
/**
* @brief ToolEndLine handler tool endLine.
* @param checked true - button checked.
*/
void ToolEndLine(bool checked); void ToolEndLine(bool checked);
/**
* @brief ToolLine handler tool line.
* @param checked true - button checked.
*/
void ToolLine(bool checked); void ToolLine(bool checked);
/**
* @brief ToolAlongLine handler tool alongLine.
* @param checked true - button checked.
*/
void ToolAlongLine(bool checked); void ToolAlongLine(bool checked);
/**
* @brief ToolShoulderPoint handler tool shoulderPoint.
* @param checked true - button checked.
*/
void ToolShoulderPoint(bool checked); void ToolShoulderPoint(bool checked);
/**
* @brief ToolNormal handler tool normal.
* @param checked true - button checked.
*/
void ToolNormal(bool checked); void ToolNormal(bool checked);
/**
* @brief ToolBisector handler tool bisector.
* @param checked true - button checked.
*/
void ToolBisector(bool checked); void ToolBisector(bool checked);
/**
* @brief ToolLineIntersect handler tool lineIntersect.
* @param checked true - button checked.
*/
void ToolLineIntersect(bool checked); void ToolLineIntersect(bool checked);
/**
* @brief ToolSpline handler tool spline.
* @param checked true - button checked.
*/
void ToolSpline(bool checked); void ToolSpline(bool checked);
/**
* @brief ToolCutSpline handler tool CutSpline.
* @param checked true - button is checked
*/
void ToolCutSpline(bool checked); void ToolCutSpline(bool checked);
/**
* @brief ToolArc handler tool arc.
* @param checked true - button checked.
*/
void ToolArc(bool checked); void ToolArc(bool checked);
/**
* @brief ToolSplinePath handler tool splinePath.
* @param checked true - button checked.
*/
void ToolSplinePath(bool checked); void ToolSplinePath(bool checked);
/**
* @brief ToolCutSplinePath handler tool CutSplinePath.
* @param checked true - button is checked
*/
void ToolCutSplinePath(bool checked); void ToolCutSplinePath(bool checked);
/**
* @brief ToolPointOfContact handler tool pointOfContact.
* @param checked true - button checked.
*/
void ToolPointOfContact(bool checked); void ToolPointOfContact(bool checked);
/**
* @brief ToolDetail handler tool detail.
* @param checked true - button checked.
*/
void ToolDetail(bool checked); void ToolDetail(bool checked);
/**
* @brief ToolHeight handler tool height.
* @param checked true - button checked.
*/
void ToolHeight(bool checked); void ToolHeight(bool checked);
/**
* @brief ToolTriangle handler tool triangle.
* @param checked true - button checked.
*/
void ToolTriangle(bool checked); void ToolTriangle(bool checked);
/**
* @brief ToolPointOfIntersection handler tool pointOfIntersection.
* @param checked true - button checked.
*/
void ToolPointOfIntersection(bool checked); void ToolPointOfIntersection(bool checked);
/**
* @brief ToolUnionDetails handler tool unionDetails.
* @param checked true - button checked.
*/
void ToolUnionDetails(bool checked); void ToolUnionDetails(bool checked);
/**
* @brief ToolCutArc handler tool cutArc.
* @param checked true - button checked.
*/
void ToolCutArc(bool checked); void ToolCutArc(bool checked);
/**
* @brief ClosedDialogEndLine actions after closing DialogEndLine.
* @param result result of dialog working.
*/
void ClosedDialogEndLine(int result); void ClosedDialogEndLine(int result);
/** // TODO ISSUE 79 : copy
* @brief ApplyDialogEndLine actions after apply in DialogEndLine.
*/
void ApplyDialogEndLine(); void ApplyDialogEndLine();
/**
* @brief ClosedDialogLine actions after closing DialogLine.
* @param result result of dialog working.
*/
void ClosedDialogLine(int result); void ClosedDialogLine(int result);
/**
* @brief ClosedDialogAlongLine actions after closing DialogAlongLine.
* @param result result of dialog working.
*/
void ClosedDialogAlongLine(int result); void ClosedDialogAlongLine(int result);
/**
* @brief ClosedDialogShoulderPoint actions after closing DialogShoulderPoint.
* @param result result of dialog working.
*/
void ClosedDialogShoulderPoint(int result); void ClosedDialogShoulderPoint(int result);
/**
* @brief ClosedDialogNormal actions after closing DialogNormal.
* @param result result of dialog working.
*/
void ClosedDialogNormal(int result); void ClosedDialogNormal(int result);
/**
* @brief ClosedDialogBisector actions after closing DialogBisector.
* @param result result of dialog working.
*/
void ClosedDialogBisector(int result); void ClosedDialogBisector(int result);
/**
* @brief ClosedDialogLineIntersect actions after closing DialogLineIntersect.
* @param result result of dialog working.
*/
void ClosedDialogLineIntersect(int result); void ClosedDialogLineIntersect(int result);
/**
* @brief ClosedDialogSpline actions after closing DialogSpline.
* @param result result of dialog working.
*/
void ClosedDialogSpline(int result); void ClosedDialogSpline(int result);
/**
* @brief ClosedDialogArc actions after closing DialogArc.
* @param result result of dialog working..
*/
void ClosedDialogArc(int result); void ClosedDialogArc(int result);
/**
* @brief ClosedDialogSplinePath actions after closing DialogSplinePath.
* @param result result of dialog working.
*/
void ClosedDialogSplinePath(int result); void ClosedDialogSplinePath(int result);
/**
* @brief ClosedDialogCutSplinePath actions after closing DialogCutSplinePath.
* @param result result of dialog working.
*/
void ClosedDialogCutSplinePath(int result); void ClosedDialogCutSplinePath(int result);
/**
* @brief ClosedDialogPointOfContact actions after closing DialogPointOfContact.
* @param result result of dialog working.
*/
void ClosedDialogPointOfContact(int result); void ClosedDialogPointOfContact(int result);
/**
* @brief ClosedDialogDetail actions after closing DialogDetail.
* @param result result of dialog working.
*/
void ClosedDialogDetail(int result); void ClosedDialogDetail(int result);
/**
* @brief ClosedDialogHeight actions after closing DialogHeight.
* @param result result of dialog working.
*/
void ClosedDialogHeight(int result); void ClosedDialogHeight(int result);
/**
* @brief ClosedDialogTriangle actions after closing DialogTriangle.
* @param result result of dialog working.
*/
void ClosedDialogTriangle(int result); void ClosedDialogTriangle(int result);
/**
* @brief ClosedDialogPointOfIntersection actions after closing DialogPointOfIntersection.
* @param result result of dialog working.
*/
void ClosedDialogPointOfIntersection(int result); void ClosedDialogPointOfIntersection(int result);
/**
* @brief ClosedDialogUnionDetails actions after closing DialogUnionDetails.
* @param result result of dialog working.
*/
void ClosedDialogUnionDetails(int result); void ClosedDialogUnionDetails(int result);
/**
* @brief ClosedDialogCutSpline actions after closing DialogCutSpline.
* @param result result of dialog working.
*/
void ClosedDialogCutSpline(int result); void ClosedDialogCutSpline(int result);
/**
* @brief ClosedDialogCutArc actions after closing DialogCutArc.
* @param result result of dialog working.
*/
void ClosedDialogCutArc(int result); void ClosedDialogCutArc(int result);
/**
* @brief About show widows about.
*/
void About(); void About();
/**
* @brief AboutQt show widows aboutQt.
*/
void AboutQt(); void AboutQt();
/**
* @brief ShowTool highlight tool.Tip show tools tooltip.
* @param toolTip tooltip text.
*/
void ShowToolTip(const QString &toolTip); void ShowToolTip(const QString &toolTip);
/**
* @brief tableClosed handle after close layout window.
*/
void tableClosed(); void tableClosed();
void OpenRecentFile(); void OpenRecentFile();
void PatternProperties(); void PatternProperties();
@ -375,24 +128,9 @@ signals:
*/ */
void ModelChosen(QVector<VItem*> listDetails, const QString &curFile, const QString &description); void ModelChosen(QVector<VItem*> listDetails, const QString &curFile, const QString &description);
protected: protected:
/**
* @brief keyPressEvent handle key press events.
* @param event key event.
*/
virtual void keyPressEvent ( QKeyEvent * event ); virtual void keyPressEvent ( QKeyEvent * event );
/**
* @brief showEvent handle after show window.
* @param event show event.
*/
virtual void showEvent( QShowEvent *event ); virtual void showEvent( QShowEvent *event );
/**
* @brief closeEvent handle after close window.
* @param event close event.
*/
virtual void closeEvent( QCloseEvent * event ); virtual void closeEvent( QCloseEvent * event );
/**
* @brief Clear reset to default window.
*/
void Clear(); void Clear();
private: private:
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
@ -471,119 +209,36 @@ private:
QAction *recentFileActs[MaxRecentFiles]; QAction *recentFileActs[MaxRecentFiles];
QAction *separatorAct; QAction *separatorAct;
QTimer *autoSaveTimer; QTimer *autoSaveTimer;
/**
* @brief ToolBarOption enable option toolbar.
*/
void ToolBarOption(); void ToolBarOption();
/**
* @brief ToolBarDraws enable draw toolbar.
*/
void ToolBarDraws(); void ToolBarDraws();
void InitToolButtons(); void InitToolButtons();
/**
* @brief CanselTool cansel tool.
*/
void CancelTool(); void CancelTool();
/**
* @brief ArrowTool enable arrow tool.
*/
void ArrowTool(); void ArrowTool();
/**
* @brief SetEnableWidgets enable action button.
* @param enable enable value.
*/
void SetEnableWidgets(bool enable); void SetEnableWidgets(bool enable);
/**
* @brief SetEnableTool enable button.
* @param enable enable value.
*/
void SetEnableTool(bool enable); void SetEnableTool(bool enable);
/**
* @brief SaveCurrentScene save scene options before set another.
*/
void SaveCurrentScene(); void SaveCurrentScene();
/**
* @brief RestoreCurrentScene restore scene options after change.
*/
void RestoreCurrentScene(); void RestoreCurrentScene();
template <typename Dialog, typename Func> template <typename Dialog, typename Func>
/** // TODO ISSUE 79 : delete // TODO ISSUE 79 : delete
* @brief SetToolButton set tool and show dialog.
* @param checked true if tool button checked.
* @param t tool type.
* @param cursor path tool cursor icon.
* @param toolTip first tooltipe.
* @param closeDialogSlot function what handle after close dialog.
*/
void SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, void SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip,
Func closeDialogSlot); Func closeDialogSlot);
/** // TODO ISSUE 79 : copy
* @brief SetToolButton set tool and show dialog.
* @param checked true if tool button checked.
* @param t tool type.
* @param cursor path tool cursor icon.
* @param toolTip first tooltipe.
* @param closeDialogSlot function to handle close of dialog.
* @param applyDialogSlot function to handle apply in dialog.
*/
template <typename Dialog, typename Func, typename Func2> template <typename Dialog, typename Func, typename Func2>
// TODO ISSUE 79 : copy
void SetToolButton2(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, void SetToolButton2(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip,
Func closeDialogSlot, Func2 applyDialogSlot); Func closeDialogSlot, Func2 applyDialogSlot);
/**
* @brief MinimumScrollBar set scroll bar to minimum.
*/
void MinimumScrollBar(); void MinimumScrollBar();
template <typename DrawTool> template <typename DrawTool>
/** // TODO ISSUE 79 : delete
* @brief ClosedDialog handle close dialog
* @param result result working dialog.
*/
void ClosedDialog(int result); void ClosedDialog(int result);
template <typename DrawTool> template <typename DrawTool>
/** // TODO ISSUE 79 : rename
* @brief ClosedDialog handle close dialog
* @param result result working dialog.
*/
void ClosedDialog2(int result); void ClosedDialog2(int result);
/** // TODO ISSUE 79 : copy
* @brief ApplyDialog handle apply in dialog
*/
template <typename DrawTool> template <typename DrawTool>
void ApplyDialog(); void ApplyDialog();
/**
* @brief SavePattern save pattern file.
* @param fileName pattern file name.
* @return true if all is good.
*/
bool SavePattern(const QString &curFile); bool SavePattern(const QString &curFile);
/**
* @brief AutoSavePattern start safe saving.
*/
void AutoSavePattern(); void AutoSavePattern();
/**
* @brief setCurrentFile the function is called to reset the state of a few variables when a file
* is loaded or saved, or when the user starts editing a new file (in which case fileName is empty).
* @param fileName file name.
*/
void setCurrentFile(const QString &fileName); void setCurrentFile(const QString &fileName);
/**
* @brief strippedName the function call around curFile to exclude the path to the file.
* @param fullFileName full path to the file.
* @return file name.
*/
QString strippedName(const QString &fullFileName); QString strippedName(const QString &fullFileName);
/**
* @brief ReadSettings read setting for app.
*/
void ReadSettings(); void ReadSettings();
/**
* @brief WriteSettings save setting for app.
*/
void WriteSettings(); void WriteSettings();
/**
* @brief MaybeSave The function is called to save pending changes.
* @return returns true in all cases, except when the user clicks Cancel.
*/
bool MaybeSave(); bool MaybeSave();
void UpdateRecentFileActions(); void UpdateRecentFileActions();
void CreateMenus(); void CreateMenus();

View File

@ -47,7 +47,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>144</width> <width>150</width>
<height>150</height> <height>150</height>
</rect> </rect>
</property> </property>
@ -302,7 +302,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>150</width>
<height>58</height> <height>58</height>
</rect> </rect>
</property> </property>
@ -378,7 +378,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>150</width>
<height>104</height> <height>104</height>
</rect> </rect>
</property> </property>
@ -579,7 +579,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>150</width>
<height>58</height> <height>58</height>
</rect> </rect>
</property> </property>
@ -703,6 +703,9 @@
<addaction name="menuHelp"/> <addaction name="menuHelp"/>
</widget> </widget>
<widget class="QToolBar" name="mainToolBar"> <widget class="QToolBar" name="mainToolBar">
<property name="windowTitle">
<string>Toolbar files</string>
</property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
</attribute> </attribute>
@ -719,7 +722,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>ToolBar modes</string>
</property> </property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
@ -733,7 +736,7 @@
</widget> </widget>
<widget class="QToolBar" name="toolBarDraws"> <widget class="QToolBar" name="toolBarDraws">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar_2</string> <string>Toolbar pattern</string>
</property> </property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
@ -745,7 +748,7 @@
</widget> </widget>
<widget class="QToolBar" name="toolBarOption"> <widget class="QToolBar" name="toolBarOption">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar_3</string> <string>Toolbar options</string>
</property> </property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>BottomToolBarArea</enum> <enum>BottomToolBarArea</enum>

View File

@ -1505,7 +1505,7 @@ void VApplication::InitPostfixOperators()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VApplication::MeasurementsFromUser(QString &newFormula, int position, const QString &token) const bool VApplication::MeasurementsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
{ {
QMap<QString, VTranslation>::const_iterator i = measurements.constBegin(); QMap<QString, VTranslation>::const_iterator i = measurements.constBegin();
while (i != measurements.constEnd()) while (i != measurements.constEnd())
@ -1513,6 +1513,7 @@ bool VApplication::MeasurementsFromUser(QString &newFormula, int position, const
if(token == i.value().translate()) if(token == i.value().translate())
{ {
newFormula.replace(position, token.length(), i.key()); newFormula.replace(position, token.length(), i.key());
bias = token.length() - i.key().length();
return true; return true;
} }
++i; ++i;
@ -1521,7 +1522,7 @@ bool VApplication::MeasurementsFromUser(QString &newFormula, int position, const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VApplication::VariablesFromUser(QString &newFormula, int position, const QString &token) const bool VApplication::VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const
{ {
QMap<QString, VTranslation>::const_iterator i = variables.constBegin(); QMap<QString, VTranslation>::const_iterator i = variables.constBegin();
while (i != variables.constEnd()) while (i != variables.constEnd())
@ -1529,6 +1530,9 @@ bool VApplication::VariablesFromUser(QString &newFormula, int position, const QS
if(token.indexOf( i.value().translate() ) == 0) if(token.indexOf( i.value().translate() ) == 0)
{ {
newFormula.replace(position, i.value().translate().length(), i.key()); newFormula.replace(position, i.value().translate().length(), i.key());
QString newToken = token;
newToken.replace(0, i.value().translate().length(), i.key());
bias = token.length() - newToken.length();
return true; return true;
} }
++i; ++i;
@ -1537,7 +1541,7 @@ bool VApplication::VariablesFromUser(QString &newFormula, int position, const QS
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VApplication::PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token) const bool VApplication::PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
{ {
QMap<QString, VTranslation>::const_iterator i = postfixOperators.constBegin(); QMap<QString, VTranslation>::const_iterator i = postfixOperators.constBegin();
while (i != postfixOperators.constEnd()) while (i != postfixOperators.constEnd())
@ -1545,6 +1549,7 @@ bool VApplication::PostfixOperatorsFromUser(QString &newFormula, int position, c
if(token == i.value().translate()) if(token == i.value().translate())
{ {
newFormula.replace(position, token.length(), i.key()); newFormula.replace(position, token.length(), i.key());
bias = token.length() - i.key().length();
return true; return true;
} }
++i; ++i;
@ -1553,7 +1558,7 @@ bool VApplication::PostfixOperatorsFromUser(QString &newFormula, int position, c
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VApplication::FunctionsFromUser(QString &newFormula, int position, const QString &token) const bool VApplication::FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
{ {
QMap<QString, VTranslation>::const_iterator i = functions.constBegin(); QMap<QString, VTranslation>::const_iterator i = functions.constBegin();
while (i != functions.constEnd()) while (i != functions.constEnd())
@ -1561,6 +1566,7 @@ bool VApplication::FunctionsFromUser(QString &newFormula, int position, const QS
if(token == i.value().translate()) if(token == i.value().translate())
{ {
newFormula.replace(position, token.length(), i.key()); newFormula.replace(position, token.length(), i.key());
bias = token.length() - i.key().length();
return true; return true;
} }
++i; ++i;
@ -1569,7 +1575,7 @@ bool VApplication::FunctionsFromUser(QString &newFormula, int position, const QS
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VApplication::VariablesToUser(QString &newFormula, int position, const QString &token) const bool VApplication::VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const
{ {
QMap<QString, VTranslation>::const_iterator i = variables.constBegin(); QMap<QString, VTranslation>::const_iterator i = variables.constBegin();
while (i != variables.constEnd()) while (i != variables.constEnd())
@ -1577,6 +1583,10 @@ bool VApplication::VariablesToUser(QString &newFormula, int position, const QStr
if(token.indexOf( i.key() ) == 0) if(token.indexOf( i.key() ) == 0)
{ {
newFormula.replace(position, i.key().length(), i.value().translate()); newFormula.replace(position, i.key().length(), i.value().translate());
QString newToken = token;
newToken.replace(0, i.key().length(), i.value().translate());
bias = token.length() - newToken.length();
return true; return true;
} }
++i; ++i;
@ -1584,6 +1594,37 @@ bool VApplication::VariablesToUser(QString &newFormula, int position, const QStr
return false; return false;
} }
void VApplication::CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens,
QMap<int, QString> &numbers)
{
if(bias == 0)
{
return;
}
BiasTokens(position, bias, tokens);
BiasTokens(position, bias, numbers);
}
void VApplication::BiasTokens(int position, int bias, QMap<int, QString> &tokens) const
{
QMap<int, QString> newTokens;
QMap<int, QString>::const_iterator i = tokens.constBegin();
while (i != tokens.constEnd())
{
if(i.key()<= position)
{
newTokens.insert(i.key(), i.value());
}
else
{
newTokens.insert(i.key()-bias, i.value());
}
++i;
}
tokens = newTokens;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VApplication::setPatternUnit(const Valentina::Units &patternUnit) void VApplication::setPatternUnit(const Valentina::Units &patternUnit)
{ {
@ -1610,7 +1651,8 @@ QString VApplication::VarToUser(const QString &var) const
} }
QString newVar = var; QString newVar = var;
if(VariablesToUser(newVar, 0, var)) int bias = 0;
if(VariablesToUser(newVar, 0, var, bias))
{ {
return newVar; return newVar;
} }
@ -1621,22 +1663,23 @@ QString VApplication::VarToUser(const QString &var) const
QString VApplication::VarFromUser(const QString &var) const QString VApplication::VarFromUser(const QString &var) const
{ {
QString newVar = var; QString newVar = var;
if(MeasurementsFromUser(newVar, 0, var)) int bias = 0;
if(MeasurementsFromUser(newVar, 0, var, bias))
{ {
return newVar; return newVar;
} }
if(VariablesFromUser(newVar, 0, var)) if(VariablesFromUser(newVar, 0, var, bias))
{ {
return newVar; return newVar;
} }
if(PostfixOperatorsFromUser(newVar, 0, var)) if(PostfixOperatorsFromUser(newVar, 0, var, bias))
{ {
return newVar; return newVar;
} }
if(FunctionsFromUser(newVar, 0, var)) if(FunctionsFromUser(newVar, 0, var, bias))
{ {
return newVar; return newVar;
} }
@ -1696,58 +1739,84 @@ QString VApplication::FormulaFromUser(const QString &formula)
return newFormula; return newFormula;
} }
QMap<int, QString>::const_iterator i = tokens.constBegin(); QList<int> tKeys = tokens.keys();
while (i != tokens.constEnd()) QList<QString> tValues = tokens.values();
for (int i = 0; i < tKeys.size(); ++i)
{ {
if(MeasurementsFromUser(newFormula, i.key(), i.value())) int bias = 0;
if(MeasurementsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
{ {
++i; if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
if(VariablesFromUser(newFormula, i.key(), i.value())) if(VariablesFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
{ {
++i; if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
if(PostfixOperatorsFromUser(newFormula, i.key(), i.value())) if(PostfixOperatorsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
{ {
++i; if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
if(FunctionsFromUser(newFormula, i.key(), i.value())) if(FunctionsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
{ {
++i; if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
++i;
} }
QLocale loc = QLocale(); QLocale loc = QLocale::system();
if(loc != QLocale(QLocale::C)) if(loc != QLocale(QLocale::C))
{ {
QMap<int, QString>::const_iterator i = numbers.constBegin(); QList<int> nKeys = numbers.keys();
while (i != numbers.constEnd()) QList<QString> nValues = numbers.values();
for (int i = 0; i < tKeys.size(); ++i)
{ {
QLocale::setDefault(QLocale::C);
bool ok = false; bool ok = false;
qreal d = QString(i.value()).toDouble(&ok); qreal d = loc.toDouble(nValues.at(i), &ok);
if(ok == false) if (ok == false)
{ {
qDebug()<<"Can't convert to double token"<<i.value(); qDebug()<<"Can't convert to double token"<<nValues.at(i);
++i;
continue; continue;
} }
if(qFloor (d) < d) if (qFloor (d) < d)
{ {
QLocale::setDefault(QLocale::system()); QLocale loc = QLocale(QLocale::C);
QLocale loc = QLocale();
QString dStr = loc.toString(d); QString dStr = loc.toString(d);
newFormula.replace(i.key(), i.value().length(), dStr); newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
int bias = nValues.at(i).length() - dStr.length();
if (bias != 0)
{
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
nKeys = numbers.keys();
nValues = numbers.values();
}
} }
++i;
} }
} }
@ -1764,7 +1833,7 @@ QString VApplication::FormulaToUser(const QString &formula)
QMap<int, QString> numbers; QMap<int, QString> numbers;
try try
{ {
Calculator cal(formula); Calculator cal(formula, false);
tokens = cal.GetTokens(); tokens = cal.GetTokens();
numbers = cal.GetNumbers(); numbers = cal.GetNumbers();
} }
@ -1778,61 +1847,91 @@ QString VApplication::FormulaToUser(const QString &formula)
return newFormula; return newFormula;
} }
QMap<int, QString>::const_iterator i = tokens.constBegin(); QList<int> tKeys = tokens.keys();
while (i != tokens.constEnd()) QList<QString> tValues = tokens.values();
for (int i = 0; i < tKeys.size(); ++i)
{ {
if (measurements.contains(i.value())) if (measurements.contains(tValues.at(i)))
{ {
newFormula.replace(i.key(), i.value().length(), measurements.value(i.value()).translate()); newFormula.replace(tKeys.at(i), tValues.at(i).length(), measurements.value(tValues.at(i)).translate());
++i; int bias = tValues.at(i).length() - measurements.value(tValues.at(i)).translate().length();
if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
if (functions.contains(i.value())) if (functions.contains(tValues.at(i)))
{ {
newFormula.replace(i.key(), i.value().length(), functions.value(i.value()).translate()); newFormula.replace(tKeys.at(i), tValues.at(i).length(), functions.value(tValues.at(i)).translate());
++i; int bias = tValues.at(i).length() - functions.value(tValues.at(i)).translate().length();
if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
if (postfixOperators.contains(i.value())) if (postfixOperators.contains(tValues.at(i)))
{ {
newFormula.replace(i.key(), i.value().length(), postfixOperators.value(i.value()).translate()); newFormula.replace(tKeys.at(i), tValues.at(i).length(), postfixOperators.value(tValues.at(i)).translate());
++i; int bias = tValues.at(i).length() - postfixOperators.value(tValues.at(i)).translate().length();
if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
if(VariablesToUser(newFormula, i.key(), i.value())) int bias = 0;
if(VariablesToUser(newFormula, tKeys.at(i), tValues.at(i), bias))
{ {
++i; if (bias != 0)
{
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
tKeys = tokens.keys();
tValues = tokens.values();
}
continue; continue;
} }
} }
QLocale loc = QLocale(); QLocale loc = QLocale::system();
if(loc != QLocale::C) if(loc != QLocale::C)
{ {
QMap<int, QString>::const_iterator i = numbers.constBegin(); QList<int> nKeys = numbers.keys();
while (i != numbers.constEnd()) QList<QString> nValues = numbers.values();
for (int i = 0; i < tKeys.size(); ++i)
{ {
QLocale loc = QLocale(QLocale::C);
bool ok = false; bool ok = false;
qreal d = QString(i.value()).toDouble(&ok); qreal d = loc.toDouble(nValues.at(i), &ok);
if(ok == false) if(ok == false)
{ {
qDebug()<<"Can't convert to double token"<<i.value(); qDebug()<<"Can't convert to double token"<<nValues.at(i);
++i;
continue; continue;
} }
if(qFloor (d) < d) if(qFloor (d) < d)
{ {
QLocale::setDefault(QLocale::C); QLocale loc = QLocale::system();
QLocale loc = QLocale();
QString dStr = loc.toString(d); QString dStr = loc.toString(d);
newFormula.replace(i.key(), i.value().length(), dStr); newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
QLocale::setDefault(QLocale::system()); int bias = nValues.at(i).length() - dStr.length();
if (bias != 0)
{
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
nKeys = numbers.keys();
nValues = numbers.values();
}
} }
++i;
} }
} }

View File

@ -97,11 +97,17 @@ private:
void InitVariables(); void InitVariables();
void InitFunctions(); void InitFunctions();
void InitPostfixOperators(); void InitPostfixOperators();
bool MeasurementsFromUser(QString &newFormula, int position, const QString &token) const; bool MeasurementsFromUser(QString &newFormula, int position, const QString &token,
bool VariablesFromUser(QString &newFormula, int position, const QString &token) const; int &bias) const;
bool PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token) const; bool VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
bool FunctionsFromUser(QString &newFormula, int position, const QString &token) const; bool PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token,
bool VariablesToUser(QString &newFormula, int position, const QString &token) const; int &bias) const;
bool FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const;
void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens,
QMap<int, QString> &numbers);
void BiasTokens(int position, int bias, QMap<int, QString> &tokens) const;
}; };
inline Valentina::Units VApplication::patternUnit() const inline Valentina::Units VApplication::patternUnit() const