DialogBisector Change

--HG--
branch : DialogTools
This commit is contained in:
Patrick Proy 2014-06-08 19:56:09 +02:00
parent 52761f04ce
commit 094f29492d
7 changed files with 161 additions and 26 deletions

View File

@ -39,9 +39,12 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent)
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
labelResultCalculation = ui->labelResultCalculation; labelResultCalculation = ui->labelResultCalculation;
lineEditFormula = ui->lineEditFormula; plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula; labelEditFormula = ui->labelEditFormula;
labelEditNamePoint = ui->labelEditNamePoint; labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight=ui->plainTextEditFormula->height();
InitOkCancelApply(ui); InitOkCancelApply(ui);
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
@ -57,7 +60,38 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent)
connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogBisector::EvalFormula); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogBisector::EvalFormula);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogBisector::NamePointChanged); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogBisector::NamePointChanged);
connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogBisector::FormulaChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogBisector::FormulaTextChanged);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogBisector::DeployFormulaTextEdit);
ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down",
QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png")));
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::FormulaTextChanged()
{
// TODO issue #79 : back to FormulaChanged when full update
// Also remove this function if only one function called here
this->FormulaChanged2();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::DeployFormulaTextEdit()
{
if (ui->plainTextEditFormula->height() < DIALOGBISECTOR_MAX_FORMULA_HEIGHT)
{
ui->plainTextEditFormula->setFixedHeight(DIALOGBISECTOR_MAX_FORMULA_HEIGHT);
//Set icon from theme (internal for Windows system)
ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next",
QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png")));
}
else
{
ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight);
//Set icon from theme (internal for Windows system)
ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down",
QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png")));
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -129,7 +163,12 @@ void DialogBisector::setTypeLine(const QString &value)
void DialogBisector::setFormula(const QString &value) void DialogBisector::setFormula(const QString &value)
{ {
formula = qApp->FormulaToUser(value); formula = qApp->FormulaToUser(value);
ui->lineEditFormula->setText(formula); // increase height if needed.
if (formula.length() > 80)
{
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(formula);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -152,12 +191,25 @@ void DialogBisector::setThirdPointId(const quint32 &value, const quint32 &id)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogBisector::DialogAccepted() void DialogBisector::DialogAccepted()
{
this->SaveData();
emit DialogClosed(QDialog::Accepted);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::DialogApply()
{
this->SaveData();
emit DialogApplied();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::SaveData()
{ {
pointName = ui->lineEditNamePoint->text(); pointName = ui->lineEditNamePoint->text();
typeLine = GetTypeLine(ui->comboBoxLineType); typeLine = GetTypeLine(ui->comboBoxLineType);
formula = ui->lineEditFormula->text(); formula = ui->plainTextEditFormula->toPlainText();
formula.replace("\n"," ");
firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint);
secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint);
thirdPointId = getCurrentObjectId(ui->comboBoxThirdPoint); thirdPointId = getCurrentObjectId(ui->comboBoxThirdPoint);
emit DialogClosed(QDialog::Accepted);
} }

View File

@ -31,6 +31,7 @@
#include "dialogtool.h" #include "dialogtool.h"
#define DIALOGBISECTOR_MAX_FORMULA_HEIGHT 64
namespace Ui namespace Ui
{ {
class DialogBisector; class DialogBisector;
@ -124,12 +125,24 @@ public slots:
* @brief DialogAccepted save data and emit signal about closed dialog. * @brief DialogAccepted save data and emit signal about closed dialog.
*/ */
virtual void DialogAccepted(); virtual void DialogAccepted();
/** TODO ISSUE 79 : create real function /**
* @brief DialogApply apply data and emit signal about applied dialog. * @brief DialogApply apply data and emit signal about applied dialog.
*/ */
virtual void DialogApply(){} virtual void DialogApply();
/**
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
private: private:
Q_DISABLE_COPY(DialogBisector) Q_DISABLE_COPY(DialogBisector)
/**
* @brief SaveData Put dialog data in local variables
*/
void SaveData();
/** /**
* @brief ui keeps information about user interface * @brief ui keeps information about user interface
*/ */
@ -162,6 +175,10 @@ private:
* @brief thirdPointId id of third point * @brief thirdPointId id of third point
*/ */
quint32 thirdPointId; quint32 thirdPointId;
/**
* @brief formulaBaseHeight base height defined by dialogui
*/
int formulaBaseHeight;
}; };
inline QString DialogBisector::getTypeLine() const inline QString DialogBisector::getTypeLine() const

View File

@ -71,17 +71,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEditFormula"> <spacer name="horizontalSpacer">
<property name="sizePolicy"> <property name="orientation">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <enum>Qt::Horizontal</enum>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="toolTip"> <property name="sizeHint" stdset="0">
<string>Calculation of length of bisector by using the formula</string> <size>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</widget> </spacer>
</item> </item>
<item> <item>
<widget class="QToolButton" name="toolButtonPutHere"> <widget class="QToolButton" name="toolButtonPutHere">
@ -147,6 +147,54 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_formula">
<item>
<widget class="QPlainTextEdit" name="plainTextEditFormula">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonGrowLength">
<property name="maximumSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show full calculation in message box&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="go-down.png"/>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
@ -429,14 +477,13 @@
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>lineEditFormula</tabstop>
<tabstop>lineEditNamePoint</tabstop> <tabstop>lineEditNamePoint</tabstop>
<tabstop>comboBoxFirstPoint</tabstop> <tabstop>comboBoxFirstPoint</tabstop>
<tabstop>comboBoxSecondPoint</tabstop> <tabstop>comboBoxSecondPoint</tabstop>

View File

@ -493,8 +493,18 @@ void MainWindow::ClosedDialogNormal(int result)
*/ */
void MainWindow::ToolBisector(bool checked) void MainWindow::ToolBisector(bool checked)
{ {
SetToolButton<DialogBisector>(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png", SetToolButton2<DialogBisector>(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png",
tr("Select first point of angle"), &MainWindow::ClosedDialogBisector); tr("Select first point of angle"), &MainWindow::ClosedDialogBisector,
&MainWindow::ApplyDialogBisector);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ApplyDialogBisector actions after apply in DialogBisector.
*/
void MainWindow::ApplyDialogBisector()
{
ApplyDialog<VToolBisector>();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -504,7 +514,7 @@ void MainWindow::ToolBisector(bool checked)
*/ */
void MainWindow::ClosedDialogBisector(int result) void MainWindow::ClosedDialogBisector(int result)
{ {
ClosedDialog<VToolBisector>(result); ClosedDialog2<VToolBisector>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -110,6 +110,7 @@ public slots:
void ClosedDialogShoulderPoint(int result); void ClosedDialogShoulderPoint(int result);
void ClosedDialogNormal(int result); void ClosedDialogNormal(int result);
void ClosedDialogBisector(int result); void ClosedDialogBisector(int result);
void ApplyDialogBisector();
void ClosedDialogLineIntersect(int result); void ClosedDialogLineIntersect(int result);
void ClosedDialogSpline(int result); void ClosedDialogSpline(int result);
void ClosedDialogArc(int result); void ClosedDialogArc(int result);

View File

@ -87,7 +87,7 @@ void VToolBisector::setDialog()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VToolBisector* VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc,
VContainer *data) VContainer *data)
{ {
SCASSERT(dialog != nullptr); SCASSERT(dialog != nullptr);
@ -99,12 +99,18 @@ void VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatte
const quint32 thirdPointId = dialogTool->getThirdPointId(); const quint32 thirdPointId = dialogTool->getThirdPointId();
const QString typeLine = dialogTool->getTypeLine(); const QString typeLine = dialogTool->getTypeLine();
const QString pointName = dialogTool->getPointName(); const QString pointName = dialogTool->getPointName();
Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data, VToolBisector *point = nullptr;
point=Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data,
Document::FullParse, Valentina::FromGui); Document::FullParse, Valentina::FromGui);
if (point != nullptr)
{
point->dialog=dialogTool;
}
return point;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolBisector::Create(const quint32 _id, QString &formula, const quint32 &firstPointId, VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, const quint32 &firstPointId,
const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine, const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine,
const QString &pointName, const qreal &mx, const qreal &my, const QString &pointName, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VPattern *doc, VContainer *data, VMainGraphicsScene *scene, VPattern *doc, VContainer *data,
@ -145,7 +151,9 @@ void VToolBisector::Create(const quint32 _id, QString &formula, const quint32 &f
doc->IncrementReferens(firstPointId); doc->IncrementReferens(firstPointId);
doc->IncrementReferens(secondPointId); doc->IncrementReferens(secondPointId);
doc->IncrementReferens(thirdPointId); doc->IncrementReferens(thirdPointId);
return point;
} }
return nullptr;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -75,7 +75,7 @@ public:
* @param doc dom document container. * @param doc dom document container.
* @param data container with variables. * @param data container with variables.
*/ */
static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); static VToolBisector* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data);
/** /**
* @brief Create help create tool. * @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet. * @param _id tool id, 0 if tool doesn't exist yet.
@ -93,7 +93,7 @@ public:
* @param parse parser file mode. * @param parse parser file mode.
* @param typeCreation way we create this tool. * @param typeCreation way we create this tool.
*/ */
static void Create(const quint32 _id, QString &formula, const quint32 &firstPointId, static VToolBisector* Create(const quint32 _id, QString &formula, const quint32 &firstPointId,
const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine, const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine,
const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene,
VPattern *doc, VContainer *data, const Document::Documents &parse, VPattern *doc, VContainer *data, const Document::Documents &parse,