diff options
Diffstat (limited to 'src/templates/qquickscrollindicator.cpp')
-rw-r--r-- | src/templates/qquickscrollindicator.cpp | 185 |
1 files changed, 96 insertions, 89 deletions
diff --git a/src/templates/qquickscrollindicator.cpp b/src/templates/qquickscrollindicator.cpp index 4dc04141..2aba3c89 100644 --- a/src/templates/qquickscrollindicator.cpp +++ b/src/templates/qquickscrollindicator.cpp @@ -82,7 +82,7 @@ class QQuickScrollIndicatorPrivate : public QQuickControlPrivate { public: QQuickScrollIndicatorPrivate() : size(0), position(0), - active(false), orientation(Qt::Vertical), indicator(Q_NULLPTR) + active(false), orientation(Qt::Vertical), indicator(nullptr) { } @@ -105,7 +105,7 @@ QQuickScrollIndicatorAttached *QQuickScrollIndicator::qmlAttachedProperties(QObj return new QQuickScrollIndicatorAttached(flickable); qWarning() << "ScrollIndicator must be attached to a Flickable" << object; - return Q_NULLPTR; + return nullptr; } /*! @@ -124,10 +124,11 @@ qreal QQuickScrollIndicator::size() const void QQuickScrollIndicator::setSize(qreal size) { Q_D(QQuickScrollIndicator); - if (!qFuzzyCompare(d->size, size)) { - d->size = size; - emit sizeChanged(); - } + if (qFuzzyCompare(d->size, size)) + return; + + d->size = size; + emit sizeChanged(); } /*! @@ -146,10 +147,11 @@ qreal QQuickScrollIndicator::position() const void QQuickScrollIndicator::setPosition(qreal position) { Q_D(QQuickScrollIndicator); - if (!qFuzzyCompare(d->position, position)) { - d->position = position; - emit positionChanged(); - } + if (qFuzzyCompare(d->position, position)) + return; + + d->position = position; + emit positionChanged(); } /*! @@ -167,10 +169,11 @@ bool QQuickScrollIndicator::isActive() const void QQuickScrollIndicator::setActive(bool active) { Q_D(QQuickScrollIndicator); - if (d->active != active) { - d->active = active; - emit activeChanged(); - } + if (d->active == active) + return; + + d->active = active; + emit activeChanged(); } /*! @@ -191,10 +194,11 @@ Qt::Orientation QQuickScrollIndicator::orientation() const void QQuickScrollIndicator::setOrientation(Qt::Orientation orientation) { Q_D(QQuickScrollIndicator); - if (d->orientation != orientation) { - d->orientation = orientation; - emit orientationChanged(); - } + if (d->orientation == orientation) + return; + + d->orientation = orientation; + emit orientationChanged(); } /*! @@ -213,19 +217,20 @@ QQuickItem *QQuickScrollIndicator::indicator() const void QQuickScrollIndicator::setIndicator(QQuickItem *indicator) { Q_D(QQuickScrollIndicator); - if (d->indicator != indicator) { - delete d->indicator; - d->indicator = indicator; - if (indicator && !indicator->parentItem()) - indicator->setParentItem(this); - emit indicatorChanged(); - } + if (d->indicator == indicator) + return; + + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); } class QQuickScrollIndicatorAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener { public: - QQuickScrollIndicatorAttachedPrivate(QQuickFlickable *flickable) : flickable(flickable), horizontal(Q_NULLPTR), vertical(Q_NULLPTR) { } + QQuickScrollIndicatorAttachedPrivate(QQuickFlickable *flickable) : flickable(flickable), horizontal(nullptr), vertical(nullptr) { } void activateHorizontal(); void activateVertical(); @@ -233,7 +238,7 @@ public: void layoutHorizontal(bool move = true); void layoutVertical(bool move = true); - void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) override; QQuickFlickable *flickable; QQuickScrollIndicator *horizontal; @@ -318,38 +323,39 @@ QQuickScrollIndicator *QQuickScrollIndicatorAttached::horizontal() const void QQuickScrollIndicatorAttached::setHorizontal(QQuickScrollIndicator *horizontal) { Q_D(QQuickScrollIndicatorAttached); - if (d->horizontal != horizontal) { - if (d->horizontal) { - QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); - disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); - } - - d->horizontal = horizontal; - - if (horizontal) { - if (!horizontal->parentItem()) - horizontal->setParentItem(d->flickable); - horizontal->setOrientation(Qt::Horizontal); - - QQuickItemPrivate::get(horizontal)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); - QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - 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()); - } - emit horizontalChanged(); + if (d->horizontal == horizontal) + return; + + if (d->horizontal) { + QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); } + + d->horizontal = horizontal; + + if (horizontal) { + if (!horizontal->parentItem()) + horizontal->setParentItem(d->flickable); + horizontal->setOrientation(Qt::Horizontal); + + QQuickItemPrivate::get(horizontal)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + 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()); + } + emit horizontalChanged(); } /*! @@ -373,38 +379,39 @@ QQuickScrollIndicator *QQuickScrollIndicatorAttached::vertical() const void QQuickScrollIndicatorAttached::setVertical(QQuickScrollIndicator *vertical) { Q_D(QQuickScrollIndicatorAttached); - if (d->vertical != vertical) { - if (d->vertical) { - QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); - disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); - } - - d->vertical = vertical; - - if (vertical) { - if (!vertical->parentItem()) - vertical->setParentItem(d->flickable); - vertical->setOrientation(Qt::Vertical); - - QQuickItemPrivate::get(vertical)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); - QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - 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()); - } - emit verticalChanged(); + if (d->vertical == vertical) + return; + + if (d->vertical) { + QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); + } + + d->vertical = vertical; + + if (vertical) { + if (!vertical->parentItem()) + vertical->setParentItem(d->flickable); + vertical->setOrientation(Qt::Vertical); + + QQuickItemPrivate::get(vertical)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + 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()); } + emit verticalChanged(); } #ifndef QT_NO_ACCESSIBILITY |