diff options
Diffstat (limited to 'examples/widgets/animation/animatedtiles/animatedtiles.py')
-rw-r--r-- | examples/widgets/animation/animatedtiles/animatedtiles.py | 75 |
1 files changed, 19 insertions, 56 deletions
diff --git a/examples/widgets/animation/animatedtiles/animatedtiles.py b/examples/widgets/animation/animatedtiles/animatedtiles.py index 01828c9ec..02fc75bf5 100644 --- a/examples/widgets/animation/animatedtiles/animatedtiles.py +++ b/examples/widgets/animation/animatedtiles/animatedtiles.py @@ -1,44 +1,6 @@ - -############################################################################# -## -## Copyright (C) 2010 Riverbank Computing Limited. -## Copyright (C) 2021 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2010 Riverbank Computing Limited. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import sys import math @@ -46,14 +8,14 @@ import math from PySide6.QtCore import (QEasingCurve, QObject, QParallelAnimationGroup, QPointF, QPropertyAnimation, QRandomGenerator, QRectF, QTimer, Qt, Property, Signal) -from PySide6.QtGui import (QBrush, QColor, QLinearGradient, QPainter, +from PySide6.QtGui import (QBrush, QLinearGradient, QPainter, QPainterPath, QPixmap, QTransform) from PySide6.QtWidgets import (QApplication, QGraphicsItem, QGraphicsPixmapItem, QGraphicsRectItem, QGraphicsScene, QGraphicsView, - QGraphicsWidget, QStyle, QWidget) + QGraphicsWidget, QStyle) from PySide6.QtStateMachine import QState, QStateMachine -import animatedtiles_rc +import animatedtiles_rc # noqa: F401 # Deriving from more than one wrapped class is not supported, so we use @@ -133,7 +95,7 @@ class Button(QGraphicsWidget): painter.drawEllipse(r.adjusted(5, 5, -5, -5)) painter.drawPixmap(-self._pix.width() / 2, -self._pix.height() / 2, - self._pix) + self._pix) def mousePressEvent(self, ev): self.pressed.emit() @@ -161,7 +123,7 @@ if __name__ == '__main__': for i in range(64): item = Pixmap(kinetic_pix) item.pixmap_item.setOffset(-kinetic_pix.width() / 2, - -kinetic_pix.height() / 2) + -kinetic_pix.height() / 2) item.pixmap_item.setZValue(i) items.append(item) scene.addItem(item.pixmap_item) @@ -199,23 +161,25 @@ if __name__ == '__main__': for i, item in enumerate(items): # Ellipse. ellipse_state.assignProperty(item, 'pos', - QPointF(math.cos((i / 63.0) * 6.28) * 250, - math.sin((i / 63.0) * 6.28) * 250)) + QPointF(math.cos((i / 63.0) * 6.28) * 250, + math.sin((i / 63.0) * 6.28) * 250)) # Figure 8. figure_8state.assignProperty(item, 'pos', - QPointF(math.sin((i / 63.0) * 6.28) * 250, - math.sin(((i * 2) / 63.0) * 6.28) * 250)) + QPointF(math.sin((i / 63.0) * 6.28) * 250, + math.sin(((i * 2) / 63.0) * 6.28) * 250)) # Random. random_state.assignProperty(item, 'pos', - QPointF(-250 + generator.bounded(0, 500), - -250 + generator.bounded(0, 500))) + QPointF(-250 + generator.bounded(0, 500), + -250 + generator.bounded(0, 500))) # Tiled. + width = kinetic_pix.width() + height = kinetic_pix.height() tiled_state.assignProperty(item, 'pos', - QPointF(((i % 8) - 4) * kinetic_pix.width() + kinetic_pix.width() / 2, - ((i // 8) - 4) * kinetic_pix.height() + kinetic_pix.height() / 2)) + QPointF(((i % 8) - 4) * width + width / 2, + ((i // 8) - 4) * height + height / 2)) # Centered. centered_state.assignProperty(item, 'pos', QPointF()) @@ -226,8 +190,7 @@ if __name__ == '__main__': view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) view.setBackgroundBrush(QBrush(bg_pix)) view.setCacheMode(QGraphicsView.CacheBackground) - view.setRenderHints( - QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) view.show() states = QStateMachine() |