a new property: snapSize if one wants to always make the scroll end aligned to a certain grid (is a size, so snap can be different horizontal and vertical)

svn path=/trunk/KDE/kdelibs/; revision=1116100
This commit is contained in:
Marco Martin 2010-04-18 16:31:07 +00:00
parent ee661f4347
commit dfb46bb03e
2 changed files with 43 additions and 0 deletions

View File

@ -18,6 +18,9 @@
*/
#include "scrollwidget.h"
#include <cmath>
//Qt
#include <QGraphicsSceneResizeEvent>
#include <QGraphicsGridLayout>
@ -443,6 +446,20 @@ public:
QObject *obj = start->targetObject();
obj->setProperty(start->propertyName(), maxExtent);
}
} else if (group == fixupAnimation.groupX && snapSize.width() > 1 &&
q->contentsSize().width() > q->viewportGeometry().width()) {
int target = snapSize.width() * round(val/snapSize.width());
end->setStartValue(val);
end->setEndValue(target);
end->setDuration(FixupDuration);
end->start();
} else if (group == fixupAnimation.groupY && snapSize.height() > 1 &&
q->contentsSize().height() > q->viewportGeometry().height()) {
int target = snapSize.height() * round(val/snapSize.height());
end->setStartValue(val);
end->setEndValue(target);
end->setDuration(FixupDuration);
end->start();
}
}
void fixupX()
@ -954,6 +971,7 @@ public:
QPropertyAnimation *endY;
} fixupAnimation;
QPropertyAnimation *directMoveAnimation;
QSizeF snapSize;
bool stealEvent;
bool hasOvershoot;
@ -1134,6 +1152,16 @@ QPointF ScrollWidget::scrollPosition() const
return QPointF();
}
void ScrollWidget::setSnapSize(const QSizeF &size)
{
d->snapSize = size;
}
QSizeF ScrollWidget::snapSize() const
{
return d->snapSize;
}
void ScrollWidget::setStyleSheet(const QString &styleSheet)
{
d->styleSheet = styleSheet;

View File

@ -49,6 +49,7 @@ class PLASMA_EXPORT ScrollWidget : public QGraphicsWidget
Q_PROPERTY(QPointF scrollPosition READ scrollPosition WRITE setScrollPosition)
Q_PROPERTY(QSizeF contentsSize READ contentsSize)
Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry)
Q_PROPERTY(QSizeF snapSize READ snapSize WRITE setSnapSize)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
Q_PROPERTY(bool overShoot READ hasOverShoot WRITE setOverShoot)
@ -200,6 +201,20 @@ public:
*/
QPointF scrollPosition() const;
/**
* Set the nap size of the kinetic scrolling:
* the scrolling will always stop at multiples of that size.
*
* @arg the desired snap size
* @since 4.5
*/
void setSnapSize(const QSizeF &size);
/**
* @return the snap size of the kinetic scrolling
* @since 4.5
*/
QSizeF snapSize() const;
/**
* Sets the stylesheet used to control the visual display of this ScrollWidget