fix: rounded-off errors

svn path=/trunk/KDE/kdelibs/; revision=1030709
This commit is contained in:
Igor Trindade Oliveira 2009-10-03 03:27:52 +00:00
parent faa91ca8e5
commit cab81476e3
3 changed files with 20 additions and 20 deletions

View File

@ -113,7 +113,7 @@ void KineticScrolling::mousePressEvent(QGraphicsSceneMouseEvent *event)
void KineticScrolling::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void KineticScrolling::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
QPoint temp = event->lastPos().toPoint() - event->pos().toPoint(); QPointF temp = event->lastPos().toPoint() - event->pos().toPoint();
if (!temp.isNull()) { if (!temp.isNull()) {
d->kinMovement += temp; d->kinMovement += temp;
} }
@ -124,7 +124,7 @@ void KineticScrolling::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void KineticScrolling::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void KineticScrolling::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
duration(); duration();
QPoint temp = event->pos().toPoint() - event->lastPos().toPoint(); QPointF temp = event->pos().toPoint() - event->lastPos().toPoint();
if (!temp.isNull()) { if (!temp.isNull()) {
d->kinMovement += temp; d->kinMovement += temp;
/* Not so fast baby! */ /* Not so fast baby! */
@ -176,7 +176,7 @@ void KineticScrolling::startAnimationTimer(int interval)
void KineticScrolling::timerEvent(QTimerEvent *event) void KineticScrolling::timerEvent(QTimerEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
d->cposition.setY(d->parent->property("verticalScrollValue").toInt()); d->cposition.setY(d->parent->property("verticalScrollValue").toReal());
if (d->direction == KineticScrollingPrivate::None) { if (d->direction == KineticScrollingPrivate::None) {
if ((qAbs(d->kinMovement.y()) < 5.0)) { if ((qAbs(d->kinMovement.y()) < 5.0)) {
@ -212,8 +212,8 @@ void KineticScrolling::setKineticScrollValue(QPointF value)
return; return;
} }
int movement = (100 * value.y())/int(d->geo.height()); qreal movement = (100 * value.y())/int(d->geo.height());
int final; qreal final;
movement += d->cposition.y(); movement += d->cposition.y();
@ -222,7 +222,7 @@ void KineticScrolling::setKineticScrollValue(QPointF value)
} else if (movement < d->minimum) { } else if (movement < d->minimum) {
d->kinMovement.setY(d->overshoot); d->kinMovement.setY(d->overshoot);
} else { } else {
final = qBound(d->minimum, movement, d->maximum); final = qBound((qreal)d->minimum, movement, (qreal)d->maximum);
d->parent->setProperty("verticalScrollValue", final); d->parent->setProperty("verticalScrollValue", final);
} }
@ -232,8 +232,8 @@ void KineticScrolling::setKineticScrollValue(QPointF value)
void KineticScrolling::bounceTimer() void KineticScrolling::bounceTimer()
{ {
d->applyFriction(); d->applyFriction();
int movement = d->kinMovement.y(); qreal movement = d->kinMovement.y();
d->cposition.setY(d->parent->property("verticalScrollValue").toInt()); d->cposition.setY(d->parent->property("verticalScrollValue").toReal());
movement += d->cposition.y(); movement += d->cposition.y();
if ((d->direction == KineticScrollingPrivate::Down) && if ((d->direction == KineticScrollingPrivate::Down) &&

View File

@ -312,7 +312,7 @@ void ScrollWidget::ensureRectVisible(const QRectF &rect)
(d->widget->pos() + delta).toPoint()); (d->widget->pos() + delta).toPoint());
} }
int ScrollWidget::horizontalScrollValue() const qreal ScrollWidget::horizontalScrollValue() const
{ {
if (!d->widget) { if (!d->widget) {
return 0; return 0;
@ -321,7 +321,7 @@ int ScrollWidget::horizontalScrollValue() const
d->scrollingWidget->size().width()); d->scrollingWidget->size().width());
} }
void ScrollWidget::setHorizontalScrollValue(int value) void ScrollWidget::setHorizontalScrollValue(qreal value)
{ {
if (!d->widget) { if (!d->widget) {
return; return;
@ -332,7 +332,7 @@ void ScrollWidget::setHorizontalScrollValue(int value)
d->widget->pos().y()); d->widget->pos().y());
} }
int ScrollWidget::verticalScrollValue() const qreal ScrollWidget::verticalScrollValue() const
{ {
if (!d->widget) { if (!d->widget) {
return 0; return 0;
@ -341,7 +341,7 @@ int ScrollWidget::verticalScrollValue() const
d->scrollingWidget->size().height()); d->scrollingWidget->size().height());
} }
void ScrollWidget::setVerticalScrollValue(int value) void ScrollWidget::setVerticalScrollValue(qreal value)
{ {
if (!d->widget) { if (!d->widget) {

View File

@ -45,8 +45,8 @@ class PLASMA_EXPORT ScrollWidget : public QGraphicsWidget
Q_PROPERTY(QGraphicsWidget *widget READ widget WRITE setWidget) Q_PROPERTY(QGraphicsWidget *widget READ widget WRITE setWidget)
Q_PROPERTY(Qt::ScrollBarPolicy horizontalScrollBarPolicy READ horizontalScrollBarPolicy WRITE setHorizontalScrollBarPolicy) Q_PROPERTY(Qt::ScrollBarPolicy horizontalScrollBarPolicy READ horizontalScrollBarPolicy WRITE setHorizontalScrollBarPolicy)
Q_PROPERTY(Qt::ScrollBarPolicy verticalScrollBarPolicy READ verticalScrollBarPolicy WRITE setVerticalScrollBarPolicy) Q_PROPERTY(Qt::ScrollBarPolicy verticalScrollBarPolicy READ verticalScrollBarPolicy WRITE setVerticalScrollBarPolicy)
Q_PROPERTY(int horizontalScrollValue READ horizontalScrollValue WRITE setHorizontalScrollValue) Q_PROPERTY(qreal horizontalScrollValue READ horizontalScrollValue WRITE setHorizontalScrollValue)
Q_PROPERTY(int verticalScrollValue READ verticalScrollValue WRITE setVerticalScrollValue) Q_PROPERTY(qreal verticalScrollValue READ verticalScrollValue WRITE setVerticalScrollValue)
Q_PROPERTY(QRectF viewport READ viewport) Q_PROPERTY(QRectF viewport READ viewport)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
@ -110,25 +110,25 @@ public:
* The horizontal scroll value, between 0 and 100 * The horizontal scroll value, between 0 and 100
* @since 4.4 * @since 4.4
*/ */
int horizontalScrollValue() const; qreal horizontalScrollValue() const;
/** /**
* Set the horizontal scroll value, between 0 and 100 * Set the horizontal scroll value, between 0 and 100
* @since 4.4 * @since 4.4
*/ */
void setHorizontalScrollValue(int value); void setHorizontalScrollValue(qreal value);
/** /**
* The horizontal scroll value, between 0 and 100 * The horizontal scroll value, between 0 and 100
* @since 4.4 * @since 4.4
*/ */
int verticalScrollValue() const; qreal verticalScrollValue() const;
/** /**
* Set the horizontal scroll value, between 0 and 100 * Set the horizontal scroll value, between 0 and 100
* @since 4.4 * @since 4.4
*/ */
void setVerticalScrollValue(int value); void setVerticalScrollValue(qreal value);
/** /**
* The scrollable widget size. * The scrollable widget size.