Skip to content

Commit 7956f57

Browse files
committed
Update view model bindings
1 parent 43223b6 commit 7956f57

File tree

9 files changed

+125
-3
lines changed

9 files changed

+125
-3
lines changed

src/plugins/visualeditor/core/ArrangementPanelInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ namespace VisualEditor {
117117

118118
d->timeViewModel = new sflow::TimeViewModel(this);
119119
d->timeLayoutViewModel = new sflow::TimeLayoutViewModel(this);
120-
d->timelineInteractionController = new sflow::TimelineInteractionController(this);
121120
d->scrollBehaviorViewModel = new sflow::ScrollBehaviorViewModel(this);
121+
d->timelineInteractionController = ProjectViewModelContext::of(d->windowHandle)->createAndBindTimelineInteractionController();
122122
d->labelSequenceInteractionControllerOfTempo = ProjectViewModelContext::of(d->windowHandle)->createAndBindLabelSequenceInteractionControllerOfTempo();
123123
d->labelSequenceInteractionControllerOfLabel = ProjectViewModelContext::of(d->windowHandle)->createAndBindLabelSequenceInteractionControllerOfLabel();
124124

src/plugins/visualeditor/core/PlaybackViewModelContextData.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include "PlaybackViewModelContextData_p.h"
22

33
#include <QLoggingCategory>
4+
#include <QQuickItem>
5+
#include <QState>
6+
#include <QStateMachine>
47

58
#include <ScopicFlowCore/PlaybackViewModel.h>
9+
#include <ScopicFlowCore/TimelineInteractionController.h>
610

711
#include <coreplugin/ProjectTimeline.h>
812
#include <coreplugin/ProjectWindowInterface.h>
@@ -13,10 +17,51 @@ namespace VisualEditor {
1317

1418
Q_STATIC_LOGGING_CATEGORY(lcPlaybackViewModelContextData, "diffscope.visualeditor.playbackviewmodelcontextdata")
1519

20+
void PlaybackViewModelContextData::initStateMachine() {
21+
stateMachine = new QStateMachine(QState::ExclusiveStates, this);
22+
idleState = new QState;
23+
rubberBandDraggingState = new QState;
24+
positionIndicatorMovingState = new QState;
25+
stateMachine->addState(idleState);
26+
stateMachine->addState(rubberBandDraggingState);
27+
stateMachine->addState(positionIndicatorMovingState);
28+
stateMachine->setInitialState(idleState);
29+
stateMachine->start();
30+
31+
idleState->addTransition(this, &PlaybackViewModelContextData::rubberBandDragWillStart, rubberBandDraggingState);
32+
rubberBandDraggingState->addTransition(this, &PlaybackViewModelContextData::rubberBandDragWillFinish, idleState);
33+
34+
idleState->addTransition(this, &PlaybackViewModelContextData::positionIndicatorMoveWillStart, positionIndicatorMovingState);
35+
positionIndicatorMovingState->addTransition(this, &PlaybackViewModelContextData::positionIndicatorMoveWillFinish, idleState);
36+
37+
connect(idleState, &QState::entered, this, [=, this] {
38+
qCInfo(lcPlaybackViewModelContextData) << "Idle state entered";
39+
});
40+
connect(idleState, &QState::exited, this, [=, this] {
41+
qCInfo(lcPlaybackViewModelContextData) << "Idle state exited";
42+
});
43+
connect(rubberBandDraggingState, &QState::entered, this, [=, this] {
44+
qCInfo(lcPlaybackViewModelContextData) << "Rubber band dragging state entered";
45+
});
46+
connect(rubberBandDraggingState, &QState::exited, this, [=, this] {
47+
qCInfo(lcPlaybackViewModelContextData) << "Rubber band dragging state exited";
48+
});
49+
connect(positionIndicatorMovingState, &QState::entered, this, [=, this] {
50+
qCInfo(lcPlaybackViewModelContextData) << "Position indicator moving state entered";
51+
onPositionIndicatorMovingStateEntered();
52+
});
53+
connect(positionIndicatorMovingState, &QState::exited, this, [=, this] {
54+
qCInfo(lcPlaybackViewModelContextData) << "Position indicator moving state exited";
55+
onPositionIndicatorMovingStateExited();
56+
});
57+
}
58+
1659
void PlaybackViewModelContextData::init() {
1760
Q_Q(ProjectViewModelContext);
1861
windowHandle = q->windowHandle();
1962
playbackViewModel = new sflow::PlaybackViewModel(q);
63+
64+
initStateMachine();
2065
}
2166

2267
void PlaybackViewModelContextData::bindPlaybackViewModel() {
@@ -49,4 +94,32 @@ namespace VisualEditor {
4994
playbackViewModel->setSecondaryPosition(projectTimeline->lastPosition());
5095
}
5196

97+
sflow::TimelineInteractionController *PlaybackViewModelContextData::createController(QObject *parent) {
98+
auto controller = new sflow::TimelineInteractionController(parent);
99+
controller->setInteraction(sflow::TimelineInteractionController::MovePositionIndicator | sflow::TimelineInteractionController::ZoomByRubberBand);
100+
101+
connect(controller, &sflow::TimelineInteractionController::rubberBandDraggingStarted, this, [=](QQuickItem *) {
102+
Q_EMIT rubberBandDragWillStart();
103+
});
104+
connect(controller, &sflow::TimelineInteractionController::rubberBandDraggingFinished, this, [=](QQuickItem *, sflow::TimelineInteractionController::InteractionFlag) {
105+
Q_EMIT rubberBandDragWillFinish();
106+
});
107+
connect(controller, &sflow::TimelineInteractionController::positionIndicatorMovingStarted, this, [=](QQuickItem *) {
108+
Q_EMIT positionIndicatorMoveWillStart();
109+
});
110+
connect(controller, &sflow::TimelineInteractionController::positionIndicatorMovingFinished, this, [=](QQuickItem *) {
111+
Q_EMIT positionIndicatorMoveWillFinish();
112+
});
113+
114+
return controller;
115+
}
116+
117+
void PlaybackViewModelContextData::onPositionIndicatorMovingStateEntered() {
118+
// TODO
119+
}
120+
121+
void PlaybackViewModelContextData::onPositionIndicatorMovingStateExited() {
122+
// TODO
123+
}
124+
52125
}

src/plugins/visualeditor/core/PlaybackViewModelContextData_p.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
#ifndef DIFFSCOPE_VISUALEDITOR_PLAYBACKVIEWMODELCONTEXTDATA_P_H
22
#define DIFFSCOPE_VISUALEDITOR_PLAYBACKVIEWMODELCONTEXTDATA_P_H
33

4+
#include <QObject>
5+
46
#include <visualeditor/ProjectViewModelContext.h>
57

8+
class QState;
9+
class QStateMachine;
10+
class QQuickItem;
11+
12+
namespace sflow {
13+
class TimelineInteractionController;
14+
}
15+
616
namespace VisualEditor {
717

8-
class PlaybackViewModelContextData {
18+
class PlaybackViewModelContextData : public QObject {
19+
Q_OBJECT
920
Q_DECLARE_PUBLIC(ProjectViewModelContext)
1021
public:
1122
ProjectViewModelContext *q_ptr;
1223

1324
Core::ProjectWindowInterface *windowHandle;
1425
sflow::PlaybackViewModel *playbackViewModel;
1526

27+
QStateMachine *stateMachine;
28+
QState *idleState;
29+
QState *rubberBandDraggingState;
30+
QState *positionIndicatorMovingState;
31+
1632
void init();
33+
void initStateMachine();
1734
void bindPlaybackViewModel();
35+
sflow::TimelineInteractionController *createController(QObject *parent);
36+
37+
void onPositionIndicatorMovingStateEntered();
38+
void onPositionIndicatorMovingStateExited();
39+
40+
Q_SIGNALS:
41+
void rubberBandDragWillStart();
42+
void rubberBandDragWillFinish();
43+
44+
void positionIndicatorMoveWillStart();
45+
void positionIndicatorMoveWillFinish();
1846
};
1947

2048
}

src/plugins/visualeditor/core/ProjectViewModelContext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ScopicFlowCore/PointSequenceViewModel.h>
66
#include <ScopicFlowCore/LabelViewModel.h>
77
#include <ScopicFlowCore/LabelSequenceInteractionController.h>
8+
#include <ScopicFlowCore/TimelineInteractionController.h>
89

910
#include <dspxmodel/Tempo.h>
1011
#include <dspxmodel/Label.h>
@@ -98,6 +99,11 @@ namespace VisualEditor {
9899
return d->labelData->labelSelectionController;
99100
}
100101

102+
sflow::TimelineInteractionController *ProjectViewModelContext::createAndBindTimelineInteractionController(QObject *parent) {
103+
Q_D(ProjectViewModelContext);
104+
return d->playbackData->createController(parent);
105+
}
106+
101107
sflow::LabelSequenceInteractionController *ProjectViewModelContext::createAndBindLabelSequenceInteractionControllerOfTempo(QObject *parent) {
102108
Q_D(ProjectViewModelContext);
103109
return d->tempoData->createController(parent);

src/plugins/visualeditor/core/ProjectViewModelContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace sflow {
1212
class LabelSequenceInteractionController;
1313
class LabelViewModel;
1414
class SelectionController;
15+
class TimelineInteractionController;
1516
}
1617

1718
namespace dspx {
@@ -61,6 +62,7 @@ namespace VisualEditor {
6162
sflow::SelectionController *tempoSelectionController() const;
6263
sflow::SelectionController *labelSelectionController() const;
6364

65+
Q_INVOKABLE sflow::TimelineInteractionController *createAndBindTimelineInteractionController(QObject *parent = nullptr);
6466
Q_INVOKABLE sflow::LabelSequenceInteractionController *createAndBindLabelSequenceInteractionControllerOfTempo(QObject *parent = nullptr);
6567
Q_INVOKABLE sflow::LabelSequenceInteractionController *createAndBindLabelSequenceInteractionControllerOfLabel(QObject *parent = nullptr);
6668

src/plugins/visualeditor/qml/ArrangementView.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ Item {
219219
timeline.dragging = false
220220
}
221221
}
222+
223+
function onRubberBandDraggingStarted() {
224+
timeline.timeLayoutViewModel.cursorPosition = -1
225+
}
222226
}
223227
}
224228
Rectangle {

src/plugins/visualeditor/qml/additionaltracks/LabelTrack.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ QtObject {
5454
control.itemBeingDragged = null
5555
}
5656
}
57+
58+
function onRubberBandDraggingStarted() {
59+
control.timeLayoutViewModel.cursorPosition = -1
60+
}
61+
5762
}
5863
}
5964

src/plugins/visualeditor/qml/additionaltracks/TempoTrack.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ QtObject {
5454
control.itemBeingDragged = null
5555
}
5656
}
57+
58+
function onRubberBandDraggingStarted() {
59+
control.timeLayoutViewModel.cursorPosition = -1
60+
}
5761
}
5862
}
5963

0 commit comments

Comments
 (0)