Skip to content

Commit

Permalink
footageviewer: auto switch waveform mode when clicking video/audio bu…
Browse files Browse the repository at this point in the history
…ttons
  • Loading branch information
itsmattkc committed Mar 20, 2023
1 parent 0a54585 commit 537908c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
25 changes: 22 additions & 3 deletions app/widget/playbackcontrols/dragbutton.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Copyright (C) 2023 Olive Studios LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,18 +20,37 @@

#include "dragbutton.h"

#include <QMouseEvent>

namespace olive {

DragButton::DragButton(QWidget *parent) :
QPushButton(parent)
{
setCursor(Qt::OpenHandCursor);
dragging_ = false;
}

void DragButton::mousePressEvent(QMouseEvent *event) {
void DragButton::mousePressEvent(QMouseEvent *event)
{
QPushButton::mousePressEvent(event);
}

void DragButton::mouseMoveEvent(QMouseEvent *event)
{
QPushButton::mouseMoveEvent(event);

if (event->buttons() && !dragging_) {
emit DragStarted();
dragging_ = true;
}
}

void DragButton::mouseReleaseEvent(QMouseEvent *event)
{
QPushButton::mouseReleaseEvent(event);

emit MousePressed();
dragging_ = false;
}

}
11 changes: 9 additions & 2 deletions app/widget/playbackcontrols/dragbutton.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Copyright (C) 2023 Olive Studios LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -34,11 +34,18 @@ class DragButton : public QPushButton
DragButton(QWidget* parent = nullptr);

signals:
void MousePressed();
void DragStarted();

protected:
virtual void mousePressEvent(QMouseEvent* event) override;

virtual void mouseMoveEvent(QMouseEvent* event) override;

virtual void mouseReleaseEvent(QMouseEvent* event) override;

private:
bool dragging_;

};

}
Expand Down
4 changes: 2 additions & 2 deletions app/widget/playbackcontrols/playbackcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ PlaybackControls::PlaybackControls(QWidget *parent) :
av_btn_layout->setContentsMargins(0, 0, 0, 0);
video_drag_btn_ = new DragButton();
connect(video_drag_btn_, &QPushButton::clicked, this, &PlaybackControls::VideoClicked);
connect(video_drag_btn_, &DragButton::MousePressed, this, &PlaybackControls::VideoPressed);
connect(video_drag_btn_, &DragButton::DragStarted, this, &PlaybackControls::VideoDragged);
av_btn_layout->addWidget(video_drag_btn_);
audio_drag_btn_ = new DragButton();
connect(audio_drag_btn_, &QPushButton::clicked, this, &PlaybackControls::AudioClicked);
connect(audio_drag_btn_, &DragButton::MousePressed, this, &PlaybackControls::AudioPressed);
connect(audio_drag_btn_, &DragButton::DragStarted, this, &PlaybackControls::AudioDragged);
av_btn_layout->addWidget(audio_drag_btn_);
lower_control_layout->addWidget(av_btn_widget);

Expand Down
4 changes: 2 additions & 2 deletions app/widget/playbackcontrols/playbackcontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public slots:

void VideoClicked();

void AudioPressed();
void AudioDragged();

void VideoPressed();
void VideoDragged();

void TimeChanged(const rational& t);

Expand Down
16 changes: 14 additions & 2 deletions app/widget/viewer/footageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ FootageViewerWidget::FootageViewerWidget(QWidget *parent) :
connect(display_widget(), &ViewerDisplayWidget::DragStarted, this, &FootageViewerWidget::StartFootageDrag);

controls_->SetAudioVideoDragButtonsVisible(true);
connect(controls_, &PlaybackControls::VideoPressed, this, &FootageViewerWidget::StartVideoDrag);
connect(controls_, &PlaybackControls::AudioPressed, this, &FootageViewerWidget::StartAudioDrag);
connect(controls_, &PlaybackControls::VideoClicked, this, &FootageViewerWidget::VideoButtonClicked);
connect(controls_, &PlaybackControls::AudioClicked, this, &FootageViewerWidget::AudioButtonClicked);
connect(controls_, &PlaybackControls::VideoDragged, this, &FootageViewerWidget::StartVideoDrag);
connect(controls_, &PlaybackControls::AudioDragged, this, &FootageViewerWidget::StartAudioDrag);

override_workarea_ = new TimelineWorkArea(this);
}
Expand Down Expand Up @@ -108,4 +110,14 @@ void FootageViewerWidget::StartAudioDrag()
StartFootageDragInternal(false, true);
}

void FootageViewerWidget::VideoButtonClicked()
{
this->SetWaveformMode(kWFAutomatic);
}

void FootageViewerWidget::AudioButtonClicked()
{
this->SetWaveformMode(kWFWaveformOnly);
}

}
4 changes: 4 additions & 0 deletions app/widget/viewer/footageviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ private slots:

void StartAudioDrag();

void VideoButtonClicked();

void AudioButtonClicked();

};

}
Expand Down
4 changes: 2 additions & 2 deletions app/widget/viewer/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public slots:

RenderTicketPtr GetSingleFrame(const rational &t, bool dry = false);

void SetWaveformMode(WaveformMode wf);

private:
int64_t GetTimestamp() const
{
Expand Down Expand Up @@ -270,8 +272,6 @@ public slots:

void CloseAudioProcessor();

void SetWaveformMode(WaveformMode wf);

void DetectMulticamNode(const rational &time);

bool IsVideoVisible() const;
Expand Down

0 comments on commit 537908c

Please sign in to comment.