DialogAlongLine Tool change

--HG--
branch : DialogTools
This commit is contained in:
Patrick Proy 2014-06-08 11:14:16 +02:00
parent db96431484
commit dab44eb163
8 changed files with 157 additions and 23 deletions

View File

@ -38,9 +38,11 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
{ {
ui->setupUi(this); ui->setupUi(this);
labelResultCalculation = ui->labelResultCalculation; labelResultCalculation = ui->labelResultCalculation;
lineEditFormula = ui->lineEditFormula; plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula; labelEditFormula = ui->labelEditFormula;
this->formulaBaseHeight=ui->plainTextEditFormula->height();
flagFormula = false; flagFormula = false;
flagName = false; flagName = false;
InitOkCancelApply(ui); InitOkCancelApply(ui);
@ -55,11 +57,37 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere); connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged);
connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula);
connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogAlongLine::FormulaChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit);
InitVariables(ui); InitVariables(ui);
connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal); connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::FormulaTextChanged()
{
// TODO issue #79 : back to FormulaChanged when full update
// Also remove this function if only one function called here
this->FormulaChanged2();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::DeployFormulaTextEdit()
{
if (ui->plainTextEditFormula->height() < DIALOGALONLINE_MAX_FORMULA_HEIGHT)
{
ui->plainTextEditFormula->setFixedHeight(DIALOGALONLINE_MAX_FORMULA_HEIGHT);
//Set icon from theme (internal for Windows system)
ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next"));
}
else
{
ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight);
//Set icon from theme (internal for Windows system)
ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down"));
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogAlongLine::~DialogAlongLine() DialogAlongLine::~DialogAlongLine()
{ {
@ -93,15 +121,27 @@ void DialogAlongLine::ChoosedObject(quint32 id, const Valentina::Scenes &type)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::DialogAccepted() void DialogAlongLine::DialogAccepted()
{
this->SaveData();
emit DialogClosed(QDialog::Accepted);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::DialogApply()
{
this->SaveData();
emit DialogApplied();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::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);
emit DialogClosed(QDialog::Accepted);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -120,7 +160,12 @@ void DialogAlongLine::setFirstPointId(const quint32 &value, const quint32 &id)
void DialogAlongLine::setFormula(const QString &value) void DialogAlongLine::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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -31,6 +31,7 @@
#include "dialogtool.h" #include "dialogtool.h"
#define DIALOGALONLINE_MAX_FORMULA_HEIGHT 64
namespace Ui namespace Ui
{ {
class DialogAlongLine; class DialogAlongLine;
@ -113,12 +114,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(DialogAlongLine) Q_DISABLE_COPY(DialogAlongLine)
/**
* @brief SaveData Put dialog data in local variables
*/
void SaveData();
/** /**
* @brief ui keeps information about user interface * @brief ui keeps information about user interface
*/ */
@ -147,6 +160,10 @@ private:
* @brief secondPointId id second point of line * @brief secondPointId id second point of line
*/ */
quint32 secondPointId; quint32 secondPointId;
/**
* @brief formulaBaseHeight base height defined by dialogui
*/
int formulaBaseHeight;
}; };
inline QString DialogAlongLine::getPointName() const inline QString DialogAlongLine::getPointName() const

View File

@ -74,11 +74,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEditFormula"> <spacer name="horizontalSpacer">
<property name="toolTip"> <property name="orientation">
<string>Formula for the calculation of length of line</string> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item> <item>
<widget class="QToolButton" name="toolButtonPutHere"> <widget class="QToolButton" name="toolButtonPutHere">
@ -150,6 +156,50 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<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>16</width>
<height>16</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">
<normaloff/>
</iconset>
</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>
@ -390,14 +440,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>toolButtonEqual</tabstop> <tabstop>toolButtonEqual</tabstop>
<tabstop>lineEditNamePoint</tabstop> <tabstop>lineEditNamePoint</tabstop>
<tabstop>comboBoxFirstPoint</tabstop> <tabstop>comboBoxFirstPoint</tabstop>

View File

@ -169,6 +169,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -186,7 +189,8 @@
<string/> <string/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="go-down"/> <iconset resource="../../share/resources/theme.qrc">
<normaloff>:/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png</normaloff>:/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -673,6 +677,7 @@
</tabstops> </tabstops>
<resources> <resources>
<include location="../../share/resources/icon.qrc"/> <include location="../../share/resources/icon.qrc"/>
<include location="../../share/resources/theme.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>

View File

@ -421,8 +421,17 @@ void MainWindow::ClosedDialogLine(int result)
*/ */
void MainWindow::ToolAlongLine(bool checked) void MainWindow::ToolAlongLine(bool checked)
{ {
SetToolButton<DialogAlongLine>(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", SetToolButton2<DialogAlongLine>(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png",
tr("Select point"), &MainWindow::ClosedDialogAlongLine); tr("Select point"), &MainWindow::ClosedDialogAlongLine, &MainWindow::ApplyDialogAlongLine);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ApplyDialogAlongLine actions after apply in DialogAlongLine.
*/
void MainWindow::ApplyDialogAlongLine()
{
ApplyDialog<VToolAlongLine>();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -432,7 +441,7 @@ void MainWindow::ToolAlongLine(bool checked)
*/ */
void MainWindow::ClosedDialogAlongLine(int result) void MainWindow::ClosedDialogAlongLine(int result)
{ {
ClosedDialog<VToolAlongLine>(result); ClosedDialog2<VToolAlongLine>(result);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -106,6 +106,7 @@ public slots:
void ApplyDialogEndLine(); void ApplyDialogEndLine();
void ClosedDialogLine(int result); void ClosedDialogLine(int result);
void ClosedDialogAlongLine(int result); void ClosedDialogAlongLine(int result);
void ApplyDialogAlongLine();
void ClosedDialogShoulderPoint(int result); void ClosedDialogShoulderPoint(int result);
void ClosedDialogNormal(int result); void ClosedDialogNormal(int result);
void ClosedDialogBisector(int result); void ClosedDialogBisector(int result);

View File

@ -158,7 +158,7 @@ void VToolAlongLine::setDialog()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) VToolAlongLine* VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data)
{ {
SCASSERT(dialog != nullptr); SCASSERT(dialog != nullptr);
DialogAlongLine *dialogTool = qobject_cast<DialogAlongLine*>(dialog); DialogAlongLine *dialogTool = qobject_cast<DialogAlongLine*>(dialog);
@ -168,12 +168,18 @@ void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatt
const quint32 secondPointId = dialogTool->getSecondPointId(); const quint32 secondPointId = dialogTool->getSecondPointId();
const QString typeLine = dialogTool->getTypeLine(); const QString typeLine = dialogTool->getTypeLine();
const QString pointName = dialogTool->getPointName(); const QString pointName = dialogTool->getPointName();
Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, VToolAlongLine *point=nullptr;
point = Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data,
Document::FullParse, Valentina::FromGui); Document::FullParse, Valentina::FromGui);
if (point != nullptr)
{
point->dialog=dialogTool;
}
return point;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula,
const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VPattern *doc, VContainer *data, VMainGraphicsScene *scene, VPattern *doc, VContainer *data,
const Document::Documents &parse, const Valentina::Sources &typeCreation) const Document::Documents &parse, const Valentina::Sources &typeCreation)
@ -212,5 +218,7 @@ void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const Q
doc->AddTool(id, point); doc->AddTool(id, point);
doc->IncrementReferens(firstPointId); doc->IncrementReferens(firstPointId);
doc->IncrementReferens(secondPointId); doc->IncrementReferens(secondPointId);
return point;
} }
return nullptr;
} }

View File

@ -64,7 +64,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 VToolAlongLine* 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.
@ -81,7 +81,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, const QString &pointName, const QString &typeLine, QString &formula, static VToolAlongLine* Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula,
const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VPattern *doc, VContainer *data, VMainGraphicsScene *scene, VPattern *doc, VContainer *data,
const Document::Documents &parse, const Valentina::Sources &typeCreation); const Document::Documents &parse, const Valentina::Sources &typeCreation);