26 #define YUILogComponent "qt-ui"
27 #include <yui/YUILog.h>
31 #include <QStyleOptionProgressBar>
34 #include "YQMultiProgressMeter.h"
35 #include <yui/YDialog.h>
43 const vector<float> & maxValues )
44 : QWidget( (QWidget *) parent->widgetRep() )
45 , YMultiProgressMeter( parent, dim, maxValues )
61 _segmentMinLength = 12;
79 QPainter painter(
this );
84 int totalLength = horizontal() ? width() : height();
85 int thickness = horizontal() ? height() : width();
93 if ( totalLength < 1 ||
thickness < 1 || segments() < 1 )
101 for(
int i=0; i < segments(); i++ )
102 totalSum += maxValue( i );
112 if ( minLength * segments() > totalLength )
113 minLength = totalLength / ( 2 * segments() );
118 if ( totalSum == 0.0 )
120 yuiError() <<
"Avoiding division by zero: totalSum" << endl;
124 float scale = ( (float) totalLength ) / totalSum;
125 float scaledMinLength = ( (float) minLength ) / scale;
130 int smallSegmentsCount = 0;
133 for (
int i=0; i < segments(); i++ )
135 if ( maxValue( i ) < scaledMinLength )
136 smallSegmentsCount++;
138 restSum += maxValue( i );
145 int distributableLength = totalLength - smallSegmentsCount * minLength;
147 if ( restSum == 0.0 )
149 yuiError() <<
"Avoiding division by zero: restSum" << endl;
155 scale = ( (float) distributableLength ) / ( restSum );
161 painter.rotate( 90 );
162 painter.scale( 1.0, -1.0 );
169 for (
int i=0; i < segments(); i++ )
173 if ( maxValue( i ) < scaledMinLength )
176 length = (int) ( maxValue( i ) * scale + 0.5 );
207 if ( maxValue( segment ) == 0.0 )
209 yuiError() <<
"Avoiding division by zero: maxValue[" << segment <<
"]" << endl;
214 const int scaledMax = 1000;
216 (int) ( 0.5 + ( currentValue( segment ) / maxValue( segment ) ) * ( (float) scaledMax ) );
220 QStyleOptionProgressBar opts;
222 opts.progress = scaledMax - scaledProgress;
224 opts.maximum = scaledMax;
225 opts.invertedAppearance =
true;
227 style()->drawControl(QStyle::CE_ProgressBarGroove, &opts, &painter,
this);
229 if ( opts.progress > 0 )
230 style()->drawControl(QStyle::CE_ProgressBarContents, &opts, &painter,
this);
234 QStyleOptionProgressBar opts;
236 opts.progress = scaledProgress;
238 opts.maximum = scaledMax;
241 style()->drawControl(QStyle::CE_ProgressBarGroove, &opts, &painter,
this);
242 if ( opts.progress > 0 )
243 style()->drawControl(QStyle::CE_ProgressBarContents, &opts, &painter,
this);
255 const QBrush & color = palette().windowText();
256 painter.setBrush( color );
266 QPointF( offset - tri+1,
margin() ),
267 QPointF( offset,
margin() + tri-1 ),
268 QPointF( offset + tri-1,
margin() )
271 painter.drawConvexPolygon( points, 3 );
279 QPointF( offset, pointOffset ),
280 QPointF( offset + tri-1, pointOffset + tri-1 ),
281 QPointF( offset - tri+1, pointOffset + tri-1 )
284 painter.drawConvexPolygon( points2, 3 );
310 _triThickness = value;
312 if ( _triThickness < 1 )
319 QWidget::setEnabled( enabled );
321 YWidget::setEnabled( enabled );
339 resize( newWidth, newHeight );
void drawMarkers(QPainter &painter, int offset, int thickness)
Draw markers between segments (or beside that spacing).
virtual ~YQMultiProgressMeter()
Destructor.
void drawSegment(int segment, QPainter &painter, int offset, int length, int thickness)
Draw segment number 'segment' with pixel length 'length' from pixel coordinate 'offset' on and fill i...
int triSpacing() const
Returns the spacing between the segment indicators and the small triangles next to the spacing betwee...
int triThickness() const
Returns the thickness (base to point) of the small triangles next to the spacing between individual s...
int segmentMinLength() const
Returns the minimal length of a segment in pixels.
void init()
Common initialization.
int thickness()
Overall thickness (in pixels) of the MultiProgressMeter.
YQMultiProgressMeter(YWidget *parent, YUIDimension dim, const vector< float > &maxValues)
Constructor.
int margin() const
Returns the margin around the widget contents.
void setTriSpacing(int value)
Sets the spacing between the segment indicators and the small triangles next to the spacing between s...
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void doUpdate()
Perform a visual update on the screen.
void setTriThickness(int value)
Set the thickness (base to point) of the small triangles next to the spacing between individual segme...
int spacing() const
Returns the spacing between segments in pixels.
virtual void paintEvent(QPaintEvent *)
Paint the widget's contents.
virtual int preferredWidth()
Preferred width of the widget.
virtual int preferredHeight()
Preferred height of the widget.
int length()
Overall length (in pixels) of the MultiProgressMeter.