[yast-commit] r46867 - in /trunk/qt: package/yast2-qt.changes src/YQMultiProgressMeter.cc src/YQMultiProgressMeter.h
Author: sh-sh-sh Date: Fri Apr 18 17:22:40 2008 New Revision: 46867 URL: http://svn.opensuse.org/viewcvs/yast?rev=46867&view=rev Log: Fixed bnc #374851: YQMultiProgressMeter integer overflow Modified: trunk/qt/package/yast2-qt.changes trunk/qt/src/YQMultiProgressMeter.cc trunk/qt/src/YQMultiProgressMeter.h Modified: trunk/qt/package/yast2-qt.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/package/yast2-qt.changes?rev=46867&r1=46866&r2=46867&view=diff ============================================================================== --- trunk/qt/package/yast2-qt.changes (original) +++ trunk/qt/package/yast2-qt.changes Fri Apr 18 17:22:40 2008 @@ -1,4 +1,9 @@ ------------------------------------------------------------------- +Fri Apr 18 17:21:53 CEST 2008 - sh@suse.de + +- Fixed bnc #374851: YQMultiProgressMeter integer overflow + +------------------------------------------------------------------- Thu Apr 17 10:47:49 CEST 2008 - coolo@suse.de - update the steps status (bnc#379539) Modified: trunk/qt/src/YQMultiProgressMeter.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQMultiProgressMeter.cc?rev=46867&r1=46866&r2=46867&view=diff ============================================================================== --- trunk/qt/src/YQMultiProgressMeter.cc (original) +++ trunk/qt/src/YQMultiProgressMeter.cc Fri Apr 18 17:22:40 2008 @@ -36,7 +36,6 @@ : QWidget( (QWidget *) parent->widgetRep() ) , YMultiProgressMeter( parent, dim, maxValues ) { - _triangularShaped = false; init(); setWidgetRep( this ); } @@ -53,24 +52,8 @@ _margin = 2; _segmentMinLength = 12; _triSpacing = 1; - - if ( triangularShaped() ) - { - _spacing = 0; - setTriThickness( -1 ); - } - else - { - _spacing = 2; - setTriThickness( 4 ); - } -} - - -void YQMultiProgressMeter::setTriangularShaped( bool triangular ) -{ - _triangularShaped = triangular; - init(); + _spacing = 2; + setTriThickness( 4 ); } @@ -149,7 +132,7 @@ // Small segments that get at least minLength pixels consume more screen - // space than initially planned, so recompute what is left for the others + // space than initially planned, so recompute what is left for the others. int distributableLength = totalLength - smallSegmentsCount * minLength; @@ -163,10 +146,7 @@ // space disproportional to their real size (maxValue). scale = ( (float) distributableLength ) / ( restSum ); - - // Calculate indentation - - int indent = triangularShaped() ? (int) ( thickness * 0.37 ) : 0; + int indent = 0; // Set up painter @@ -189,7 +169,7 @@ else length = (int) ( maxValue( i ) * scale + 0.5 ); - drawSegment( i, painter, offset, length, thickness, indent ); + drawSegment( i, painter, offset, length, thickness ); if ( i > 0 ) drawMarkers( painter, offset, thickness ); @@ -199,28 +179,11 @@ } -void YQMultiProgressMeter::mouseDoubleClickEvent ( QMouseEvent * event ) -{ - if ( event && event->button() == Qt::RightButton ) - { - // Easter egg: Switch between rectangular and triangular shape - - yuiMilestone() << "Switching shape" << endl; - setTriangularShaped( ! triangularShaped() ); - setSize( vertical() ? preferredWidth() : width(), - horizontal() ? preferredHeight() : height() ); - findDialog()->recalcLayout(); - QWidget::update(); - } -} - - void YQMultiProgressMeter::drawSegment( int segment, QPainter & painter, int offset, int length, - int thickness, - int indent ) + int thickness ) { // // Fill segment @@ -241,13 +204,18 @@ return; } + // Use 0..1000 range to avoid overflow with huge numbers (Gigabytes). + const int scaledMax = 1000; + int scaledProgress = + (int) ( 0.5 + ( currentValue( segment ) / maxValue( segment ) ) * ( (float) scaledMax ) ); + if ( vertical() ) // fill thermometer-like from bottom to top { QStyleOptionProgressBarV2 opts; opts.initFrom(this); - opts.progress = (int) currentValue( segment); + opts.progress = scaledMax - scaledProgress; opts.minimum = 0; - opts.maximum = (int) maxValue( segment); + opts.maximum = scaledMax; opts.invertedAppearance = true; opts.rect = QRect( offset, border, length, thickness ); style()->drawControl(QStyle::CE_ProgressBarGroove, &opts, &painter, this); @@ -259,9 +227,9 @@ { QStyleOptionProgressBarV2 opts; opts.initFrom(this); - opts.progress = (int) ( maxValue( segment) - currentValue( segment) ); + opts.progress = scaledProgress; opts.minimum = 0; - opts.maximum = (int) maxValue( segment); + opts.maximum = scaledMax; opts.rect = QRect( offset, border, length, thickness ); style()->drawControl(QStyle::CE_ProgressBarGroove, &opts, &painter, this); @@ -288,10 +256,11 @@ int tri = triThickness(); QPointF points[3] = - { QPointF( offset - tri+1, margin() ), // top left (base) - QPointF( offset, margin() + tri-1 ), // lower center (point) - QPointF( offset + tri-1, margin() ) // top right (base) - }; + { + QPointF( offset - tri+1, margin() ), // top left (base) + QPointF( offset, margin() + tri-1 ), // lower center (point) + QPointF( offset + tri-1, margin() ) // top right (base) + }; painter.drawConvexPolygon( points, 3 ); @@ -300,10 +269,11 @@ int pointOffset = margin() + tri + thickness + 2 * triSpacing(); QPointF points2[3] = - { QPointF( offset, pointOffset ), // top center (point) - QPointF( offset + tri-1, pointOffset + tri-1 ), // top right (base) - QPointF( offset - tri+1, pointOffset + tri-1 ) // bottom left (base) - }; + { + QPointF( offset, pointOffset ), // top center (point) + QPointF( offset + tri-1, pointOffset + tri-1 ), // top right (base) + QPointF( offset - tri+1, pointOffset + tri-1 ) // bottom left (base) + }; painter.drawConvexPolygon( points2, 3 ); } @@ -311,7 +281,7 @@ int YQMultiProgressMeter::thickness() { - int thickness = triangularShaped() ? 35 : 23; + int thickness = 23; thickness += 2 * margin(); if ( triThickness() > 0 ) Modified: trunk/qt/src/YQMultiProgressMeter.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQMultiProgressMeter.h?rev=46867&r1=46866&r2=46867&view=diff ============================================================================== --- trunk/qt/src/YQMultiProgressMeter.h (original) +++ trunk/qt/src/YQMultiProgressMeter.h Fri Apr 18 17:22:40 2008 @@ -125,17 +125,6 @@ void setTriSpacing( int value ) { _triSpacing = value; } /** - * Returns "true" if the segments of this widget are triangular shaped. - **/ - bool triangularShaped() const { return _triangularShaped; } - - /** - * Set triangular shape (true) or normal rectangular shape. - * This call does not trigger a screen update. - **/ - void setTriangularShaped( bool triangular = true ); - - /** * Set enabled/disabled state. * * Reimplemented from YWidget. @@ -184,13 +173,6 @@ virtual void paintEvent ( QPaintEvent * ); /** - * Mouse double click - - * - * reimplemented from QWidget. - **/ - virtual void mouseDoubleClickEvent ( QMouseEvent * e ); - - /** * Draw segment number 'segment' with pixel length 'length' from pixel * coordinate 'offset' on and fill it according to that segment's current * value. 'painter' is set up previously to take rotating into account @@ -200,8 +182,7 @@ QPainter & painter, int offset, int length, - int thickness, - int indent ); + int thickness ); /** * Draw markers between segments (or beside that spacing). @@ -211,7 +192,6 @@ private: - bool _triangularShaped; int _margin; int _spacing; int _segmentMinLength; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org