aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickscrollindicator.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-11-24 14:42:09 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-11-24 15:10:19 +0000
commit9c038a71c383a7fb01a9ef4bc847b34807cec31f (patch)
treee08c88bab529181b5c8af4555a970e921e55dea0 /src/templates/qquickscrollindicator.cpp
parenta7245a57ee782ab9b68dffc7278ca9d1dce6f0a1 (diff)
Fix ScrollIndicator layouting
QQuickScrollIndicator was relying on itemGeometryChanged() for the attached flickable. If the flickable geometry didn't change _after_ scroll indicator was attached, the indicator was not positioned and resized as appropriate. Change-Id: Ib5b4816b4ba96ad73873722045ac4e3b7e47038d Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickscrollindicator.cpp')
-rw-r--r--src/templates/qquickscrollindicator.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/templates/qquickscrollindicator.cpp b/src/templates/qquickscrollindicator.cpp
index 81a96ac5..94b47e4d 100644
--- a/src/templates/qquickscrollindicator.cpp
+++ b/src/templates/qquickscrollindicator.cpp
@@ -228,6 +228,9 @@ public:
void activateHorizontal();
void activateVertical();
+ void layoutHorizontal(bool move = true);
+ void layoutVertical(bool move = true);
+
void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
QQuickFlickable *flickable;
@@ -245,27 +248,34 @@ void QQuickScrollIndicatorAttachedPrivate::activateVertical()
vertical->setActive(flickable->isMovingVertically());
}
+void QQuickScrollIndicatorAttachedPrivate::layoutHorizontal(bool move)
+{
+ Q_ASSERT(horizontal && flickable);
+ horizontal->setWidth(flickable->width());
+ if (move)
+ horizontal->setY(flickable->height() - horizontal->height());
+}
+
+void QQuickScrollIndicatorAttachedPrivate::layoutVertical(bool move)
+{
+ Q_ASSERT(vertical && flickable);
+ vertical->setHeight(flickable->height());
+ if (move && !QQuickItemPrivate::get(vertical)->isMirrored())
+ vertical->setX(flickable->width() - vertical->width());
+}
+
void QQuickScrollIndicatorAttachedPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_UNUSED(item);
+ Q_UNUSED(newGeometry);
Q_ASSERT(item == flickable);
if (horizontal) {
- QQuickItemPrivate *p = QQuickItemPrivate::get(horizontal);
- if (!p->widthValid) {
- horizontal->setWidth(newGeometry.width());
- p->widthValid = false;
- }
- if (qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), oldGeometry.height() - horizontal->height()))
- horizontal->setY(newGeometry.height() - horizontal->height());
+ bool move = qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), oldGeometry.height() - horizontal->height());
+ layoutHorizontal(move);
}
if (vertical) {
- QQuickItemPrivate *p = QQuickItemPrivate::get(vertical);
- if (!p->heightValid) {
- vertical->setHeight(newGeometry.height());
- p->heightValid = false;
- }
- if (!p->isMirrored() && (qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), oldGeometry.width() - vertical->width())))
- vertical->setX(newGeometry.width() - vertical->width());
+ bool move = qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), oldGeometry.width() - vertical->width());
+ layoutVertical(move);
}
}
@@ -322,6 +332,7 @@ void QQuickScrollIndicatorAttached::setHorizontal(QQuickScrollIndicator *horizon
connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal)));
connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal)));
+ d->layoutHorizontal();
horizontal->setSize(area->property("widthRatio").toReal());
horizontal->setPosition(area->property("xPosition").toReal());
}
@@ -374,6 +385,7 @@ void QQuickScrollIndicatorAttached::setVertical(QQuickScrollIndicator *vertical)
connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal)));
connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal)));
+ d->layoutVertical();
vertical->setSize(area->property("heightRatio").toReal());
vertical->setPosition(area->property("yPosition").toReal());
}