mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-02 23:35:28 +08:00
qt 6.5.1 original
This commit is contained in:
1
examples/widgets/animation/CMakeLists.txt
Normal file
1
examples/widgets/animation/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
qt_internal_add_example(easing)
|
8
examples/widgets/animation/README
Normal file
8
examples/widgets/animation/README
Normal file
@ -0,0 +1,8 @@
|
||||
The animation framework aims to provide an easy way for creating animated and
|
||||
smooth GUI's. By animating Qt properties, the framework provides great freedom
|
||||
for animating widgets and other QObjects. The framework can also be used with
|
||||
the Graphics View framework.
|
||||
|
||||
|
||||
Documentation for these examples can be found via the Examples
|
||||
link in the main Qt documentation.
|
3
examples/widgets/animation/animation.pro
Normal file
3
examples/widgets/animation/animation.pro
Normal file
@ -0,0 +1,3 @@
|
||||
TEMPLATE = \
|
||||
subdirs
|
||||
SUBDIRS += easing
|
51
examples/widgets/animation/easing/CMakeLists.txt
Normal file
51
examples/widgets/animation/easing/CMakeLists.txt
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(easing LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/animation/easing")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(easing
|
||||
animation.h
|
||||
form.ui
|
||||
main.cpp
|
||||
window.cpp window.h
|
||||
)
|
||||
|
||||
set_target_properties(easing PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(easing PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(easing_resource_files
|
||||
"images/qt-logo.png"
|
||||
)
|
||||
|
||||
qt_add_resources(easing "easing"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${easing_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS easing
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
63
examples/widgets/animation/easing/animation.h
Normal file
63
examples/widgets/animation/easing/animation.h
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef ANIMATION_H
|
||||
#define ANIMATION_H
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include <QtCore/qpropertyanimation.h>
|
||||
|
||||
class Animation : public QPropertyAnimation {
|
||||
public:
|
||||
enum PathType {
|
||||
LinearPath,
|
||||
CirclePath,
|
||||
NPathTypes
|
||||
};
|
||||
Animation(QObject *target, const QByteArray &prop, QObject *parent = nullptr)
|
||||
: QPropertyAnimation(target, prop, parent)
|
||||
{
|
||||
setPathType(LinearPath);
|
||||
}
|
||||
|
||||
void setPathType(PathType pathType)
|
||||
{
|
||||
if (pathType >= NPathTypes)
|
||||
qWarning("Unknown pathType %d", pathType);
|
||||
|
||||
m_pathType = pathType;
|
||||
m_path = QPainterPath();
|
||||
}
|
||||
|
||||
void updateCurrentTime(int currentTime) override
|
||||
{
|
||||
if (m_pathType == CirclePath) {
|
||||
if (m_path.isEmpty()) {
|
||||
QPointF to = endValue().toPointF();
|
||||
QPointF from = startValue().toPointF();
|
||||
m_path.moveTo(from);
|
||||
m_path.addEllipse(QRectF(from, to));
|
||||
}
|
||||
int dura = duration();
|
||||
const qreal progress = ((dura == 0) ? 1 : ((((currentTime - 1) % dura) + 1) / qreal(dura)));
|
||||
|
||||
qreal easedProgress = easingCurve().valueForProgress(progress);
|
||||
if (easedProgress > 1.0) {
|
||||
easedProgress -= 1.0;
|
||||
} else if (easedProgress < 0) {
|
||||
easedProgress += 1.0;
|
||||
}
|
||||
QPointF pt = m_path.pointAtPercent(easedProgress);
|
||||
updateCurrentValue(pt);
|
||||
emit valueChanged(pt);
|
||||
} else {
|
||||
QPropertyAnimation::updateCurrentTime(currentTime);
|
||||
}
|
||||
}
|
||||
|
||||
QPainterPath m_path;
|
||||
PathType m_pathType;
|
||||
};
|
||||
|
||||
#endif // ANIMATION_H
|
15
examples/widgets/animation/easing/easing.pro
Normal file
15
examples/widgets/animation/easing/easing.pro
Normal file
@ -0,0 +1,15 @@
|
||||
QT += widgets
|
||||
requires(qtConfig(listwidget))
|
||||
|
||||
HEADERS = window.h \
|
||||
animation.h
|
||||
SOURCES = main.cpp \
|
||||
window.cpp
|
||||
|
||||
FORMS = form.ui
|
||||
|
||||
RESOURCES = easing.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/animation/easing
|
||||
INSTALLS += target
|
5
examples/widgets/animation/easing/easing.qrc
Normal file
5
examples/widgets/animation/easing/easing.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>images/qt-logo.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
270
examples/widgets/animation/easing/form.ui
Normal file
270
examples/widgets/animation/easing/form.ui
Normal file
@ -0,0 +1,270 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>545</width>
|
||||
<height>471</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Easing curves</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QListWidget" name="easingCurvePicker">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>120</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="movement">
|
||||
<enum>QListView::Static</enum>
|
||||
</property>
|
||||
<property name="isWrapping" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::IconMode</enum>
|
||||
</property>
|
||||
<property name="selectionRectVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<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="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>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string>buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</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>buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Properties</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="periodSpinBox">
|
||||
<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>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>-1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>-1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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="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>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>-1.000000000000000</double>
|
||||
</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>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QGraphicsView" name="graphicsView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="buttonGroup"/>
|
||||
</buttongroups>
|
||||
</ui>
|
BIN
examples/widgets/animation/easing/images/qt-logo.png
Normal file
BIN
examples/widgets/animation/easing/images/qt-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
17
examples/widgets/animation/easing/main.cpp
Normal file
17
examples/widgets/animation/easing/main.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtWidgets>
|
||||
#include "window.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Q_INIT_RESOURCE(easing);
|
||||
QApplication app(argc, argv);
|
||||
Window w;
|
||||
|
||||
w.resize(400, 400);
|
||||
w.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
162
examples/widgets/animation/easing/window.cpp
Normal file
162
examples/widgets/animation/easing/window.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "window.h"
|
||||
|
||||
Window::Window(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_iconSize(64, 64)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
m_ui.easingCurvePicker->setIconSize(m_iconSize);
|
||||
m_ui.easingCurvePicker->setMinimumHeight(m_iconSize.height() + 50);
|
||||
m_ui.buttonGroup->setId(m_ui.lineRadio, 0);
|
||||
m_ui.buttonGroup->setId(m_ui.circleRadio, 1);
|
||||
|
||||
QEasingCurve dummy;
|
||||
m_ui.periodSpinBox->setValue(dummy.period());
|
||||
m_ui.amplitudeSpinBox->setValue(dummy.amplitude());
|
||||
m_ui.overshootSpinBox->setValue(dummy.overshoot());
|
||||
|
||||
connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged,
|
||||
this, &Window::curveChanged);
|
||||
connect(m_ui.buttonGroup, &QButtonGroup::buttonClicked,
|
||||
this, &Window::pathChanged);
|
||||
connect(m_ui.periodSpinBox, &QDoubleSpinBox::valueChanged,
|
||||
this, &Window::periodChanged);
|
||||
connect(m_ui.amplitudeSpinBox, &QDoubleSpinBox::valueChanged,
|
||||
this, &Window::amplitudeChanged);
|
||||
connect(m_ui.overshootSpinBox, &QDoubleSpinBox::valueChanged,
|
||||
this, &Window::overshootChanged);
|
||||
createCurveIcons();
|
||||
|
||||
QPixmap pix(QLatin1String(":/images/qt-logo.png"));
|
||||
m_item = new PixmapItem(pix);
|
||||
m_scene.addItem(m_item);
|
||||
m_ui.graphicsView->setScene(&m_scene);
|
||||
|
||||
m_anim = new Animation(m_item, "pos", this);
|
||||
m_anim->setEasingCurve(QEasingCurve::OutBounce);
|
||||
m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce));
|
||||
|
||||
startAnimation();
|
||||
}
|
||||
|
||||
static QEasingCurve createEasingCurve(QEasingCurve::Type curveType)
|
||||
{
|
||||
QEasingCurve curve(curveType);
|
||||
|
||||
if (curveType == QEasingCurve::BezierSpline) {
|
||||
curve.addCubicBezierSegment(QPointF(0.4, 0.1), QPointF(0.6, 0.9), QPointF(1.0, 1.0));
|
||||
|
||||
} else if (curveType == QEasingCurve::TCBSpline) {
|
||||
curve.addTCBSegment(QPointF(0.0, 0.0), 0, 0, 0);
|
||||
curve.addTCBSegment(QPointF(0.3, 0.4), 0.2, 1, -0.2);
|
||||
curve.addTCBSegment(QPointF(0.7, 0.6), -0.2, 1, 0.2);
|
||||
curve.addTCBSegment(QPointF(1.0, 1.0), 0, 0, 0);
|
||||
}
|
||||
|
||||
return curve;
|
||||
}
|
||||
|
||||
void Window::createCurveIcons()
|
||||
{
|
||||
QPixmap pix(m_iconSize);
|
||||
QPainter painter(&pix);
|
||||
QLinearGradient gradient(0,0, 0, m_iconSize.height());
|
||||
gradient.setColorAt(0.0, QColor(240, 240, 240));
|
||||
gradient.setColorAt(1.0, QColor(224, 224, 224));
|
||||
QBrush brush(gradient);
|
||||
const QMetaObject &mo = QEasingCurve::staticMetaObject;
|
||||
QMetaEnum metaEnum = mo.enumerator(mo.indexOfEnumerator("Type"));
|
||||
// Skip QEasingCurve::Custom
|
||||
for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) {
|
||||
painter.fillRect(QRect(QPoint(0, 0), m_iconSize), brush);
|
||||
QEasingCurve curve = createEasingCurve(static_cast<QEasingCurve::Type>(i));
|
||||
painter.setPen(QColor(0, 0, 255, 64));
|
||||
qreal xAxis = m_iconSize.height()/1.5;
|
||||
qreal yAxis = m_iconSize.width()/3;
|
||||
painter.drawLine(QLineF(0, xAxis, m_iconSize.width(), xAxis));
|
||||
painter.drawLine(QLineF(yAxis, 0, yAxis, m_iconSize.height()));
|
||||
|
||||
qreal curveScale = m_iconSize.height()/2;
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
// start point
|
||||
painter.setBrush(Qt::red);
|
||||
QPoint start(qRound(yAxis), qRound(xAxis - curveScale * curve.valueForProgress(0)));
|
||||
painter.drawRect(start.x() - 1, start.y() - 1, 3, 3);
|
||||
|
||||
// end point
|
||||
painter.setBrush(Qt::blue);
|
||||
QPoint end(qRound(yAxis + curveScale), qRound(xAxis - curveScale * curve.valueForProgress(1)));
|
||||
painter.drawRect(end.x() - 1, end.y() - 1, 3, 3);
|
||||
|
||||
QPainterPath curvePath;
|
||||
curvePath.moveTo(start);
|
||||
for (qreal t = 0; t <= 1.0; t+=1.0/curveScale) {
|
||||
QPointF to;
|
||||
to.setX(yAxis + curveScale * t);
|
||||
to.setY(xAxis - curveScale * curve.valueForProgress(t));
|
||||
curvePath.lineTo(to);
|
||||
}
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
painter.strokePath(curvePath, QColor(32, 32, 32));
|
||||
painter.setRenderHint(QPainter::Antialiasing, false);
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
item->setIcon(QIcon(pix));
|
||||
item->setText(metaEnum.key(i));
|
||||
m_ui.easingCurvePicker->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::startAnimation()
|
||||
{
|
||||
m_anim->setStartValue(QPointF(0, 0));
|
||||
m_anim->setEndValue(QPointF(100, 100));
|
||||
m_anim->setDuration(2000);
|
||||
m_anim->setLoopCount(-1); // forever
|
||||
m_anim->start();
|
||||
}
|
||||
|
||||
void Window::curveChanged(int row)
|
||||
{
|
||||
QEasingCurve::Type curveType = static_cast<QEasingCurve::Type>(row);
|
||||
m_anim->setEasingCurve(createEasingCurve(curveType));
|
||||
m_anim->setCurrentTime(0);
|
||||
|
||||
bool isElastic = curveType >= QEasingCurve::InElastic && curveType <= QEasingCurve::OutInElastic;
|
||||
bool isBounce = curveType >= QEasingCurve::InBounce && curveType <= QEasingCurve::OutInBounce;
|
||||
m_ui.periodSpinBox->setEnabled(isElastic);
|
||||
m_ui.amplitudeSpinBox->setEnabled(isElastic || isBounce);
|
||||
m_ui.overshootSpinBox->setEnabled(curveType >= QEasingCurve::InBack && curveType <= QEasingCurve::OutInBack);
|
||||
}
|
||||
|
||||
void Window::pathChanged(QAbstractButton *button)
|
||||
{
|
||||
const int index = m_ui.buttonGroup->id(button);
|
||||
m_anim->setPathType(Animation::PathType(index));
|
||||
}
|
||||
|
||||
void Window::periodChanged(double value)
|
||||
{
|
||||
QEasingCurve curve = m_anim->easingCurve();
|
||||
curve.setPeriod(value);
|
||||
m_anim->setEasingCurve(curve);
|
||||
}
|
||||
|
||||
void Window::amplitudeChanged(double value)
|
||||
{
|
||||
QEasingCurve curve = m_anim->easingCurve();
|
||||
curve.setAmplitude(value);
|
||||
m_anim->setEasingCurve(curve);
|
||||
}
|
||||
|
||||
void Window::overshootChanged(double value)
|
||||
{
|
||||
QEasingCurve curve = m_anim->easingCurve();
|
||||
curve.setOvershoot(value);
|
||||
m_anim->setEasingCurve(curve);
|
||||
}
|
||||
|
44
examples/widgets/animation/easing/window.h
Normal file
44
examples/widgets/animation/easing/window.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "ui_form.h"
|
||||
#include "animation.h"
|
||||
|
||||
class PixmapItem : public QObject, public QGraphicsPixmapItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
||||
public:
|
||||
PixmapItem(const QPixmap &pix) : QGraphicsPixmapItem(pix)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class Window : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Window(QWidget *parent = nullptr);
|
||||
private slots:
|
||||
void curveChanged(int row);
|
||||
void pathChanged(QAbstractButton *button);
|
||||
void periodChanged(double);
|
||||
void amplitudeChanged(double);
|
||||
void overshootChanged(double);
|
||||
|
||||
private:
|
||||
void createCurveIcons();
|
||||
void startAnimation();
|
||||
|
||||
Ui::Form m_ui;
|
||||
QGraphicsScene m_scene;
|
||||
PixmapItem *m_item;
|
||||
Animation *m_anim;
|
||||
QSize m_iconSize;
|
||||
};
|
||||
|
||||
#endif // WINDOW_H
|
Reference in New Issue
Block a user