tuchulcha  0.10.1
Graphical Workflow Configuration Editor
NodeProperty.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Jonathan Wuest
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17 */
24 #include "NodeProperty.h"
25 #include <QPainter>
26 #include <QHelpEvent>
27 #include <QCoreApplication>
28 #include "ConnectionLine.h"
29 #include "GraphModel.h"
30 #include "NodeHandler.h"
31 #include "Node.h"
32 #include "ParameterFileModel.h"
33 
35  Node* parentNode, QString name, int propNr,
36  bool input, const ParameterFileModel* pF) :
37  QGraphicsItem(parentNode),
38  _propNr(propNr),
39  _name(name),
40  _displayname(name),
41  _isInput(input),
42  _node(parentNode),
43  _pFile(pF)
44 {
45  Q_ASSERT(_node);
46  setAcceptHoverEvents(true);
47  _color=Qt::lightGray;
48 }
49 
51  Node* parentNode, QString name,QString displayname, int propNr,
52  bool input, const ParameterFileModel* pF) :
53  QGraphicsItem(parentNode),
54  _propNr(propNr),
55  _name(name),
56  _displayname(displayname),
57  _isInput(input),
58  _node(parentNode),
59  _pFile(pF)
60 {
61  Q_ASSERT(_node);
62  setAcceptHoverEvents(true);
63  _color=Qt::lightGray;
64 }
65 
66 void NodeProperty::moveBy(qreal, qreal) {
67  for (int i = 0; i < _connectionList.size(); i++) {
68  ConnectionLine *cline = _connectionList.at(i);
69  if (cline->getStartProp() == this) {
70  cline->setStartPoint(scenePos()+_getSocketRect().center());
71  } else {
72  cline->setEndPoint(scenePos()+_getSocketRect().center());
73  }
74  }
75 }
76 
78  _connectionList.push_back(nl);
79 }
80 
81 QString NodeProperty::getType() const {
82  QString tt;
83  if (_pFile) {
85  tt.replace("<","&lt;").replace(">","&gt;");
86  }
87  return tt;
88 }
89 
91  int yy = 28 + _propNr * 25;
92  return QRectF(-7, yy-1, _node->getWidth()+13, 21);
93 }
94 
96  QRectF ret = boundingRect();
97  ret.adjust(1,5,-1,-5);
98  if (isInput()) {
99  ret.setRight(ret.left()+11);
100  }
101  else {
102  ret.setLeft(ret.right()-11);
103  }
104  return ret;
105 }
106 
108  return _node->pos() + _getSocketRect().center();
109 }
110 
112  QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
113  QRectF inner = boundingRect();
114  inner.adjust(12,0,-12,0);
115  painter->setPen(QPen(Qt::black,0.5f));
116  painter->setOpacity(1);
117  //painter->setBrush(isUnderMouse() ? Qt::green : Qt::lightGray);
118  painter->setBrush(_color);
119  painter->drawRoundRect(inner, 10, 100);
120  painter->setBrush(Qt::black);
121  inner.adjust(10,0,-10,0);
122  QFont f = painter->font();
123  f.setPixelSize(14);
124  painter->setFont(f);
125  painter->drawText(inner, _displayname);
126  painter->setBrush(_getSocketColor(getType()));
127  painter->drawEllipse(_getSocketRect());
128 }
129 
130 QString NodeProperty::getFullName() const {
131  return _node->getInstanceName() + "." + _name;
132 }
133 
134 bool NodeProperty::isInput() const {
135  return _isInput;
136 }
137 
138 void NodeProperty::hoverEnterEvent(QGraphicsSceneHoverEvent* ev) {
139  QListIterator<ConnectionLine *> cl(_connectionList);
140  ConnectionLine* connectedLine;
141  QStringList cNodes;
142  while (cl.hasNext()) {
143  connectedLine=cl.next();
144  NodeProperty* prop=connectedLine->getEndProp();
145  if (prop==this) {
146  prop=connectedLine->getStartProp();
147  }
148  cNodes << QString("%1: <code>%2</code>")
149  .arg(cNodes.size()).arg(prop->getFullName());
150  }
151  if (cNodes.isEmpty()) {
152  cNodes << QString("<i>%1</i>").arg(
153  QCoreApplication::translate("NodeProperty","no connections"));
154  }
155  setToolTip(QString(
156  "<p style='white-space:pre'>"
157  "<b>%11: <i>%1</i></b><br>"
158  "<b>%12:</b><br><code>%2</code><br>"
159  "<b>%13:</b><br>%3<br>"
160  "<b>%14:</b><br>%4</p>")
161  .arg(_displayname)
162  .arg(getType())
163  .arg(_pFile?_pFile->getDoc(_node->getInstanceName()+"."+_name):QString())
164  .arg(cNodes.join("<br>"))
165  .arg(QCoreApplication::translate("NodeProperty","slot"))
166  .arg(QCoreApplication::translate("NodeProperty","type"))
167  .arg(QCoreApplication::translate("NodeProperty","documentation"))
168  .arg(QCoreApplication::translate("NodeProperty","connected to")));
169 
170  _color=Qt::green;
171  changeConnectionLineColor(Qt::green);
172  QGraphicsItem::hoverEnterEvent(ev);
173 }
174 
175 void NodeProperty::hoverLeaveEvent(QGraphicsSceneHoverEvent* ev) {
176  _color=Qt::lightGray;
177  changeConnectionLineColor(Qt::black, false);
178  QGraphicsItem::hoverLeaveEvent(ev);
179 }
180 
181 void NodeProperty::changeConnectionLineColor(QColor lineColor, bool isHover){
182  QListIterator<ConnectionLine *> cl(_connectionList);
183  ConnectionLine* connectedLine;
184  while (cl.hasNext()) {
185  connectedLine = cl.next();
186  // reset color to blue if not hovering and one of the parents is
187  // selected
188  if(!isHover && (
189  connectedLine->getStartProp()->_node->isSelectedNode() ||
190  connectedLine->getEndProp()->_node->isSelectedNode())) {
191  connectedLine->setLineColor(Qt::blue);
192  }
193  // else use given color (i.e. black/green)
194  else{
195  connectedLine->setLineColor(lineColor);
196  }
197  NodeProperty* prop=connectedLine->getEndProp();
198  if(prop==this)
199  prop=connectedLine->getStartProp();
200  if(isHover)
201  prop->setColor(Qt::red);
202  else
203  prop->setColor(Qt::lightGray);
204  }
205 }
206 
207 QColor NodeProperty::_getSocketColor(QString tName) {
208  if (tName.contains("cimg",Qt::CaseInsensitive)) {
209  return Qt::yellow;
210  }
211  else if (tName.contains("vigra",Qt::CaseInsensitive)) {
212  return Qt::darkYellow;
213  }
214  else if(tName.contains("roi",Qt::CaseInsensitive)) {
215  return Qt::green;
216  }
217  else if(tName.contains("interpolator",Qt::CaseInsensitive)) {
218  return Qt::blue;
219  }
220 
221  // add more color presets here
222  return Qt::gray;
223 }
224 
225 void NodeProperty::setColor(QColor socketColor)
226 {
227  _color = socketColor;
228 }
QString _name
name of the property
Definition: NodeProperty.h:118
QString _displayname
name of the property
Definition: NodeProperty.h:121
bool isSelectedNode()
state of node selections
Definition: Node.cpp:104
QGraphicsItem that contains nodeproperties and draws the node.
Definition: Node.h:36
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
update tool tip
Declaration of class ParameterFileModel.
NodeProperty * getEndProp() const
get property at end of line
Declaration of class Node.
NodeProperty * getStartProp() const
get property at start of line
bool _isInput
pointer to PropType of the property
Definition: NodeProperty.h:127
Declaration of class GraphModel.
void setLineColor(const QColor &newColor)
set color connected line
QPointF getSocketCenter() const
socket center including node position
Declaration of class NodeProperty.
void addConnection(ConnectionLine *cl)
add a connectionline to the property
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
draws the property
bool isInput() const
returns the PropType of the property
This model serves to provide a model frontend to access a ParameterFile instance. ...
QString getFullName() const
property name including node instance name
int getWidth() const
node width
Definition: Node.cpp:166
void setStartPoint(int x, int y)
sets start point (for drawing)
Declaration of class ConnectionLine.
QList< ConnectionLine * > _connectionList
list of all connectionlines
Definition: NodeProperty.h:124
static QColor _getSocketColor(QString typeName)
get color from type
void moveBy(qreal dx, qreal dy)
moves the property and if connected all connectionlines
Line that connects two slots of two different nodes.
QColor _color
Socket color.
Definition: NodeProperty.h:142
QString getDoc(QString parName) const
pass to metaInfo, use dynamic metadata if needed
unsigned int _propNr
number of property
Definition: NodeProperty.h:115
Property(/Parameter) of a node.
Definition: NodeProperty.h:35
virtual QRectF boundingRect() const
area for hover event
QString getInstanceName()
get node name
Definition: Node.cpp:66
QRectF _getSocketRect() const
center of the socket, used to draw end and start of connectionline
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
clear color of connected line when leave hoverevent
Declaration of class NodeHandler.
QString getType(QString parName, bool applyTmplType=true) const
Get type of some parameter or slot.
void setColor(QColor socketColor)
Set the color of the socket.
const ParameterFileModel * _pFile
link to parameter file
Definition: NodeProperty.h:133
void setEndPoint(int x, int y)
sets end point (for drawing)
QString getType() const
get property type
void changeConnectionLineColor(QColor lineColor, bool isHover=true)
change color all connected line of hovering property isHover set to true when the property was hovere...
Node * _node
pointer to parent node
Definition: NodeProperty.h:130
NodeProperty(Node *parentNode, QString name, int propNr, bool input, const ParameterFileModel *pFile)
default constructor