2014-08-29 11:19:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vformulapropertyeditor.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 28 8, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2014 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vformulapropertyeditor.h"
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QColorDialog>
|
|
|
|
|
2014-10-17 22:26:30 +02:00
|
|
|
#include "../../libs/vpropertyexplorer/vproperty.h"
|
2014-08-29 11:19:11 +02:00
|
|
|
#include "../dialogs/tools/dialogeditwrongformula.h"
|
|
|
|
|
|
|
|
using namespace VPE;
|
|
|
|
|
|
|
|
// VFormulaPropertyEditor
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-09-11 16:15:49 +02:00
|
|
|
VFormulaPropertyEditor::VFormulaPropertyEditor(QWidget *parent)
|
|
|
|
: QWidget(parent), formula(VFormula()), ToolButton(nullptr), TextLabel(nullptr), Spacer(nullptr)
|
2014-08-29 11:19:11 +02:00
|
|
|
{
|
|
|
|
setAutoFillBackground(true);
|
|
|
|
|
|
|
|
// Create the tool button
|
|
|
|
ToolButton = new QToolButton(this);
|
|
|
|
ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
|
|
|
|
ToolButton->setText(tr("..."));
|
|
|
|
ToolButton->setFixedWidth(20);
|
|
|
|
ToolButton->installEventFilter(this);
|
2014-09-10 19:57:08 +02:00
|
|
|
setFocusProxy(ToolButton); // Make the ToolButton the focus proxy
|
2014-08-29 11:19:11 +02:00
|
|
|
setFocusPolicy(ToolButton->focusPolicy());
|
|
|
|
connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked()));
|
|
|
|
|
|
|
|
// Create the text label
|
|
|
|
TextLabel = new QLabel(this);
|
2014-09-01 16:34:45 +02:00
|
|
|
TextLabel->setText(formula.getStringValue());
|
2014-08-29 11:19:11 +02:00
|
|
|
|
|
|
|
// Spacer (this is needed for proper display of the label and button)
|
|
|
|
Spacer = new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored);
|
|
|
|
|
|
|
|
// The layout (a horizontal layout)
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
|
|
layout->setSpacing(3);
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->addWidget(TextLabel);
|
|
|
|
layout->addItem(Spacer);
|
|
|
|
layout->addWidget(ToolButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VFormulaPropertyEditor::setFormula(const VFormula& formula)
|
|
|
|
{
|
|
|
|
if (this->formula != formula)
|
|
|
|
{
|
|
|
|
this->formula = formula;
|
2014-09-01 16:34:45 +02:00
|
|
|
TextLabel->setText(this->formula.getStringValue());
|
2014-08-29 11:19:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VFormulaPropertyEditor::onToolButtonClicked()
|
|
|
|
{
|
2014-08-29 15:57:12 +02:00
|
|
|
DialogEditWrongFormula* tmpWidget = new DialogEditWrongFormula(formula.getData(), formula.getToolId(),
|
|
|
|
qApp->getMainWindow());
|
2014-08-29 11:19:11 +02:00
|
|
|
tmpWidget->setCheckZero(formula.getCheckZero());
|
|
|
|
tmpWidget->setPostfix(formula.getPostfix());
|
2014-08-29 15:42:53 +02:00
|
|
|
tmpWidget->setFormula(formula.getFormula(FormulaType::FromUser));
|
2014-08-29 11:19:11 +02:00
|
|
|
|
|
|
|
if (tmpWidget->exec() == QDialog::Accepted)
|
|
|
|
{
|
2014-08-29 15:42:53 +02:00
|
|
|
formula.setFormula(tmpWidget->getFormula(), FormulaType::ToUser);
|
2014-09-01 16:34:45 +02:00
|
|
|
TextLabel->setText(formula.getStringValue());
|
2014-08-29 11:19:11 +02:00
|
|
|
delete tmpWidget;
|
|
|
|
emit dataChangedByUser(formula, this);
|
|
|
|
UserChangeEvent *event = new UserChangeEvent();
|
|
|
|
QCoreApplication::postEvent ( this, event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VFormulaPropertyEditor::eventFilter(QObject *obj, QEvent *ev)
|
|
|
|
{
|
2014-09-11 19:15:07 +02:00
|
|
|
if (obj == ToolButton && ev->type() == QEvent::KeyPress)
|
2014-08-29 11:19:11 +02:00
|
|
|
{
|
|
|
|
// Ignore the event, so that eventually the delegate gets the event.
|
|
|
|
ev->ignore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::eventFilter(obj, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VFormulaPropertyEditor::~VFormulaPropertyEditor()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-09-14 11:16:59 +02:00
|
|
|
VFormula VFormulaPropertyEditor::getFormula() const
|
2014-08-29 11:19:11 +02:00
|
|
|
{
|
|
|
|
return formula;
|
|
|
|
}
|