fully implemented clip markers, fixes #333

This commit is contained in:
itsmattkc
2019-02-04 10:54:05 +11:00
parent 7fca1f2792
commit 53f6d2278f
5 changed files with 119 additions and 101 deletions
+72 -54
View File
@@ -6,84 +6,102 @@
#include "project/sequence.h"
#include "project/clip.h"
#include "panels/panels.h"
#include "panels/viewer.h"
#include <QInputDialog>
#include <QCoreApplication>
void draw_marker(QPainter &p, int x, int y, int bottom, bool selected, bool flipped) {
const QPoint points[5] = {
QPoint(x, bottom),
QPoint(x + MARKER_SIZE, bottom - MARKER_SIZE),
QPoint(x + MARKER_SIZE, y),
QPoint(x - MARKER_SIZE, y),
QPoint(x - MARKER_SIZE, bottom - MARKER_SIZE)
};
p.setPen(Qt::black);
if (selected) {
p.setBrush(QColor(208, 255, 208));
} else {
p.setBrush(QColor(128, 224, 128));
}
p.drawPolygon(points, 5);
const QPoint points[5] = {
QPoint(x, bottom),
QPoint(x + MARKER_SIZE, bottom - MARKER_SIZE),
QPoint(x + MARKER_SIZE, y),
QPoint(x - MARKER_SIZE, y),
QPoint(x - MARKER_SIZE, bottom - MARKER_SIZE)
};
p.setPen(Qt::black);
if (selected) {
p.setBrush(QColor(208, 255, 208));
} else {
p.setBrush(QColor(128, 224, 128));
}
p.drawPolygon(points, 5);
}
void set_marker_internal(Sequence* seq, const QVector<int>& clips) {
// if clips is empty, the marker is being added to the sequence
// if clips is empty, the marker is being added to the sequence
// add_marker is used to determine whether we're adding a marker, depending on whether the user input a marker name
// however if (config.set_name_with_marker) is true, we don't need a marker name so we just add
bool add_marker = !config.set_name_with_marker;
// add_marker is used to determine whether we're adding a marker, depending on whether the user input a marker name
// however if (config.set_name_with_marker) is true, we don't need a marker name so we just add
bool add_marker = !config.set_name_with_marker;
QString marker_name;
QString marker_name;
// if (config.set_name_with_marker) is false (set above), ask for a marker name
if (!add_marker) {
QInputDialog d(mainWindow);
d.setWindowTitle(QCoreApplication::translate("Marker", "Set Marker"));
d.setLabelText(clips.size() > 0
? QCoreApplication::translate("Marker", "Set clip marker name:")
: QCoreApplication::translate("Marker", "Set sequence marker name:"));
d.setInputMode(QInputDialog::TextInput);
add_marker = (d.exec() == QDialog::Accepted);
marker_name = d.textValue();
}
// if (config.set_name_with_marker) is false (set above), ask for a marker name
if (!add_marker) {
QInputDialog d(mainWindow);
d.setWindowTitle(QCoreApplication::translate("Marker", "Set Marker"));
d.setLabelText(clips.size() > 0
? QCoreApplication::translate("Marker", "Set clip marker name:")
: QCoreApplication::translate("Marker", "Set sequence marker name:"));
d.setInputMode(QInputDialog::TextInput);
add_marker = (d.exec() == QDialog::Accepted);
marker_name = d.textValue();
}
// if we've decided to add a marker
if (add_marker) {
// if we've decided to add a marker
if (add_marker) {
ComboAction* ca = new ComboAction();
ComboAction* ca = new ComboAction();
if (clips.size() > 0) {
if (clips.size() > 0) {
// add a marker action for each clip
foreach (int i, clips) {
Clip* c = seq->clips.at(i);
ca->append(new AddMarkerAction(false,
c,
seq->playhead - c->timeline_in + c->clip_in,
marker_name));
}
// add a marker action for each clip
foreach (int i, clips) {
Clip* c = seq->clips.at(i);
ca->append(new AddMarkerAction(&c->get_markers(),
seq->playhead - c->timeline_in + c->clip_in,
marker_name));
}
} else {
} else {
// if no clips are selected, we're adding a marker to the sequence
ca->append(new AddMarkerAction(true, seq, seq->playhead, marker_name));
// if no clips are selected, we're adding a marker to the sequence
}
// kind of hacky, we get the correct marker structure from the viewer panel object that the sequence is attached to
if (seq == panel_footage_viewer->seq) {
// get correct marker reference from footage viewer
ca->append(new AddMarkerAction(panel_footage_viewer->marker_ref, seq->playhead, marker_name));
} else if (seq == panel_sequence_viewer->seq) {
// get correct marker reference from sequence viewer
ca->append(new AddMarkerAction(panel_sequence_viewer->marker_ref, seq->playhead, marker_name));
} else {
// fallback to using markers from sequence provided
ca->append(new AddMarkerAction(&seq->markers, seq->playhead, marker_name));
}
}
// push action
undo_stack.push(ca);
// push action
undo_stack.push(ca);
// redraw UI for new markers
update_ui(false);
// redraw UI for new markers
update_ui(false);
panel_footage_viewer->update_viewer();
}
}
}
void set_marker_internal(Sequence* seq) {
// create empty clip array
QVector<int> clips;
// create empty clip array
QVector<int> clips;
set_marker_internal(seq, clips);
set_marker_internal(seq, clips);
}
+13 -22
View File
@@ -804,23 +804,18 @@ void SetAutoscaleAction::redo() {
mainWindow->setWindowModified(true);
}
AddMarkerAction::AddMarkerAction(bool is_sequence, void* s, long t, QString n) :
is_sequence_internal(is_sequence),
target(s),
AddMarkerAction::AddMarkerAction(QVector<Marker>* m, long t, QString n) :
active_array(m),
time(t),
name(n),
old_project_changed(mainWindow->isWindowModified())
{}
void AddMarkerAction::undo() {
QVector<Marker>& markers = is_sequence_internal ?
static_cast<Sequence*>(target)->markers :
static_cast<Clip*>(target)->get_markers();
if (index == -1) {
markers.removeLast();
active_array->removeLast();
} else {
markers[index].name = old_name;
active_array[0][index].name = old_name;
}
mainWindow->setWindowModified(old_project_changed);
@@ -829,12 +824,8 @@ void AddMarkerAction::undo() {
void AddMarkerAction::redo() {
index = -1;
QVector<Marker>& markers = is_sequence_internal ?
static_cast<Sequence*>(target)->markers :
static_cast<Clip*>(target)->get_markers();
for (int i=0;i<markers.size();i++) {
if (markers.at(i).frame == time) {
for (int i=0;i<active_array->size();i++) {
if (active_array->at(i).frame == time) {
index = i;
break;
}
@@ -844,10 +835,10 @@ void AddMarkerAction::redo() {
Marker m;
m.frame = time;
m.name = name;
markers.append(m);
active_array->append(m);
} else {
old_name = markers.at(index).name;
markers[index].name = name;
old_name = active_array->at(index).name;
active_array[0][index].name = name;
}
mainWindow->setWindowModified(true);
@@ -871,14 +862,14 @@ void MoveMarkerAction::redo() {
}
DeleteMarkerAction::DeleteMarkerAction(QVector<Marker> *m) :
active_array(m),
active_array(m),
sorted(false),
old_project_changed(mainWindow->isWindowModified())
{}
void DeleteMarkerAction::undo() {
for (int i=markers.size()-1;i>=0;i--) {
active_array->insert(markers.at(i), copies.at(i));
active_array->insert(markers.at(i), copies.at(i));
}
mainWindow->setWindowModified(old_project_changed);
}
@@ -887,14 +878,14 @@ void DeleteMarkerAction::redo() {
for (int i=0;i<markers.size();i++) {
// correct future removals
if (!sorted) {
copies.append(active_array->at(markers.at(i)));
copies.append(active_array->at(markers.at(i)));
for (int j=i+1;j<markers.size();j++) {
if (markers.at(j) > markers.at(i)) {
markers[j]--;
}
}
}
active_array->removeAt(markers.at(i));
active_array->removeAt(markers.at(i));
}
sorted = true;
mainWindow->setWindowModified(true);
+4 -5
View File
@@ -384,12 +384,11 @@ private:
class AddMarkerAction : public QUndoCommand {
public:
AddMarkerAction(bool is_sequence, void* s, long t, QString n);
AddMarkerAction(QVector<Marker>* m, long t, QString n);
void undo();
void redo();
private:
bool is_sequence_internal;
void* target;
QVector<Marker>* active_array;
long time;
QString name;
QString old_name;
@@ -411,12 +410,12 @@ private:
class DeleteMarkerAction : public QUndoCommand {
public:
DeleteMarkerAction(QVector<Marker>* m);
DeleteMarkerAction(QVector<Marker>* m);
void undo();
void redo();
QVector<int> markers;
private:
QVector<Marker>* active_array;
QVector<Marker>* active_array;
QVector<Marker> copies;
bool sorted;
bool old_project_changed;