mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 16:25:27 +08:00
qt 6.5.1 original
This commit is contained in:
18
tests/benchmarks/gui/animation/qanimation/CMakeLists.txt
Normal file
18
tests/benchmarks/gui/animation/qanimation/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qanimation Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qanimation
|
||||
SOURCES
|
||||
dummyanimation.cpp dummyanimation.h
|
||||
dummyobject.cpp dummyobject.h
|
||||
main.cpp
|
||||
rectanimation.cpp rectanimation.h
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Test
|
||||
Qt::Widgets
|
||||
)
|
24
tests/benchmarks/gui/animation/qanimation/dummyanimation.cpp
Normal file
24
tests/benchmarks/gui/animation/qanimation/dummyanimation.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "dummyanimation.h"
|
||||
#include "dummyobject.h"
|
||||
|
||||
|
||||
DummyAnimation::DummyAnimation(DummyObject *d) : m_dummy(d)
|
||||
{
|
||||
}
|
||||
|
||||
void DummyAnimation::updateCurrentValue(const QVariant &value)
|
||||
{
|
||||
if (state() == Stopped)
|
||||
return;
|
||||
if (m_dummy)
|
||||
m_dummy->setRect(value.toRect());
|
||||
}
|
||||
|
||||
void DummyAnimation::updateState(State newstate, State oldstate)
|
||||
{
|
||||
Q_UNUSED(newstate);
|
||||
Q_UNUSED(oldstate);
|
||||
}
|
22
tests/benchmarks/gui/animation/qanimation/dummyanimation.h
Normal file
22
tests/benchmarks/gui/animation/qanimation/dummyanimation.h
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#ifndef _DUMMYANIMATION_H__
|
||||
|
||||
class DummyObject;
|
||||
|
||||
class DummyAnimation : public QVariantAnimation
|
||||
{
|
||||
public:
|
||||
DummyAnimation(DummyObject *d);
|
||||
|
||||
void updateCurrentValue(const QVariant &value) override;
|
||||
void updateState(State newstate, State oldstate) override;
|
||||
|
||||
private:
|
||||
DummyObject *m_dummy;
|
||||
};
|
||||
|
||||
#endif
|
28
tests/benchmarks/gui/animation/qanimation/dummyobject.cpp
Normal file
28
tests/benchmarks/gui/animation/qanimation/dummyobject.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "dummyobject.h"
|
||||
|
||||
DummyObject::DummyObject()
|
||||
{
|
||||
}
|
||||
|
||||
QRect DummyObject::rect() const
|
||||
{
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
void DummyObject::setRect(const QRect &r)
|
||||
{
|
||||
m_rect = r;
|
||||
}
|
||||
|
||||
float DummyObject::opacity() const
|
||||
{
|
||||
return m_opacity;
|
||||
}
|
||||
|
||||
void DummyObject::setOpacity(float o)
|
||||
{
|
||||
m_opacity = o;
|
||||
}
|
26
tests/benchmarks/gui/animation/qanimation/dummyobject.h
Normal file
26
tests/benchmarks/gui/animation/qanimation/dummyobject.h
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#ifndef _DUMMYOBJECT_H__
|
||||
|
||||
class DummyObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRect rect READ rect WRITE setRect)
|
||||
Q_PROPERTY(float opacity READ opacity WRITE setOpacity)
|
||||
public:
|
||||
DummyObject();
|
||||
QRect rect() const;
|
||||
void setRect(const QRect &r);
|
||||
float opacity() const;
|
||||
void setOpacity(float);
|
||||
|
||||
private:
|
||||
QRect m_rect;
|
||||
float m_opacity;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
153
tests/benchmarks/gui/animation/qanimation/main.cpp
Normal file
153
tests/benchmarks/gui/animation/qanimation/main.cpp
Normal file
@ -0,0 +1,153 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <qtest.h>
|
||||
|
||||
#include "dummyobject.h"
|
||||
#include "dummyanimation.h"
|
||||
#include "rectanimation.h"
|
||||
|
||||
#define ITERATION_COUNT 10e3
|
||||
|
||||
class tst_qanimation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void itemPropertyAnimation();
|
||||
void itemPropertyAnimation_data() { data();}
|
||||
void dummyAnimation();
|
||||
void dummyAnimation_data() { data();}
|
||||
void dummyPropertyAnimation();
|
||||
void dummyPropertyAnimation_data() { data();}
|
||||
void rectAnimation();
|
||||
void rectAnimation_data() { data();}
|
||||
|
||||
void floatAnimation_data() { data(); }
|
||||
void floatAnimation();
|
||||
|
||||
private:
|
||||
void data();
|
||||
};
|
||||
|
||||
|
||||
void tst_qanimation::data()
|
||||
{
|
||||
QTest::addColumn<bool>("started");
|
||||
QTest::newRow("NotRunning") << false;
|
||||
QTest::newRow("Running") << true;
|
||||
}
|
||||
|
||||
void tst_qanimation::itemPropertyAnimation()
|
||||
{
|
||||
QFETCH(bool, started);
|
||||
QGraphicsWidget item;
|
||||
|
||||
//then the property animation
|
||||
{
|
||||
QPropertyAnimation anim(&item, "pos");
|
||||
anim.setDuration(ITERATION_COUNT);
|
||||
anim.setStartValue(QPointF(0,0));
|
||||
anim.setEndValue(QPointF(ITERATION_COUNT,ITERATION_COUNT));
|
||||
if (started)
|
||||
anim.start();
|
||||
QBENCHMARK {
|
||||
for(int i = 0; i < ITERATION_COUNT; ++i) {
|
||||
anim.setCurrentTime(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void tst_qanimation::dummyAnimation()
|
||||
{
|
||||
QFETCH(bool, started);
|
||||
DummyObject dummy;
|
||||
|
||||
//first the dummy animation
|
||||
{
|
||||
DummyAnimation anim(&dummy);
|
||||
anim.setDuration(ITERATION_COUNT);
|
||||
anim.setStartValue(QRect(0, 0, 0, 0));
|
||||
anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
|
||||
if (started)
|
||||
anim.start();
|
||||
QBENCHMARK {
|
||||
for(int i = 0; i < anim.duration(); ++i) {
|
||||
anim.setCurrentTime(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qanimation::dummyPropertyAnimation()
|
||||
{
|
||||
QFETCH(bool, started);
|
||||
DummyObject dummy;
|
||||
|
||||
//then the property animation
|
||||
{
|
||||
QPropertyAnimation anim(&dummy, "rect");
|
||||
anim.setDuration(ITERATION_COUNT);
|
||||
anim.setStartValue(QRect(0, 0, 0, 0));
|
||||
anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
|
||||
if (started)
|
||||
anim.start();
|
||||
QBENCHMARK {
|
||||
for(int i = 0; i < ITERATION_COUNT; ++i) {
|
||||
anim.setCurrentTime(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qanimation::rectAnimation()
|
||||
{
|
||||
//this is the simplest animation you can do
|
||||
QFETCH(bool, started);
|
||||
DummyObject dummy;
|
||||
|
||||
//then the property animation
|
||||
{
|
||||
RectAnimation anim(&dummy);
|
||||
anim.setDuration(ITERATION_COUNT);
|
||||
anim.setStartValue(QRect(0, 0, 0, 0));
|
||||
anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
|
||||
if (started)
|
||||
anim.start();
|
||||
QBENCHMARK {
|
||||
for(int i = 0; i < ITERATION_COUNT; ++i) {
|
||||
anim.setCurrentTime(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qanimation::floatAnimation()
|
||||
{
|
||||
//this is the simplest animation you can do
|
||||
QFETCH(bool, started);
|
||||
DummyObject dummy;
|
||||
|
||||
//then the property animation
|
||||
{
|
||||
QPropertyAnimation anim(&dummy, "opacity");
|
||||
anim.setDuration(ITERATION_COUNT);
|
||||
anim.setStartValue(0.f);
|
||||
anim.setEndValue(1.f);
|
||||
if (started)
|
||||
anim.start();
|
||||
QBENCHMARK {
|
||||
for(int i = 0; i < ITERATION_COUNT; ++i) {
|
||||
anim.setCurrentTime(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
QTEST_MAIN(tst_qanimation)
|
||||
|
||||
#include "main.moc"
|
56
tests/benchmarks/gui/animation/qanimation/rectanimation.cpp
Normal file
56
tests/benchmarks/gui/animation/qanimation/rectanimation.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "rectanimation.h"
|
||||
#include "dummyobject.h"
|
||||
|
||||
static inline int interpolateInteger(int from, int to, qreal progress)
|
||||
{
|
||||
return from + (to - from) * progress;
|
||||
}
|
||||
|
||||
|
||||
RectAnimation::RectAnimation(DummyObject *obj) : m_object(obj), m_dura(250)
|
||||
{
|
||||
}
|
||||
|
||||
void RectAnimation::setEndValue(const QRect &rect)
|
||||
{
|
||||
m_end = rect;
|
||||
}
|
||||
|
||||
void RectAnimation::setStartValue(const QRect &rect)
|
||||
{
|
||||
m_start = rect;
|
||||
}
|
||||
|
||||
void RectAnimation::setDuration(int d)
|
||||
{
|
||||
m_dura = d;
|
||||
}
|
||||
|
||||
int RectAnimation::duration() const
|
||||
{
|
||||
return m_dura;
|
||||
}
|
||||
|
||||
|
||||
void RectAnimation::updateCurrentTime(int currentTime)
|
||||
{
|
||||
qreal progress = m_easing.valueForProgress( currentTime / qreal(m_dura) );
|
||||
QRect now;
|
||||
now.setCoords(interpolateInteger(m_start.left(), m_end.left(), progress),
|
||||
interpolateInteger(m_start.top(), m_end.top(), progress),
|
||||
interpolateInteger(m_start.right(), m_end.right(), progress),
|
||||
interpolateInteger(m_start.bottom(), m_end.bottom(), progress));
|
||||
|
||||
bool changed = (now != m_current);
|
||||
if (changed)
|
||||
m_current = now;
|
||||
|
||||
if (state() == Stopped)
|
||||
return;
|
||||
|
||||
if (m_object)
|
||||
m_object->setRect(m_current);
|
||||
}
|
32
tests/benchmarks/gui/animation/qanimation/rectanimation.h
Normal file
32
tests/benchmarks/gui/animation/qanimation/rectanimation.h
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#ifndef _RECTANIMATION_H__
|
||||
|
||||
class DummyObject;
|
||||
|
||||
//this class is even simpler than the dummy
|
||||
//and uses no QVariant at all
|
||||
class RectAnimation : public QAbstractAnimation
|
||||
{
|
||||
public:
|
||||
RectAnimation(DummyObject *obj);
|
||||
|
||||
void setEndValue(const QRect &rect);
|
||||
void setStartValue(const QRect &rect);
|
||||
|
||||
void setDuration(int d);
|
||||
int duration() const override;
|
||||
|
||||
void updateCurrentTime(int currentTime) override;
|
||||
|
||||
private:
|
||||
DummyObject *m_object;
|
||||
QEasingCurve m_easing;
|
||||
QRect m_start, m_end, m_current;
|
||||
int m_dura;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user