1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_CanvasControlNodePrs.cxx
6 // Author : Natalia KOPNOVA
11 #include "SUPERVGUI_CanvasControlNodePrs.h"
12 #include "SUPERVGUI_CanvasControlNode.h"
13 #include "SUPERVGUI_Canvas.h"
15 #define SHIFT LABEL_HEIGHT/2
17 //=====================================================================
18 // Control node presentation
19 //=====================================================================
20 SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs(QCanvas* theCanvas, SUPERVGUI_CanvasNode* theNode):
21 SUPERVGUI_CanvasNodePrs(theCanvas, theNode)
23 Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
24 setLabelVisible(false);
25 setNodeColor(Qt::cyan.light());
28 void SUPERVGUI_CanvasControlNodePrs::hideAll()
30 bool aDisp = isVisible();
33 setPortVisible(false);
41 void SUPERVGUI_CanvasControlNodePrs::showAll()
43 bool aDisp = isVisible();
54 QRect SUPERVGUI_CanvasControlNodePrs::getStatusRect() const
56 return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+
57 getBodyHeight()+getGateHeight(),
58 width(), getStatusHeight());
61 QRect SUPERVGUI_CanvasControlNodePrs::getBodyRect() const
63 return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight(),
64 width(), getBodyHeight());
67 QRect SUPERVGUI_CanvasControlNodePrs::getGateRect() const
69 return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+getBodyHeight(),
70 width(), getGateHeight());
73 //=====================================================================
74 // Start control node presentation
75 //=====================================================================
76 SUPERVGUI_CanvasStartNodePrs::SUPERVGUI_CanvasStartNodePrs(QCanvas* theCanvas, SUPERVGUI_CanvasStartNode* theNode):
77 SUPERVGUI_CanvasControlNodePrs(theCanvas, theNode)
79 Trace("SUPERVGUI_CanvasStartNodePrs::SUPERVGUI_CanvasStartNodePrs");
82 QPointArray SUPERVGUI_CanvasStartNodePrs::areaPoints() const
85 int h = height()+2; // add width of pen
87 int h1 = getTitleHeight()+1;
88 int h2 = getStatusHeight()+1;
91 QPoint p((int)x(), (int)y()-1);
92 aPnts[0] = p + QPoint(0, h1);
93 aPnts[1] = p + QPoint(SHIFT, 0);
94 aPnts[2] = aPnts[1] + QPoint(w, 0);
95 aPnts[3] = aPnts[0] + QPoint(w, 0);
96 aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
97 aPnts[5] = aPnts[2] + QPoint(0, h);
98 aPnts[6] = aPnts[1] + QPoint(0, h);
99 aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
103 void SUPERVGUI_CanvasStartNodePrs::drawFrame(QPainter& thePainter)
107 int h1 = getTitleHeight();
108 int h2 = getStatusHeight();
110 QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
112 QBrush saved = thePainter.brush();
113 thePainter.setBrush(NoBrush);
114 thePainter.drawRect(r0);
115 thePainter.setBrush(saved);
118 void SUPERVGUI_CanvasStartNodePrs::drawTitleShape(QPainter& thePainter)
120 QRect r = getTitleRect();
123 QPointArray aPnts(4);
124 aPnts[0] = r.topLeft() + QPoint(0, r.height());
125 aPnts[1] = r.topLeft() + QPoint(SHIFT, 0);
126 aPnts[2] = aPnts[1] + QPoint(w, 0);
127 aPnts[3] = aPnts[0] + QPoint(w, 0);
129 thePainter.setBrush(Qt::red.light());
130 thePainter.drawPolygon(aPnts);
133 void SUPERVGUI_CanvasStartNodePrs::drawStatusShape(QPainter& thePainter)
135 QRect r = getStatusRect();
138 QPointArray aPnts(4);
139 aPnts[0] = r.topLeft() + QPoint(SHIFT, r.height());
140 aPnts[1] = r.topLeft();
141 aPnts[2] = aPnts[1] + QPoint(w, 0);
142 aPnts[3] = aPnts[0] + QPoint(w, 0);
144 thePainter.drawPolygon(aPnts);
148 void SUPERVGUI_CanvasStartNodePrs::setState(SUPERV::GraphState theState)
150 QRect r = getStatusRect();
151 canvas()->setChanged(QRect(r.x(), r.y(), r.width()+SHIFT, r.height()));
152 SUPERVGUI_CanvasNodePrs::setState(theState);
156 //=====================================================================
157 // End control node presentation
158 //=====================================================================
159 SUPERVGUI_CanvasEndNodePrs::SUPERVGUI_CanvasEndNodePrs(QCanvas* theCanvas, SUPERVGUI_CanvasEndNode* theNode):
160 SUPERVGUI_CanvasControlNodePrs(theCanvas, theNode)
162 Trace("SUPERVGUI_CanvasEndNodePrs::SUPERVGUI_CanvasEndNodePrs");
165 QPointArray SUPERVGUI_CanvasEndNodePrs::areaPoints() const
170 int h1 = getTitleHeight()+1;
171 int h2 = getStatusHeight()+1;
173 QPointArray aPnts(8);
174 QPoint p((int)x(), (int)y()-1);
175 aPnts[0] = p + QPoint(0, h1);
176 aPnts[1] = p + QPoint(-SHIFT, 0);
177 aPnts[2] = aPnts[1] + QPoint(w, 0);
178 aPnts[3] = aPnts[0] + QPoint(w, 0);
179 aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
180 aPnts[5] = aPnts[2] + QPoint(0, h);
181 aPnts[6] = aPnts[1] + QPoint(0, h);
182 aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
186 void SUPERVGUI_CanvasEndNodePrs::drawFrame(QPainter& thePainter)
190 int h1 = getTitleHeight();
191 int h2 = getStatusHeight();
193 QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
195 QBrush saved = thePainter.brush();
196 thePainter.setBrush(NoBrush);
197 thePainter.drawRect(r0);
198 thePainter.setBrush(saved);
201 void SUPERVGUI_CanvasEndNodePrs::drawTitleShape(QPainter& thePainter)
203 QRect r = getTitleRect();
206 QPointArray aPnts(4);
207 aPnts[0] = r.topLeft() + QPoint(0, r.height());
208 aPnts[1] = r.topLeft() + QPoint(-SHIFT, 0);
209 aPnts[2] = aPnts[1] + QPoint(w, 0);
210 aPnts[3] = aPnts[0] + QPoint(w, 0);
212 thePainter.setBrush(Qt::red.light());
213 thePainter.drawPolygon(aPnts);
216 void SUPERVGUI_CanvasEndNodePrs::drawStatusShape(QPainter& thePainter)
218 QRect r = getStatusRect();
221 QPointArray aPnts(4);
222 aPnts[0] = r.topLeft() + QPoint(-SHIFT, r.height());
223 aPnts[1] = r.topLeft();
224 aPnts[2] = aPnts[1] + QPoint(w, 0);
225 aPnts[3] = aPnts[0] + QPoint(w, 0);
227 thePainter.drawPolygon(aPnts);
230 void SUPERVGUI_CanvasEndNodePrs::setState(SUPERV::GraphState theState)
232 QRect r = getStatusRect();
233 canvas()->setChanged(QRect(r.x()-SHIFT, r.y(), r.width()+SHIFT, r.height()));
234 SUPERVGUI_CanvasNodePrs::setState(theState);
237 //=====================================================================
238 // Goto control node presentation
239 //=====================================================================
240 SUPERVGUI_CanvasGotoNodePrs::SUPERVGUI_CanvasGotoNodePrs(QCanvas* theCanvas, SUPERVGUI_CanvasGotoNode* theNode):
241 SUPERVGUI_CanvasControlNodePrs(theCanvas, theNode)
243 Trace("SUPERVGUI_CanvasGotoNodePrs::SUPERVGUI_CanvasGotoNodePrs");
246 QPointArray SUPERVGUI_CanvasGotoNodePrs::areaPoints() const
251 int h1 = getTitleHeight()+1;
252 int h2 = getStatusHeight()+1;
254 QPointArray aPnts(8);
255 QPoint p((int)x(), (int)y()-1);
256 aPnts[0] = p + QPoint(0, h1);
257 aPnts[1] = p + QPoint(SHIFT, 0);
258 aPnts[2] = aPnts[1] + QPoint(w-2*SHIFT, 0);
259 aPnts[3] = aPnts[0] + QPoint(w, 0);
260 aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
261 aPnts[5] = aPnts[2] + QPoint(0, h);
262 aPnts[6] = aPnts[1] + QPoint(0, h);
263 aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
267 void SUPERVGUI_CanvasGotoNodePrs::drawFrame(QPainter& thePainter)
271 int h1 = getTitleHeight();
272 int h2 = getStatusHeight();
274 QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
276 QBrush saved = thePainter.brush();
277 thePainter.setBrush(NoBrush);
278 thePainter.drawRect(r0);
279 thePainter.setBrush(saved);
282 void SUPERVGUI_CanvasGotoNodePrs::drawTitleShape(QPainter& thePainter)
284 QRect r = getTitleRect();
287 QPointArray aPnts(4);
288 aPnts[0] = r.topLeft() + QPoint(0, r.height());
289 aPnts[1] = r.topLeft() + QPoint(SHIFT, 0);
290 aPnts[2] = aPnts[1] + QPoint(w-2*SHIFT, 0);
291 aPnts[3] = aPnts[0] + QPoint(w, 0);
293 thePainter.setBrush(Qt::green.light());
294 thePainter.drawPolygon(aPnts);
297 void SUPERVGUI_CanvasGotoNodePrs::drawStatusShape(QPainter& thePainter)
299 QRect r = getStatusRect();
302 QPointArray aPnts(4);
303 aPnts[0] = r.topLeft() + QPoint(SHIFT, r.height());
304 aPnts[1] = r.topLeft();
305 aPnts[2] = aPnts[1] + QPoint(w, 0);
306 aPnts[3] = aPnts[0] + QPoint(w-2*SHIFT, 0);
308 thePainter.drawPolygon(aPnts);
312 //=====================================================================
313 // Macro node presentation
314 //=====================================================================
315 SUPERVGUI_CanvasMacroNodePrs::SUPERVGUI_CanvasMacroNodePrs(QCanvas* theCanvas, SUPERVGUI_CanvasMacroNode* theNode):
316 SUPERVGUI_CanvasNodePrs(theCanvas, theNode)
318 Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
319 setNodeColor(QColor(255, 186, 149)); //QColor(255, 200, 170));
322 void SUPERVGUI_CanvasMacroNodePrs::drawFrame(QPainter& thePainter)
324 SUPERVGUI_CanvasNodePrs::drawFrame(thePainter);
326 QPen saved = thePainter.pen();
327 thePainter.setPen(QPen(saved.color(), 2));
330 thePainter.drawLine(r.left(), r.top(), r.left(), r.bottom());
331 thePainter.drawLine(r.left()+3, r.top(), r.left()+3, r.bottom());
332 thePainter.drawLine(r.right()-3, r.top(), r.right()-3, r.bottom());
333 thePainter.drawLine(r.right(), r.top(), r.right(), r.bottom());
334 thePainter.setPen(saved);
337 QPointArray SUPERVGUI_CanvasMacroNodePrs::areaPoints() const
339 int w = width()+2; // add width of pen
342 QPointArray aPnts(4);
343 aPnts[0] = QPoint((int)x()-1, (int)y());
344 aPnts[1] = aPnts[0] + QPoint(w, 0);
345 aPnts[2] = aPnts[1] + QPoint(0, h);
346 aPnts[3] = aPnts[0] + QPoint(0, h);