1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SceneProgressItem.hxx"
21 #include "SceneHeaderNodeItem.hxx"
22 #include "SceneTextItem.hxx"
24 #include <QGraphicsSceneMouseEvent>
26 #include "Resource.hxx"
31 #include "YacsTrace.hxx"
34 using namespace YACS::ENGINE;
35 using namespace YACS::HMI;
38 SceneProgressItem::SceneProgressItem(QGraphicsScene *scene, SceneItem *parent,
40 : SceneItem(scene, parent, label)
44 _width = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
45 _height = Resource::progressBar_Height;
48 _brushColor = Resource::Header_brush;
49 _hiBrushColor = Resource::Header_hiBrush;
50 _penColor = Resource::Header_pen;
51 _hiPenColor = Resource::Header_hiPen;
52 int x = Resource::Border_Margin;
53 int y = Resource::DataPort_Height + 2*Resource::Space_Margin;
54 setTopLeft(QPointF(x, y));
57 SceneProgressItem::~SceneProgressItem()
61 QRectF SceneProgressItem::getMinimalBoundingRect() const
63 return QRectF(x(), y(), _width, _height);
66 void SceneProgressItem::paint(QPainter *painter,
67 const QStyleOptionGraphicsItem *option,
70 // DEBTRACE("SceneProgressItem::paint");
73 int w = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
74 if (_parent->getWidth() > w) w = _parent->getWidth() - Resource::Corner_Margin - Resource::Space_Margin;
75 int h = Resource::progressBar_Height;
76 QPen pen(getPenColor());
77 pen.setWidth(Resource::Thickness);
79 QRect boundRect(0, 0, w, h);
80 painter->drawRect(boundRect);
82 painter->setBrush(Resource::progressBarColor);
83 //correct width according to progress
84 int corr_w = w * _progress / 100;
85 painter->drawRect(QRect(0, 0, corr_w, h));
89 void SceneProgressItem::setProgress(QString newProgress)
91 QString percentageLabel;
92 QString nbStepsLabel = "-/-";
93 QStringList aSteps = newProgress.split('/');
94 if (aSteps.count() == 2)
95 { //case '5/10' view of progress
96 _progress = aSteps.at(0).toInt() * 100 / aSteps.at(1).toInt();
97 nbStepsLabel = newProgress;
100 { //case '50' view of progress
101 _progress = newProgress.toInt(); //set 0 if the conversion fails.
103 percentageLabel = QString("%1\%").arg(_progress);
105 switch(Resource::progressBarLabel)
107 case 0: //Percentage: 50%
108 resultLabel = QString("%1").arg(percentageLabel);
110 case 1: //Nb.steps: 5/10
111 resultLabel = QString("%1").arg(nbStepsLabel);
113 case 2: //Both: 50% (5/10)
114 resultLabel = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
117 setText(resultLabel);
118 _tooltip = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
122 void SceneProgressItem::setText(QString label)
125 _text = new SceneTextItem(_scene, this, label, true);
127 _text->setPlainTextTrunc(label);
128 //QGraphicsItem::update();
131 void SceneProgressItem::popupMenu(QWidget *caller, const QPoint &globalPos)
133 if (_parent) _parent->popupMenu(caller, globalPos);
136 void SceneProgressItem::adjustGeometry()
138 prepareGeometryChange();
139 _width = _parent->getWidth() - Resource::Corner_Margin - Resource::Space_Margin;
143 QColor SceneProgressItem::getPenColor()
148 QColor SceneProgressItem::getBrushColor()
150 QColor color = _brushColor;
151 if (dynamic_cast<SceneHeaderNodeItem*>(this))
152 if (getParent()->isSelected())
153 color = _hiBrushColor;
155 color = hoverColor(color);
159 void SceneProgressItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
164 QString SceneProgressItem::getToolTip()