diff options
author | Liang Qi <liang.qi@qt.io> | 2018-09-26 15:39:35 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-10-12 14:26:15 +0000 |
commit | c593492d1678a2ec08f1bfffcb572459b3bc6c00 (patch) | |
tree | a9427b13e0f3aa252d68decc862de5acb4dc3b17 /src/widgets/itemviews | |
parent | 0509383cf2852f2aebd1efd75413835747c8f341 (diff) |
Modernize the "animation" feature
Change-Id: Ibc164b3df3cf87db569ef4813de458a9067b7f7d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qcolumnview.cpp | 16 | ||||
-rw-r--r-- | src/widgets/itemviews/qcolumnview_p.h | 4 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 28 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreeview.h | 4 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreeview_p.h | 6 |
5 files changed, 31 insertions, 27 deletions
diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp index 5100d2a427..1fe17721ba 100644 --- a/src/widgets/itemviews/qcolumnview.cpp +++ b/src/widgets/itemviews/qcolumnview.cpp @@ -103,12 +103,12 @@ void QColumnViewPrivate::initialize() { Q_Q(QColumnView); q->setTextElideMode(Qt::ElideMiddle); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) QObject::connect(¤tAnimation, SIGNAL(finished()), q, SLOT(_q_changeCurrentColumn())); currentAnimation.setTargetObject(hbar); currentAnimation.setPropertyName("value"); currentAnimation.setEasingCurve(QEasingCurve::InOutQuad); -#endif //QT_NO_ANIMATION +#endif // animation delete itemDelegate; q->setItemDelegate(new QColumnViewDelegate(q)); } @@ -258,12 +258,12 @@ void QColumnView::scrollTo(const QModelIndex &index, ScrollHint hint) if (!index.isValid() || d->columns.isEmpty()) return; -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (d->currentAnimation.state() == QPropertyAnimation::Running) return; d->currentAnimation.stop(); -#endif //QT_NO_ANIMATION +#endif // animation // Fill up what is needed to get to index d->closeColumns(index, true); @@ -326,13 +326,13 @@ void QColumnView::scrollTo(const QModelIndex &index, ScrollHint hint) } } -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (const int animationDuration = style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, this)) { d->currentAnimation.setDuration(animationDuration); d->currentAnimation.setEndValue(newScrollbarValue); d->currentAnimation.start(); } else -#endif //QT_NO_ANIMATION +#endif // animation { horizontalScrollBar()->setValue(newScrollbarValue); } @@ -402,10 +402,10 @@ void QColumnView::resizeEvent(QResizeEvent *event) void QColumnViewPrivate::updateScrollbars() { Q_Q(QColumnView); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (currentAnimation.state() == QPropertyAnimation::Running) return; -#endif //QT_NO_ANIMATION +#endif // animation // find the total horizontal length of the laid out columns int horizontalLength = 0; diff --git a/src/widgets/itemviews/qcolumnview_p.h b/src/widgets/itemviews/qcolumnview_p.h index 850ab02747..9f0d2a40dc 100644 --- a/src/widgets/itemviews/qcolumnview_p.h +++ b/src/widgets/itemviews/qcolumnview_p.h @@ -57,7 +57,9 @@ #include <private/qabstractitemview_p.h> #include <QtCore/qabstractitemmodel.h> +#if QT_CONFIG(animation) #include <QtCore/qpropertyanimation.h> +#endif #include <QtWidgets/qabstractitemdelegate.h> #include <QtWidgets/qabstractitemview.h> #include <QtWidgets/qitemdelegate.h> @@ -169,7 +171,7 @@ public: QVector<int> columnSizes; // used during init and corner moving bool showResizeGrips; int offset; -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) QPropertyAnimation currentAnimation; #endif QWidget *previewWidget; diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index fbfbe56246..7f99a2c6cb 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1334,12 +1334,12 @@ void QTreeView::paintEvent(QPaintEvent *event) Q_D(QTreeView); d->executePostedLayout(); QPainter painter(viewport()); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (d->isAnimating()) { drawTree(&painter, event->region() - d->animatedOperation.rect()); d->drawAnimatedOperation(&painter); } else -#endif //QT_NO_ANIMATION +#endif // animation { drawTree(&painter, event->region()); #if QT_CONFIG(draganddrop) @@ -3056,10 +3056,10 @@ void QTreeViewPrivate::initialize() header->setStretchLastSection(true); header->setDefaultAlignment(Qt::AlignLeft|Qt::AlignVCenter); q->setHeader(header); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, q) > 0; QObject::connect(&animatedOperation, SIGNAL(finished()), q, SLOT(_q_endAnimatedOperation())); -#endif //QT_NO_ANIMATION +#endif // animation } void QTreeViewPrivate::expand(int item, bool emitSignal) @@ -3072,10 +3072,10 @@ void QTreeViewPrivate::expand(int item, bool emitSignal) if (index.flags() & Qt::ItemNeverHasChildren) return; -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (emitSignal && animationsEnabled) prepareAnimatedOperation(item, QVariantAnimation::Forward); -#endif //QT_NO_ANIMATION +#endif // animation //if already animating, stateBeforeAnimation is set to the correct value if (state != QAbstractItemView::AnimatingState) stateBeforeAnimation = state; @@ -3089,10 +3089,10 @@ void QTreeViewPrivate::expand(int item, bool emitSignal) model->fetchMore(index); if (emitSignal) { emit q->expanded(index); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (animationsEnabled) beginAnimatedOperation(); -#endif //QT_NO_ANIMATION +#endif // animation } } @@ -3147,10 +3147,10 @@ void QTreeViewPrivate::collapse(int item, bool emitSignal) if (it == expandedIndexes.end() || viewItems.at(item).expanded == false) return; // nothing to do -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (emitSignal && animationsEnabled) prepareAnimatedOperation(item, QVariantAnimation::Backward); -#endif //QT_NO_ANIMATION +#endif // animation //if already animating, stateBeforeAnimation is set to the correct value if (state != QAbstractItemView::AnimatingState) @@ -3168,14 +3168,14 @@ void QTreeViewPrivate::collapse(int item, bool emitSignal) if (emitSignal) { emit q->collapsed(modelIndex); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) if (animationsEnabled) beginAnimatedOperation(); -#endif //QT_NO_ANIMATION +#endif // animation } } -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) void QTreeViewPrivate::prepareAnimatedOperation(int item, QVariantAnimation::Direction direction) { animatedOperation.item = item; @@ -3280,7 +3280,7 @@ void QTreeViewPrivate::_q_endAnimatedOperation() q->updateGeometries(); viewport->update(); } -#endif //QT_NO_ANIMATION +#endif // animation void QTreeViewPrivate::_q_modelAboutToBeReset() { diff --git a/src/widgets/itemviews/qtreeview.h b/src/widgets/itemviews/qtreeview.h index 09ce0e3fff..33dbf1c1ce 100644 --- a/src/widgets/itemviews/qtreeview.h +++ b/src/widgets/itemviews/qtreeview.h @@ -230,9 +230,9 @@ private: Q_DECLARE_PRIVATE(QTreeView) Q_DISABLE_COPY(QTreeView) -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) Q_PRIVATE_SLOT(d_func(), void _q_endAnimatedOperation()) -#endif //QT_NO_ANIMATION +#endif // animation Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset()) Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order)) }; diff --git a/src/widgets/itemviews/qtreeview_p.h b/src/widgets/itemviews/qtreeview_p.h index 9a391ee88a..061bd1fc57 100644 --- a/src/widgets/itemviews/qtreeview_p.h +++ b/src/widgets/itemviews/qtreeview_p.h @@ -53,7 +53,9 @@ #include <QtWidgets/private/qtwidgetsglobal_p.h> #include "private/qabstractitemview_p.h" +#if QT_CONFIG(animation) #include <QtCore/qvariantanimation.h> +#endif #include <QtCore/qabstractitemmodel.h> #include <QtCore/qvector.h> @@ -105,7 +107,7 @@ public: QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const override; void adjustViewOptionsForIndex(QStyleOptionViewItem *option, const QModelIndex ¤t) const override; -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) struct AnimatedOperation : public QVariantAnimation { int item; @@ -123,7 +125,7 @@ public: void drawAnimatedOperation(QPainter *painter) const; QPixmap renderTreeToPixmapForAnimation(const QRect &rect) const; void _q_endAnimatedOperation(); -#endif //QT_NO_ANIMATION +#endif // animation void expand(int item, bool emitSignal); void collapse(int item, bool emitSignal); |