added razor/edit tool snapping
This commit is contained in:
@@ -175,3 +175,10 @@ void MainWindow::on_action_Redo_triggered()
|
||||
panel_timeline->redo();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionSplit_at_Playhead_triggered()
|
||||
{
|
||||
if (panel_timeline->focused()) {
|
||||
panel_timeline->split_at_playhead();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ private slots:
|
||||
|
||||
void on_action_Redo_triggered();
|
||||
|
||||
void on_actionSplit_at_Playhead_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
void setup_layout();
|
||||
|
||||
+11
-1
@@ -24,7 +24,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>653</width>
|
||||
<height>21</height>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu_File">
|
||||
@@ -64,6 +64,8 @@
|
||||
<addaction name="actionRipple_Delete"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSelect_All"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSplit_at_Playhead"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuWindow">
|
||||
<property name="title">
|
||||
@@ -287,6 +289,14 @@
|
||||
<string>Shift+Del</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSplit_at_Playhead">
|
||||
<property name="text">
|
||||
<string>Split at Playhead</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+K</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.6.1, 2018-06-07T16:17:16. -->
|
||||
<!-- Written by QtCreator 4.6.1, 2018-06-07T21:15:23. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -292,7 +292,7 @@
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">olive.pro</value>
|
||||
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">C:/Users/Matt/Documents/temp</value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
|
||||
+38
-2
@@ -20,7 +20,7 @@ Timeline::Timeline(QWidget *parent) :
|
||||
{
|
||||
selecting = moving_init = moving_proc = splitting = importing = playing = trim_in = snapped = false;
|
||||
snapping = true;
|
||||
last_frame = playhead = snap_point = 0;
|
||||
last_frame = playhead = snap_point = cursor_frame = cursor_track = 0;
|
||||
trim_target = -1;
|
||||
|
||||
ui->setupUi(this);
|
||||
@@ -340,6 +340,42 @@ void Timeline::on_toolSlipButton_toggled(bool checked)
|
||||
void Timeline::on_snappingButton_toggled(bool checked)
|
||||
{
|
||||
snapping = checked;
|
||||
}
|
||||
|
||||
qDebug() << "clips vector size:" << sizeof(Clip) * sequence->clip_count();
|
||||
void Timeline::split_at_playhead() {
|
||||
bool split_selected = false;
|
||||
|
||||
if (selections.size() > 0) {
|
||||
// see if whole clips are selected
|
||||
for (int j=0;j<sequence->clip_count();j++) {
|
||||
if (is_clip_selected(j)) {
|
||||
sequence->split_clip(j, playhead);
|
||||
split_selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
// split a selection if not
|
||||
if (!split_selected) {
|
||||
for (int j=0;j<sequence->clip_count();j++) {
|
||||
for (int i=0;i<selections.size();i++) {
|
||||
const Selection& s = selections.at(i);
|
||||
if (s.track == sequence->get_clip(j).track) {
|
||||
sequence->split_clip(j, s.in);
|
||||
sequence->split_clip(j, s.out);
|
||||
split_selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if nothing was selected or no selections fell within playhead, simply split at playhead
|
||||
if (!split_selected) {
|
||||
for (int j=0;j<sequence->clip_count();j++) {
|
||||
sequence->split_clip(j, playhead);
|
||||
split_selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (split_selected) redraw_all_clips();
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
void zoom_out();
|
||||
void undo();
|
||||
void redo();
|
||||
void split_at_playhead();
|
||||
void set_sequence(Sequence* s);
|
||||
|
||||
Sequence* sequence;
|
||||
@@ -85,6 +86,8 @@ public:
|
||||
|
||||
// shared information
|
||||
int tool;
|
||||
long cursor_frame;
|
||||
int cursor_track;
|
||||
float zoom;
|
||||
long drag_frame_start;
|
||||
int drag_track_start;
|
||||
|
||||
@@ -113,20 +113,10 @@ void Sequence::split_clip(int i, long frame) {
|
||||
}
|
||||
}
|
||||
|
||||
void Sequence::split_at_playhead(long frame) {
|
||||
for (int j=0;j<clip_count();j++) {
|
||||
Clip& c = get_clip(j);
|
||||
if (c.timeline_in < frame && c.timeline_out > frame) {
|
||||
split_clip(j, frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sequence::undo_add_current() {
|
||||
undo_pointer++;
|
||||
undo_stack.resize(undo_pointer);
|
||||
undo_stack.append(clips);
|
||||
qDebug() << "a pointer:" << undo_pointer << undo_stack.size();
|
||||
}
|
||||
|
||||
void Sequence::undo() {
|
||||
@@ -136,7 +126,6 @@ void Sequence::undo() {
|
||||
} else {
|
||||
qDebug() << "[INFO] No more undos";
|
||||
}
|
||||
qDebug() << "u pointer:" << undo_pointer << undo_stack.size();
|
||||
}
|
||||
void Sequence::redo() {
|
||||
if (undo_pointer == undo_stack.size() - 1) {
|
||||
@@ -145,5 +134,4 @@ void Sequence::redo() {
|
||||
undo_pointer++;
|
||||
clips = undo_stack[undo_pointer];
|
||||
}
|
||||
qDebug() << "r pointer:" << undo_pointer << undo_stack.size();
|
||||
}
|
||||
|
||||
+1
-2
@@ -18,8 +18,7 @@ public:
|
||||
Clip& get_clip(int i);
|
||||
void delete_clip(int i);
|
||||
void delete_area(long in, long out, int track);
|
||||
void split_clip(int i, long frame);
|
||||
void split_at_playhead(long frame);
|
||||
void split_clip(int i, long frame);
|
||||
void get_track_limits(int* video_tracks, int* audio_tracks);
|
||||
long getEndFrame();
|
||||
int width;
|
||||
|
||||
+27
-19
@@ -128,10 +128,15 @@ void TimelineWidget::dropEvent(QDropEvent* event) {
|
||||
}
|
||||
|
||||
void TimelineWidget::mousePressEvent(QMouseEvent *event) {
|
||||
QPoint pos = event->pos();
|
||||
if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) {
|
||||
panel_timeline->drag_frame_start = panel_timeline->cursor_frame;
|
||||
panel_timeline->drag_track_start = panel_timeline->cursor_track;
|
||||
} else {
|
||||
QPoint pos = event->pos();
|
||||
panel_timeline->drag_frame_start = getFrameFromScreenPoint(pos.x(), false);
|
||||
panel_timeline->drag_track_start = getTrackFromScreenPoint(pos.y());
|
||||
}
|
||||
|
||||
panel_timeline->drag_frame_start = getFrameFromScreenPoint(pos.x(), false);
|
||||
panel_timeline->drag_track_start = getTrackFromScreenPoint(pos.y());
|
||||
int clip_index = panel_timeline->trim_target;
|
||||
if (clip_index == -1) clip_index = getClipIndexFromCoords(panel_timeline->drag_frame_start, panel_timeline->drag_track_start);
|
||||
|
||||
@@ -311,12 +316,12 @@ bool subvalidate_snapping(Ghost& g, long* frame_diff, long snap_point) {
|
||||
long in_validator = g.old_in + *frame_diff - snap_point;
|
||||
long out_validator = g.old_out + *frame_diff - snap_point;
|
||||
|
||||
if (in_validator > -snap_range && in_validator < snap_range) {
|
||||
if ((panel_timeline->trim_target == -1 || panel_timeline->trim_in) && in_validator > -snap_range && in_validator < snap_range) {
|
||||
*frame_diff -= in_validator;
|
||||
panel_timeline->snap_point = snap_point;
|
||||
panel_timeline->snapped = true;
|
||||
return true;
|
||||
} else if (out_validator > -snap_range && out_validator < snap_range) {
|
||||
} else if (!panel_timeline->trim_in && out_validator > -snap_range && out_validator < snap_range) {
|
||||
*frame_diff -= out_validator;
|
||||
panel_timeline->snap_point = snap_point;
|
||||
panel_timeline->snapped = true;
|
||||
@@ -505,25 +510,30 @@ void TimelineWidget::update_ghosts(QPoint& mouse_pos) {
|
||||
}
|
||||
|
||||
void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (panel_timeline->selecting) {
|
||||
QPoint pos = event->pos();
|
||||
if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) {
|
||||
panel_timeline->cursor_frame = getFrameFromScreenPoint(event->pos().x(), false);
|
||||
panel_timeline->cursor_track = getTrackFromScreenPoint(event->pos().y());
|
||||
|
||||
int current_selection_track = getTrackFromScreenPoint(pos.y());
|
||||
long current_selection_frame = getFrameFromScreenPoint(pos.x(), false);;
|
||||
int selection_count = 1 + qMax(current_selection_track, panel_timeline->drag_track_start) - qMin(current_selection_track, panel_timeline->drag_track_start);
|
||||
int limit = getFrameFromScreenPoint(10, false);
|
||||
if (panel_timeline->snapping && panel_timeline->cursor_frame > panel_timeline->playhead-limit-1 && panel_timeline->cursor_frame < panel_timeline->playhead+limit+1) {
|
||||
panel_timeline->cursor_frame = panel_timeline->playhead;
|
||||
}
|
||||
}
|
||||
if (panel_timeline->selecting) {
|
||||
int selection_count = 1 + qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start) - qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start);
|
||||
if (panel_timeline->selections.size() != selection_count) {
|
||||
panel_timeline->selections.resize(selection_count);
|
||||
}
|
||||
int minimum_selection_track = qMin(current_selection_track, panel_timeline->drag_track_start);
|
||||
int minimum_selection_track = qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start);
|
||||
for (int i=0;i<selection_count;i++) {
|
||||
Selection* s = &panel_timeline->selections[i];
|
||||
s->track = minimum_selection_track + i;
|
||||
long in = panel_timeline->drag_frame_start;
|
||||
long out = current_selection_frame;
|
||||
long out = panel_timeline->cursor_frame;
|
||||
s->in = qMin(in, out);
|
||||
s->out = qMax(in, out);
|
||||
}
|
||||
panel_timeline->playhead = qMin(panel_timeline->drag_frame_start, current_selection_frame);
|
||||
panel_timeline->playhead = qMin(panel_timeline->drag_frame_start, panel_timeline->cursor_frame);
|
||||
panel_timeline->repaint_timeline();
|
||||
} else if (panel_timeline->moving_init) {
|
||||
QPoint pos = event->pos();
|
||||
@@ -608,7 +618,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
|
||||
} else if (panel_timeline->splitting) {
|
||||
QPoint pos = event->pos();
|
||||
|
||||
int track = getTrackFromScreenPoint(pos.y());
|
||||
int track = panel_timeline->cursor_track;
|
||||
bool repaint = false;
|
||||
for (int i=0;i<panel_timeline->sequence->clip_count();i++) {
|
||||
if (panel_timeline->sequence->get_clip(i).track == track) {
|
||||
@@ -770,11 +780,9 @@ void TimelineWidget::paintEvent(QPaintEvent*) {
|
||||
|
||||
// Draw edit cursor
|
||||
if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) {
|
||||
QPoint mouse_pos = mapFromGlobal(QCursor::pos());
|
||||
int track = getTrackFromScreenPoint(mouse_pos.y());
|
||||
if (is_track_visible(track)) {
|
||||
int cursor_x = getScreenPointFromFrame(getFrameFromScreenPoint(mouse_pos.x(), false));
|
||||
int cursor_y = getScreenPointFromTrack(track);
|
||||
if (is_track_visible(panel_timeline->cursor_track)) {
|
||||
int cursor_x = getScreenPointFromFrame(panel_timeline->cursor_frame);
|
||||
int cursor_y = getScreenPointFromTrack(panel_timeline->cursor_track);
|
||||
|
||||
p.setPen(Qt::gray);
|
||||
p.drawLine(cursor_x, cursor_y, cursor_x, cursor_y + track_height);
|
||||
|
||||
Reference in New Issue
Block a user