Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2014-06-25 17:18:35 +03:00
parent 881c203a8c
commit f8882f48f1
5 changed files with 14 additions and 196 deletions

View File

@ -58,15 +58,15 @@ VToolCutArc::VToolCutArc(VPattern *doc, VContainer *data, const quint32 &id, con
Q_ASSERT_X(arc1id > 0, Q_FUNC_INFO, "arc1id <= 0");
Q_ASSERT_X(arc2id > 0, Q_FUNC_INFO, "arc2id <= 0");
firstArc = new VSimpleArc(arc1id, &currentColor, &factor);
RefreshArc(firstArc, arc1id, SimpleArcPoint::ForthPoint);
firstArc = new VSimpleCurve(arc1id, &currentColor, &factor);
RefreshArc(firstArc, arc1id, SimpleCurvePoint::ForthPoint);
firstArc->setParentItem(this);
connect(firstArc, &VSimpleArc::Choosed, this, &VToolCutArc::ArcChoosed);
connect(firstArc, &VSimpleCurve::Choosed, this, &VToolCutArc::ArcChoosed);
secondArc = new VSimpleArc(arc2id, &currentColor, &factor);
RefreshArc(secondArc, arc2id, SimpleArcPoint::FirstPoint);
secondArc = new VSimpleCurve(arc2id, &currentColor, &factor);
RefreshArc(secondArc, arc2id, SimpleCurvePoint::FirstPoint);
secondArc->setParentItem(this);
connect(secondArc, &VSimpleArc::Choosed, this, &VToolCutArc::ArcChoosed);
connect(secondArc, &VSimpleCurve::Choosed, this, &VToolCutArc::ArcChoosed);
if (typeCreation == Source::FromGui)
{
@ -311,8 +311,8 @@ void VToolCutArc::RefreshDataInFile()
*/
void VToolCutArc::RefreshGeometry()
{
RefreshArc(firstArc, arc1id, SimpleArcPoint::ForthPoint);
RefreshArc(secondArc, arc2id, SimpleArcPoint::FirstPoint);
RefreshArc(firstArc, arc1id, SimpleCurvePoint::ForthPoint);
RefreshArc(secondArc, arc2id, SimpleCurvePoint::FirstPoint);
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
@ -337,13 +337,13 @@ void VToolCutArc::SaveDialog(QDomElement &domElement)
* @param arcid arc id.
* @param tr arc type.
*/
void VToolCutArc::RefreshArc(VSimpleArc *sArc, quint32 arcid, SimpleArcPoint tr)
void VToolCutArc::RefreshArc(VSimpleCurve *sArc, quint32 arcid, SimpleCurvePoint tr)
{
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(arcid);
QPainterPath path;
path.addPath(arc->GetPath());
path.setFillRule( Qt::WindingFill );
if (tr == SimpleArcPoint::FirstPoint)
if (tr == SimpleCurvePoint::FirstPoint)
{
path.translate(-arc->GetP1().x(), -arc->GetP1().y());
}

View File

@ -30,7 +30,7 @@
#define VTOOLCUTARC_H
#include "vtoolpoint.h"
#include "../../widgets/vsimplearc.h"
#include "../../widgets/vsimplecurve.h"
/**
* @brief The VToolCutArc class tool for cutting arc.
@ -70,17 +70,17 @@ private:
quint32 arcId;
/** @brief firstArc first arc after cutting. */
VSimpleArc *firstArc;
VSimpleCurve *firstArc;
/** @brief secondArc second arc after cutting. */
VSimpleArc *secondArc;
VSimpleCurve *secondArc;
/** @brief arc1id id first arc after cutting. */
const quint32 arc1id;
/** @brief arc2id id second arc after cutting. */
const quint32 arc2id;
void RefreshArc(VSimpleArc *sArc, quint32 arcid, SimpleArcPoint tr);
void RefreshArc(VSimpleCurve *sArc, quint32 arcid, SimpleCurvePoint tr);
};
#endif // VTOOLCUTARC_H

View File

@ -1,113 +0,0 @@
/************************************************************************
**
** @file vsimplearc.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 7 1, 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) 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/>.
**
*************************************************************************/
#include "vsimplearc.h"
#include "../widgets/vapplication.h"
#include <QPen>
#include <QGraphicsSceneMouseEvent>
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VSimpleArc constructor.
* @param id arc id.
* @param currentColor current color.
* @param factor scale factor.
* @param parent parent object.
*/
VSimpleArc::VSimpleArc(quint32 id, Qt::GlobalColor *currentColor, qreal *factor, QObject *parent)
:QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor)
{
if (factor == nullptr)
{
setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())));
}
else
{
setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/ *factor));
}
setFlag(QGraphicsItem::ItemIsSelectable, true);
setAcceptHoverEvents(true);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimpleArc::ChangedActivDraw(const bool &flag)
{
setFlag(QGraphicsItem::ItemIsSelectable, flag);
setAcceptHoverEvents(flag);
setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @param event mouse release event.
*/
void VSimpleArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit Choosed(id);
}
QGraphicsItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief hoverMoveEvent handle hover move events.
* @param event hover move event.
*/
void VSimpleArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
if (factor == nullptr)
{
this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine())));
}
else
{
this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor));
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief hoverLeaveEvent handle hover leave events.
* @param event hover leave event.
*/
void VSimpleArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
if (factor == nullptr)
{
this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())));
}
else
{
this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor));
}
}

View File

@ -1,67 +0,0 @@
/************************************************************************
**
** @file vsimplearc.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 7 1, 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) 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/>.
**
*************************************************************************/
#ifndef VSIMPLEARC_H
#define VSIMPLEARC_H
#include <QGraphicsPathItem>
enum class SimpleArcPoint : char { FirstPoint, ForthPoint };
/**
* @brief The VSimpleArc class for simple arc. This object used when we cut arc and want show peaces.
*/
class VSimpleArc : public QObject, public QGraphicsPathItem
{
Q_OBJECT
public:
VSimpleArc(quint32 id, Qt::GlobalColor *currentColor, qreal *factor = nullptr, QObject *parent = nullptr);
void ChangedActivDraw(const bool &flag);
signals:
/**
* @brief Choosed send id when clicked.
* @param id arc id.
*/
void Choosed(quint32 id);
protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
private:
Q_DISABLE_COPY(VSimpleArc)
/** @brief id arc id. */
quint32 id;
/** @brief factor scale factor. */
qreal *factor;
/** @brief currentColor current color. */
Qt::GlobalColor *currentColor;
};
#endif // VSIMPLEARC_H

View File

@ -8,7 +8,6 @@ HEADERS += \
widgets/vapplication.h \
widgets/doubledelegate.h \
widgets/vsimplesplinepath.h \
widgets/vsimplearc.h \
widgets/textdelegate.h \
widgets/vtranslation.h \
widgets/undoevent.h \
@ -24,7 +23,6 @@ SOURCES += \
widgets/vapplication.cpp \
widgets/doubledelegate.cpp \
widgets/vsimplesplinepath.cpp \
widgets/vsimplearc.cpp \
widgets/textdelegate.cpp \
widgets/vtranslation.cpp \
widgets/undoevent.cpp \