1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SUPERV SUPERVGUI : GUI for Supervisor component
23 // File : SUPERVGUI_CanvasCellNodePrs.cxx
27 #include "SUPERVGUI_CanvasCellNodePrs.h"
28 #include "SUPERVGUI_Canvas.h"
30 #include "SUIT_ResourceMgr.h"
34 // ----------------------------------------------------------
35 // Cell widget of the table on QCanvas
36 // ----------------------------------------------------------
37 SUPERVGUI_CanvasCellNodePrs::SUPERVGUI_CanvasCellNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasCellNode* theNode):
38 myTitleWidth(CELL_WIDTH_PART),
39 myLabelWidth(CELL_WIDTH_PART),
40 myStatusWidth(CELL_WIDTH_PART),
41 SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode, true)
43 myPortVisible = false;
46 SUPERVGUI_CanvasCellNodePrs::~SUPERVGUI_CanvasCellNodePrs()
50 void SUPERVGUI_CanvasCellNodePrs::moveBy(double dx, double dy) {
51 //Trace("SUPERVGUI_CanvasCellNodePrs::moveBy");
52 int aX = (int) (x()+dx);
53 int aY = (int) (y()+dy);
55 int w = aX + width() + GRAPH_MARGIN;
56 int h = aY + height() + GRAPH_MARGIN;
57 if (canvas()->width() > w) w = canvas()->width();
58 if (canvas()->height() > h) h = canvas()->height();
59 if (canvas()->width() < w || canvas()->height() < h)
60 canvas()->resize(w, h);
61 QCanvasPolygonalItem::moveBy(dx, dy);
64 void SUPERVGUI_CanvasCellNodePrs::drawShape(QPainter& thePainter) {
65 drawTitle(thePainter);
66 drawLabel(thePainter);
67 drawStatus(thePainter);
68 drawFrame(thePainter);
71 void drawCellText(QPainter& thePainter, const QString& theText,
72 const QRect& theRect, int theHAlign = Qt::AlignAuto)
74 int flags = theHAlign | Qt::AlignVCenter;
75 QRect r(theRect.x() + TEXT_MARGIN, theRect.y(),
76 theRect.width() - 2*TEXT_MARGIN, theRect.height());
78 QWMatrix aMat = thePainter.worldMatrix();
79 if (aMat.m11() != 1.0) {
80 // for scaled picture only
81 QRect r1 = aMat.mapRect(r);
82 QFont saved = thePainter.font();
84 if (f.pointSize() == -1) {
85 f.setPixelSize((int)(f.pixelSize()*aMat.m11()));
88 f.setPointSize((int)(f.pointSize()*aMat.m11()));
92 thePainter.setWorldMatrix(m);
93 thePainter.setFont(f);
94 thePainter.drawText(r1, flags, theText);
95 thePainter.setFont(saved);
99 thePainter.drawText(r, flags, theText);
103 void SUPERVGUI_CanvasCellNodePrs::drawTitle(QPainter& thePainter) {
104 QBrush saved = thePainter.brush();
105 if (getNode()->getEngine()->IsLoop() || getNode()->getEngine()->IsEndLoop()
107 getNode()->getEngine()->IsSwitch() || getNode()->getEngine()->IsEndSwitch())
108 thePainter.setBrush(Qt::red.light());
109 else if (getNode()->getEngine()->IsGOTO())
110 thePainter.setBrush(Qt::green.light());
112 QBrush br( resMgr()->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
113 thePainter.setBrush(br);
115 drawTitleShape(thePainter);
116 thePainter.setBrush(saved);
118 drawCellText(thePainter, getNode()->getEngine()->Name(), getTitleRect(), Qt::AlignLeft);
121 void SUPERVGUI_CanvasCellNodePrs::drawLabel(QPainter& thePainter)
123 QRect r = getLabelRect();
125 QPen saved = thePainter.pen();
126 thePainter.setPen(NoPen);
127 thePainter.drawRect(r);
128 thePainter.setPen(saved);
130 drawCellText(thePainter, getNode()->getLabelText(), r, Qt::AlignLeft);
133 void SUPERVGUI_CanvasCellNodePrs::drawStatus(QPainter& thePainter)
135 QRect r = getStatusRect();
137 QBrush savedB = thePainter.brush();
138 thePainter.setBrush(getStatusColor());
139 drawStatusShape(thePainter);
140 thePainter.setBrush(savedB);
142 drawCellText(thePainter, getStatus(), r, Qt::AlignHCenter);
145 QRect SUPERVGUI_CanvasCellNodePrs::getTitleRect() const
147 return QRect((int)x(), (int)y(), getTitleWidth(), getTitleHeight());
150 QRect SUPERVGUI_CanvasCellNodePrs::getLabelRect() const
152 return QRect(((int)x())+getTitleWidth(), (int)y(), getLabelWidth(), getLabelHeight());
155 QRect SUPERVGUI_CanvasCellNodePrs::getStatusRect() const
157 return QRect(((int)x())+getTitleWidth()+getLabelWidth(), (int)y(),
158 getStatusWidth(), getStatusHeight());
161 int SUPERVGUI_CanvasCellNodePrs::getTitleWidth() const {
165 int SUPERVGUI_CanvasCellNodePrs::getLabelWidth() const {
169 int SUPERVGUI_CanvasCellNodePrs::getStatusWidth() const {
170 return myStatusWidth;
173 int SUPERVGUI_CanvasCellNodePrs::width() const
175 return myTitleWidth + myLabelWidth + myStatusWidth;
178 int SUPERVGUI_CanvasCellNodePrs::height() const
180 return getTitleHeight();
183 void SUPERVGUI_CanvasCellNodePrs::setState(SUPERV::GraphState theState)
187 setStatus("Waiting");
188 setStatusColor(QColor(35, 192, 255));
192 case SUPERV::ReadyState:
193 setStatus("Running");
194 setStatusColor(QColor(32,210,32));
198 case SUPERV::SuspendReadyState:
199 setStatus("Suspended");
200 setStatusColor(QColor(255,180, 0));
204 setStatus("Finished");
205 setStatusColor(QColor(255, 158, 255));
209 setStatus("Aborted");
210 setStatusColor(Qt::red);
215 setStatusColor(Qt::red);
218 case SUPERV::LoadingState:
219 setStatus("Loading");
220 setStatusColor(QColor(56,255,56));
224 setStatus("No Status");
225 setStatusColor( resMgr()->colorValue( "SUPERVGraph", "NodeBody", DEF_MAIN_BACK ) ); // mkr : IPAL10829
229 canvas()->setChanged(getStatusRect());