aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/animation/easing/easing.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/animation/easing/easing.py')
-rw-r--r--examples/widgets/animation/easing/easing.py168
1 files changed, 59 insertions, 109 deletions
diff --git a/examples/widgets/animation/easing/easing.py b/examples/widgets/animation/easing/easing.py
index ba7f2d363..ba5032458 100644
--- a/examples/widgets/animation/easing/easing.py
+++ b/examples/widgets/animation/easing/easing.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
from enum import IntEnum
import sys
@@ -46,10 +8,10 @@ import sys
from PySide6.QtCore import (Property, QEasingCurve, QObject, QPropertyAnimation,
QPoint, QPointF, QRect, QRectF, QSize, Qt)
from PySide6.QtGui import (QBrush, QColor, QIcon, QLinearGradient, QPainter,
- QPainterPath, QPen, QPixmap)
+ QPainterPath, QPixmap)
from PySide6.QtWidgets import (QApplication, QGraphicsPixmapItem,
- QGraphicsItem, QGraphicsScene, QGraphicsView,
- QListWidget, QListWidgetItem, QWidget)
+ QGraphicsItem, QGraphicsScene,
+ QListWidgetItem, QWidget)
from ui_form import Ui_Form
@@ -148,13 +110,12 @@ class Window(QWidget):
self._anim = Animation(self._item, b'pos')
self._anim.setEasingCurve(QEasingCurve.OutBounce)
- self._ui.easingCurvePicker.setCurrentRow(int(QEasingCurve.OutBounce))
+ self._ui.easingCurvePicker.setCurrentRow(0)
self.start_animation()
def create_curve_icons(self):
pix = QPixmap(self._iconSize)
- painter = QPainter()
gradient = QLinearGradient(0, 0, 0, self._iconSize.height())
gradient.setColorAt(0.0, QColor(240, 240, 240))
@@ -162,63 +123,52 @@ class Window(QWidget):
brush = QBrush(gradient)
- # The original C++ code uses undocumented calls to get the names of the
- # different curve types. We do the Python equivalant (but without
- # cheating)
- curve_types = [(n, c) for n, c in QEasingCurve.__dict__.items()
- if (isinstance(c, QEasingCurve.Type)
- and c != QEasingCurve.Custom
- and c != QEasingCurve.NCurveTypes
- and c != QEasingCurve.TCBSpline)]
- curve_types.sort(key=lambda ct: ct[1])
-
- painter.begin(pix)
-
- for curve_name, curve_type in curve_types:
- painter.fillRect(QRect(QPoint(0, 0), self._iconSize), brush)
- curve = QEasingCurve(curve_type)
-
- painter.setPen(QColor(0, 0, 255, 64))
- x_axis = self._iconSize.height() / 1.5
- y_axis = self._iconSize.width() / 3.0
- painter.drawLine(0, x_axis, self._iconSize.width(), x_axis)
- painter.drawLine(y_axis, 0, y_axis, self._iconSize.height())
-
- curve_scale = self._iconSize.height() / 2.0
-
- painter.setPen(Qt.NoPen)
-
- # Start point.
- painter.setBrush(Qt.red)
- start = QPoint(y_axis,
- x_axis - curve_scale * curve.valueForProgress(0))
- painter.drawRect(start.x() - 1, start.y() - 1, 3, 3)
-
- # End point.
- painter.setBrush(Qt.blue)
- end = QPoint(y_axis + curve_scale,
- x_axis - curve_scale * curve.valueForProgress(1))
- painter.drawRect(end.x() - 1, end.y() - 1, 3, 3)
-
- curve_path = QPainterPath()
- curve_path.moveTo(QPointF(start))
- t = 0.0
- while t <= 1.0:
- to = QPointF(y_axis + curve_scale * t,
- x_axis - curve_scale * curve.valueForProgress(t))
- curve_path.lineTo(to)
- t += 1.0 / curve_scale
-
- painter.setRenderHint(QPainter.Antialiasing, True)
- painter.strokePath(curve_path, QColor(32, 32, 32))
- painter.setRenderHint(QPainter.Antialiasing, False)
-
- item = QListWidgetItem()
- item.setIcon(QIcon(pix))
- item.setText(curve_name)
- self._ui.easingCurvePicker.addItem(item)
-
- painter.end()
+ curve_types = [(f"QEasingCurve.{e.name}", e) for e in QEasingCurve.Type if e.value <= 40]
+
+ with QPainter(pix) as painter:
+
+ for curve_name, curve_type in curve_types:
+ painter.fillRect(QRect(QPoint(0, 0), self._iconSize), brush)
+ curve = QEasingCurve(curve_type)
+
+ painter.setPen(QColor(0, 0, 255, 64))
+ x_axis = self._iconSize.height() / 1.5
+ y_axis = self._iconSize.width() / 3.0
+ painter.drawLine(0, x_axis, self._iconSize.width(), x_axis)
+ painter.drawLine(y_axis, 0, y_axis, self._iconSize.height())
+
+ curve_scale = self._iconSize.height() / 2.0
+
+ painter.setPen(Qt.NoPen)
+
+ # Start point.
+ painter.setBrush(Qt.red)
+ start = QPoint(y_axis, x_axis - curve_scale * curve.valueForProgress(0))
+ painter.drawRect(start.x() - 1, start.y() - 1, 3, 3)
+
+ # End point.
+ painter.setBrush(Qt.blue)
+ end = QPoint(y_axis + curve_scale,
+ x_axis - curve_scale * curve.valueForProgress(1))
+ painter.drawRect(end.x() - 1, end.y() - 1, 3, 3)
+
+ curve_path = QPainterPath()
+ curve_path.moveTo(QPointF(start))
+ t = 0.0
+ while t <= 1.0:
+ to = QPointF(y_axis + curve_scale * t,
+ x_axis - curve_scale * curve.valueForProgress(t))
+ curve_path.lineTo(to)
+ t += 1.0 / curve_scale
+
+ painter.setRenderHint(QPainter.Antialiasing, True)
+ painter.strokePath(curve_path, QColor(32, 32, 32))
+ painter.setRenderHint(QPainter.Antialiasing, False)
+
+ item = QListWidgetItem()
+ item.setIcon(QIcon(pix))
+ item.setText(curve_name)
+ self._ui.easingCurvePicker.addItem(item)
def start_animation(self):
self._anim.setStartValue(QPointF(0, 0))
@@ -232,15 +182,15 @@ class Window(QWidget):
self._anim.setEasingCurve(curve_type)
self._anim.setCurrentTime(0)
- is_elastic = (curve_type >= QEasingCurve.InElastic
- and curve_type <= QEasingCurve.OutInElastic)
- is_bounce = (curve_type >= QEasingCurve.InBounce
- and curve_type <= QEasingCurve.OutInBounce)
+ is_elastic = (curve_type.value >= QEasingCurve.InElastic.value
+ and curve_type.value <= QEasingCurve.OutInElastic.value)
+ is_bounce = (curve_type.value >= QEasingCurve.InBounce.value
+ and curve_type.value <= QEasingCurve.OutInBounce.value)
self._ui.periodSpinBox.setEnabled(is_elastic)
self._ui.amplitudeSpinBox.setEnabled(is_elastic or is_bounce)
- self._ui.overshootSpinBox.setEnabled(curve_type >= QEasingCurve.InBack
- and curve_type <= QEasingCurve.OutInBack)
+ self._ui.overshootSpinBox.setEnabled(curve_type.value >= QEasingCurve.InBack.value
+ and curve_type.value <= QEasingCurve.OutInBack.value)
def path_changed(self, index):
self._anim.set_path_type(index)