2015-06-20 18:14:04 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vsimplepoint.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 20 6, 2015
|
|
|
|
**
|
|
|
|
** @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) 2015 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 "vsimplepoint.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QFlags>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QGraphicsLineItem>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <Qt>
|
|
|
|
|
2017-06-16 13:53:08 +02:00
|
|
|
#include "global.h"
|
2015-06-20 18:14:04 +02:00
|
|
|
#include "../vgeometry/vgobject.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vgraphicssimpletextitem.h"
|
2017-06-16 13:53:08 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2015-06-20 18:14:04 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-16 13:53:08 +02:00
|
|
|
VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, QObject *parent)
|
|
|
|
: VAbstractSimple(id, parent),
|
|
|
|
VScenePoint(),
|
2017-05-16 12:07:53 +02:00
|
|
|
m_visualizationMode(false),
|
2017-06-16 13:53:08 +02:00
|
|
|
m_alwaysHovered(false)
|
2015-06-20 18:14:04 +02:00
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_baseColor = currentColor;
|
2017-09-16 16:25:14 +02:00
|
|
|
connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::contextMenuEvent);
|
2017-06-16 13:53:08 +02:00
|
|
|
connect(m_namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel);
|
|
|
|
connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed);
|
|
|
|
connect(m_namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VSimplePoint::PointSelected);
|
|
|
|
connect(m_namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VSimplePoint::ChangedPosition);
|
2016-11-30 14:26:40 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 15:57:49 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::SetVisualizationMode(bool value)
|
|
|
|
{
|
|
|
|
m_visualizationMode = value;
|
2017-06-16 13:53:08 +02:00
|
|
|
setFlag(QGraphicsItem::ItemIsFocusable, not m_visualizationMode);
|
2017-01-13 15:57:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VSimplePoint::IsVisualizationMode() const
|
|
|
|
{
|
|
|
|
return m_visualizationMode;
|
|
|
|
}
|
|
|
|
|
2016-11-30 14:26:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::SetPointHighlight(bool value)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_alwaysHovered = value;
|
|
|
|
m_isHovered = value;
|
2015-06-20 18:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::SetEnabled(bool enabled)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
setEnabled(enabled);
|
|
|
|
m_namePoint->setEnabled(enabled);
|
2015-06-20 18:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::EnableToolMove(bool move)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_namePoint->setFlag(QGraphicsItem::ItemIsMovable, move);
|
2015-06-20 18:14:04 +02:00
|
|
|
}
|
|
|
|
|
2016-03-31 16:01:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::AllowLabelHover(bool enabled)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_namePoint->setAcceptHoverEvents(enabled);
|
2016-03-31 16:01:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::AllowLabelSelecting(bool enabled)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled);
|
2016-03-31 16:01:41 +02:00
|
|
|
}
|
|
|
|
|
2016-03-31 19:10:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::ToolSelectionType(const SelectionType &type)
|
|
|
|
{
|
2016-05-12 21:11:21 +02:00
|
|
|
VAbstractSimple::ToolSelectionType(type);
|
2017-06-16 13:53:08 +02:00
|
|
|
m_namePoint->LabelSelectionType(type);
|
2016-03-31 19:10:20 +02:00
|
|
|
}
|
|
|
|
|
2015-06-20 18:14:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::DeleteFromLabel()
|
|
|
|
{
|
|
|
|
emit Delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::PointChoosed()
|
|
|
|
{
|
|
|
|
emit Choosed(id);
|
|
|
|
}
|
|
|
|
|
2016-04-05 19:14:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::PointSelected(bool selected)
|
|
|
|
{
|
2016-05-19 16:11:02 +02:00
|
|
|
setSelected(selected);
|
2016-04-05 19:14:12 +02:00
|
|
|
}
|
|
|
|
|
2015-06-20 18:14:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::ChangedPosition(const QPointF &pos)
|
|
|
|
{
|
2016-05-12 21:11:21 +02:00
|
|
|
emit NameChangedPosition(pos, id);
|
2015-06-20 18:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-11 12:05:08 +01:00
|
|
|
void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
2016-03-31 16:01:41 +02:00
|
|
|
{
|
2017-01-13 15:57:49 +01:00
|
|
|
if (m_visualizationMode)
|
2016-05-24 11:43:30 +02:00
|
|
|
{
|
2017-01-13 15:57:49 +01:00
|
|
|
event->ignore();
|
2016-03-31 19:10:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-13 15:57:49 +01:00
|
|
|
// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
QGraphicsEllipseItem::mousePressEvent(event);
|
|
|
|
|
|
|
|
// Somehow clicking on notselectable object do not clean previous selections.
|
|
|
|
if (not (flags() & ItemIsSelectable) && scene())
|
|
|
|
{
|
|
|
|
scene()->clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectionType == SelectionType::ByMouseRelease)
|
|
|
|
{// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else
|
2016-03-31 19:10:20 +02:00
|
|
|
{
|
2017-01-13 15:57:49 +01:00
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
emit Choosed(id);
|
|
|
|
}
|
2016-03-31 19:10:20 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-31 16:01:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
2015-06-20 18:14:04 +02:00
|
|
|
{
|
2017-01-13 15:57:49 +01:00
|
|
|
if (not m_visualizationMode)
|
2015-06-20 18:14:04 +02:00
|
|
|
{
|
2017-01-13 15:57:49 +01:00
|
|
|
if (selectionType == SelectionType::ByMouseRelease)
|
2016-03-31 19:10:20 +02:00
|
|
|
{
|
2017-01-13 15:57:49 +01:00
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
emit Choosed(id);
|
|
|
|
}
|
2016-03-31 19:10:20 +02:00
|
|
|
}
|
2017-06-16 13:53:08 +02:00
|
|
|
VScenePoint::mouseReleaseEvent(event);
|
2015-06-20 18:14:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_isHovered = true;
|
2015-06-20 18:14:04 +02:00
|
|
|
QGraphicsEllipseItem::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
if (not m_alwaysHovered)
|
|
|
|
{
|
|
|
|
m_isHovered = false;
|
|
|
|
}
|
2015-06-20 18:14:04 +02:00
|
|
|
QGraphicsEllipseItem::hoverLeaveEvent(event);
|
|
|
|
}
|
|
|
|
|
2016-05-08 17:04:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
emit Delete();
|
|
|
|
return; //Leave this method immediately after call!!!
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-06-16 13:53:08 +02:00
|
|
|
VScenePoint::keyReleaseEvent ( event );
|
2015-06-20 18:14:04 +02:00
|
|
|
}
|
|
|
|
|
2016-04-05 19:14:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
if (change == QGraphicsItem::ItemSelectedChange)
|
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_namePoint->blockSignals(true);
|
|
|
|
m_namePoint->setSelected(value.toBool());
|
|
|
|
m_namePoint->blockSignals(false);
|
2016-04-05 19:14:12 +02:00
|
|
|
emit Selected(value.toBool(), id);
|
|
|
|
}
|
|
|
|
|
2017-06-16 13:53:08 +02:00
|
|
|
return VScenePoint::itemChange(change, value);
|
2016-04-05 19:14:12 +02:00
|
|
|
}
|
2016-05-25 10:43:36 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimplePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2017-09-16 16:25:14 +02:00
|
|
|
emit ShowContextMenu(event, id);
|
2016-05-25 10:43:36 +02:00
|
|
|
}
|