Allow a user to select a point covered by visualization.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-13 16:57:49 +02:00
parent c44a16197b
commit 59c9a0b400
3 changed files with 47 additions and 18 deletions

View File

@ -92,6 +92,7 @@ VSimplePoint *VisToolPiecePath::GetPoint(quint32 i, const QColor &color)
VSimplePoint *point = new VSimplePoint(NULL_ID, color, *Visualization::data->GetPatternUnit(), &factor);
point->SetPointHighlight(true);
point->setParentItem(this);
point->SetVisualizationMode(true);
m_points.append(point);
return point;

View File

@ -59,7 +59,8 @@ VSimplePoint::VSimplePoint(quint32 id, const QColor &currentColor, Unit patternU
namePoint(nullptr),
lineName(nullptr),
m_onlyPoint(false),
m_isHighlight(false)
m_isHighlight(false),
m_visualizationMode(false)
{
namePoint = new VGraphicsSimpleTextItem(this);
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu);
@ -92,6 +93,19 @@ bool VSimplePoint::IsOnlyPoint() const
return m_onlyPoint;
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::SetVisualizationMode(bool value)
{
m_visualizationMode = value;
this->setFlag(QGraphicsItem::ItemIsFocusable, not m_visualizationMode);
}
//---------------------------------------------------------------------------------------------------------------------
bool VSimplePoint::IsVisualizationMode() const
{
return m_visualizationMode;
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::SetPointHighlight(bool value)
{
@ -209,24 +223,31 @@ void VSimplePoint::ChangedPosition(const QPointF &pos)
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// 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())
if (m_visualizationMode)
{
scene()->clearSelection();
}
if (selectionType == SelectionType::ByMouseRelease)
{
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
event->ignore();
}
else
{
if (event->button() == Qt::LeftButton)
// 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())
{
emit Choosed(id);
scene()->clearSelection();
}
if (selectionType == SelectionType::ByMouseRelease)
{// Special for not selectable item first need to call standard mousePressEvent then accept event
event->accept();
}
else
{
if (event->button() == Qt::LeftButton)
{
emit Choosed(id);
}
}
}
}
@ -234,14 +255,17 @@ void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (selectionType == SelectionType::ByMouseRelease)
if (not m_visualizationMode)
{
if (event->button() == Qt::LeftButton)
if (selectionType == SelectionType::ByMouseRelease)
{
emit Choosed(id);
if (event->button() == Qt::LeftButton)
{
emit Choosed(id);
}
}
QGraphicsEllipseItem::mouseReleaseEvent(event);
}
QGraphicsEllipseItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -65,6 +65,9 @@ public:
void SetOnlyPoint(bool value);
bool IsOnlyPoint() const;
void SetVisualizationMode(bool value);
bool IsVisualizationMode() const;
void SetPointHighlight(bool value);
void RefreshLine();
@ -112,6 +115,7 @@ private:
bool m_onlyPoint;
bool m_isHighlight;
bool m_visualizationMode;
};
#endif // VSIMPLEPOINT_H