2017-06-16 13:53:08 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 14 6, 2017
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2017-06-16 13:53:08 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2017 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 "vscenepoint.h"
|
|
|
|
#include "../vmisc/def.h"
|
2018-02-06 18:30:27 +01:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2017-06-16 13:53:08 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "vgraphicssimpletextitem.h"
|
2017-06-23 11:25:02 +02:00
|
|
|
#include "scalesceneitems.h"
|
2017-06-16 13:53:08 +02:00
|
|
|
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QFont>
|
2017-10-29 10:06:17 +01:00
|
|
|
#include <QPainter>
|
2017-06-16 13:53:08 +02:00
|
|
|
#include <QPen>
|
2017-10-29 10:06:17 +01:00
|
|
|
#include <QStyle>
|
|
|
|
#include <QStyleOptionGraphicsItem>
|
2017-06-16 13:53:08 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VScenePoint::VScenePoint(QGraphicsItem *parent)
|
|
|
|
: QGraphicsEllipseItem(parent),
|
|
|
|
m_namePoint(nullptr),
|
|
|
|
m_lineName(nullptr),
|
|
|
|
m_onlyPoint(false),
|
|
|
|
m_isHovered(false),
|
2017-09-17 08:19:13 +02:00
|
|
|
m_showLabel(true),
|
2017-10-30 07:34:18 +01:00
|
|
|
m_baseColor(Qt::black),
|
|
|
|
m_selectedFromChild(false)
|
2017-06-16 13:53:08 +02:00
|
|
|
{
|
|
|
|
m_namePoint = new VGraphicsSimpleTextItem(this);
|
2017-06-23 11:25:02 +02:00
|
|
|
m_lineName = new VScaledLine(this);
|
2018-02-06 18:30:27 +01:00
|
|
|
m_lineName->SetBoldLine(false);
|
2017-06-23 15:02:59 +02:00
|
|
|
m_lineName->setLine(QLineF(0, 0, 1, 0));
|
|
|
|
m_lineName->setVisible(false);
|
|
|
|
|
2017-06-16 13:53:08 +02:00
|
|
|
this->setBrush(QBrush(Qt::NoBrush));
|
|
|
|
this->setAcceptHoverEvents(true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VScenePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
const qreal scale = SceneScale(scene());
|
|
|
|
|
2017-10-28 12:02:51 +02:00
|
|
|
if (m_namePoint->BaseFontSize()*scale < minVisibleFontSize)
|
2017-06-16 13:53:08 +02:00
|
|
|
{
|
|
|
|
m_namePoint->setVisible(false);
|
|
|
|
m_lineName->setVisible(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ScaleMainPenWidth(scale);
|
|
|
|
ScaleCircleSize(this, scale);
|
|
|
|
|
|
|
|
if (not m_onlyPoint)
|
|
|
|
{
|
2017-09-17 08:19:13 +02:00
|
|
|
m_namePoint->setVisible(m_showLabel);
|
2017-06-16 13:53:08 +02:00
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
QPen lPen = m_lineName->pen();
|
2017-10-21 15:26:22 +02:00
|
|
|
QColor color = CorrectColor(m_lineName, Qt::black);
|
|
|
|
color.setAlpha(50);
|
|
|
|
lPen.setColor(color);
|
2017-06-23 11:25:02 +02:00
|
|
|
m_lineName->setPen(lPen);
|
2017-06-16 13:53:08 +02:00
|
|
|
|
|
|
|
RefreshLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-29 10:06:17 +01:00
|
|
|
PaintWithFixItemHighlightSelected<QGraphicsEllipseItem>(this, painter, option, widget);
|
2017-06-16 13:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VScenePoint::RefreshPointGeometry(const VPointF &point)
|
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
|
|
|
setPos(static_cast<QPointF>(point));
|
|
|
|
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
|
2017-09-17 08:19:13 +02:00
|
|
|
m_showLabel = point.IsShowLabel();
|
|
|
|
|
2017-06-16 13:53:08 +02:00
|
|
|
m_namePoint->blockSignals(true);
|
2019-05-05 16:31:45 +02:00
|
|
|
m_namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
|
|
|
m_namePoint->SetRealPos(QPointF(point.mx(), point.my()));
|
|
|
|
m_namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
m_namePoint->blockSignals(false);
|
|
|
|
|
2017-06-16 13:53:08 +02:00
|
|
|
m_namePoint->setText(point.name());
|
2017-09-17 08:19:13 +02:00
|
|
|
m_namePoint->setVisible(m_showLabel);
|
2017-06-16 13:53:08 +02:00
|
|
|
|
|
|
|
RefreshLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VScenePoint::SetOnlyPoint(bool value)
|
|
|
|
{
|
|
|
|
m_onlyPoint = value;
|
|
|
|
m_namePoint->setVisible(not m_onlyPoint);
|
|
|
|
m_lineName->setVisible(not m_onlyPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VScenePoint::IsOnlyPoint() const
|
|
|
|
{
|
|
|
|
return m_onlyPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VScenePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
m_isHovered = true;
|
|
|
|
QGraphicsEllipseItem::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VScenePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
m_isHovered = false;
|
|
|
|
QGraphicsEllipseItem::hoverLeaveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VScenePoint::RefreshLine()
|
|
|
|
{
|
|
|
|
QRectF nRec = m_namePoint->sceneBoundingRect();
|
|
|
|
nRec.translate(- scenePos());
|
|
|
|
if (not rect().intersects(nRec))
|
|
|
|
{
|
|
|
|
const QRectF nameRec = m_namePoint->sceneBoundingRect();
|
2017-06-19 16:44:18 +02:00
|
|
|
QPointF p1;
|
|
|
|
QPointF p2;
|
2017-06-16 13:53:08 +02:00
|
|
|
VGObject::LineIntersectCircle(QPointF(), ScaledRadius(SceneScale(scene())),
|
|
|
|
QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2);
|
|
|
|
const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
|
|
|
|
|
2017-10-21 15:26:22 +02:00
|
|
|
if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4/qMax(1.0, SceneScale(scene())), Unit::Mm))
|
2017-06-16 13:53:08 +02:00
|
|
|
{
|
|
|
|
m_lineName->setVisible(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-23 15:02:59 +02:00
|
|
|
m_lineName->setLine(QLineF(p1, pRec - scenePos()));
|
2017-09-17 08:19:13 +02:00
|
|
|
m_lineName->setVisible(m_showLabel);
|
2017-06-16 13:53:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lineName->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VScenePoint::ScaleMainPenWidth(qreal scale)
|
|
|
|
{
|
2018-02-06 18:30:27 +01:00
|
|
|
const qreal width = ScaleWidth(m_isHovered ? qApp->Settings()->WidthMainLine() : qApp->Settings()->WidthHairLine(),
|
|
|
|
scale);
|
2017-06-16 13:53:08 +02:00
|
|
|
|
|
|
|
setPen(QPen(CorrectColor(this, m_baseColor), width));
|
|
|
|
}
|