1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 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 // File : SUPERVGUI_CanvasCellNodePrs.cxx
26 #include "SUPERVGUI_CanvasCellNodePrs.h"
27 #include "SUPERVGUI_Canvas.h"
29 #include "SUIT_ResourceMgr.h"
33 // ----------------------------------------------------------
34 // Cell widget of the table on QCanvas
35 // ----------------------------------------------------------
36 SUPERVGUI_CanvasCellNodePrs::SUPERVGUI_CanvasCellNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasCellNode* theNode):
37 myTitleWidth(CELL_WIDTH_PART),
38 myLabelWidth(CELL_WIDTH_PART),
39 myStatusWidth(CELL_WIDTH_PART),
40 SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode, true)
42 myPortVisible = false;
45 SUPERVGUI_CanvasCellNodePrs::~SUPERVGUI_CanvasCellNodePrs()
49 void SUPERVGUI_CanvasCellNodePrs::moveBy(double dx, double dy) {
50 //Trace("SUPERVGUI_CanvasCellNodePrs::moveBy");
51 int aX = (int) (x()+dx);
52 int aY = (int) (y()+dy);
54 int w = aX + width() + GRAPH_MARGIN;
55 int h = aY + height() + GRAPH_MARGIN;
56 if (canvas()->width() > w) w = canvas()->width();
57 if (canvas()->height() > h) h = canvas()->height();
58 if (canvas()->width() < w || canvas()->height() < h)
59 canvas()->resize(w, h);
60 QCanvasPolygonalItem::moveBy(dx, dy);
63 void SUPERVGUI_CanvasCellNodePrs::drawShape(QPainter& thePainter) {
64 drawTitle(thePainter);
65 drawLabel(thePainter);
66 drawStatus(thePainter);
67 drawFrame(thePainter);
70 void drawCellText(QPainter& thePainter, const QString& theText,
71 const QRect& theRect, int theHAlign = Qt::AlignAuto)
73 int flags = theHAlign | Qt::AlignVCenter;
74 QRect r(theRect.x() + TEXT_MARGIN, theRect.y(),
75 theRect.width() - 2*TEXT_MARGIN, theRect.height());
77 QWMatrix aMat = thePainter.worldMatrix();
78 if (aMat.m11() != 1.0) {
79 // for scaled picture only
80 QRect r1 = aMat.mapRect(r);
81 QFont saved = thePainter.font();
83 if (f.pointSize() == -1) {
84 f.setPixelSize((int)(f.pixelSize()*aMat.m11()));
87 f.setPointSize((int)(f.pointSize()*aMat.m11()));
91 thePainter.setWorldMatrix(m);
92 thePainter.setFont(f);
93 thePainter.drawText(r1, flags, theText);
94 thePainter.setFont(saved);
98 thePainter.drawText(r, flags, theText);
102 void SUPERVGUI_CanvasCellNodePrs::drawTitle(QPainter& thePainter) {
103 QBrush saved = thePainter.brush();
104 if (getNode()->getEngine()->IsLoop() || getNode()->getEngine()->IsEndLoop()
106 getNode()->getEngine()->IsSwitch() || getNode()->getEngine()->IsEndSwitch())
107 thePainter.setBrush(Qt::red.light());
108 else if (getNode()->getEngine()->IsGOTO())
109 thePainter.setBrush(Qt::green.light());
111 QBrush br( resMgr()->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
112 thePainter.setBrush(br);
114 drawTitleShape(thePainter);
115 thePainter.setBrush(saved);
117 drawCellText(thePainter, getNode()->getEngine()->Name(), getTitleRect(), Qt::AlignLeft);
120 void SUPERVGUI_CanvasCellNodePrs::drawLabel(QPainter& thePainter)
122 QRect r = getLabelRect();
124 QPen saved = thePainter.pen();
125 thePainter.setPen(NoPen);
126 thePainter.drawRect(r);
127 thePainter.setPen(saved);
129 drawCellText(thePainter, getNode()->getLabelText(), r, Qt::AlignLeft);
132 void SUPERVGUI_CanvasCellNodePrs::drawStatus(QPainter& thePainter)
134 QRect r = getStatusRect();
136 QBrush savedB = thePainter.brush();
137 thePainter.setBrush(getStatusColor());
138 drawStatusShape(thePainter);
139 thePainter.setBrush(savedB);
141 drawCellText(thePainter, getStatus(), r, Qt::AlignHCenter);
144 QRect SUPERVGUI_CanvasCellNodePrs::getTitleRect() const
146 return QRect((int)x(), (int)y(), getTitleWidth(), getTitleHeight());
149 QRect SUPERVGUI_CanvasCellNodePrs::getLabelRect() const
151 return QRect(((int)x())+getTitleWidth(), (int)y(), getLabelWidth(), getLabelHeight());
154 QRect SUPERVGUI_CanvasCellNodePrs::getStatusRect() const
156 return QRect(((int)x())+getTitleWidth()+getLabelWidth(), (int)y(),
157 getStatusWidth(), getStatusHeight());
160 int SUPERVGUI_CanvasCellNodePrs::getTitleWidth() const {
164 int SUPERVGUI_CanvasCellNodePrs::getLabelWidth() const {
168 int SUPERVGUI_CanvasCellNodePrs::getStatusWidth() const {
169 return myStatusWidth;
172 int SUPERVGUI_CanvasCellNodePrs::width() const
174 return myTitleWidth + myLabelWidth + myStatusWidth;
177 int SUPERVGUI_CanvasCellNodePrs::height() const
179 return getTitleHeight();
182 void SUPERVGUI_CanvasCellNodePrs::setState(SUPERV::GraphState theState)
186 setStatus("Waiting");
187 setStatusColor(QColor(35, 192, 255));
191 case SUPERV::ReadyState:
192 setStatus("Running");
193 setStatusColor(QColor(32,210,32));
197 case SUPERV::SuspendReadyState:
198 setStatus("Suspended");
199 setStatusColor(QColor(255,180, 0));
203 setStatus("Finished");
204 setStatusColor(QColor(255, 158, 255));
208 setStatus("Aborted");
209 setStatusColor(Qt::red);
214 setStatusColor(Qt::red);
217 case SUPERV::LoadingState:
218 setStatus("Loading");
219 setStatusColor(QColor(56,255,56));
223 setStatus("No Status");
224 setStatusColor( resMgr()->colorValue( "SUPERVGraph", "NodeBody", DEF_MAIN_BACK ) ); // mkr : IPAL10829
228 canvas()->setChanged(getStatusRect());