VPTissue Reference Manual
EditableNodeItem.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
21 
22 #include "bio/Cell.h"
23 #include "bio/Wall.h"
24 
25 #include <QEvent>
26 #include <QStyleOptionGraphicsItem>
27 
28 namespace SimPT_Editor {
29 
30 const QColor EditableNodeItem::DEFAULT_HIGHLIGHT_COLOR(230,0,0,255);//(51, 102, 0, 255)
31 
33  : QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius), m_node(node),
34  m_highlight_color(DEFAULT_HIGHLIGHT_COLOR), m_prev_pos((*node)[0], (*node)[1]), m_radius(radius)
35 {
36  setPos((*node)[0], (*node)[1]);
37  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
38  setAcceptHoverEvents(true);
39 }
40 
42 
44 {
45  return m_node->IsAtBoundary();
46 }
47 
49 {
50  return m_node == node;
51 }
52 
53 void EditableNodeItem::Highlight(bool highlighted)
54 {
55  QPen pen(this->pen());
56  if (highlighted) {
57  pen.setWidthF(0.3);
58  setZValue(5); //Draw selected node on top of other items.
59  setBrush(m_highlight_color);
60  }
61  else {
62  pen.setWidthF(0.1);
63  setZValue(4); //Draw nodes on top of other items.
64  }
65  setPen(pen);
66 }
67 
68 void EditableNodeItem::SetHighlightColor(const QColor& color)
69 {
70  m_highlight_color = color;
71 }
72 
73 void EditableNodeItem::SetToolTip(std::list<SimPT_Sim::Cell*> cells, std::list<SimPT_Sim::Wall*> walls) {
74  QString toolTip;
75  toolTip.append(QString("ID: ") + QString::number(m_node->GetIndex()) + "\n\n");
76  toolTip.append(QString("fixed: ") + (m_node->IsFixed() ? "true" : "false") + '\n');
77  toolTip.append(QString("sam: ") + (m_node->IsFixed() ? "true" : "false") + "\n\n");
78  toolTip.append("cells: ");
79  for (SimPT_Sim::Cell* c : cells) {
80  toolTip.append(QString::number(c->GetIndex()) + ' ');
81  }
82  toolTip.append('\n');
83  toolTip.append("walls: ");
84  for (SimPT_Sim::Wall* w : walls) {
85  toolTip.append(QString::number(w->GetIndex()) + ' ');
86  }
87  setToolTip(toolTip);
88 }
89 
91 {
92  return m_node;
93 }
94 
96 {
97  setPos(m_prev_pos);
98  emit Moved();
99 }
100 
102 {
103  setPos((*m_node)[0], (*m_node)[1]);
104  emit Moved();
105 }
106 
107 QVariant EditableNodeItem::itemChange(GraphicsItemChange change, const QVariant &value)
108 {
109  if (change == QGraphicsItem::ItemPositionChange) {
110  m_prev_pos = pos();
111 
112  emit Moved();
113  }
114 
115  return QGraphicsItem::itemChange(change, value);
116 }
117 
118 void EditableNodeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
119 {
120  if (flags().testFlag(QGraphicsItem::ItemIsSelectable)) {
121  setBrush(QBrush(QColor(220,220,220,255)));
122  setRect(-m_radius, -m_radius, 2*m_radius, 2*m_radius);
123  }
124  else {
125  setBrush(QBrush(QColor(255,255,255,255)));
126  setRect(-0.5, -0.5, 1, 1);
127  }
128  Highlight(isSelected());
129 
130  QStyleOptionGraphicsItem noRectBorder(*option);
131  noRectBorder.state &= !QStyle::State_Selected;
132  QGraphicsEllipseItem::paint(painter, &noRectBorder, widget);
133 }
134 
135 } // namespace
virtual void SetHighlightColor(const QColor &color=DEFAULT_HIGHLIGHT_COLOR)
Set the color the item should get when it gets highlighted.
void Moved()
Emitted when this node has been moved in the scene.
A cell contains walls and nodes.
Definition: Cell.h:48
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
Node in cell wall.
Definition: Node.h:39
SimPT_Sim::Node * Node() const
Get the node associated with this item.
virtual ~EditableNodeItem()
Destructor.
void Update()
Update the node.
virtual bool IsAtBoundary() const
Checks whether the node is at the boundary of the complex.
void SetToolTip(std::list< SimPT_Sim::Cell * > cells, std::list< SimPT_Sim::Wall * > walls)
Update the tool tip of this item.
see the online Qt documentation
Interface for Cell.
bool Contains(SimPT_Sim::Node *node) const
Checks whether this item represents the given node.
virtual void Highlight(bool highlighted)
Highlights the node in the canvas.
Interface for EditableNodeItem.
void Revert()
Revert the node to its previous position.
see the online Qt documentation
A cell wall, runs between cell corner points and consists of wall elements.
Definition: Wall.h:48
EditableNodeItem(SimPT_Sim::Node *node, double radius)
Constructor.
Interface for Wall.