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
24
25namespace 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
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 {
165 }
166 }
167} // namespace armarx
#define option(type, fn)
void setText(const QString &text)
void setPixmap(const QPixmap &pixmap)
void updateNodeActivation(const QPointF &)
void setColor(const QColor &penColor)
void setRect(QRectF boundingBox)
QRectF boundingRect() const override
TermNodeGraphicsItem(TermTreeGraphicsScene *scene, TermNode *node)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
This file offers overloads of toIce() and fromIce() functions for STL container types.