diff options
Diffstat (limited to 'src/quick/items/qquickspriteengine_p.h')
-rw-r--r-- | src/quick/items/qquickspriteengine_p.h | 86 |
1 files changed, 31 insertions, 55 deletions
diff --git a/src/quick/items/qquickspriteengine_p.h b/src/quick/items/qquickspriteengine_p.h index d3944b4620..3bd129cf98 100644 --- a/src/quick/items/qquickspriteengine_p.h +++ b/src/quick/items/qquickspriteengine_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQuick module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QQUICKSPRITEENGINE_P_H #define QQUICKSPRITEENGINE_P_H @@ -58,19 +22,19 @@ QT_REQUIRE_CONFIG(quick_sprite); #include <QObject> #include <QVector> #include <QTimer> -#include <QTime> +#include <QElapsedTimer> #include <QList> #include <QQmlListProperty> #include <QImage> #include <QPair> #include <QRandomGenerator> -#include <private/qquickpixmapcache_p.h> +#include <private/qquickpixmap_p.h> #include <private/qtquickglobal_p.h> QT_BEGIN_NAMESPACE class QQuickSprite; -class Q_QUICK_PRIVATE_EXPORT QQuickStochasticState : public QObject //Currently for internal use only - Sprite and ParticleGroup +class Q_QUICK_EXPORT QQuickStochasticState : public QObject //Currently for internal use only - Sprite and ParticleGroup { Q_OBJECT Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) @@ -183,12 +147,12 @@ private: bool m_randomStart = false; }; -class Q_QUICK_PRIVATE_EXPORT QQuickStochasticEngine : public QObject +class Q_QUICK_EXPORT QQuickStochasticEngine : public QObject { Q_OBJECT //TODO: Optimize single state case? - Q_PROPERTY(QString globalGoal READ globalGoal WRITE setGlobalGoal NOTIFY globalGoalChanged) - Q_PROPERTY(QQmlListProperty<QQuickStochasticState> states READ states) + Q_PROPERTY(QString globalGoal READ globalGoal WRITE setGlobalGoal NOTIFY globalGoalChanged FINAL) + Q_PROPERTY(QQmlListProperty<QQuickStochasticState> states READ states FINAL) public: explicit QQuickStochasticEngine(QObject *parent = nullptr); QQuickStochasticEngine(const QList<QQuickStochasticState*> &states, QObject *parent = nullptr); @@ -196,7 +160,7 @@ public: QQmlListProperty<QQuickStochasticState> states() { - return QQmlListProperty<QQuickStochasticState>(this, m_states); + return QQmlListProperty<QQuickStochasticState>(this, &m_states); } QString globalGoal() const @@ -204,7 +168,7 @@ public: return m_globalGoal; } - int count() const {return m_things.count();} + int count() const {return m_things.size();} void setCount(int c); void setGoal(int state, int sprite=0, bool jump=false); @@ -217,13 +181,13 @@ public: QQuickStochasticState* state(int idx) const {return m_states[idx];} int stateIndex(QQuickStochasticState* s) const {return m_states.indexOf(s);} int stateIndex(const QString& s) const { - for (int i=0; i<m_states.count(); i++) + for (int i=0; i<m_states.size(); i++) if (m_states[i]->name() == s) return i; return -1; } - int stateCount() {return m_states.count();} + int stateCount() {return m_states.size();} private: Q_SIGNALS: @@ -254,7 +218,7 @@ protected: QVector<int> m_startTimes; QVector<QPair<uint, QVector<int> > > m_stateUpdates;//### This could be done faster - priority queue? - QTime m_advanceTime; + QElapsedTimer m_advanceTimer; uint m_timeOffset; QString m_globalGoal; int m_maxFrames; @@ -262,17 +226,17 @@ protected: bool m_addAdvance; }; -class Q_QUICK_PRIVATE_EXPORT QQuickSpriteEngine : public QQuickStochasticEngine +class Q_QUICK_EXPORT QQuickSpriteEngine : public QQuickStochasticEngine { Q_OBJECT - Q_PROPERTY(QQmlListProperty<QQuickSprite> sprites READ sprites) + Q_PROPERTY(QQmlListProperty<QQuickSprite> sprites READ sprites FINAL) public: explicit QQuickSpriteEngine(QObject *parent = nullptr); QQuickSpriteEngine(const QList<QQuickSprite*> &sprites, QObject *parent = nullptr); ~QQuickSpriteEngine() override; QQmlListProperty<QQuickSprite> sprites() { - return QQmlListProperty<QQuickSprite>(this, m_sprites); + return QQmlListProperty<QQuickSprite>(this, &m_sprites); } QQuickSprite* sprite(int sprite = 0) const; @@ -314,7 +278,7 @@ inline void spriteAppend(QQmlListProperty<QQuickSprite> *p, QQuickSprite* s) p->object->metaObject()->invokeMethod(p->object, "createEngine"); } -inline QQuickSprite* spriteAt(QQmlListProperty<QQuickSprite> *p, int idx) +inline QQuickSprite* spriteAt(QQmlListProperty<QQuickSprite> *p, qsizetype idx) { return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->at(idx); } @@ -325,9 +289,21 @@ inline void spriteClear(QQmlListProperty<QQuickSprite> *p) p->object->metaObject()->invokeMethod(p->object, "createEngine"); } -inline int spriteCount(QQmlListProperty<QQuickSprite> *p) +inline qsizetype spriteCount(QQmlListProperty<QQuickSprite> *p) { - return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->count(); + return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->size(); +} + +inline void spriteReplace(QQmlListProperty<QQuickSprite> *p, qsizetype idx, QQuickSprite *s) +{ + reinterpret_cast<QList<QQuickSprite *> *>(p->data)->replace(idx, s); + p->object->metaObject()->invokeMethod(p->object, "createEngine"); +} + +inline void spriteRemoveLast(QQmlListProperty<QQuickSprite> *p) +{ + reinterpret_cast<QList<QQuickSprite *> *>(p->data)->removeLast(); + p->object->metaObject()->invokeMethod(p->object, "createEngine"); } QT_END_NAMESPACE |