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
|
|
|
|
|
|
|
|
#include <QObject>
|
2014-08-19 22:13:50 +02:00
|
|
|
#include <QGraphicsItem>
|
2015-04-01 14:51:54 +02:00
|
|
|
|
2014-09-25 17:44:06 +02:00
|
|
|
#include "../core/vapplication.h"
|
2015-06-15 14:50:59 +02:00
|
|
|
#include "../libs/vwidgets/vmaingraphicsscene.h"
|
2015-06-15 13:43:41 +02:00
|
|
|
#include "../vmisc/logging.h"
|
2015-06-15 11:32:27 +02:00
|
|
|
#include "../../libs/vpatterndb/vcontainer.h"
|
2014-11-24 14:03:34 +01:00
|
|
|
|
|
|
|
Q_DECLARE_LOGGING_CATEGORY(vVis)
|
2014-08-15 12:48:11 +02:00
|
|
|
|
|
|
|
class Visualization : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
Visualization(const VContainer *data);
|
|
|
|
virtual ~Visualization();
|
|
|
|
|
|
|
|
virtual void RefreshGeometry()=0;
|
|
|
|
|
|
|
|
void setPoint1Id(const quint32 &value);
|
|
|
|
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);
|
|
|
|
signals:
|
|
|
|
void ToolTip(const QString &toolTip);
|
|
|
|
public slots:
|
|
|
|
void SetFactor(qreal factor);
|
|
|
|
void MousePos(const QPointF &scenePos);
|
|
|
|
protected:
|
|
|
|
const VContainer *data;
|
|
|
|
qreal factor;
|
|
|
|
QPointF scenePos;
|
|
|
|
QColor mainColor;
|
|
|
|
QColor supportColor;
|
|
|
|
Qt::PenStyle lineStyle;
|
|
|
|
quint32 point1Id;
|
|
|
|
QString toolTip;
|
|
|
|
|
|
|
|
virtual void InitPen()=0;
|
|
|
|
virtual void AddOnScene()=0;
|
|
|
|
|
2014-08-15 15:54:24 +02:00
|
|
|
QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent) const;
|
|
|
|
QRectF PointRect(const qreal &radius) const;
|
|
|
|
qreal FindLength(const QString &expression);
|
|
|
|
qreal FindVal(const QString &expression);
|
|
|
|
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
|
|
|
|
Qt::PenStyle style = Qt::SolidLine);
|
2014-10-04 08:37:19 +02:00
|
|
|
virtual void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
2014-08-18 16:42:53 +02:00
|
|
|
Qt::PenStyle style = Qt::SolidLine);
|
2014-10-23 10:38:57 +02:00
|
|
|
void DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, 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>
|
|
|
|
void AddItem(Item *item)
|
|
|
|
{
|
|
|
|
SCASSERT(item != nullptr);
|
2015-05-12 17:15:10 +02:00
|
|
|
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2014-08-15 12:48:11 +02:00
|
|
|
SCASSERT(scene != nullptr);
|
|
|
|
|
|
|
|
scene->addItem(item);
|
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, item, &Visualization::SetFactor);
|
|
|
|
connect(scene, &VMainGraphicsScene::mouseMove, item, &Visualization::MousePos);
|
|
|
|
}
|
2014-08-16 14:14:55 +02:00
|
|
|
|
|
|
|
template <class Item>
|
|
|
|
Item *InitItem(const QColor &color, QGraphicsItem *parent)
|
|
|
|
{
|
|
|
|
Item *item = new Item(parent);
|
2015-06-15 11:32:27 +02:00
|
|
|
item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*data->GetPatternUnit()))/factor));
|
2014-08-16 14:14:55 +02:00
|
|
|
item->setZValue(1);
|
|
|
|
item->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
2014-12-24 14:13:13 +01:00
|
|
|
item->setVisible(false);
|
2014-08-16 14:14:55 +02:00
|
|
|
return item;
|
|
|
|
}
|
2014-08-15 12:48:11 +02:00
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(Visualization)
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VISUALIZATION_H
|