From 5aca8b881d2d9a941fe84f07d8d58f5698022c5f Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 25 Dec 2018 21:12:25 +1100 Subject: [PATCH] accurate math on timeline, near-accurate on viewer --- panels/timeline.cpp | 10 +++++----- panels/timeline.h | 4 ++-- panels/viewer.cpp | 7 ++++--- panels/viewer.h | 2 +- ui/resizablescrollbar.cpp | 32 +++++++++++++++++++++++++------- ui/resizablescrollbar.h | 2 +- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/panels/timeline.cpp b/panels/timeline.cpp index a5efdb4be..23e37b03e 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -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); } diff --git a/panels/timeline.h b/panels/timeline.h index 3829f934a..7c91881c1 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -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; }; diff --git a/panels/viewer.cpp b/panels/viewer.cpp index 52d7bfd79..f46810b01 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -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); } diff --git a/panels/viewer.h b/panels/viewer.h index b9cdc7a14..a443254bf 100644 --- a/panels/viewer.h +++ b/panels/viewer.h @@ -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); diff --git a/ui/resizablescrollbar.cpp b/ui/resizablescrollbar.cpp index 77dec0e1a..fd09f46c6 100644 --- a/ui/resizablescrollbar.cpp +++ b/ui/resizablescrollbar.cpp @@ -4,6 +4,8 @@ #include #include +#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; diff --git a/ui/resizablescrollbar.h b/ui/resizablescrollbar.h index 3ba8ab21d..d3d8d0720 100644 --- a/ui/resizablescrollbar.h +++ b/ui/resizablescrollbar.h @@ -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;