Skip to content

Commit 7cf090f

Browse files
committed
Update tempo editing and add label editing
1 parent fadf6f6 commit 7cf090f

20 files changed

+1041
-201
lines changed

src/plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function(diffscope_add_builtin_plugin _target)
3838

3939
qm_configure_target(${_target}
4040
SOURCES ${_src}
41+
INCLUDE_PRIVATE *
4142
${FUNC_UNPARSED_ARGUMENTS}
4243
)
4344

src/plugins/visualeditor/core/ArrangementPanelInterface.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ namespace VisualEditor {
120120
d->timelineInteractionController = new sflow::TimelineInteractionController(this);
121121
d->scrollBehaviorViewModel = new sflow::ScrollBehaviorViewModel(this);
122122
d->labelSequenceInteractionControllerOfTempo = ProjectViewModelContext::of(d->windowHandle)->createAndBindLabelSequenceInteractionControllerOfTempo();
123+
d->labelSequenceInteractionControllerOfLabel = ProjectViewModelContext::of(d->windowHandle)->createAndBindLabelSequenceInteractionControllerOfLabel();
123124

124125
d->positionAlignmentManipulator = new PositionAlignmentManipulator(this);
125126
d->positionAlignmentManipulator->setTimeLayoutViewModel(d->timeLayoutViewModel);
@@ -135,8 +136,7 @@ namespace VisualEditor {
135136
}
136137
auto o = component.createWithInitialProperties({
137138
{"addOn", QVariant::fromValue(d->addon)},
138-
{"arrangementPanelInterface", QVariant::fromValue(this)},
139-
{"projectViewModelContext", QVariant::fromValue(ProjectViewModelContext::of(d->windowHandle))},
139+
{"arrangementPanelInterface", QVariant::fromValue(this)}
140140
});
141141
if (component.isError()) {
142142
qFatal() << component.errorString();
@@ -190,6 +190,11 @@ namespace VisualEditor {
190190
return d->labelSequenceInteractionControllerOfTempo;
191191
}
192192

193+
sflow::LabelSequenceInteractionController *ArrangementPanelInterface::labelSequenceInteractionControllerOfLabel() const {
194+
Q_D(const ArrangementPanelInterface);
195+
return d->labelSequenceInteractionControllerOfLabel;
196+
}
197+
193198
PositionAlignmentManipulator *ArrangementPanelInterface::positionAlignmentManipulator() const {
194199
Q_D(const ArrangementPanelInterface);
195200
return d->positionAlignmentManipulator;

src/plugins/visualeditor/core/ArrangementPanelInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace VisualEditor {
4242
Q_PROPERTY(sflow::ScrollBehaviorViewModel *scrollBehaviorViewModel READ scrollBehaviorViewModel CONSTANT)
4343
Q_PROPERTY(sflow::TimelineInteractionController *timelineInteractionController READ timelineInteractionController CONSTANT)
4444
Q_PROPERTY(sflow::LabelSequenceInteractionController *labelSequenceInteractionControllerOfTempo READ labelSequenceInteractionControllerOfTempo CONSTANT)
45+
Q_PROPERTY(sflow::LabelSequenceInteractionController *labelSequenceInteractionControllerOfLabel READ labelSequenceInteractionControllerOfLabel CONSTANT)
4546
Q_PROPERTY(PositionAlignmentManipulator *positionAlignmentManipulator READ positionAlignmentManipulator CONSTANT)
4647
Q_PROPERTY(AutoPageScrollingManipulator *autoPageScrollingManipulator READ autoPageScrollingManipulator CONSTANT)
4748
Q_PROPERTY(QQuickItem *arrangementView READ arrangementView CONSTANT)
@@ -61,6 +62,7 @@ namespace VisualEditor {
6162
sflow::ScrollBehaviorViewModel *scrollBehaviorViewModel() const;
6263
sflow::TimelineInteractionController *timelineInteractionController() const;
6364
sflow::LabelSequenceInteractionController *labelSequenceInteractionControllerOfTempo() const;
65+
sflow::LabelSequenceInteractionController *labelSequenceInteractionControllerOfLabel() const;
6466

6567
PositionAlignmentManipulator *positionAlignmentManipulator() const;
6668
AutoPageScrollingManipulator *autoPageScrollingManipulator() const;

src/plugins/visualeditor/core/ArrangementPanelInterface_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace VisualEditor {
2020
sflow::TimelineInteractionController *timelineInteractionController;
2121
sflow::ScrollBehaviorViewModel *scrollBehaviorViewModel;
2222
sflow::LabelSequenceInteractionController *labelSequenceInteractionControllerOfTempo;
23+
sflow::LabelSequenceInteractionController *labelSequenceInteractionControllerOfLabel;
2324

2425
PositionAlignmentManipulator *positionAlignmentManipulator;
2526
AutoPageScrollingManipulator *autoPageScrollingManipulator;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include "LabelSelectionController_p.h"
2+
3+
#include <algorithm>
4+
#include <iterator>
5+
6+
#include <QLoggingCategory>
7+
#include <QQuickWindow>
8+
9+
#include <ScopicFlowCore/LabelViewModel.h>
10+
11+
#include <dspxmodel/Label.h>
12+
#include <dspxmodel/LabelSelectionModel.h>
13+
#include <dspxmodel/LabelSequence.h>
14+
#include <dspxmodel/Model.h>
15+
#include <dspxmodel/SelectionModel.h>
16+
#include <dspxmodel/Timeline.h>
17+
18+
#include <coreplugin/DspxDocument.h>
19+
#include <coreplugin/ProjectDocumentContext.h>
20+
#include <coreplugin/ProjectWindowInterface.h>
21+
22+
#include <visualeditor/ProjectViewModelContext.h>
23+
24+
namespace VisualEditor {
25+
26+
Q_STATIC_LOGGING_CATEGORY(lcLabelSelectionController, "diffscope.visualeditor.labelselectioncontroller")
27+
28+
LabelSelectionController::LabelSelectionController(ProjectViewModelContext *parent)
29+
: SelectionController(parent), q(parent) {
30+
labelSequence = q->windowHandle()->projectDocumentContext()->document()->model()->timeline()->labels();
31+
selectionModel = q->windowHandle()->projectDocumentContext()->document()->selectionModel();
32+
labelSelectionModel = q->windowHandle()->projectDocumentContext()->document()->selectionModel()->labelSelectionModel();
33+
connect(labelSelectionModel, &dspx::LabelSelectionModel::currentItemChanged, this, &SelectionController::currentItemChanged);
34+
}
35+
36+
LabelSelectionController::~LabelSelectionController() = default;
37+
38+
QObjectList LabelSelectionController::getSelectedItems() const {
39+
QObjectList viewItems;
40+
std::ranges::transform(labelSelectionModel->selectedItems(), std::back_inserter(viewItems), [=, this](dspx::Label *item) {
41+
auto viewItem = q->getLabelViewItemFromDocumentItem(item);
42+
Q_ASSERT(viewItem);
43+
return viewItem;
44+
});
45+
return viewItems;
46+
}
47+
48+
QObjectList LabelSelectionController::getItemsBetween(QObject *startItem, QObject *endItem) const {
49+
auto startDocumentItem = startItem ? q->getLabelDocumentItemFromViewItem(qobject_cast<sflow::LabelViewModel *>(startItem)) : labelSequence->firstItem();
50+
auto endDocumentItem = endItem ? q->getLabelDocumentItemFromViewItem(qobject_cast<sflow::LabelViewModel *>(endItem)) : labelSequence->lastItem();
51+
Q_ASSERT(startDocumentItem && endDocumentItem);
52+
QObjectList viewItems;
53+
if (startDocumentItem->pos() > endDocumentItem->pos()) {
54+
std::swap(startDocumentItem, endDocumentItem);
55+
}
56+
for (auto item = startDocumentItem; item; item = labelSequence->nextItem(item)) {
57+
auto viewItem = q->getLabelViewItemFromDocumentItem(item);
58+
Q_ASSERT(viewItem);
59+
viewItems.append(viewItem);
60+
if (item == endDocumentItem) {
61+
break;
62+
}
63+
}
64+
return viewItems;
65+
}
66+
67+
void LabelSelectionController::select(QObject *item, SelectionCommand command) {
68+
qCDebug(lcLabelSelectionController) << "Label view item selected" << item << command;
69+
dspx::SelectionModel::SelectionCommand documentSelectionCommand = {};
70+
if (command & Select) {
71+
documentSelectionCommand |= dspx::SelectionModel::Select;
72+
}
73+
if (command & Deselect) {
74+
documentSelectionCommand |= dspx::SelectionModel::Deselect;
75+
}
76+
if (command & ClearPreviousSelection) {
77+
documentSelectionCommand |= dspx::SelectionModel::ClearPreviousSelection;
78+
}
79+
if (command & SetCurrentItem) {
80+
documentSelectionCommand |= dspx::SelectionModel::SetCurrentItem;
81+
}
82+
auto documentItem = q->getLabelDocumentItemFromViewItem(qobject_cast<sflow::LabelViewModel *>(item));
83+
Q_ASSERT(!item || documentItem);
84+
selectionModel->select(documentItem, documentSelectionCommand, dspx::SelectionModel::ST_Label);
85+
}
86+
87+
QObject *LabelSelectionController::currentItem() const {
88+
return q->getLabelViewItemFromDocumentItem(labelSelectionModel->currentItem());
89+
}
90+
91+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef DIFFSCOPE_VISUALEDITOR_LABELSELECTIONCONTROLLER_P_H
2+
#define DIFFSCOPE_VISUALEDITOR_LABELSELECTIONCONTROLLER_P_H
3+
4+
#include <ScopicFlowCore/SelectionController.h>
5+
6+
class QQuickItem;
7+
8+
namespace dspx {
9+
class SelectionModel;
10+
class Label;
11+
class LabelSelectionModel;
12+
class LabelSequence;
13+
}
14+
15+
namespace VisualEditor {
16+
17+
class ProjectViewModelContext;
18+
19+
class LabelSelectionController : public sflow::SelectionController {
20+
Q_OBJECT
21+
public:
22+
explicit LabelSelectionController(ProjectViewModelContext *parent);
23+
~LabelSelectionController() override;
24+
25+
QObjectList getSelectedItems() const override;
26+
QObjectList getItemsBetween(QObject *startItem, QObject *endItem) const override;
27+
void select(QObject *item, SelectionCommand command) override;
28+
QObject *currentItem() const override;
29+
30+
private:
31+
ProjectViewModelContext *q;
32+
dspx::LabelSequence *labelSequence;
33+
dspx::SelectionModel *selectionModel;
34+
dspx::LabelSelectionModel *labelSelectionModel;
35+
};
36+
37+
}
38+
39+
#endif //DIFFSCOPE_VISUALEDITOR_LABELSELECTIONCONTROLLER_P_H

0 commit comments

Comments
 (0)