diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-20 07:10:34 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-21 16:20:08 +0000 |
commit | 737bdea1e3dc41b5b30bb26c36224e31966ebd54 (patch) | |
tree | f1a2d013db2b7aa21c251553baae29f89712c861 /src/templates/qquickscrollbar.cpp | |
parent | 1cec731d40f6ed8a7755c9e3c0d100afbe099ed8 (diff) |
ScrollBar: use contentItem instead of handle
Thanks to virtual resizeContent() we can finally use contentItem like
everywhere else, and cleanup the special handle item.
Change-Id: I9e52ec3ff327d19cda3d85d2e2d9b73d80442bbc
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickscrollbar.cpp')
-rw-r--r-- | src/templates/qquickscrollbar.cpp | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/src/templates/qquickscrollbar.cpp b/src/templates/qquickscrollbar.cpp index 60e68e3b..e457e510 100644 --- a/src/templates/qquickscrollbar.cpp +++ b/src/templates/qquickscrollbar.cpp @@ -85,7 +85,7 @@ class QQuickScrollBarPrivate : public QQuickControlPrivate public: QQuickScrollBarPrivate() : size(0), position(0), offset(0), active(false), pressed(false), moving(false), - orientation(Qt::Vertical), handle(nullptr) + orientation(Qt::Vertical) { } @@ -96,6 +96,8 @@ public: qreal positionAt(const QPoint &point) const; + void resizeContent() override; + qreal size; qreal position; qreal offset; @@ -103,7 +105,6 @@ public: bool pressed; bool moving; Qt::Orientation orientation; - QQuickItem *handle; }; qreal QQuickScrollBarPrivate::positionAt(const QPoint &point) const @@ -115,6 +116,21 @@ qreal QQuickScrollBarPrivate::positionAt(const QPoint &point) const return point.y() / q->height(); } +void QQuickScrollBarPrivate::resizeContent() +{ + Q_Q(QQuickScrollBar); + if (!contentItem) + return; + + if (orientation == Qt::Horizontal) { + contentItem->setPosition(QPointF(q->leftPadding() + position * q->availableWidth(), q->topPadding())); + contentItem->setSize(QSizeF(q->availableWidth() * size, q->availableHeight())); + } else { + contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding() + position * q->availableHeight())); + contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight() * size)); + } +} + QQuickScrollBar::QQuickScrollBar(QQuickItem *parent) : QQuickControl(*(new QQuickScrollBarPrivate), parent) { @@ -152,6 +168,8 @@ void QQuickScrollBar::setSize(qreal size) return; d->size = size; + if (isComponentComplete()) + d->resizeContent(); emit sizeChanged(); } @@ -175,6 +193,8 @@ void QQuickScrollBar::setPosition(qreal position) return; d->position = position; + if (isComponentComplete()) + d->resizeContent(); emit positionChanged(); } @@ -245,35 +265,11 @@ void QQuickScrollBar::setOrientation(Qt::Orientation orientation) return; d->orientation = orientation; + if (isComponentComplete()) + d->resizeContent(); emit orientationChanged(); } -/*! - \qmlproperty Item Qt.labs.controls::ScrollBar::handle - - This property holds the handle item. - - \sa {Customizing ScrollBar} -*/ -QQuickItem *QQuickScrollBar::handle() const -{ - Q_D(const QQuickScrollBar); - return d->handle; -} - -void QQuickScrollBar::setHandle(QQuickItem *handle) -{ - Q_D(QQuickScrollBar); - if (d->handle == handle) - return; - - delete d->handle; - d->handle = handle; - if (handle && !handle->parentItem()) - handle->setParentItem(this); - emit handleChanged(); -} - void QQuickScrollBar::mousePressEvent(QMouseEvent *event) { Q_D(QQuickScrollBar); |