accurate math on timeline, near-accurate on viewer

This commit is contained in:
itsmattkc
2018-12-25 21:12:25 +11:00
parent edf6f00271
commit 5aca8b881d
6 changed files with 38 additions and 19 deletions
+5 -5
View File
@@ -108,7 +108,7 @@ Timeline::Timeline(QWidget *parent) :
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(setScroll(int)));
connect(ui->videoScrollbar, SIGNAL(valueChanged(int)), ui->video_area, SLOT(setScroll(int)));
connect(ui->audioScrollbar, SIGNAL(valueChanged(int)), ui->audio_area, SLOT(setScroll(int)));
connect(ui->horizontalScrollBar, SIGNAL(resized_scroll(double)), this, SLOT(resized_scroll_listener(double)));
connect(ui->horizontalScrollBar, SIGNAL(resize_move(double)), this, SLOT(resize_move(double)));
update_sequence();
}
@@ -451,7 +451,7 @@ void Timeline::repaint_timeline() {
if (sequence != NULL) {
long sequenceEndFrame = sequence->getEndFrame();
ui->headers->set_scrollbar_max(ui->horizontalScrollBar, sequenceEndFrame, (ui->editAreas->width()/2));
ui->headers->set_scrollbar_max(ui->horizontalScrollBar, sequenceEndFrame, ui->editAreas->width() - getScreenPointFromFrame(zoom, 200));
if (last_frame != sequence->playhead) {
ui->audio_monitor->update();
@@ -1403,7 +1403,7 @@ void Timeline::deselect() {
}
long getFrameFromScreenPoint(double zoom, int x) {
long f = qCeil((float) x / zoom);
long f = qCeil((float) x / zoom);
if (f < 0) {
return 0;
}
@@ -1411,7 +1411,7 @@ long getFrameFromScreenPoint(double zoom, int x) {
}
int getScreenPointFromFrame(double zoom, long frame) {
return (int) qFloor(frame*zoom);
return (int) qFloor(frame*zoom);
}
long Timeline::getTimelineFrameFromScreenPoint(int x) {
@@ -1576,7 +1576,7 @@ void Timeline::transition_menu_select(QAction* a) {
ui->toolTransitionButton->setChecked(true);
}
void Timeline::resized_scroll_listener(double z) {
void Timeline::resize_move(double z) {
set_zoom_value(zoom * z);
}
+2 -2
View File
@@ -223,7 +223,7 @@ private slots:
void transition_menu_select(QAction*);
void resized_scroll_listener(double z);
void resize_move(double d);
private:
void set_zoom_value(double v);
@@ -231,7 +231,7 @@ private:
void decheck_tool_buttons(QObject* sender);
void set_tool(int tool);
long last_frame;
int scroll;
int scroll;
int default_track_height;
};
+4 -3
View File
@@ -65,7 +65,7 @@ Viewer::Viewer(QWidget *parent) :
connect(&recording_flasher, SIGNAL(timeout()), this, SLOT(recording_flasher_update()));
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), ui->headers, SLOT(set_scroll(int)));
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), viewer_widget, SLOT(set_waveform_scroll(int)));
connect(ui->horizontalScrollBar, SIGNAL(resized_scroll(double)), this, SLOT(resized_scroll_listener(double)));
connect(ui->horizontalScrollBar, SIGNAL(resize_move(double)), this, SLOT(resize_move(double)));
connect(ui->zoomComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(zoom_update(int)));
update_playhead_timecode(0);
@@ -431,7 +431,8 @@ void Viewer::set_zoom_value(double d) {
viewer_widget->update();
}
ui->headers->set_scrollbar_max(ui->horizontalScrollBar, seq->getEndFrame(), ui->headers->width());
center_scroll_to_playhead(ui->horizontalScrollBar, ui->headers->get_zoom(), seq->playhead);
if (!ui->horizontalScrollBar->is_resizing())
center_scroll_to_playhead(ui->horizontalScrollBar, ui->headers->get_zoom(), seq->playhead);
}
void Viewer::set_media(Media* m) {
@@ -573,7 +574,7 @@ void Viewer::zoom_update(int i) {
ui->glViewerPane->adjust();
}
void Viewer::resized_scroll_listener(double d) {
void Viewer::resize_move(double d) {
set_zoom_value(ui->headers->get_zoom()*d);
}
+1 -1
View File
@@ -84,7 +84,7 @@ private slots:
void timer_update();
void recording_flasher_update();
void zoom_update(int i);
void resized_scroll_listener(double d);
void resize_move(double d);
private:
void clean_created_seq();
void set_sequence(bool main, Sequence* s);
+25 -7
View File
@@ -4,6 +4,8 @@
#include <QStyle>
#include <QStyleOptionSlider>
#include "debug.h"
#define RESIZE_HANDLE_SIZE 10
ResizableScrollBar::ResizableScrollBar(QWidget *parent) :
@@ -20,6 +22,12 @@ bool ResizableScrollBar::is_resizing() {
void ResizableScrollBar::mousePressEvent(QMouseEvent *e) {
if (resize_init) {
QStyleOptionSlider opt;
initStyleOption(&opt);
QRect sr = style()->subControlRect(QStyle::CC_ScrollBar, &opt,
QStyle::SC_ScrollBarSlider, this);
resize_proc = true;
resize_start = e->pos().x();
} else {
@@ -33,16 +41,26 @@ void ResizableScrollBar::mouseMoveEvent(QMouseEvent *e) {
QRect sr = style()->subControlRect(QStyle::CC_ScrollBar, &opt,
QStyle::SC_ScrollBarSlider, this);
QRect gr = style()->subControlRect(QStyle::CC_ScrollBar, &opt,
QStyle::SC_ScrollBarGroove, this);
if (resize_proc) {
int diff = e->pos().x() - resize_start;
if (resize_top) {
setValue(value() + diff);
diff = -diff;
int diff = (e->pos().x() - resize_start);
if (resize_top) diff = -diff;
double scale = double(sr.width())/double(sr.width()+diff);
if (!qIsInf(scale) && !qIsNull(scale)) {
emit resize_move(scale);
resize_start = e->pos().x();
if (resize_top) {
int slider_min = gr.x();
int slider_max = gr.right() - (sr.width()+diff) + 1;
int val = QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().x() - slider_min, slider_max - slider_min, opt.upsideDown);
setValue(val);
} else {
setValue(qRound(value() * scale));
}
}
int w = sr.width() + diff;
emit resized_scroll(double(sr.width())/double(w));
resize_start = e->pos().x();
} else {
bool new_resize_init = false;
+1 -1
View File
@@ -10,7 +10,7 @@ public:
ResizableScrollBar(QWidget * parent = 0);
bool is_resizing();
signals:
void resized_scroll(double d);
void resize_move(double i);
protected:
void mousePressEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;