diff options
Diffstat (limited to 'examples/widgets/animation/easing')
-rw-r--r-- | examples/widgets/animation/easing/easing.py | 168 | ||||
-rw-r--r-- | examples/widgets/animation/easing/form.ui | 105 | ||||
-rw-r--r-- | examples/widgets/animation/easing/images/qt-logo.png | bin | 5149 -> 0 bytes | |||
-rw-r--r-- | examples/widgets/animation/easing/ui_form.py | 80 |
4 files changed, 197 insertions, 156 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) diff --git a/examples/widgets/animation/easing/form.ui b/examples/widgets/animation/easing/form.ui index 2397b1787..364aebeda 100644 --- a/examples/widgets/animation/easing/form.ui +++ b/examples/widgets/animation/easing/form.ui @@ -49,12 +49,27 @@ <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QGroupBox" name="groupBox_2"> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>16777215</height> + </size> + </property> <property name="title"> <string>Path type</string> </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> <widget class="QRadioButton" name="lineRadio"> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>40</height> + </size> + </property> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> <property name="text"> <string>Line</string> </property> @@ -62,17 +77,23 @@ <bool>true</bool> </property> <attribute name="buttonGroup"> - <string notr="true">buttonGroup</string> + <string>buttonGroup</string> </attribute> </widget> </item> - <item> + <item row="1" column="0"> <widget class="QRadioButton" name="circleRadio"> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>40</height> + </size> + </property> <property name="text"> <string>Circle</string> </property> <attribute name="buttonGroup"> - <string notr="true">buttonGroup</string> + <string>buttonGroup</string> </attribute> </widget> </item> @@ -96,6 +117,18 @@ </property> <item row="0" column="0"> <widget class="QLabel" name="label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>30</height> + </size> + </property> <property name="text"> <string>Period</string> </property> @@ -106,6 +139,18 @@ <property name="enabled"> <bool>false</bool> </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>30</height> + </size> + </property> <property name="minimum"> <double>-1.000000000000000</double> </property> @@ -117,18 +162,17 @@ </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Amplitude</string> - </property> - </widget> - </item> - <item row="1" column="1"> + <item row="2" column="1"> <widget class="QDoubleSpinBox" name="amplitudeSpinBox"> <property name="enabled"> <bool>false</bool> </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>30</height> + </size> + </property> <property name="minimum"> <double>-1.000000000000000</double> </property> @@ -140,18 +184,30 @@ </property> </widget> </item> - <item row="2" column="0"> + <item row="4" column="0"> <widget class="QLabel" name="label_3"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>30</height> + </size> + </property> <property name="text"> <string>Overshoot</string> </property> </widget> </item> - <item row="2" column="1"> + <item row="4" column="1"> <widget class="QDoubleSpinBox" name="overshootSpinBox"> <property name="enabled"> <bool>false</bool> </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>30</height> + </size> + </property> <property name="minimum"> <double>-1.000000000000000</double> </property> @@ -163,6 +219,19 @@ </property> </widget> </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>30</height> + </size> + </property> + <property name="text"> + <string>Amplitude</string> + </property> + </widget> + </item> </layout> </widget> </item> @@ -196,10 +265,6 @@ <resources/> <connections/> <buttongroups> - <buttongroup name="buttonGroup"> - <property name="exclusive"> - <bool>true</bool> - </property> - </buttongroup> + <buttongroup name="buttonGroup"/> </buttongroups> </ui> diff --git a/examples/widgets/animation/easing/images/qt-logo.png b/examples/widgets/animation/easing/images/qt-logo.png Binary files differdeleted file mode 100644 index 14ddf2a02..000000000 --- a/examples/widgets/animation/easing/images/qt-logo.png +++ /dev/null diff --git a/examples/widgets/animation/easing/ui_form.py b/examples/widgets/animation/easing/ui_form.py index d7e79ebd2..2925cbae7 100644 --- a/examples/widgets/animation/easing/ui_form.py +++ b/examples/widgets/animation/easing/ui_form.py @@ -3,15 +3,22 @@ ################################################################################ ## Form generated from reading UI file 'form.ui' ## -## Created by: Qt User Interface Compiler version 6.2.0 +## Created by: Qt User Interface Compiler version 6.7.0 ## ## WARNING! All changes made in this file will be lost when recompiling UI file! ################################################################################ -from PySide6.QtCore import * -from PySide6.QtGui import * -from PySide6.QtWidgets import * - +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QButtonGroup, QDoubleSpinBox, QFormLayout, + QGraphicsView, QGridLayout, QGroupBox, QLabel, + QListView, QListWidget, QListWidgetItem, QRadioButton, + QSizePolicy, QSpacerItem, QVBoxLayout, QWidget) class Ui_Form(object): def setupUi(self, Form): @@ -22,7 +29,7 @@ class Ui_Form(object): self.gridLayout.setObjectName(u"gridLayout") self.easingCurvePicker = QListWidget(Form) self.easingCurvePicker.setObjectName(u"easingCurvePicker") - sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) + sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.easingCurvePicker.sizePolicy().hasHeightForWidth()) @@ -40,30 +47,33 @@ class Ui_Form(object): self.verticalLayout.setObjectName(u"verticalLayout") self.groupBox_2 = QGroupBox(Form) self.groupBox_2.setObjectName(u"groupBox_2") - self.verticalLayout_2 = QVBoxLayout(self.groupBox_2) - self.verticalLayout_2.setObjectName(u"verticalLayout_2") + self.groupBox_2.setMaximumSize(QSize(16777215, 16777215)) + self.gridLayout_2 = QGridLayout(self.groupBox_2) + self.gridLayout_2.setObjectName(u"gridLayout_2") self.lineRadio = QRadioButton(self.groupBox_2) self.buttonGroup = QButtonGroup(Form) self.buttonGroup.setObjectName(u"buttonGroup") - self.buttonGroup.setExclusive(True) self.buttonGroup.addButton(self.lineRadio) self.lineRadio.setObjectName(u"lineRadio") + self.lineRadio.setMaximumSize(QSize(16777215, 40)) + self.lineRadio.setLayoutDirection(Qt.LeftToRight) self.lineRadio.setChecked(True) - self.verticalLayout_2.addWidget(self.lineRadio) + self.gridLayout_2.addWidget(self.lineRadio, 0, 0, 1, 1) self.circleRadio = QRadioButton(self.groupBox_2) self.buttonGroup.addButton(self.circleRadio) self.circleRadio.setObjectName(u"circleRadio") + self.circleRadio.setMaximumSize(QSize(16777215, 40)) - self.verticalLayout_2.addWidget(self.circleRadio) + self.gridLayout_2.addWidget(self.circleRadio, 1, 0, 1, 1) self.verticalLayout.addWidget(self.groupBox_2) self.groupBox = QGroupBox(Form) self.groupBox.setObjectName(u"groupBox") - sizePolicy1 = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) + sizePolicy1 = QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Preferred) sizePolicy1.setHorizontalStretch(0) sizePolicy1.setVerticalStretch(0) sizePolicy1.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth()) @@ -73,50 +83,66 @@ class Ui_Form(object): self.formLayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) self.label = QLabel(self.groupBox) self.label.setObjectName(u"label") + sizePolicy2 = QSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Preferred) + sizePolicy2.setHorizontalStretch(0) + sizePolicy2.setVerticalStretch(0) + sizePolicy2.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) + self.label.setSizePolicy(sizePolicy2) + self.label.setMinimumSize(QSize(0, 30)) self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label) self.periodSpinBox = QDoubleSpinBox(self.groupBox) self.periodSpinBox.setObjectName(u"periodSpinBox") self.periodSpinBox.setEnabled(False) + sizePolicy3 = QSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed) + sizePolicy3.setHorizontalStretch(0) + sizePolicy3.setVerticalStretch(0) + sizePolicy3.setHeightForWidth(self.periodSpinBox.sizePolicy().hasHeightForWidth()) + self.periodSpinBox.setSizePolicy(sizePolicy3) + self.periodSpinBox.setMinimumSize(QSize(0, 30)) self.periodSpinBox.setMinimum(-1.000000000000000) self.periodSpinBox.setSingleStep(0.100000000000000) self.periodSpinBox.setValue(-1.000000000000000) self.formLayout.setWidget(0, QFormLayout.FieldRole, self.periodSpinBox) - self.label_2 = QLabel(self.groupBox) - self.label_2.setObjectName(u"label_2") - - self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label_2) - self.amplitudeSpinBox = QDoubleSpinBox(self.groupBox) self.amplitudeSpinBox.setObjectName(u"amplitudeSpinBox") self.amplitudeSpinBox.setEnabled(False) + self.amplitudeSpinBox.setMinimumSize(QSize(0, 30)) self.amplitudeSpinBox.setMinimum(-1.000000000000000) self.amplitudeSpinBox.setSingleStep(0.100000000000000) self.amplitudeSpinBox.setValue(-1.000000000000000) - self.formLayout.setWidget(1, QFormLayout.FieldRole, self.amplitudeSpinBox) + self.formLayout.setWidget(2, QFormLayout.FieldRole, self.amplitudeSpinBox) self.label_3 = QLabel(self.groupBox) self.label_3.setObjectName(u"label_3") + self.label_3.setMinimumSize(QSize(0, 30)) - self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_3) + self.formLayout.setWidget(4, QFormLayout.LabelRole, self.label_3) self.overshootSpinBox = QDoubleSpinBox(self.groupBox) self.overshootSpinBox.setObjectName(u"overshootSpinBox") self.overshootSpinBox.setEnabled(False) + self.overshootSpinBox.setMinimumSize(QSize(0, 30)) self.overshootSpinBox.setMinimum(-1.000000000000000) self.overshootSpinBox.setSingleStep(0.100000000000000) self.overshootSpinBox.setValue(-1.000000000000000) - self.formLayout.setWidget(2, QFormLayout.FieldRole, self.overshootSpinBox) + self.formLayout.setWidget(4, QFormLayout.FieldRole, self.overshootSpinBox) + + self.label_2 = QLabel(self.groupBox) + self.label_2.setObjectName(u"label_2") + self.label_2.setMinimumSize(QSize(0, 30)) + + self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_2) self.verticalLayout.addWidget(self.groupBox) - self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) + self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding) self.verticalLayout.addItem(self.verticalSpacer) @@ -125,11 +151,11 @@ class Ui_Form(object): self.graphicsView = QGraphicsView(Form) self.graphicsView.setObjectName(u"graphicsView") - sizePolicy2 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - sizePolicy2.setHorizontalStretch(0) - sizePolicy2.setVerticalStretch(0) - sizePolicy2.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth()) - self.graphicsView.setSizePolicy(sizePolicy2) + sizePolicy4 = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) + sizePolicy4.setHorizontalStretch(0) + sizePolicy4.setVerticalStretch(0) + sizePolicy4.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth()) + self.graphicsView.setSizePolicy(sizePolicy4) self.gridLayout.addWidget(self.graphicsView, 1, 1, 1, 1) @@ -146,7 +172,7 @@ class Ui_Form(object): self.circleRadio.setText(QCoreApplication.translate("Form", u"Circle", None)) self.groupBox.setTitle(QCoreApplication.translate("Form", u"Properties", None)) self.label.setText(QCoreApplication.translate("Form", u"Period", None)) - self.label_2.setText(QCoreApplication.translate("Form", u"Amplitude", None)) self.label_3.setText(QCoreApplication.translate("Form", u"Overshoot", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"Amplitude", None)) # retranslateUi |