diff --git a/src/plugins/qmldesigner/CMakeLists.txt b/src/plugins/qmldesigner/CMakeLists.txt index fa19266fdd5..92d037e9b07 100644 --- a/src/plugins/qmldesigner/CMakeLists.txt +++ b/src/plugins/qmldesigner/CMakeLists.txt @@ -969,7 +969,7 @@ extend_qtc_plugin(QmlDesigner timeline.qrc timelineabstracttool.cpp timelineabstracttool.h timelineactions.cpp timelineactions.h - timelineanimationform.cpp timelineanimationform.h timelineanimationform.ui + timelineanimationform.cpp timelineanimationform.h timelineconstants.h timelinecontext.cpp timelinecontext.h timelinecontrols.cpp timelinecontrols.h diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.cpp b/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.cpp index 494674891ea..d7b700dde81 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "timelineanimationform.h" -#include "ui_timelineanimationform.h" #include #include @@ -18,42 +17,118 @@ #include #include +#include #include +#include +#include +#include +#include +#include + namespace QmlDesigner { TimelineAnimationForm::TimelineAnimationForm(QWidget *parent) : QWidget(parent) - , ui(new Ui::TimelineAnimationForm) { - ui->setupUi(this); + constexpr int minimumLabelWidth = 160; + constexpr int spinBoxWidth = 80; - connectSpinBox(ui->duration, "duration"); - connectSpinBox(ui->loops, "loops"); + auto mainL = new QLabel(tr("Animation Settings")); + QFont f = mainL->font(); + f.setBold(true); + mainL->setFont(f); - connectSpinBox(ui->startFrame, "from"); - connectSpinBox(ui->endFrame, "to"); + auto idL = new QLabel(tr("Animation ID:")); + idL->setToolTip(tr("Name for the animation.")); + idL->setMinimumWidth(minimumLabelWidth); + m_idLineEdit = new QLineEdit; - connect(ui->loops, &QSpinBox::valueChanged, this, [this] { - ui->continuous->setChecked(ui->loops->value() == -1); + auto runningL = new QLabel(tr("Running in base state")); + runningL->setToolTip( + tr("Runs the animation automatically when the base state is active.")); + m_running = new QCheckBox; + m_running->setEnabled(false); + + auto startFrameL = new QLabel(tr("Start frame:")); + startFrameL->setToolTip(tr("First frame of the animation.")); + m_startFrame = new QSpinBox; + m_startFrame->setFixedWidth(spinBoxWidth); + m_startFrame->setRange(-100000, 100000); + + auto endFrameL = new QLabel(tr("End frame:")); + endFrameL->setToolTip(tr("Last frame of the animation.")); + m_endFrame = new QSpinBox; + m_endFrame->setFixedWidth(spinBoxWidth); + m_endFrame->setRange(-100000, 100000); + + auto durationL = new QLabel(tr("Duration:")); + durationL->setToolTip(tr("Length of the animation in milliseconds. If you set a shorter duration than the number of frames, frames are left out from the end of the animation.")); + m_duration = new QSpinBox; + m_duration->setFixedWidth(spinBoxWidth); + m_duration->setRange(0, 100000); + + auto continuousL = new QLabel(tr("Continuous")); + continuousL->setToolTip(tr("Sets the animation to loop indefinitely.")); + m_continuous = new QCheckBox; + + auto loopsL = new QLabel(tr("Loops:")); + loopsL->setToolTip(tr("Number of times the animation runs before it stops.")); + m_loops = new QSpinBox; + m_loops->setFixedWidth(spinBoxWidth); + m_loops->setRange(-1, 1000); + + auto pingPongL = new QLabel(tr("Ping pong")); + pingPongL->setToolTip( + tr("Runs the animation backwards to the beginning when it reaches the end.")); + m_pingPong = new QCheckBox; + + auto transitionToStateL = new QLabel(tr("Finished:")); + transitionToStateL->setToolTip(tr("State to activate when the animation finishes.")); + m_transitionToState = new QComboBox; + m_transitionToState->addItem(tr("none")); + + auto str = new QWidget; + QSizePolicy sp(QSizePolicy::MinimumExpanding, QSizePolicy::Ignored); + sp.setHorizontalStretch(2); + str->setSizePolicy(sp); + + using namespace Layouting; + Grid { + Span(4, mainL), br, + empty(), br, + idL, Span(2, m_idLineEdit), Span(2, Row{ runningL, m_running }), br, + empty(), startFrameL, m_startFrame, endFrameL, m_endFrame, durationL, m_duration, br, + empty(), continuousL, m_continuous, loopsL, m_loops, pingPongL, m_pingPong, str, br, + tr("Transition to state:"), transitionToStateL, m_transitionToState, br, + }.attachTo(this); + + connectSpinBox(m_duration, "duration"); + connectSpinBox(m_loops, "loops"); + + connectSpinBox(m_startFrame, "from"); + connectSpinBox(m_endFrame, "to"); + + connect(m_loops, &QSpinBox::valueChanged, this, [this] { + m_continuous->setChecked(m_loops->value() == -1); }); - connect(ui->continuous, &QCheckBox::toggled, this, [this](bool checked) { + connect(m_continuous, &QCheckBox::toggled, this, [this](bool checked) { if (checked) { setProperty("loops", -1); - ui->loops->setValue(-1); + m_loops->setValue(-1); } else { setProperty("loops", 1); - ui->loops->setValue(1); + m_loops->setValue(1); } }); - connect(ui->idLineEdit, &QLineEdit::editingFinished, this, [this] { + connect(m_idLineEdit, &QLineEdit::editingFinished, this, [this] { QTC_ASSERT(m_timeline.isValid(), return ); static QString lastString; - const QString newId = ui->idLineEdit->text(); + const QString newId = m_idLineEdit->text(); if (lastString == newId) return; @@ -79,11 +154,11 @@ TimelineAnimationForm::TimelineAnimationForm(QWidget *parent) if (error) { lastString.clear(); - ui->idLineEdit->setText(animation().id()); + m_idLineEdit->setText(animation().id()); } }); - connect(ui->running, &QCheckBox::clicked, this, [this](bool checked) { + connect(m_running, &QCheckBox::clicked, this, [this](bool checked) { if (checked) { setProperty("running", true); } else { @@ -91,7 +166,7 @@ TimelineAnimationForm::TimelineAnimationForm(QWidget *parent) } }); - connect(ui->pingPong, &QCheckBox::clicked, this, [this](bool checked) { + connect(m_pingPong, &QCheckBox::clicked, this, [this](bool checked) { if (checked) { setProperty("pingPong", true); } else { @@ -99,7 +174,7 @@ TimelineAnimationForm::TimelineAnimationForm(QWidget *parent) } }); - connect(ui->transitionToState, &QComboBox::activated, this, [this](int index) { + connect(m_transitionToState, &QComboBox::activated, this, [this](int index) { if (!m_animation.isValid()) return; if (!m_animation.view()->rootModelNode().hasId()) @@ -116,16 +191,11 @@ TimelineAnimationForm::TimelineAnimationForm(QWidget *parent) } else { m_animation.signalHandlerProperty("onFinished") .setSource(rootNode.id() + ".state = \"" - + ui->transitionToState->currentText() + "\""); + + m_transitionToState->currentText() + "\""); } }); } -TimelineAnimationForm::~TimelineAnimationForm() -{ - delete ui; -} - void TimelineAnimationForm::setup(const ModelNode &animation) { m_timeline = QmlTimeline(animation.parentProperty().parentModelNode()); @@ -151,40 +221,40 @@ void TimelineAnimationForm::setupAnimation() if (m_animation.isValid()) { setEnabled(true); - ui->idLineEdit->setText(m_animation.id()); + m_idLineEdit->setText(m_animation.id()); if (m_animation.hasVariantProperty("duration")) - ui->duration->setValue(m_animation.variantProperty("duration").value().toInt()); + m_duration->setValue(m_animation.variantProperty("duration").value().toInt()); else - ui->duration->setValue(0); + m_duration->setValue(0); - ui->startFrame->setValue(m_animation.variantProperty("from").value().toInt()); - ui->endFrame->setValue(m_animation.variantProperty("to").value().toInt()); + m_startFrame->setValue(m_animation.variantProperty("from").value().toInt()); + m_endFrame->setValue(m_animation.variantProperty("to").value().toInt()); if (m_animation.hasVariantProperty("loops")) - ui->loops->setValue(m_animation.variantProperty("loops").value().toInt()); + m_loops->setValue(m_animation.variantProperty("loops").value().toInt()); else - ui->loops->setValue(0); + m_loops->setValue(0); if (m_animation.hasVariantProperty("running")) - ui->running->setChecked(m_animation.variantProperty("running").value().toBool()); + m_running->setChecked(m_animation.variantProperty("running").value().toBool()); else - ui->running->setChecked(false); + m_running->setChecked(false); if (m_animation.hasVariantProperty("pingPong")) - ui->pingPong->setChecked(m_animation.variantProperty("pingPong").value().toBool()); + m_pingPong->setChecked(m_animation.variantProperty("pingPong").value().toBool()); else - ui->pingPong->setChecked(false); + m_pingPong->setChecked(false); - ui->continuous->setChecked(ui->loops->value() == -1); + m_continuous->setChecked(m_loops->value() == -1); } populateStateComboBox(); - ui->duration->setEnabled(m_animation.isValid()); - ui->running->setEnabled(m_animation.isValid()); - ui->continuous->setEnabled(m_animation.isValid()); - ui->loops->setEnabled(m_animation.isValid()); + m_duration->setEnabled(m_animation.isValid()); + m_running->setEnabled(m_animation.isValid()); + m_continuous->setEnabled(m_animation.isValid()); + m_loops->setEnabled(m_animation.isValid()); } void TimelineAnimationForm::setProperty(const PropertyName &propertyName, const QVariant &value) @@ -207,15 +277,15 @@ void TimelineAnimationForm::connectSpinBox(QSpinBox *spinBox, const PropertyName void TimelineAnimationForm::populateStateComboBox() { - ui->transitionToState->clear(); - ui->transitionToState->addItem(tr("none")); - ui->transitionToState->addItem(tr("Base State")); + m_transitionToState->clear(); + m_transitionToState->addItem(tr("none")); + m_transitionToState->addItem(tr("Base State")); if (!m_animation.isValid()) return; QmlObjectNode rootNode = QmlObjectNode(m_animation.view()->rootModelNode()); if (rootNode.isValid() && rootNode.modelNode().hasId()) { for (const QmlModelState &state : QmlVisualNode(rootNode).states().allStates()) { - ui->transitionToState + m_transitionToState ->addItem(state.modelNode().variantProperty("name").value().toString(), QVariant::fromValue(state.modelNode())); } @@ -227,9 +297,9 @@ void TimelineAnimationForm::populateStateComboBox() name.chop(1); name.remove(0, 1); if (name.isEmpty()) - ui->transitionToState->setCurrentIndex(1); + m_transitionToState->setCurrentIndex(1); else - ui->transitionToState->setCurrentText(name); + m_transitionToState->setCurrentText(name); } } } diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.h b/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.h index bc1fc08d0ca..8cdb4c1d5f0 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.h +++ b/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.h @@ -7,21 +7,21 @@ #include -QT_FORWARD_DECLARE_CLASS(QSpinBox) +QT_BEGIN_NAMESPACE +class QCheckBox; +class QComboBox; +class QLineEdit; +class QSpinBox; +QT_END_NAMESPACE namespace QmlDesigner { -namespace Ui { -class TimelineAnimationForm; -} - class TimelineAnimationForm : public QWidget { Q_OBJECT public: explicit TimelineAnimationForm(QWidget *parent); - ~TimelineAnimationForm() override; void setup(const ModelNode &animation); ModelNode animation() const; @@ -33,7 +33,15 @@ private: void connectSpinBox(QSpinBox *spinBox, const PropertyName &propertyName); void populateStateComboBox(); - Ui::TimelineAnimationForm *ui; + QLineEdit *m_idLineEdit; + QCheckBox *m_running; + QSpinBox *m_startFrame; + QSpinBox *m_endFrame; + QSpinBox *m_duration; + QCheckBox *m_continuous; + QSpinBox *m_loops; + QCheckBox *m_pingPong; + QComboBox *m_transitionToState; QmlTimeline m_timeline; ModelNode m_animation; diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.ui b/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.ui deleted file mode 100644 index 3329d30af66..00000000000 --- a/src/plugins/qmldesigner/components/timelineeditor/timelineanimationform.ui +++ /dev/null @@ -1,354 +0,0 @@ - - - QmlDesigner::TimelineAnimationForm - - - - 0 - 0 - 641 - 176 - - - - - - - Number of times the animation runs before it stops. - - - Loops: - - - - - - - - - - - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - -1 - - - 1000 - - - - - - - Sets the animation to loop indefinitely. - - - Continuous - - - - - - - - - - - - - - - none - - - - - - - - - 160 - 0 - - - - - 75 - true - - - - Animation Settings - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 213 - 20 - - - - - - - - - 140 - 0 - - - - Name for the animation. - - - Animation ID: - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 213 - 20 - - - - - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - 0 - - - 100000 - - - - - - - State to activate when the animation finishes. - - - Finished: - - - - - - - Runs the animation backwards to the beginning when it reaches the end. - - - Ping pong - - - - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 213 - 20 - - - - - - - - - 140 - 0 - - - - Transition to state: - - - - - - - animation02 - - - - - - - true - - - Runs the animation automatically when the base state is active. - - - Running in base state - - - - - - - - 0 - 0 - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - -100000 - - - 100000 - - - - - - - First frame of the animation. - - - Start frame: - - - - - - - false - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 213 - 20 - - - - - - - - Length of the animation in milliseconds. If you set a shorter duration than the number of frames, frames are left out from the end of the animation. - - - Duration: - - - - - - - Last frame of the animation. - - - End frame: - - - - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - -100000 - - - 100000 - - - - - - - -