diff options
Diffstat (limited to 'src/corelib/doc/snippets')
5 files changed, 124 insertions, 84 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qparallelanimationgroup.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qparallelanimationgroup.cpp index 6328cb00119..db3a9ee2dc0 100644 --- a/src/corelib/doc/snippets/code/src_corelib_animation_qparallelanimationgroup.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_animation_qparallelanimationgroup.cpp @@ -1,10 +1,15 @@ // Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//! [0] - QParallelAnimationGroup *group = new QParallelAnimationGroup; - group->addAnimation(anim1); - group->addAnimation(anim2); +#include <QParallelAnimationGroup> - group->start(); -//! [0] +void example(QAbstractAnimation *anim1, QAbstractAnimation *anim2) +{ + //! [0] + QParallelAnimationGroup *group = new QParallelAnimationGroup; + group->addAnimation(anim1); + group->addAnimation(anim2); + + group->start(); + //! [0] +} diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp index 4b77ab607db..7f259e99fb8 100644 --- a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp @@ -1,28 +1,102 @@ // Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QParallelAnimationGroup> +#include <QSequentialAnimationGroup> -//! [0] +//! [includes] #include <QApplication> #include <QPushButton> #include <QPropertyAnimation> +//![includes] + +//! [class_decl] class MyButtonWidget : public QWidget { public: MyButtonWidget(QWidget *parent = nullptr); }; +//! [class_decl] + +//! [ctor_impl] MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent) { - QPushButton *button = new QPushButton(tr("Animated Button"), this); - QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this); - anim->setDuration(10000); - anim->setStartValue(QPoint(0, 0)); - anim->setEndValue(QPoint(100, 250)); - anim->start(); +//![ctor_impl] + { + //! [first_example] + QPushButton *button = new QPushButton(tr("Animated Button"), this); + QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this); + anim->setDuration(10000); + anim->setStartValue(QPoint(0, 0)); + anim->setEndValue(QPoint(100, 250)); + anim->start(); + //! [first_example] + } + + { + //! [easing-curve] + QPushButton *button = new QPushButton(tr("Animated Button"), this); + QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this); + anim->setDuration(10000); + anim->setStartValue(QPoint(0, 0)); + anim->setEndValue(QPoint(100, 250)); + anim->setEasingCurve(QEasingCurve::OutBounce); + anim->start(); + //! [easing-curve] + } + + { + //! [animation-group1] + QPushButton *bonnie = new QPushButton(tr("Bonnie"), this); + QPushButton *clyde = new QPushButton(tr("Clyde"), this); + + QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this); + anim1->setDuration(3000); + anim1->setStartValue(QPoint(0, 0)); + anim1->setEndValue(QPoint(100, 250)); + + QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this); + anim2->setDuration(3000); + anim2->setStartValue(QPoint(100, 250)); + anim2->setEndValue(QPoint(500, 500)); + + QParallelAnimationGroup *parallelAnim = new QParallelAnimationGroup; + parallelAnim->addAnimation(anim1); + parallelAnim->addAnimation(anim2); + parallelAnim->start(); + //! [animation-group1] + } + + { + //! [animation-group2] + QPushButton *bonnie = new QPushButton(tr("Bonnie"), this); + QPushButton *clyde = new QPushButton(tr("Clyde"), this); + + QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this); + anim1->setDuration(3000); + anim1->setStartValue(QPoint(0, 0)); + anim1->setEndValue(QPoint(100, 250)); + + QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this); + anim2->setDuration(3000); + anim2->setStartValue(QPoint(0, 0)); + anim2->setEndValue(QPoint(200, 250)); + + QSequentialAnimationGroup *sequenceAnim = new QSequentialAnimationGroup; + sequenceAnim->addAnimation(anim1); + sequenceAnim->addAnimation(anim2); + sequenceAnim->start(); + //! [animation-group2] + } + +//! [ctor_close] } +//! [ctor_close] + +//! [main] int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -31,65 +105,4 @@ int main(int argc, char *argv[]) buttonAnimWidget.show(); return a.exec(); } -//! [0] - - -//! [easing-curve] -MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent) -{ - QPushButton *button = new QPushButton(tr("Animated Button"), this); - QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this); - anim->setDuration(10000); - anim->setStartValue(QPoint(0, 0)); - anim->setEndValue(QPoint(100, 250)); - anim->setEasingCurve(QEasingCurve::OutBounce); - anim->start(); -} -//! [easing-curve] - - -//! [animation-group1] -MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent) -{ - QPushButton *bonnie = new QPushButton(tr("Bonnie"), this); - QPushButton *clyde = new QPushButton(tr("Clyde"), this); - - QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this); - anim1->setDuration(3000); - anim1->setStartValue(QPoint(0, 0)); - anim1->setEndValue(QPoint(100, 250)); - - QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this); - anim2->setDuration(3000); - anim2->setStartValue(QPoint(100, 250)); - anim2->setEndValue(QPoint(500, 500)); - - QParallelAnimationGroup *parallelAnim = new QParallelAnimationGroup; - parallelAnim->addAnimation(anim1); - parallelAnim->addAnimation(anim2); - parallelAnim->start(); -} -//! [animation-group1] - -//! [animation-group2] -MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent) -{ - QPushButton *bonnie = new QPushButton(tr("Bonnie"), this); - QPushButton *clyde = new QPushButton(tr("Clyde"), this); - - QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this); - anim1->setDuration(3000); - anim1->setStartValue(QPoint(0, 0)); - anim1->setEndValue(QPoint(100, 250)); - - QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this); - anim2->setDuration(3000); - anim2->setStartValue(QPoint(0, 0)); - anim2->setEndValue(QPoint(200, 250)); - - QSequentialAnimationGroup *sequenceAnim = new QSequentialAnimationGroup; - sequenceAnim->addAnimation(anim1); - sequenceAnim->addAnimation(anim2); - sequenceAnim->start(); -} -//! [animation-group2] +//! [main] diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp index a429fe20b2d..c00a723a26c 100644 --- a/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp @@ -1,6 +1,10 @@ // Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QSequentialAnimationGroup> + +void example(QAbstractAnimation *anim1, QAbstractAnimation *anim2) +{ //! [0] QSequentialAnimationGroup *group = new QSequentialAnimationGroup; @@ -9,3 +13,4 @@ group->start(); //! [0] +} diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp index be7f549f655..be7e51e1b44 100644 --- a/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp @@ -1,14 +1,22 @@ // Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QVariantAnimation> +#include <QColor> + //! [0] - QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress) - { - ... - return QColor(...); - } - ... +QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress) +{ + // ... + return QColor(/*...*/); +} +// ... +void someFunc() +{ + // ... qRegisterAnimationInterpolator<QColor>(myColorInterpolator); + // ... +} //! [0] //! [1] diff --git a/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp b/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp index 4cba70e62d4..56a0532ac21 100644 --- a/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp @@ -1,6 +1,10 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#include <QThreadPool> +#include <QRunnable> +#include <QDebug> + //! [0] class HelloWorldTask : public QRunnable { @@ -10,7 +14,12 @@ class HelloWorldTask : public QRunnable } }; -HelloWorldTask *hello = new HelloWorldTask(); -// QThreadPool takes ownership and deletes 'hello' automatically -QThreadPool::globalInstance()->start(hello); +int main() +{ + //... + HelloWorldTask *hello = new HelloWorldTask(); + // QThreadPool takes ownership and deletes 'hello' automatically + QThreadPool::globalInstance()->start(hello); + //... +} //! [0] |
