2014-08-15 12:48:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file visualization.h
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 15 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.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-08-15 12:48:11 +02:00
|
|
|
** <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 VISUALIZATION_H
|
|
|
|
#define VISUALIZATION_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <qcompilerdetection.h>
|
2014-08-19 22:13:50 +02:00
|
|
|
#include <QGraphicsItem>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QtGlobal>
|
2015-04-01 14:51:54 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/def.h"
|
2015-06-15 13:43:41 +02:00
|
|
|
#include "../vmisc/logging.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2015-10-08 20:11:50 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2017-05-16 12:07:53 +02:00
|
|
|
#include "../vwidgets/vcurvepathitem.h"
|
2017-06-16 13:53:08 +02:00
|
|
|
#include "../vwidgets/global.h"
|
2014-11-24 14:03:34 +01:00
|
|
|
|
|
|
|
Q_DECLARE_LOGGING_CATEGORY(vVis)
|
2014-08-15 12:48:11 +02:00
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
class VScaledEllipse;
|
|
|
|
class VScaledLine;
|
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
enum class Mode : char {Creation, Show};
|
|
|
|
|
2014-08-15 12:48:11 +02:00
|
|
|
class Visualization : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-10-12 13:52:48 +02:00
|
|
|
explicit Visualization(const VContainer *data);
|
2017-04-01 16:27:55 +02:00
|
|
|
virtual ~Visualization() Q_DECL_EQ_DEFAULT;
|
2014-08-15 12:48:11 +02:00
|
|
|
|
|
|
|
virtual void RefreshGeometry()=0;
|
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
void setObject1Id(const quint32 &value);
|
2014-08-15 12:48:11 +02:00
|
|
|
void setLineStyle(const Qt::PenStyle &value);
|
|
|
|
void setScenePos(const QPointF &value);
|
2015-05-27 18:24:20 +02:00
|
|
|
virtual void VisualMode(const quint32 &pointId);
|
2014-08-15 12:48:11 +02:00
|
|
|
void setMainColor(const QColor &value);
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2017-02-06 12:38:47 +01:00
|
|
|
const VContainer *GetData() const;
|
|
|
|
void SetData(const VContainer *data);
|
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
Mode GetMode() const;
|
|
|
|
void SetMode(const Mode &value);
|
2016-02-25 20:23:16 +01:00
|
|
|
|
|
|
|
static qreal FindLength(const QString &expression, const QHash<QString, qreal *> &vars);
|
|
|
|
static qreal FindVal(const QString &expression, const QHash<QString, qreal *> &vars);
|
2014-08-15 12:48:11 +02:00
|
|
|
signals:
|
|
|
|
void ToolTip(const QString &toolTip);
|
|
|
|
public slots:
|
|
|
|
void MousePos(const QPointF &scenePos);
|
|
|
|
protected:
|
|
|
|
const VContainer *data;
|
|
|
|
QPointF scenePos;
|
|
|
|
QColor mainColor;
|
|
|
|
QColor supportColor;
|
|
|
|
Qt::PenStyle lineStyle;
|
2016-01-24 17:15:08 +01:00
|
|
|
quint32 object1Id;
|
2014-08-15 12:48:11 +02:00
|
|
|
QString toolTip;
|
2016-02-12 19:10:01 +01:00
|
|
|
Mode mode;
|
2014-08-15 12:48:11 +02:00
|
|
|
|
|
|
|
virtual void InitPen()=0;
|
|
|
|
virtual void AddOnScene()=0;
|
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
VScaledEllipse *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const;
|
|
|
|
void DrawPoint(VScaledEllipse *point, const QPointF &pos, const QColor &color,
|
2014-08-15 15:54:24 +02:00
|
|
|
Qt::PenStyle style = Qt::SolidLine);
|
2017-06-23 11:25:02 +02:00
|
|
|
virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color,
|
2014-08-18 16:42:53 +02:00
|
|
|
Qt::PenStyle style = Qt::SolidLine);
|
2017-05-16 12:07:53 +02:00
|
|
|
void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color,
|
2014-10-23 10:38:57 +02:00
|
|
|
Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap);
|
2017-05-16 12:07:53 +02:00
|
|
|
void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QPainterPath &direction,
|
|
|
|
const QColor &color, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap);
|
2014-08-15 15:54:24 +02:00
|
|
|
|
2014-08-15 12:48:11 +02:00
|
|
|
template <typename Item>
|
2015-07-03 16:03:19 +02:00
|
|
|
void AddItem(Item *item);
|
2014-08-16 14:14:55 +02:00
|
|
|
|
|
|
|
template <class Item>
|
2015-07-03 16:03:19 +02:00
|
|
|
Item *InitItem(const QColor &color, QGraphicsItem *parent);
|
2016-11-05 09:56:44 +01:00
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
static VScaledEllipse *GetPointItem(QVector<VScaledEllipse *> &points, quint32 i, const QColor &color,
|
|
|
|
QGraphicsItem *parent);
|
2014-08-15 12:48:11 +02:00
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(Visualization)
|
2016-11-05 09:56:44 +01:00
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
static VScaledEllipse* InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0);
|
2014-08-15 12:48:11 +02:00
|
|
|
};
|
|
|
|
|
2015-07-03 16:03:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename Item>
|
|
|
|
inline void Visualization::AddItem(Item *item)
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(item != nullptr)
|
2015-07-03 16:03:19 +02:00
|
|
|
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
2015-07-03 16:03:19 +02:00
|
|
|
|
|
|
|
scene->addItem(item);
|
|
|
|
connect(scene, &VMainGraphicsScene::mouseMove, item, &Visualization::MousePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class Item>
|
|
|
|
inline Item *Visualization::InitItem(const QColor &color, QGraphicsItem *parent)
|
|
|
|
{
|
|
|
|
Item *item = new Item(parent);
|
2017-06-16 13:53:08 +02:00
|
|
|
|
|
|
|
QPen visPen = item->pen();
|
|
|
|
visPen.setColor(color);
|
|
|
|
|
|
|
|
item->setPen(visPen);
|
2015-07-03 16:03:19 +02:00
|
|
|
item->setZValue(1);
|
|
|
|
item->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
|
|
|
item->setVisible(false);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-08-15 12:48:11 +02:00
|
|
|
#endif // VISUALIZATION_H
|