-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGraphicItemWireLineSegment.cpp
140 lines (114 loc) · 6.12 KB
/
GraphicItemWireLineSegment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
////////////////////////////////////////////////////////////////////////
// Copyright 2009-2018 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2018, NTESS
// All rights reserved.
//
// Portions are copyright of other developers:
// See the file CONTRIBUTORS.TXT in the top level directory
// the distribution for more information.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
////////////////////////////////////////////////////////////////////////
#include "GraphicItemWireLineSegment.h"
////////////////////////////////////////////////////////////
GraphicItemWireLineSegment::GraphicItemWireLineSegment(Position LineSegPosition, ItemProperties* ParentProperties, QGraphicsItem* parent/*=0*/)
: QGraphicsLineItem(parent), GraphicItemBase(GraphicItemBase::ITEMTYPE_WIRELINESEGMENT)
{
// Point this objects properties to the parent's properties
SetExistingPropertiesStructure(ParentProperties);
// Setup the internal member variables
m_LineSegPosition = LineSegPosition; // Identifies what type of Line Segment it is
m_AutoMoveFlag = true; // Identifies if the application can automatically move this wire segment,
// or is it under user control
// Set Graphic parameters for the Line Segment Items
setFlag(QGraphicsItem::ItemIsSelectable);
setFlag(QGraphicsItem::ItemSendsGeometryChanges);
// Handle cases for the middle lines; make them moveable
if ( IsWireLineAMiddleSegment()) {
setFlag(QGraphicsItem::ItemIsMovable);
}
}
GraphicItemWireLineSegment::~GraphicItemWireLineSegment()
{
// Our properties pointer actually points to the parent
// properties, so we just null it out and let the parent delete it.
SetExistingPropertiesStructure(NULL);
}
void GraphicItemWireLineSegment::SaveData(QDataStream& DataStreamOut)
{
Q_UNUSED(DataStreamOut)
// All Wire Data is saved in GraphicItemWire
}
bool GraphicItemWireLineSegment::IsWireLineAMiddleSegment()
{
return ( (m_LineSegPosition != SEGPOS_STARTLINE) && (m_LineSegPosition != SEGPOS_ENDLINE));
}
void GraphicItemWireLineSegment::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget /*=0*/)
{
Q_UNUSED(option)
Q_UNUSED(widget)
// We have to paint our own line because normally when the line is selected,
// a large bounding rectable is shown... This bounding rect is drawn
// by default by the base class paint function, therefore we override it
painter->setPen(pen());
painter->drawLine(line());
// Uncomment the following to show the selection outline when item is selected
//QGraphicsLineItem::paint(painter, option, widget);
}
QVariant GraphicItemWireLineSegment::itemChange(GraphicsItemChange change, const QVariant& value)
{
QPointF OldPos;
QPointF NewPos;
QPointF FinalPos;
bool SelectedState;
// Did this get called to to a Selection Change?
if (change == ItemSelectedChange && scene()) {
// value is the selected state
SelectedState = value.toBool();
}
// Check to see if the X/Y position of the wire segement is potentially changing
// NOTE: Position is not the same as the line. Position is the single X/Y coordinate relative
// to the parent item, and is used as an offset for drawing the line. Therefore,
// We really dont want the position (offset relative to the parent) to change, but we do want
// to know what the user has requested it to move by. We send this positional change up
// to the parent so it can redraw the line in the correct position. Also, this routine
// may be called multiple times when the user is trying to move a line segment, and it
// will call the parent handler each time.
if (change == ItemPositionChange && scene()) {
// Check the new position to allow change only in Horizontal or Vertical directions
// Get the old position and the proposed new position
NewPos = value.toPointF();
OldPos = pos();
// Depending upon what line segment, control what direction (Horizontal or Vertical) that it can move
switch (m_LineSegPosition) {
case SEGPOS_STARTLINE : FinalPos = OldPos; break; // STARTLINE cannot change position
case SEGPOS_MIDDLEVLINE1 : FinalPos = QPointF(NewPos.x(), OldPos.y()); break; // Can only move in the X direction (Horizontal)
case SEGPOS_MIDDLEHLINE : FinalPos = QPointF(OldPos.x(), NewPos.y()); break; // Can only move in the Y direction (Vertical)
case SEGPOS_MIDDLEVLINE2 : FinalPos = QPointF(NewPos.x(), OldPos.y()); break; // Can only move in the X direction (Horizontal)
case SEGPOS_ENDLINE : FinalPos = OldPos; break; // ENDLINE cannot change position
}
// Call the Parent's handler, to update the position of the peer Line Segments
// NOTE: We dont move the position (offset relative to the parent), instead
// we let the parent move the lines by the offset amount.
((GraphicItemWire*)parentItem())->HandleWireLineSegmentItemChange(FinalPos, this, change, value);
// Dont move the position (offset relative to the parent),
return QVariant(OldPos);
}
// For all other conditions, Call the Parent's handler and then the base Handler
// Note: FinalPos will = 0, 0 in this casse.
((GraphicItemWire*)parentItem())->HandleWireLineSegmentItemChange(FinalPos, this, change, value);
// Then call the default handler
return QGraphicsLineItem::itemChange(change, value);
}
void GraphicItemWireLineSegment::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
// Notify the parent that we have released the mouse (basiclly we are done moving this item)
((GraphicItemWire*)parentItem())->HandleWireLineSegmentMouseReleaseEvent(event);
// Call the default handler
QGraphicsLineItem::mouseReleaseEvent(event);
}