forked from qt-creator/qt-creator
Display the current frame in a dedicated control
Enable immediate dragging of the playhead after clicking into the time-scale Rename "Curve Picker" to "Easing Curve Editor" and "Curve Editor" to "Animation Curve Editor" Change-Id: I0085a26d0ea510286586d89c6cddb9bbe720e49e Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -113,9 +113,20 @@ QToolBar *CurveEditor::createToolBar()
|
||||
durationWidget->setLayout(durationBox);
|
||||
bar->addWidget(durationWidget);
|
||||
|
||||
auto *cfspin = new QSpinBox;
|
||||
cfspin->setMinimum(0);
|
||||
cfspin->setMaximum(std::numeric_limits<int>::max());
|
||||
|
||||
auto intSignal = static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged);
|
||||
connect(cfspin, intSignal, [this](int val) { m_view->setCurrentFrame(val, false); });
|
||||
connect(m_view, &GraphicsView::notifyFrameChanged, [cfspin](int val) {
|
||||
QSignalBlocker blocker(cfspin);
|
||||
cfspin->setValue(val);
|
||||
});
|
||||
|
||||
auto *positionBox = new QHBoxLayout;
|
||||
positionBox->addWidget(new QLabel(tr("Current Frame")));
|
||||
positionBox->addWidget(new QSpinBox);
|
||||
positionBox->addWidget(cfspin);
|
||||
auto *positionWidget = new QWidget;
|
||||
positionWidget->setLayout(positionBox);
|
||||
bar->addWidget(positionWidget);
|
||||
|
@@ -184,11 +184,14 @@ void GraphicsView::setZoomY(double zoom, const QPoint &pivot)
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void GraphicsView::setCurrentFrame(int frame)
|
||||
void GraphicsView::setCurrentFrame(int frame, bool notify)
|
||||
{
|
||||
int clampedFrame = clamp(frame, m_model->minimumTime(), m_model->maximumTime());
|
||||
m_playhead.moveToFrame(clampedFrame, this);
|
||||
viewport()->update();
|
||||
|
||||
if (notify)
|
||||
notifyFrameChanged(frame);
|
||||
}
|
||||
|
||||
void GraphicsView::scrollContent(double x, double y)
|
||||
@@ -251,6 +254,7 @@ void GraphicsView::mousePressEvent(QMouseEvent *event)
|
||||
QPointF pos = mapToScene(event->pos());
|
||||
if (timeScaleRect().contains(pos)) {
|
||||
setCurrentFrame(std::round(mapXtoTime(pos.x())));
|
||||
m_playhead.setMoving(true);
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
@@ -45,6 +45,9 @@ class GraphicsView : public QGraphicsView
|
||||
|
||||
friend class Playhead;
|
||||
|
||||
signals:
|
||||
void notifyFrameChanged(int frame);
|
||||
|
||||
public:
|
||||
GraphicsView(CurveEditorModel *model, QWidget *parent = nullptr);
|
||||
|
||||
@@ -94,7 +97,7 @@ public:
|
||||
|
||||
void setZoomY(double zoom, const QPoint &pivot = QPoint());
|
||||
|
||||
void setCurrentFrame(int frame);
|
||||
void setCurrentFrame(int frame, bool notify = true);
|
||||
|
||||
void scrollContent(double x, double y);
|
||||
|
||||
|
@@ -56,6 +56,11 @@ int Playhead::currentFrame() const
|
||||
return m_frame;
|
||||
}
|
||||
|
||||
void Playhead::setMoving(bool moving)
|
||||
{
|
||||
m_moving = moving;
|
||||
}
|
||||
|
||||
void Playhead::moveToFrame(int frame, GraphicsView *view)
|
||||
{
|
||||
m_frame = frame;
|
||||
|
@@ -45,6 +45,8 @@ public:
|
||||
|
||||
void paint(QPainter *painter, GraphicsView *view) const;
|
||||
|
||||
void setMoving(bool moving);
|
||||
|
||||
void moveToFrame(int frame, GraphicsView *view);
|
||||
|
||||
void resize(GraphicsView *view);
|
||||
|
@@ -272,7 +272,7 @@ void TimelineToolBar::createLeftControls()
|
||||
|
||||
auto *curveEditorAction = createAction(TimelineConstants::C_CURVE_EDITOR,
|
||||
TimelineIcons::CURVE_EDITORDIALOG.icon(),
|
||||
tr("Curve Editor"),
|
||||
tr("Animation Curve Editor"),
|
||||
QKeySequence(Qt::Key_C));
|
||||
|
||||
connect(curveEditorAction,
|
||||
@@ -396,10 +396,10 @@ void TimelineToolBar::createCenterControls()
|
||||
|
||||
auto *curvePicker = createAction(TimelineConstants::C_CURVE_PICKER,
|
||||
TimelineIcons::CURVE_EDITOR.icon(),
|
||||
tr("Curve Picker"),
|
||||
tr("Easing Curve Editor"),
|
||||
QKeySequence(Qt::Key_C));
|
||||
|
||||
curvePicker->setObjectName("Curve Picker");
|
||||
curvePicker->setObjectName("Easing Curve Editor");
|
||||
connect(curvePicker, &QAction::triggered, this, &TimelineToolBar::openEasingCurveEditor);
|
||||
addAction(curvePicker);
|
||||
|
||||
|
Reference in New Issue
Block a user