This commit is contained in:
itsmattkc
2018-06-23 02:00:51 -07:00
parent fb81bba255
commit f607a31078
5 changed files with 85 additions and 57 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.6.2, 2018-06-23T00:49:14. -->
<!-- Written by QtCreator 4.6.2, 2018-06-23T01:02:11. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
+34 -4
View File
@@ -144,6 +144,26 @@ void Timeline::go_to_end() {
seek(sequence->getEndFrame());
}
int Timeline::get_track_height_size(bool video) {
if (video) {
return video_track_heights.size();
} else {
return audio_track_heights.size();
}
}
int Timeline::calculate_track_height(int track, int value) {
int index = (track < 0) ? qAbs(track + 1) : track;
QVector<int>& vector = (track < 0) ? video_track_heights : audio_track_heights;
while (vector.size() < index+1) {
vector.append(TRACK_DEFAULT_HEIGHT);
}
if (value > -1) {
vector[index] = value;
}
return vector.at(index);
}
void Timeline::update_sequence() {
bool null_sequence = (sequence == NULL);
@@ -677,13 +697,23 @@ 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();
for (int i=0;i<video_track_heights.size();i++) {
video_track_heights[i] += TRACK_HEIGHT_INCREMENT;
}
for (int i=0;i<audio_track_heights.size();i++) {
audio_track_heights[i] += TRACK_HEIGHT_INCREMENT;
}
}
void Timeline::decrease_track_height() {
ui->video_area->decrease_track_height();
ui->audio_area->decrease_track_height();
for (int i=0;i<video_track_heights.size();i++) {
video_track_heights[i] -= TRACK_HEIGHT_INCREMENT;
if (video_track_heights[i] < TRACK_MIN_HEIGHT) video_track_heights[i] = TRACK_MIN_HEIGHT;
}
for (int i=0;i<audio_track_heights.size();i++) {
audio_track_heights[i] -= TRACK_HEIGHT_INCREMENT;
if (audio_track_heights[i] < TRACK_MIN_HEIGHT) audio_track_heights[i] = TRACK_MIN_HEIGHT;
}
}
void Timeline::deselect() {
+5
View File
@@ -108,6 +108,11 @@ public:
int drag_track_start;
void redraw_all_clips(bool changed);
QVector<int> video_track_heights;
QVector<int> audio_track_heights;
int get_track_height_size(bool video);
int calculate_track_height(int track, int height);
// snapping
bool snapping;
bool snapped;
+41 -48
View File
@@ -22,10 +22,6 @@
#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;
@@ -48,14 +44,6 @@ 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);
}
return track_heights.at(index);
}
void TimelineWidget::resizeEvent(QResizeEvent*) {
if (sequence != NULL) redraw_clips();
}
@@ -169,6 +157,8 @@ void TimelineWidget::dropEvent(QDropEvent* event) {
panel_timeline->importing = false;
panel_timeline->snapped = false;
setFocus();
panel_timeline->redraw_all_clips(true);
}
}
@@ -654,10 +644,8 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
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();
}
panel_timeline->calculate_track_height(track_target, new_height);
redraw_clips();
} else if (panel_timeline->moving_proc) {
QPoint pos = event->pos();
update_ghosts(pos);
@@ -788,15 +776,16 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
// 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);
for (int i=0;i<panel_timeline->get_track_height_size(bottom_align);i++) {
int track = (bottom_align) ? -1-i : i;
int track_height = panel_timeline->calculate_track_height(track, -1);
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_target = track;
track_resize_old_value = track_height;
}
}
@@ -845,7 +834,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, calculate_track_height(clip->track));
QRect clip_rect(panel_timeline->getScreenPointFromFrame(clip->timeline_in), getScreenPointFromTrack(clip->track), clip->getLength() * panel_timeline->zoom, panel_timeline->calculate_track_height(clip->track, -1));
clip_painter.fillRect(clip_rect, QColor(clip->color_r, clip->color_g, clip->color_b));
// draw thumbnail/waveform
@@ -918,7 +907,8 @@ 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) + calculate_track_height(i);
// TODO just make i+1?
int line_y = getScreenPointFromTrack(i) + panel_timeline->calculate_track_height(i, -1);
clip_painter.drawLine(0, line_y, rect().width(), line_y);
}
}
@@ -939,7 +929,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, calculate_track_height(s.track), QColor(0, 0, 0, 64));
p.fillRect(selection_x, selection_y, panel_timeline->getScreenPointFromFrame(s.out) - selection_x, panel_timeline->calculate_track_height(s.track, -1), QColor(0, 0, 0, 64));
}
}
@@ -950,7 +940,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 = calculate_track_height(g.track) - 1;
int ghost_height = panel_timeline->calculate_track_height(g.track, -1) - 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);
@@ -981,27 +971,12 @@ 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 + calculate_track_height(panel_timeline->cursor_track));
p.drawLine(cursor_x, cursor_y, cursor_x, cursor_y + panel_timeline->calculate_track_height(panel_timeline->cursor_track, -1));
}
}
}
}
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));
}
@@ -1011,22 +986,40 @@ bool TimelineWidget::is_track_visible(int track) {
// **************************************
int TimelineWidget::getTrackFromScreenPoint(int y) {
// if (bottom_align) {
// y = -(y - rect().height());
// }
// y--;
// int height_measure = 0;
// int counter = (bottom_align && y > 0) ? -1 : 0;
// int track_height = panel_timeline->calculate_track_height(counter, -1);
// while (y > height_measure+track_height) {
// if (show_track_lines && counter != -1) y--;
// height_measure += track_height;
// if (bottom_align && y > 0) {
// counter--;
// } else {
// counter++;
// }
// track_height = panel_timeline->calculate_track_height(counter, -1);
// }
// return counter;
if (bottom_align) {
y = qAbs(y - rect().height());
y = -(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) {
int counter = ((!bottom_align && y > 0) || (bottom_align && y < 0)) ? 0 : -1;
int track_height = panel_timeline->calculate_track_height(counter, -1);
while (qAbs(y) > height_measure+track_height) {
if (show_track_lines && counter != -1) y--;
height_measure += track_height;
if (bottom_align) {
counter--;
} else {
if ((!bottom_align && y > 0) || (bottom_align && y < 0)) {
counter++;
} else {
counter--;
}
track_height = calculate_track_height(counter);
track_height = panel_timeline->calculate_track_height(counter, -1);
}
return counter;
}
@@ -1036,7 +1029,7 @@ int TimelineWidget::getScreenPointFromTrack(int track) {
int counter = 0;
while (counter != track) {
if (bottom_align) counter--;
y += calculate_track_height(counter);
y += panel_timeline->calculate_track_height(counter, -1);
if (!bottom_align) counter++;
if (show_track_lines && counter != -1) y++;
}
+4 -4
View File
@@ -7,6 +7,10 @@
#define GHOST_THICKNESS 2 // thiccccc
#define CLIP_TEXT_PADDING 3
#define TRACK_MIN_HEIGHT 30
#define TRACK_DEFAULT_HEIGHT 60
#define TRACK_HEIGHT_INCREMENT 10
struct Sequence;
struct Clip;
class Timeline;
@@ -20,8 +24,6 @@ public:
bool bottom_align;
void redraw_clips();
void increase_track_height();
void decrease_track_height();
protected:
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent*);
@@ -43,12 +45,10 @@ private:
int getScreenPointFromTrack(int track);
int getClipIndexFromCoords(long frame, int track);
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;