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, SIGNAL(graphicsSceneClicked(const QPointF&)), this, SLOT(updateNodeActivation(const QPointF&)));
35  }
36 
37  // setters
38  void TermNodeGraphicsItem::setRect(QRectF boundingBox)
39  {
40  prepareGeometryChange();
41  this->boundingBox = boundingBox;
42 
43  update();
44  }
45 
46  void TermNodeGraphicsItem::setText(const QString& text)
47  {
48  this->text = text;
49 
50  update();
51  }
52 
53  void TermNodeGraphicsItem::setColor(const QColor& penColor)
54  {
55  this->penColor = penColor;
56 
57  update();
58  }
59 
60  void TermNodeGraphicsItem::setPixmap(const QPixmap& pixmap)
61  {
62  this->pixmap = pixmap;
63  pixmapSet = true;
64 
65  update();
66  }
67 
68  // pute virtual in QGraphicsItem
70  {
71  return boundingBox;
72  }
73 
74  void TermNodeGraphicsItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
75  QWidget* widget)
76  {
77  // draw ellipse
78  {
79  QBrush penBrush(penColor);
80  QPen pen(penBrush, 3, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin);
81 
82  QBrush brush(Qt::lightGray);
83  painter->setPen(pen);
84 
85  if (activated)
86  {
87  painter->setBrush(brush);
88  }
89  else
90  {
91  painter->setBrush(Qt::NoBrush);
92  }
93 
94  painter->drawEllipse(boundingBox);
95  }
96 
97  // draw text
98  if (text.length() > 0)
99  {
100  QPen pen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin);
101  painter->setPen(pen);
102  painter->drawText(boundingBox, Qt::AlignCenter, text);
103  }
104 
105  // draw pixmap
106  pixmapSet = true;
107 
108  if (pixmapSet)
109  {
110  QRect bbPixmap(boundingBox.center().x() - boundingBox.width() / 4, boundingBox.center().y() - boundingBox.height() / 4, boundingBox.width() / 2, boundingBox.height() / 2);
111  painter->drawPixmap(bbPixmap, pixmap);
112  }
113  }
114 
115  // slots
117  {
118  activated = true;
119  emit nodeActivated();
120  update();
121  }
122 
124  {
125  activated = true;
126  update();
127  }
129  {
130  activated = false;
131  emit nodeDeactivated();
132  update();
133  }
134 
136  {
137  // from scene pos to local pos
138  QPointF inLocal = point - scenePos();
139 
140  if (contains(inLocal))
141  {
142  activateNode();
143  }
144  else
145  {
146  deactivateNode();
147  }
148  }
149 }
armarx::TermNodeGraphicsItem::boundingRect
QRectF boundingRect() const override
Definition: TermNodeGraphicsItem.cpp:69
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:558
armarx::TermNodeGraphicsItem::activateNodeSilent
void activateNodeSilent()
Definition: TermNodeGraphicsItem.cpp:123
armarx::TermNodeGraphicsItem::setPixmap
void setPixmap(const QPixmap &pixmap)
Definition: TermNodeGraphicsItem.cpp:60
armarx::TermNodeGraphicsItem::nodeActivated
void nodeActivated()
armarx::TermNodeGraphicsItem::deactivateNode
void deactivateNode()
Definition: TermNodeGraphicsItem.cpp:128
armarx::TermNodeGraphicsItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition: TermNodeGraphicsItem.cpp:74
armarx::TermTreeGraphicsScene
Definition: TermTreeGraphicsScene.h:32
armarx::TermNodeGraphicsItem::setText
void setText(const QString &text)
Definition: TermNodeGraphicsItem.cpp:46
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
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:53
armarx::TermNodeGraphicsItem::updateNodeActivation
void updateNodeActivation(const QPointF &)
Definition: TermNodeGraphicsItem.cpp:135
TermNodeGraphicsItem.h
armarx::TermNodeGraphicsItem::activateNode
void activateNode()
Definition: TermNodeGraphicsItem.cpp:116
armarx::TermNode
Definition: TermNode.h:47
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::TermNodeGraphicsItem::setRect
void setRect(QRectF boundingBox)
Definition: TermNodeGraphicsItem.cpp:38