TermNodeGraphicsItem.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::Gui
17 * @author Kai Welke (welke@kit.edu)
18 * @copyright 2012 Humanoids Group, IAIM, IFA
19 * @license http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "TermNodeGraphicsItem.h"
24 
25 namespace armarx
26 {
28  {
29  this->node = node;
30  activated = false;
31  pixmapSet = false;
32 
33  // connections to / from TermNode
34  connect(scene,
35  SIGNAL(graphicsSceneClicked(const QPointF&)),
36  this,
37  SLOT(updateNodeActivation(const QPointF&)));
38  }
39 
40  // setters
41  void
42  TermNodeGraphicsItem::setRect(QRectF boundingBox)
43  {
44  prepareGeometryChange();
45  this->boundingBox = boundingBox;
46 
47  update();
48  }
49 
50  void
51  TermNodeGraphicsItem::setText(const QString& text)
52  {
53  this->text = text;
54 
55  update();
56  }
57 
58  void
59  TermNodeGraphicsItem::setColor(const QColor& penColor)
60  {
61  this->penColor = penColor;
62 
63  update();
64  }
65 
66  void
67  TermNodeGraphicsItem::setPixmap(const QPixmap& pixmap)
68  {
69  this->pixmap = pixmap;
70  pixmapSet = true;
71 
72  update();
73  }
74 
75  // pute virtual in QGraphicsItem
76  QRectF
78  {
79  return boundingBox;
80  }
81 
82  void
83  TermNodeGraphicsItem::paint(QPainter* painter,
84  const QStyleOptionGraphicsItem* option,
85  QWidget* widget)
86  {
87  // draw ellipse
88  {
89  QBrush penBrush(penColor);
90  QPen pen(penBrush, 3, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin);
91 
92  QBrush brush(Qt::lightGray);
93  painter->setPen(pen);
94 
95  if (activated)
96  {
97  painter->setBrush(brush);
98  }
99  else
100  {
101  painter->setBrush(Qt::NoBrush);
102  }
103 
104  painter->drawEllipse(boundingBox);
105  }
106 
107  // draw text
108  if (text.length() > 0)
109  {
110  QPen pen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin);
111  painter->setPen(pen);
112  painter->drawText(boundingBox, Qt::AlignCenter, text);
113  }
114 
115  // draw pixmap
116  pixmapSet = true;
117 
118  if (pixmapSet)
119  {
120  QRect bbPixmap(boundingBox.center().x() - boundingBox.width() / 4,
121  boundingBox.center().y() - boundingBox.height() / 4,
122  boundingBox.width() / 2,
123  boundingBox.height() / 2);
124  painter->drawPixmap(bbPixmap, pixmap);
125  }
126  }
127 
128  // slots
129  void
131  {
132  activated = true;
133  emit nodeActivated();
134  update();
135  }
136 
137  void
139  {
140  activated = true;
141  update();
142  }
143 
144  void
146  {
147  activated = false;
148  emit nodeDeactivated();
149  update();
150  }
151 
152  void
154  {
155  // from scene pos to local pos
156  QPointF inLocal = point - scenePos();
157 
158  if (contains(inLocal))
159  {
160  activateNode();
161  }
162  else
163  {
164  deactivateNode();
165  }
166  }
167 } // namespace armarx
armarx::TermNodeGraphicsItem::boundingRect
QRectF boundingRect() const override
Definition: TermNodeGraphicsItem.cpp:77
armarx::TermNodeGraphicsItem::nodeDeactivated
void nodeDeactivated()
armarx::armem::contains
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
Definition: MemoryID.cpp:563
armarx::TermNodeGraphicsItem::activateNodeSilent
void activateNodeSilent()
Definition: TermNodeGraphicsItem.cpp:138
armarx::TermNodeGraphicsItem::setPixmap
void setPixmap(const QPixmap &pixmap)
Definition: TermNodeGraphicsItem.cpp:67
armarx::TermNodeGraphicsItem::nodeActivated
void nodeActivated()
armarx::TermNodeGraphicsItem::deactivateNode
void deactivateNode()
Definition: TermNodeGraphicsItem.cpp:145
armarx::TermNodeGraphicsItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition: TermNodeGraphicsItem.cpp:83
armarx::TermTreeGraphicsScene
Definition: TermTreeGraphicsScene.h:33
armarx::TermNodeGraphicsItem::setText
void setText(const QString &text)
Definition: TermNodeGraphicsItem.cpp:51
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:68
option
#define option(type, fn)
armarx::TermNodeGraphicsItem::TermNodeGraphicsItem
TermNodeGraphicsItem(TermTreeGraphicsScene *scene, TermNode *node)
Definition: TermNodeGraphicsItem.cpp:27
armarx::TermNodeGraphicsItem::setColor
void setColor(const QColor &penColor)
Definition: TermNodeGraphicsItem.cpp:59
armarx::TermNodeGraphicsItem::updateNodeActivation
void updateNodeActivation(const QPointF &)
Definition: TermNodeGraphicsItem.cpp:153
TermNodeGraphicsItem.h
armarx::TermNodeGraphicsItem::activateNode
void activateNode()
Definition: TermNodeGraphicsItem.cpp:130
armarx::TermNode
Definition: TermNode.h:47
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::TermNodeGraphicsItem::setRect
void setRect(QRectF boundingBox)
Definition: TermNodeGraphicsItem.cpp:42