valentina/src/app/dialogs/tools/dialogtool.h

470 lines
16 KiB
C
Raw Normal View History

/************************************************************************
**
** @file dialogtool.h
** @author Roman Telezhinsky <dismine@gmail.com>
** @date November 15, 2013
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
2013-07-28 00:18:06 +02:00
#ifndef DIALOGTOOL_H
#define DIALOGTOOL_H
#include <QComboBox>
2013-07-28 00:18:06 +02:00
#include <QDialog>
#include <QDoubleSpinBox>
#include <QLabel>
#include <QListWidgetItem>
#include <QRadioButton>
2014-03-06 14:28:46 +01:00
#include <QDialogButtonBox>
#include <QPushButton>
#include "../../container/vcontainer.h"
#include "../../widgets/vapplication.h"
2013-07-28 00:18:06 +02:00
namespace ComboMode
{
/**
* @brief The ComboBoxCutSpline enum
*/
enum ComboBoxCutSpline { CutSpline, NoCutSpline };
Q_DECLARE_FLAGS(ComboBoxCutSplines, ComboBoxCutSpline)
2014-01-08 15:05:32 +01:00
enum ComboBoxCutArc { CutArc, NoCutArc};
Q_DECLARE_FLAGS(ComboBoxCutArcs, ComboBoxCutArc)
}
Q_DECLARE_OPERATORS_FOR_FLAGS( ComboMode::ComboBoxCutSplines )
2014-01-08 15:05:32 +01:00
Q_DECLARE_OPERATORS_FOR_FLAGS( ComboMode::ComboBoxCutArcs )
/**
* @brief The DialogTool class parent for all dialog of tools.
*/
class DialogTool : public QDialog
{
2013-07-28 00:18:06 +02:00
Q_OBJECT
public:
/**
* @brief DialogTool create dialog
* @param data container with data
* @param parent parent widget
*/
DialogTool(const VContainer *data, QWidget *parent = nullptr);
2013-10-26 19:55:06 +02:00
virtual ~DialogTool() {}
2013-07-28 00:18:06 +02:00
signals:
/**
* @brief DialogClosed signal dialog closed
* @param result keep result
*/
2013-07-28 00:18:06 +02:00
void DialogClosed(int result);
/**
* @brief ToolTip emit tooltipe for tool
* @param toolTip text tooltipe
*/
void ToolTip(const QString &toolTip);
2013-07-28 00:18:06 +02:00
public slots:
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
* @param id id of point or detail
* @param type type of object
*/
2014-03-11 12:43:24 +01:00
virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type);
/**
* @brief NamePointChanged check name of point
*/
2013-07-28 00:18:06 +02:00
void NamePointChanged();
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
*/
2013-07-28 00:18:06 +02:00
virtual void DialogAccepted();
/**
* @brief DialogRejected emit signal dialog rejected
*/
2013-07-28 00:18:06 +02:00
virtual void DialogRejected();
/**
* @brief formula check formula
*/
2013-07-28 00:18:06 +02:00
void FormulaChanged();
/**
* @brief ArrowUp set angle value 90 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowUp();
/**
* @brief ArrowDown set angle value 270 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowDown();
/**
* @brief ArrowLeft set angle value 180 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowLeft();
/**
* @brief ArrowRight set angle value 0 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowRight();
/**
* @brief ArrowLeftUp set angle value 135 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowLeftUp();
/**
* @brief ArrowLeftDown set angle value 225 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowLeftDown();
/**
* @brief ArrowRightUp set angle value 45 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowRightUp();
/**
* @brief ArrowRightDown set angle value 315 degree
*/
2013-07-28 00:18:06 +02:00
void ArrowRightDown();
/**
* @brief EvalFormula evaluate formula
*/
2013-07-28 00:18:06 +02:00
void EvalFormula();
/**
* @brief SizeHeight show in list base variables
*/
void SizeHeight();
/**
* @brief Measurements show in list measurements
*/
void Measurements();
/**
* @brief LengthLines show in list lengths of lines variables
*/
2013-07-28 00:18:06 +02:00
void LengthLines();
/**
* @brief LengthArcs show in list lengths of arcs variables
*/
void LengthArcs();
/**
* @brief LengthCurves show in list lengths of curves variables
*/
void LengthCurves();
/**
* @brief Increments show in list increment variables
*/
2013-07-28 00:18:06 +02:00
void Increments();
/**
* @brief PutHere put variable into edit
*/
2013-07-28 00:18:06 +02:00
void PutHere();
/**
* @brief PutVal put variable into edit
* @param item chosen item of list widget
*/
2013-07-28 00:18:06 +02:00
void PutVal(QListWidgetItem * item);
/**
* @brief ValChenged show description when current variable changed
* @param row number of row
*/
2013-08-06 09:56:09 +02:00
virtual void ValChenged(int row);
/**
* @brief UpdateList update lists of variables
*/
2013-07-28 00:18:06 +02:00
void UpdateList();
protected:
Q_DISABLE_COPY(DialogTool)
/**
* @brief data container with data
*/
2013-07-28 00:18:06 +02:00
const VContainer *data;
/**
* @brief isInitialized true if window is initialized
*/
2013-07-28 00:18:06 +02:00
bool isInitialized;
/**
* @brief flagName true if name is correct
*/
2013-07-28 00:18:06 +02:00
bool flagName;
/**
* @brief flagFormula true if formula correct
*/
2013-07-28 00:18:06 +02:00
bool flagFormula;
/**
* @brief timerFormula timer for check formula
*/
2013-07-28 00:18:06 +02:00
QTimer *timerFormula;
/**
* @brief bOk button ok
*/
2013-07-28 00:18:06 +02:00
QPushButton *bOk;
/**
* @brief spinBoxAngle spinbox for angle
*/
2013-09-12 16:18:31 +02:00
QDoubleSpinBox *spinBoxAngle;
/**
* @brief lineEditFormula linEdit for formula
*/
2013-07-28 00:18:06 +02:00
QLineEdit *lineEditFormula;
/**
* @brief listWidget listWidget with variables
*/
2013-07-28 00:18:06 +02:00
QListWidget *listWidget;
/**
* @brief labelResultCalculation label with result of calculation
*/
2013-07-28 00:18:06 +02:00
QLabel *labelResultCalculation;
/**
* @brief labelDescription description of variable
*/
2013-07-28 00:18:06 +02:00
QLabel *labelDescription;
/**
* @brief labelEditNamePoint label used when need show wrong name of point
*/
QLabel *labelEditNamePoint;
/**
* @brief labelEditFormula label used when need show wrong formula
*/
QLabel *labelEditFormula;
/**
* @brief radioButtonSizeGrowth radio button for base variables
*/
2013-07-28 00:18:06 +02:00
QRadioButton *radioButtonSizeGrowth;
/**
* @brief radioButtonStandardTable radio button for standard table variables
*/
QRadioButton *radioButtonStandardTable;
/**
* @brief radioButtonIncrements radio button for increments variables
*/
2013-07-28 00:18:06 +02:00
QRadioButton *radioButtonIncrements;
/**
* @brief radioButtonLengthLine radio button for lengths od lines variables
*/
2013-07-28 00:18:06 +02:00
QRadioButton *radioButtonLengthLine;
/**
* @brief radioButtonLengthArc radio button for lengths of arcs variables
*/
QRadioButton *radioButtonLengthArc;
/**
* @brief radioButtonLengthCurve radio button for lengths of curves variables
*/
QRadioButton *radioButtonLengthCurve;
/**
* @brief lineStyles list supported line styles.
*/
QStringList lineStyles;
/**
* @brief closeEvent handle when dialog cloded
* @param event event
*/
2013-08-15 22:39:00 +02:00
virtual void closeEvent ( QCloseEvent * event );
/**
* @brief showEvent handle when window show
* @param event event
*/
2013-08-15 22:39:00 +02:00
virtual void showEvent( QShowEvent *event );
/**
* @brief FillComboBoxPoints fill comboBox list of points
* @param box comboBox
* @param id don't show this id in list
*/
void FillComboBoxPoints(QComboBox *box, const quint32 &id = 0)const;
void FillComboBoxArcs(QComboBox *box, const quint32 &id = 0,
2014-01-08 15:05:32 +01:00
ComboMode::ComboBoxCutArc cut = ComboMode::NoCutArc)const;
/**
* @brief FillComboBoxSplines fill comboBox list of splines
* @param box comboBox
* @param id don't show id in list
* @param cut if set to ComboMode::CutSpline don't show id+1 and id+2
*/
void FillComboBoxSplines(QComboBox *box, const quint32 &id = 0,
ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline)const;
/**
* @brief FillComboBoxSplinesPath
* @param box comboBox
* @param id don't show id in list
* @param cut if set to ComboMode::CutSpline don't show id+1 and id+2
*/
void FillComboBoxSplinesPath(QComboBox *box, const quint32 &id = 0,
ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline)const;
/**
* @brief FillComboBoxTypeLine fill comboBox list of type lines
* @param box comboBox
*/
2013-07-28 00:18:06 +02:00
void FillComboBoxTypeLine(QComboBox *box) const;
/**
* @brief CheckState enable, when all is correct, or disable, when something wrong, button ok
*/
2013-07-31 13:34:39 +02:00
virtual void CheckState();
/**
* @brief getTypeLine return type of line
* @param box combobox
* @return type
*/
2013-07-28 00:18:06 +02:00
QString GetTypeLine(const QComboBox *box)const;
template <class key, class val>
/**
* @brief ShowVariable show variables in list
* @param var container with variables
*/
void ShowVariable(const QHash<key, val> *var);
/**
* @brief SetupTypeLine setupe type of line
* @param box combobox
* @param value string from pattern file
*/
2013-07-29 14:55:40 +02:00
void SetupTypeLine(QComboBox *box, const QString &value);
/**
* @brief ChangeCurrentText select item in combobox by name
* @param box combobox
* @param value name of item
*/
2013-07-29 14:55:40 +02:00
void ChangeCurrentText(QComboBox *box, const QString &value);
/**
* @brief ChangeCurrentData select item in combobox by id
* @param box combobox
* @param value id of item
*/
void ChangeCurrentData(QComboBox *box, const quint32 &value) const;
/**
* @brief PutValHere put variable into line edit from list
* @param lineEdit lineEdit
* @param listWidget listWidget
*/
2013-08-06 09:56:09 +02:00
void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget);
/**
* @brief ValFormulaChanged handle change formula
* @param flag flag state of formula
* @param edit LineEdit
* @param timer timer of formula
*/
2013-08-06 09:56:09 +02:00
void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer);
/**
* @brief Eval evaluate formula and show result
* @param edit lineEdit of formula
* @param flag flag state of formula
* @param timer timer of formula
* @param label label for signal error
*/
2013-08-06 09:56:09 +02:00
void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label);
/**
* @brief setCurrentPointId set current point id in combobox
* @param box combobox
* @param pointId save current point id
* @param value point id
* @param id don't show this id in list
*/
void setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const;
/**
* @brief setCurrentSplineId set current spline id in combobox
* @param box combobox
* @param splineId save current spline id
* @param value spline id
* @param id don't show this id in list
* @param cut if set to ComboMode::CutSpline don't show id+1 and id+2
*/
void setCurrentSplineId(QComboBox *box, quint32 &splineId, const quint32 &value, const quint32 &id,
ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline) const;
/**
* @brief setCurrentArcId
* @param box combobox
* @param arcId save current arc id
* @param value arc id
* @param id don't show this id in list
* @param cut if set to ComboMode::CutArc don't show id+1 and id+2
*/
void setCurrentArcId(QComboBox *box, quint32 &arcId, const quint32 &value, const quint32 &id,
2014-01-08 15:05:32 +01:00
ComboMode::ComboBoxCutArc cut = ComboMode::NoCutArc) const;
/**
* @brief setCurrentSplinePathId set current splinePath id in combobox
* @param box combobox
* @param splinePathId save current splinePath id
* @param value splinePath id
* @param id don't show this id in list
* @param cut if set to ComboMode::CutSpline don't show id+1 and id+2
*/
2014-02-26 10:51:37 +01:00
void setCurrentSplinePathId(QComboBox *box, quint32 &splinePathId, const quint32 &value,
const quint32 &id,
ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline) const;
/**
* @brief getCurrentPointId return current point id in combobox
* @param box combobox
* @return id or -1 if combobox is empty
*/
2014-03-06 14:28:46 +01:00
quint32 getCurrentObjectId(QComboBox *box) const;
bool ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip);
2014-03-04 19:14:11 +01:00
template <typename T>
2014-03-06 14:28:46 +01:00
void InitArrow(T *ui)
2014-03-04 19:14:11 +01:00
{
Q_CHECK_PTR(ui);
spinBoxAngle = ui->doubleSpinBoxAngle;
connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, &DialogTool::ArrowDown);
connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, &DialogTool::ArrowUp);
connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, &DialogTool::ArrowLeft);
connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, &DialogTool::ArrowRight);
connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, &DialogTool::ArrowLeftUp);
connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, &DialogTool::ArrowLeftDown);
connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, &DialogTool::ArrowRightUp);
connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, &DialogTool::ArrowRightDown);
}
2014-03-06 14:28:46 +01:00
template <typename T>
void InitVariables(T *ui)
{
listWidget = ui->listWidget;
labelDescription = ui->labelDescription;
radioButtonSizeGrowth = ui->radioButtonSizeGrowth;
radioButtonStandardTable = ui->radioButtonStandardTable;
radioButtonIncrements = ui->radioButtonIncrements;
radioButtonLengthLine = ui->radioButtonLengthLine;
radioButtonLengthArc = ui->radioButtonLengthArc;
radioButtonLengthCurve = ui->radioButtonLengthSpline;
connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged);
if (qApp->patternType() == Pattern::Standard)
{
SizeHeight();
connect(radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogTool::SizeHeight);
}
else
{
radioButtonSizeGrowth->setVisible(false);
Measurements();
}
connect(radioButtonStandardTable, &QRadioButton::clicked, this, &DialogTool::Measurements);
2014-03-06 14:28:46 +01:00
connect(radioButtonIncrements, &QRadioButton::clicked, this, &DialogTool::Increments);
connect(radioButtonLengthLine, &QRadioButton::clicked, this, &DialogTool::LengthLines);
connect(radioButtonLengthArc, &QRadioButton::clicked, this, &DialogTool::LengthArcs);
connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves);
}
template <typename T>
void InitOkCansel(T *ui)
{
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
Q_CHECK_PTR(bOk);
connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted);
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
Q_CHECK_PTR(bCansel);
connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected);
}
private:
/**
* @brief FillList fill combobox list
* @param box combobox
* @param list list with ids and names
*/
void FillList(QComboBox *box, const QMap<QString, quint32> &list)const;
2013-07-28 00:18:06 +02:00
};
#endif // DIALOGTOOL_H