Version: 9.16.0
SceneProgressItem.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#include "SceneProgressItem.hxx"
22#include "SceneTextItem.hxx"
23#include "Scene.hxx"
24#include <QGraphicsSceneMouseEvent>
25
26#include "Resource.hxx"
27
28#include <cassert>
29
30//#define _DEVDEBUG_
31#include "YacsTrace.hxx"
32
33using namespace std;
34using namespace YACS::ENGINE;
35using namespace YACS::HMI;
36
37
38SceneProgressItem::SceneProgressItem(QGraphicsScene *scene, SceneItem *parent,
39 QString label)
40 : SceneItem(scene, parent, label)
41{
43 _progress = 0;
46 _text=0;
47 _tooltip = "";
54 setTopLeft(QPointF(x, y));
55}
56
58{
59}
60
62{
63 return QRectF(x(), y(), _width, _height);
64}
65
66void SceneProgressItem::paint(QPainter *painter,
67 const QStyleOptionGraphicsItem *option,
68 QWidget *widget)
69{
70// DEBTRACE("SceneProgressItem::paint");
71 painter->save();
72
76 QPen pen(getPenColor());
77 pen.setWidth(Resource::Thickness);
78 painter->setPen(pen);
79 QRect boundRect(0, 0, w, h);
80 painter->drawRect(boundRect);
81
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));
86 painter->restore();
87}
88
89void SceneProgressItem::setProgress(QString newProgress)
90{
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;
98 }
99 else
100 { //case '50' view of progress
101 _progress = newProgress.toInt(); //set 0 if the conversion fails.
102 }
103 percentageLabel = QString("%1\%").arg(_progress);
104 QString resultLabel;
106 {
107 case 0: //Percentage: 50%
108 resultLabel = QString("%1").arg(percentageLabel);
109 break;
110 case 1: //Nb.steps: 5/10
111 resultLabel = QString("%1").arg(nbStepsLabel);
112 break;
113 case 2: //Both: 50% (5/10)
114 resultLabel = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
115 break;
116 }
117 setText(resultLabel);
118 _tooltip = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
119 update();
120}
121
122void SceneProgressItem::setText(QString label)
123{
124 if (!_text)
125 _text = new SceneTextItem(_scene, this, label, true);
126 else
127 _text->setPlainTextTrunc(label);
128 //QGraphicsItem::update();
129}
130
131void SceneProgressItem::popupMenu(QWidget *caller, const QPoint &globalPos)
132{
133 if (_parent) _parent->popupMenu(caller, globalPos);
134}
135
137{
138 prepareGeometryChange();
140 update();
141}
142
144{
145 return _hiPenColor;
146}
147
149{
150 QColor color = _brushColor;
151 if (dynamic_cast<SceneHeaderNodeItem*>(this))
152 if (getParent()->isSelected())
153 color = _hiBrushColor;
154 if (_hover)
155 color = hoverColor(color);
156 return color;
157}
158
159void SceneProgressItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
160{
161 event->ignore();
162}
163
165{
166 return _tooltip;;
167}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
YACS::HMI::Scene * _scene
Definition: SceneItem.hxx:98
static int DataPort_Width
Definition: Resource.hxx:305
static QColor Header_brush
Definition: Resource.hxx:283
static int Corner_Margin
Definition: Resource.hxx:318
static int Border_Margin
Definition: Resource.hxx:310
static QColor progressBarColor
Definition: Resource.hxx:215
static int progressBarLabel
Definition: Resource.hxx:216
static int DataPort_Height
Definition: Resource.hxx:306
static int Space_Margin
Definition: Resource.hxx:311
static int Thickness
Definition: Resource.hxx:308
static QColor Header_hiPen
Definition: Resource.hxx:286
static QColor Header_pen
Definition: Resource.hxx:285
static int progressBar_Height
Definition: Resource.hxx:322
static QColor Header_hiBrush
Definition: Resource.hxx:284
virtual void popupMenu(QWidget *caller, const QPoint &globalPos)
virtual void setTopLeft(QPointF topLeft)
Definition: SceneItem.cxx:241
QColor hoverColor(QColor origColor)
virtual void setProgress(QString newProgress)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
virtual QRectF getMinimalBoundingRect() const
virtual void setText(QString label)
virtual void popupMenu(QWidget *caller, const QPoint &globalPos)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual void setPlainTextTrunc(QString label)
def h(x, y, destx, desty)
Definition: graph.py:272