Skip to content

Commit

Permalink
[Qt/gui] Reset thumb slider on seek error, try to resume playback
Browse files Browse the repository at this point in the history
This fixes the issue of debug messages emitted indefinitely when the
thumb slider has been moved by the mouse wheel and not returned to the
neutral position by the user, potentially consuming all available space
on the filesystem when redirected to file like on macOS and Windows.
  • Loading branch information
eumagga0x2a committed Jun 7, 2021
1 parent 04fc95a commit cd206a7
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 31 deletions.
72 changes: 51 additions & 21 deletions avidemux/qt4/ADM_userInterfaces/ADM_gui/Q_gui2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,59 @@ void MainWindow::sliderWheel(int way)
sendAction(ACT_PreviousKFrame);

}

/**
* \fn thumbSlider_valueEmitted
* \brief Slot to handle signals from the thumb slider.
*/
void MainWindow::thumbSlider_valueEmitted(int value)
{
if (value > 0)
nextIntraFrame();
else
previousIntraFrame();
if (!avifileinfo)
{
if (value)
thumbSlider->reset();
return;
}

if (playing)
{
if (getPreviewMode() != ADM_PREVIEW_NONE)
return;
sendAction(ACT_PlayAvi); // stop playback;
dragWhilePlay = true;
return;
} else if (dragWhilePlay && !value)
{
dragWhilePlay = false;
if (getPreviewMode() == ADM_PREVIEW_NONE)
sendAction(ACT_PlayAvi); // resume playback;
return;
}

if (!value) return;

bool success = true;
if (value > 0)
success = admPreview::nextKeyFrame();
else
success = admPreview::previousKeyFrame();
if (success)
{
uint64_t total = video_body->getVideoDuration();
if (total)
{
uint64_t pts = admPreview::getCurrentPts();
UI_setCurrentTime(pts);

double percentage = pts;
percentage /= total;
percentage *= 100;

UI_setScale(percentage);
}
return;
}
thumbSlider->reset();
dragWhilePlay = false;
}

void MainWindow::volumeChange( int u )
Expand Down Expand Up @@ -1854,22 +1900,6 @@ void MainWindow::setBlockResizingFlag(bool block)
blockResizing = block;
}

void MainWindow::previousIntraFrame(void)
{
if (ui.spinBox_TimeValue->hasFocus())
ui.spinBox_TimeValue->stepDown();
else
sendAction(ACT_PreviousKFrame);
}

void MainWindow::nextIntraFrame(void)
{
if (ui.spinBox_TimeValue->hasFocus())
ui.spinBox_TimeValue->stepUp();
else
sendAction(ACT_NextKFrame);
}

/**
\fn volumeWidgetOperational
*/
Expand Down
2 changes: 0 additions & 2 deletions avidemux/qt4/ADM_userInterfaces/ADM_gui/Q_gui2.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ public slots:
void audioToggled(bool checked);
void previewModeChangedFromMenu(bool status);
void previewModeChangedFromToolbar(bool status);
void previousIntraFrame(void);
void nextIntraFrame(void);
void timeChangeFinished(void);
void currentFrameChanged(void);
void currentTimeChanged(void);
Expand Down
33 changes: 26 additions & 7 deletions avidemux/qt4/ADM_userInterfaces/ADM_gui/T_thumbSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ThumbSlider::ThumbSlider(QWidget *parent) : QAbstractSlider(parent)
setMinimum(-100);
setValue(0);

timerId = count = lock = pos = 0;
timerId = count = lock = pos = stopping = 0;
}

void ThumbSlider::timerEvent(QTimerEvent *event)
Expand Down Expand Up @@ -51,6 +51,16 @@ void ThumbSlider::timerEvent(QTimerEvent *event)
lock--;
}

void ThumbSlider::stop(void)
{
if (timerId)
killTimer(timerId);
setValue(0);
timerId = count = pos = 0;

triggerAction(SliderNoAction);
}

void ThumbSlider::paintEvent(QPaintEvent *event)
{
QPainter painter;
Expand All @@ -67,6 +77,7 @@ void ThumbSlider::paintEvent(QPaintEvent *event)

void ThumbSlider::mousePressEvent(QMouseEvent *event)
{
if (stopping) return;
if (event->buttons() & Qt::LeftButton)
{
int value = QStyle::sliderValueFromPosition(minimum(), maximum(), event->x(), width(), false);
Expand All @@ -79,6 +90,7 @@ void ThumbSlider::mousePressEvent(QMouseEvent *event)

void ThumbSlider::mouseMoveEvent(QMouseEvent *event)
{
if (stopping) return;
if (event->buttons() & Qt::LeftButton)
{
int value = QStyle::sliderValueFromPosition(minimum(), maximum(), event->x(), width(), false);
Expand All @@ -92,11 +104,9 @@ void ThumbSlider::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() & Qt::LeftButton)
{
killTimer(timerId);
setValue(0);
timerId = count = pos = 0;

triggerAction(SliderNoAction);
stop();
stopping = 0;
emit valueEmitted(0);
}
}

Expand All @@ -120,7 +130,8 @@ void ThumbSlider::wheelEvent(QWheelEvent *event)
{
if (timerId)
killTimer(timerId);
timerId = count = 0;
timerId = count = stopping = 0;
emit valueEmitted(0);
}

if (value)
Expand All @@ -129,6 +140,14 @@ void ThumbSlider::wheelEvent(QWheelEvent *event)
triggerAction(SliderNoAction);
}

void ThumbSlider::reset(void)
{
stopping = 1;
stop();
setSliderPosition(0);
emit valueEmitted(0);
}

void ThumbSlider::drawBackground(QPainter *painter)
{
int middle = width() / 2;
Expand Down
4 changes: 3 additions & 1 deletion avidemux/qt4/ADM_userInterfaces/ADM_gui/T_thumbSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ class ThumbSlider : public QAbstractSlider
Q_OBJECT

private:
int timerId, count, lock, pos;
int timerId, count, lock, pos, stopping;

void stop(void);
void drawBackground(QPainter *painter);
void drawLines(QPainter *painter);
void drawBorders(QPainter *painter);
void drawEdges(QPainter *painter);

public:
ThumbSlider(QWidget *parent = 0);
void reset(void);

protected:
void timerEvent(QTimerEvent *event);
Expand Down

0 comments on commit cd206a7

Please sign in to comment.