QmlDesigner: Inline timelineform.ui

Change-Id: I81e26b62fb289ca95d04b9f8a755de7251c52f6a
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2023-06-14 22:05:44 +02:00
parent 0cf1477324
commit ae83cc375b
4 changed files with 92 additions and 272 deletions

View File

@@ -973,7 +973,7 @@ extend_qtc_plugin(QmlDesigner
timelineconstants.h
timelinecontext.cpp timelinecontext.h
timelinecontrols.cpp timelinecontrols.h
timelineform.cpp timelineform.h timelineform.ui
timelineform.cpp timelineform.h
timelinegraphicslayout.cpp timelinegraphicslayout.h
timelinegraphicsscene.cpp timelinegraphicsscene.h
timelineicons.h

View File

@@ -2,7 +2,6 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "timelineform.h"
#include "ui_timelineform.h"
#include <abstractview.h>
#include <bindingproperty.h>
@@ -15,22 +14,80 @@
#include <coreplugin/messagebox.h>
#include <utils/algorithm.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <QLabel>
#include <QLineEdit>
#include <QRadioButton>
#include <QSpinBox>
namespace QmlDesigner {
TimelineForm::TimelineForm(QWidget *parent)
: QWidget(parent)
, ui(new Ui::TimelineForm)
{
ui->setupUi(this);
constexpr int minimumLabelWidth = 160;
constexpr int spinBoxWidth = 80;
connect(ui->expressionBindingLineEdit, &QLineEdit::editingFinished, [this]() {
auto mainL = new QLabel(tr("Timeline Settings"));
QFont f = mainL->font();
f.setBold(true);
mainL->setFont(f);
auto idL = new QLabel(tr("Timeline ID:"));
idL->setToolTip(tr("Name for the timeline."));
m_idLineEdit = new QLineEdit;
auto startFrameL = new QLabel(tr("Start frame:"));
startFrameL->setToolTip(tr("First frame of the timeline. Negative numbers are allowed."));
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 timeline."));
m_endFrame = new QSpinBox;
m_endFrame->setFixedWidth(spinBoxWidth);
m_endFrame->setRange(-100000, 100000);
m_expressionBinding = new QRadioButton(tr("Expression binding"));
m_expressionBinding->setToolTip(tr("To create an expression binding animation, delete all animations from this timeline."));
m_expressionBinding->setEnabled(false);
m_animation = new QRadioButton(tr("Animation"));
m_animation->setEnabled(false);
m_animation->setChecked(true);
QSizePolicy sp(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
auto expressionBindingL = new QLabel(tr("Expression binding:"));
expressionBindingL->setToolTip(tr("Sets the expression to bind the current keyframe to."));
expressionBindingL->setMinimumWidth(minimumLabelWidth);
m_expressionBindingLineEdit = new QLineEdit;
m_expressionBindingLineEdit->setMinimumWidth(240);
sp.setHorizontalStretch(2);
m_expressionBindingLineEdit->setSizePolicy(sp);
auto str = new QWidget;
sp.setHorizontalStretch(1);
str->setSizePolicy(sp);
using namespace Layouting;
Grid {
Span(2, mainL), br,
idL, m_idLineEdit, br,
empty(), Row { startFrameL, m_startFrame, st(), endFrameL, m_endFrame }, str, br,
empty(), Row { m_expressionBinding, m_animation, st() }, br,
expressionBindingL, m_expressionBindingLineEdit, br,
}.attachTo(this);
connect(m_expressionBindingLineEdit, &QLineEdit::editingFinished, [this]() {
QTC_ASSERT(m_timeline.isValid(), return );
const QString bindingText = ui->expressionBindingLineEdit->text();
const QString bindingText = m_expressionBindingLineEdit->text();
if (bindingText.isEmpty()) {
ui->animation->setChecked(true);
m_animation->setChecked(true);
try {
m_timeline.modelNode().removeProperty("currentFrame");
} catch (const Exception &e) {
@@ -39,7 +96,7 @@ TimelineForm::TimelineForm(QWidget *parent)
return;
}
ui->expressionBinding->setChecked(true);
m_expressionBinding->setChecked(true);
try {
m_timeline.modelNode()
@@ -50,12 +107,12 @@ TimelineForm::TimelineForm(QWidget *parent)
}
});
connect(ui->idLineEdit, &QLineEdit::editingFinished, [this]() {
connect(m_idLineEdit, &QLineEdit::editingFinished, [this]() {
QTC_ASSERT(m_timeline.isValid(), return );
static QString lastString;
const QString newId = ui->idLineEdit->text();
const QString newId = m_idLineEdit->text();
if (newId == lastString)
return;
@@ -81,37 +138,32 @@ TimelineForm::TimelineForm(QWidget *parent)
if (error) {
lastString.clear();
ui->idLineEdit->setText(m_timeline.modelNode().id());
m_idLineEdit->setText(m_timeline.modelNode().id());
}
});
connectSpinBox(ui->startFrame, "startFrame");
connectSpinBox(ui->endFrame, "endFrame");
}
TimelineForm::~TimelineForm()
{
delete ui;
connectSpinBox(m_startFrame, "startFrame");
connectSpinBox(m_endFrame, "endFrame");
}
void TimelineForm::setTimeline(const QmlTimeline &timeline)
{
m_timeline = timeline;
ui->expressionBindingLineEdit->clear();
m_expressionBindingLineEdit->clear();
if (m_timeline.isValid()) {
ui->idLineEdit->setText(m_timeline.modelNode().displayName());
ui->startFrame->setValue(
m_idLineEdit->setText(m_timeline.modelNode().displayName());
m_startFrame->setValue(
m_timeline.modelNode().variantProperty("startFrame").value().toInt());
ui->endFrame->setValue(m_timeline.modelNode().variantProperty("endFrame").value().toInt());
m_endFrame->setValue(m_timeline.modelNode().variantProperty("endFrame").value().toInt());
if (m_timeline.modelNode().hasBindingProperty("currentFrame")) {
ui->expressionBindingLineEdit->setText(
m_expressionBindingLineEdit->setText(
m_timeline.modelNode().bindingProperty("currentFrame").expression());
ui->expressionBinding->setChecked(true);
m_expressionBinding->setChecked(true);
} else {
ui->expressionBinding->setChecked(false);
m_expressionBinding->setChecked(false);
}
}
}
@@ -123,9 +175,9 @@ QmlTimeline TimelineForm::timeline() const
void TimelineForm::setHasAnimation(bool b)
{
ui->expressionBinding->setChecked(!b);
ui->animation->setChecked(b);
ui->expressionBindingLineEdit->setDisabled(b);
m_expressionBinding->setChecked(!b);
m_animation->setChecked(b);
m_expressionBindingLineEdit->setDisabled(b);
}
void TimelineForm::setProperty(const PropertyName &propertyName, const QVariant &value)

View File

@@ -7,21 +7,20 @@
#include <QWidget>
QT_FORWARD_DECLARE_CLASS(QSpinBox)
QT_BEGIN_NAMESPACE
class QLineEdit;
class QRadioButton;
class QSpinBox;
QT_END_NAMESPACE
namespace QmlDesigner {
namespace Ui {
class TimelineForm;
}
class TimelineForm : public QWidget
{
Q_OBJECT
public:
explicit TimelineForm(QWidget *parent);
~TimelineForm() override;
void setTimeline(const QmlTimeline &timeline);
QmlTimeline timeline() const;
void setHasAnimation(bool b);
@@ -30,7 +29,13 @@ private:
void setProperty(const PropertyName &propertyName, const QVariant &value);
void connectSpinBox(QSpinBox *spinBox, const PropertyName &propertyName);
Ui::TimelineForm *ui;
QLineEdit *m_idLineEdit;
QSpinBox *m_startFrame;
QSpinBox *m_endFrame;
QRadioButton *m_expressionBinding;
QRadioButton *m_animation;
QLineEdit *m_expressionBindingLineEdit;
QmlTimeline m_timeline;
};

View File

@@ -1,237 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QmlDesigner::TimelineForm</class>
<widget class="QWidget" name="QmlDesigner::TimelineForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>170</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="6" colspan="2">
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>49</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="6" colspan="2">
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>49</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="4">
<widget class="QLabel" name="label_7">
<property name="toolTip">
<string>Last frame of the timeline.</string>
</property>
<property name="text">
<string>End frame:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string>First frame of the timeline. Negative numbers are allowed.</string>
</property>
<property name="text">
<string>Start frame:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2" colspan="2">
<widget class="QSpinBox" name="startFrame">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="minimum">
<number>-100000</number>
</property>
<property name="maximum">
<number>100000</number>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QRadioButton" name="expressionBinding">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>To create an expression binding animation, delete all animations from this timeline.</string>
</property>
<property name="text">
<string>Expression binding</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>Name for the timeline.</string>
</property>
<property name="text">
<string>Timeline ID:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>160</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Timeline Settings</string>
</property>
</widget>
</item>
<item row="3" column="3" colspan="2">
<widget class="QRadioButton" name="animation">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Animation</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="6" colspan="2">
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>49</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_8">
<property name="toolTip">
<string>Sets the expression to bind the current keyframe to.</string>
</property>
<property name="text">
<string>Expression binding:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QSpinBox" name="endFrame">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="minimum">
<number>-100000</number>
</property>
<property name="maximum">
<number>100000</number>
</property>
</widget>
</item>
<item row="1" column="1" colspan="5">
<widget class="QLineEdit" name="idLineEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1" colspan="5">
<widget class="QLineEdit" name="expressionBindingLineEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>240</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="2" column="6" colspan="2">
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>49</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>