added resizable tracks #75

This commit is contained in:
itsmattkc
2018-06-22 16:05:30 -07:00
parent 2fbd9835a3
commit 045015e096
7 changed files with 170 additions and 43 deletions
+10
View File
@@ -433,3 +433,13 @@ void MainWindow::on_actionPreferences_triggered()
PreferencesDialog pd(this);
pd.exec();
}
void MainWindow::on_actionIncrease_Track_Height_triggered()
{
panel_timeline->increase_track_height();
}
void MainWindow::on_actionDecrease_Track_Height_triggered()
{
panel_timeline->decrease_track_height();
}
+4
View File
@@ -111,6 +111,10 @@ private slots:
void on_actionPreferences_triggered();
void on_actionIncrease_Track_Height_triggered();
void on_actionDecrease_Track_Height_triggered();
private:
Ui::MainWindow *ui;
void setup_layout();
+18
View File
@@ -92,6 +92,8 @@
<addaction name="actionTimeline_Track_Lines"/>
<addaction name="actionZoom_In"/>
<addaction name="actionZoom_out"/>
<addaction name="actionIncrease_Track_Height"/>
<addaction name="actionDecrease_Track_Height"/>
</widget>
<widget class="QMenu" name="menuPlayback">
<property name="title">
@@ -474,6 +476,22 @@
<string>Edit Tool Also Seeks</string>
</property>
</action>
<action name="actionIncrease_Track_Height">
<property name="text">
<string>Increase Track Height</string>
</property>
<property name="shortcut">
<string>Ctrl+=</string>
</property>
</action>
<action name="actionDecrease_Track_Height">
<property name="text">
<string>Decrease Track Height</string>
</property>
<property name="shortcut">
<string>Ctrl+-</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
+19 -6
View File
@@ -224,15 +224,17 @@ void Timeline::repaint_timeline() {
}
void Timeline::redraw_all_clips() {
project_changed = true;
if (sequence != NULL) {
project_changed = true;
ui->video_area->redraw_clips();
ui->audio_area->redraw_clips();
ui->headers->update();
ui->video_area->redraw_clips();
ui->audio_area->redraw_clips();
ui->headers->update();
panel_viewer->ui->endTimecode->setText(frame_to_timecode(sequence->getEndFrame()));
panel_viewer->ui->endTimecode->setText(frame_to_timecode(sequence->getEndFrame()));
reset_all_audio();
reset_all_audio();
}
}
void Timeline::select_all() {
@@ -241,6 +243,7 @@ void Timeline::select_all() {
Clip* c = sequence->get_clip(i);
selections.append({c->timeline_in, c->timeline_out, c->track});
}
repaint_timeline();
}
void Timeline::delete_selection(bool ripple_delete) {
@@ -667,6 +670,16 @@ void Timeline::snap_to_clip(long* l, bool playhead_inclusive) {
}
}
void Timeline::increase_track_height() {
ui->video_area->increase_track_height();
ui->audio_area->increase_track_height();
}
void Timeline::decrease_track_height() {
ui->video_area->decrease_track_height();
ui->audio_area->decrease_track_height();
}
void Timeline::deselect() {
selections.clear();
repaint_timeline();
+2
View File
@@ -70,6 +70,8 @@ public:
void split_clip_and_relink(Clip* clip, long frame, bool relink);
void delete_areas_and_relink(QVector<Selection> areas);
void update_sequence();
void increase_track_height();
void decrease_track_height();
int get_snap_range();
int getScreenPointFromFrame(long frame);
+108 -36
View File
@@ -22,11 +22,15 @@
#include <QMenu>
#include <QtMath>
#define TRACK_MIN_HEIGHT 30
#define TRACK_DEFAULT_HEIGHT 60
#define TRACK_HEIGHT_INCREMENT 10
TimelineWidget::TimelineWidget(QWidget *parent) : QWidget(parent)
{
bottom_align = false;
setMouseTracking(true);
track_height = 80;
track_resizing = false;
setMouseTracking(true);
setAcceptDrops(true);
@@ -44,6 +48,15 @@ bool same_sign(int a, int b) {
return (a < 0) == (b < 0);
}
int TimelineWidget::calculate_track_height(int track) {
int index = (track < 0) ? qAbs(track + 1) : track;
while (track_heights.size() < index+1) {
track_heights.append(TRACK_DEFAULT_HEIGHT);
}
qDebug() << track_heights.at(index);
return track_heights.at(index);
}
void TimelineWidget::resizeEvent(QResizeEvent*) {
if (sequence != NULL) redraw_clips();
}
@@ -184,7 +197,10 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) {
case TIMELINE_TOOL_RIPPLE:
case TIMELINE_TOOL_SLIP:
{
if (clip_index >= 0) {
if (track_resizing) {
track_resize_mouse_cache = event->pos().y();
panel_timeline->moving_init = true;
} else if (clip_index >= 0) {
if (panel_timeline->is_clip_selected(sequence->get_clip(clip_index))) {
// TODO if shift is down, deselect it
} else {
@@ -620,7 +636,20 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
panel_timeline->repaint_timeline();
}
} else if (panel_timeline->moving_init) {
if (panel_timeline->moving_proc) {
if (track_resizing) {
int diff = track_resize_mouse_cache - event->pos().y();
int new_height = track_resize_old_value;
if (bottom_align) {
new_height += diff;
} else {
new_height -= diff;
}
if (new_height < TRACK_MIN_HEIGHT) new_height = TRACK_MIN_HEIGHT;
if (new_height != track_heights.at(track_target)) {
track_heights[track_target] = new_height;
redraw_clips();
}
} else if (panel_timeline->moving_proc) {
QPoint pos = event->pos();
update_ghosts(pos);
} else {
@@ -687,10 +716,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
}
}
}
}
// debug code - print the information we got
// qDebug() << "found" << pre_clips.size() << "preceding clips and" << post_clips.size() << "following";
}
}
init_ghosts();
@@ -712,6 +738,8 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
// redraw clips since we changed them
if (repaint) panel_timeline->redraw_all_clips();
} else if (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->tool == TIMELINE_TOOL_RIPPLE) {
track_resizing = false;
QPoint pos = event->pos();
int lim = 5;
@@ -746,8 +774,29 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
if (found) {
setCursor(Qt::SizeHorCursor);
} else {
unsetCursor();
panel_timeline->trim_target = -1;
panel_timeline->trim_target = -1;
// look for track heights
found = false;
int track_y = 0;
for (int i=0;i<track_heights.size();i++) {
int track_height = calculate_track_height(i);
track_y += track_height;
int y_test_value = (bottom_align) ? rect().bottom() - track_y : track_y;
int test_range = 5;
if (pos.y() > y_test_value-test_range && pos.y() < y_test_value+test_range) {
found = true;
track_resizing = true;
track_target = i;
track_resize_old_value = track_height;
}
}
if (found) {
setCursor(Qt::SizeVerCursor);
} else {
unsetCursor();
}
}
} else if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) {
// redraw because we have a cursor
@@ -787,7 +836,7 @@ void TimelineWidget::redraw_clips() {
audio_track_limit = clip->track;
}
QRect clip_rect(panel_timeline->getScreenPointFromFrame(clip->timeline_in), getScreenPointFromTrack(clip->track), clip->getLength() * panel_timeline->zoom, track_height);
QRect clip_rect(panel_timeline->getScreenPointFromFrame(clip->timeline_in), getScreenPointFromTrack(clip->track), clip->getLength() * panel_timeline->zoom, calculate_track_height(clip->track));
clip_painter.fillRect(clip_rect, QColor(clip->color_r, clip->color_g, clip->color_b));
// draw thumbnail/waveform
@@ -860,7 +909,7 @@ void TimelineWidget::redraw_clips() {
} else {
// only draw lines for audio tracks
for (int i=0;i<audio_track_limit;i++) {
int line_y = getScreenPointFromTrack(i) + track_height;
int line_y = getScreenPointFromTrack(i) + calculate_track_height(i);
clip_painter.drawLine(0, line_y, rect().width(), line_y);
}
}
@@ -881,7 +930,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) {
if (is_track_visible(s.track)) {
int selection_y = getScreenPointFromTrack(s.track);
int selection_x = panel_timeline->getScreenPointFromFrame(s.in);
p.fillRect(selection_x, selection_y, panel_timeline->getScreenPointFromFrame(s.out) - selection_x, track_height, QColor(0, 0, 0, 64));
p.fillRect(selection_x, selection_y, panel_timeline->getScreenPointFromFrame(s.out) - selection_x, calculate_track_height(s.track), QColor(0, 0, 0, 64));
}
}
@@ -892,7 +941,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) {
int ghost_x = panel_timeline->getScreenPointFromFrame(g.in);
int ghost_y = getScreenPointFromTrack(g.track);
int ghost_width = panel_timeline->getScreenPointFromFrame(g.out - g.in) - 1;
int ghost_height = track_height - 1;
int ghost_height = calculate_track_height(g.track) - 1;
p.setPen(QColor(255, 255, 0));
for (int j=0;j<GHOST_THICKNESS;j++) {
p.drawRect(ghost_x+j, ghost_y+j, ghost_width-j-j, ghost_height-j-j);
@@ -923,12 +972,27 @@ void TimelineWidget::paintEvent(QPaintEvent*) {
int cursor_y = getScreenPointFromTrack(panel_timeline->cursor_track);
p.setPen(Qt::gray);
p.drawLine(cursor_x, cursor_y, cursor_x, cursor_y + track_height);
p.drawLine(cursor_x, cursor_y, cursor_x, cursor_y + calculate_track_height(panel_timeline->cursor_track));
}
}
}
}
void TimelineWidget::increase_track_height() {
for (int i=0;i<track_heights.size();i++) {
track_heights[i] += TRACK_HEIGHT_INCREMENT;
}
redraw_clips();
}
void TimelineWidget::decrease_track_height() {
for (int i=0;i<track_heights.size();i++) {
track_heights[i] -= TRACK_HEIGHT_INCREMENT;
if (track_heights[i] < TRACK_MIN_HEIGHT) track_heights[i] = TRACK_MIN_HEIGHT;
}
redraw_clips();
}
bool TimelineWidget::is_track_visible(int track) {
return ((bottom_align && track < 0) || (!bottom_align && track >= 0));
}
@@ -937,30 +1001,38 @@ bool TimelineWidget::is_track_visible(int track) {
// screen point <-> frame/track functions
// **************************************
int TimelineWidget::getTrackFromScreenPoint(int y) {
if (bottom_align) {
y -= rect().bottom();
if (show_track_lines) y -= 1;
} else {
y -= 1;
}
int temp_track_height = track_height;
if (show_track_lines) temp_track_height--;
return (int)qFloor((float) (y)/ (float) temp_track_height);
int TimelineWidget::getTrackFromScreenPoint(int y) {
if (bottom_align) {
y = qAbs(y - rect().height());
}
y--;
int height_measure = 0;
int counter = (bottom_align) ? -1 : 0;
int track_height = calculate_track_height(counter);
while (y > height_measure+track_height) {
if (show_track_lines && counter != -1) y--;
height_measure += track_height;
if (bottom_align) {
counter--;
} else {
counter++;
}
track_height = calculate_track_height(counter);
}
return counter;
}
int TimelineWidget::getScreenPointFromTrack(int track) {
int temp_track_height = track_height;
if (show_track_lines) temp_track_height++;
int y = track * temp_track_height;
if (bottom_align) { // video track
y += rect().bottom();
if (show_track_lines) y += 1;
} else { // audio track
y += 1;
}
return y;
int y = 0;
int counter = 0;
while (counter != track) {
if (bottom_align) counter--;
y += calculate_track_height(counter);
if (!bottom_align) counter++;
if (show_track_lines && counter != -1) y++;
}
y++;
return (bottom_align) ? rect().height() - y : y;
}
int TimelineWidget::getClipIndexFromCoords(long frame, int track) {
+9 -1
View File
@@ -20,6 +20,8 @@ public:
bool bottom_align;
void redraw_clips();
void increase_track_height();
void decrease_track_height();
protected:
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent*);
@@ -40,7 +42,13 @@ private:
int getTrackFromScreenPoint(int y);
int getScreenPointFromTrack(int track);
int getClipIndexFromCoords(long frame, int track);
int track_height;
QVector<int> track_heights;
int track_resize_mouse_cache;
int track_resize_old_value;
bool track_resizing;
int track_target;
int calculate_track_height(int track);
QList<Clip*> pre_clips;
QList<Clip*> post_clips;