26 #define YUILogComponent "qt-ui"
27 #include <yui/YUILog.h>
31 #include <QStyleOptionProgressBarV2>
34 #include "YQMultiProgressMeter.h"
35 #include <yui/YDialog.h>
41 const vector<float> & maxValues )
42 : QWidget( (QWidget *) parent->widgetRep() )
43 , YMultiProgressMeter( parent, dim, maxValues )
59 _segmentMinLength = 12;
77 QPainter painter(
this );
82 int totalLength = horizontal() ? width() : height();
83 int thickness = horizontal() ? height() : width();
91 if ( totalLength < 1 || thickness < 1 || segments() < 1 )
99 for(
int i=0; i < segments(); i++ )
100 totalSum += maxValue( i );
110 if ( minLength * segments() > totalLength )
111 minLength = totalLength / ( 2 * segments() );
116 if ( totalSum == 0.0 )
118 yuiError() <<
"Avoiding division by zero: totalSum" << std::endl;
122 float scale = ( (float) totalLength ) / totalSum;
123 float scaledMinLength = ( (float) minLength ) / scale;
128 int smallSegmentsCount = 0;
131 for (
int i=0; i < segments(); i++ )
133 if ( maxValue( i ) < scaledMinLength )
134 smallSegmentsCount++;
136 restSum += maxValue( i );
143 int distributableLength = totalLength - smallSegmentsCount * minLength;
145 if ( restSum == 0.0 )
147 yuiError() <<
"Avoiding division by zero: restSum" << std::endl;
153 scale = ( (float) distributableLength ) / ( restSum );
159 painter.rotate( 90 );
160 painter.scale( 1.0, -1.0 );
167 for (
int i=0; i < segments(); i++ )
171 if ( maxValue( i ) < scaledMinLength )
174 length = (int) ( maxValue( i ) * scale + 0.5 );
176 drawSegment( i, painter, offset, length, thickness );
205 if ( maxValue( segment ) == 0.0 )
207 yuiError() <<
"Avoiding division by zero: maxValue[" << segment <<
"]" << std::endl;
212 const int scaledMax = 1000;
214 (int) ( 0.5 + ( currentValue( segment ) / maxValue( segment ) ) * ( (float) scaledMax ) );
218 QStyleOptionProgressBarV2 opts;
220 opts.progress = scaledMax - scaledProgress;
222 opts.maximum = scaledMax;
223 opts.invertedAppearance =
true;
224 opts.rect = QRect( offset, border, length, thickness );
225 style()->drawControl(QStyle::CE_ProgressBarGroove, &opts, &painter,
this);
227 if ( opts.progress > 0 )
228 style()->drawControl(QStyle::CE_ProgressBarContents, &opts, &painter,
this);
232 QStyleOptionProgressBarV2 opts;
234 opts.progress = scaledProgress;
236 opts.maximum = scaledMax;
237 opts.rect = QRect( offset, border, length, thickness );
239 style()->drawControl(QStyle::CE_ProgressBarGroove, &opts, &painter,
this);
240 if ( opts.progress > 0 )
241 style()->drawControl(QStyle::CE_ProgressBarContents, &opts, &painter,
this);
253 const QBrush & color = palette().foreground();
254 painter.setBrush( color );
264 QPointF( offset - tri+1,
margin() ),
265 QPointF( offset,
margin() + tri-1 ),
266 QPointF( offset + tri-1,
margin() )
269 painter.drawConvexPolygon( points, 3 );
277 QPointF( offset, pointOffset ),
278 QPointF( offset + tri-1, pointOffset + tri-1 ),
279 QPointF( offset - tri+1, pointOffset + tri-1 )
282 painter.drawConvexPolygon( points2, 3 );
289 thickness += 2 *
margin();
308 _triThickness = value;
310 if ( _triThickness < 1 )
317 QWidget::setEnabled( enabled );
319 YWidget::setEnabled( enabled );
337 resize( newWidth, newHeight );
342 #include "YQMultiProgressMeter.moc"
int margin() const
Returns the margin around the widget contents.
int triSpacing() const
Returns the spacing between the segment indicators and the small triangles next to the spacing betwee...
void setTriThickness(int value)
Set the thickness (base to point) of the small triangles next to the spacing between individual segme...
void setTriSpacing(int value)
Sets the spacing between the segment indicators and the small triangles next to the spacing between s...
int segmentMinLength() const
Returns the minimal length of a segment in pixels.
void init()
Common initialization.
int spacing() const
Returns the spacing between segments in pixels.
virtual int preferredHeight()
Preferred height of the widget.
YQMultiProgressMeter(YWidget *parent, YUIDimension dim, const vector< float > &maxValues)
Constructor.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void doUpdate()
Perform a visual update on the screen.
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...
virtual ~YQMultiProgressMeter()
Destructor.
int thickness()
Overall thickness (in pixels) of the MultiProgressMeter.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual int preferredWidth()
Preferred width of the widget.
virtual void paintEvent(QPaintEvent *)
Paint the widget's contents.
int length()
Overall length (in pixels) of the MultiProgressMeter.
void drawMarkers(QPainter &painter, int offset, int thickness)
Draw markers between segments (or beside that spacing).
int triThickness() const
Returns the thickness (base to point) of the small triangles next to the spacing between individual s...