change: change code style to Linux style except indent.

This commit is contained in:
Mike Solar
2025-08-03 03:09:40 +08:00
parent 65ab76edc8
commit 74f73ab3be
789 changed files with 77113 additions and 68888 deletions
+171 -157
View File
@@ -27,283 +27,297 @@
#include "widget/timebased/timebasedwidget.h"
namespace olive {
TimeBasedView::TimeBasedView(QWidget *parent) :
HandMovableView(parent),
playhead_scene_left_(-1),
playhead_scene_right_(-1),
dragging_playhead_(false),
snapped_(false),
snap_service_(nullptr),
y_axis_enabled_(false),
y_scale_(1.0),
viewer_(nullptr)
namespace olive
{
// Sets scene to our scene
setScene(&scene_);
// Set default scale (ensures non-zero scale from beginning)
SetScale(1.0);
TimeBasedView::TimeBasedView(QWidget *parent)
: HandMovableView(parent)
, playhead_scene_left_(-1)
, playhead_scene_right_(-1)
, dragging_playhead_(false)
, snapped_(false)
, snap_service_(nullptr)
, y_axis_enabled_(false)
, y_scale_(1.0)
, viewer_(nullptr)
{
// Sets scene to our scene
setScene(&scene_);
// Default to no default drag mode
SetDefaultDragMode(NoDrag);
// Set default scale (ensures non-zero scale from beginning)
SetScale(1.0);
// Signal to update bounding rect when the scene changes
connect(&scene_, &QGraphicsScene::changed, this, &TimeBasedView::UpdateSceneRect);
// Default to no default drag mode
SetDefaultDragMode(NoDrag);
// Workaround for Qt drawing issues with the default MinimalViewportUpdate. While this might be
// slower (Qt documentation says it may actually be faster in some situations),
// MinimalViewportUpdate causes all sorts of graphical crud building up in the scene
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
// Signal to update bounding rect when the scene changes
connect(&scene_, &QGraphicsScene::changed, this,
&TimeBasedView::UpdateSceneRect);
// Workaround for Qt drawing issues with the default MinimalViewportUpdate. While this might be
// slower (Qt documentation says it may actually be faster in some situations),
// MinimalViewportUpdate causes all sorts of graphical crud building up in the scene
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
}
void TimeBasedView::TimebaseChangedEvent(const rational &)
{
// Timebase influences position/visibility of playhead
viewport()->update();
// Timebase influences position/visibility of playhead
viewport()->update();
}
void TimeBasedView::EnableSnap(const std::vector<rational> &points)
{
snapped_ = true;
snap_time_ = points;
snapped_ = true;
snap_time_ = points;
viewport()->update();
viewport()->update();
}
void TimeBasedView::DisableSnap()
{
snapped_ = false;
snapped_ = false;
viewport()->update();
viewport()->update();
}
const double &TimeBasedView::GetYScale() const
{
return y_scale_;
return y_scale_;
}
void TimeBasedView::VerticalScaleChangedEvent(double)
{
}
void TimeBasedView::ZoomIntoCursorPosition(QWheelEvent *event, double scale_multiplier, const QPointF &cursor_pos)
void TimeBasedView::ZoomIntoCursorPosition(QWheelEvent *event,
double scale_multiplier,
const QPointF &cursor_pos)
{
// If CTRL is held (or a preference is set to swap CTRL behavior), we zoom instead of scrolling
bool only_vertical = false;
bool only_horizontal = false;
// If CTRL is held (or a preference is set to swap CTRL behavior), we zoom instead of scrolling
bool only_vertical = false;
bool only_horizontal = false;
// Ctrl+Shift limits to only one axis
// Alt switches between horizontal only (alt held) or vertical only (alt not held)
if (y_axis_enabled_) {
if (event->modifiers() & Qt::ShiftModifier) {
if (event->modifiers() & Qt::AltModifier) {
only_horizontal = true;
} else {
only_vertical = true;
}
}
} else {
only_horizontal = true;
}
// Ctrl+Shift limits to only one axis
// Alt switches between horizontal only (alt held) or vertical only (alt not held)
if (y_axis_enabled_) {
if (event->modifiers() & Qt::ShiftModifier) {
if (event->modifiers() & Qt::AltModifier) {
only_horizontal = true;
} else {
only_vertical = true;
}
}
} else {
only_horizontal = true;
}
if (!only_vertical) {
double old_scroll = horizontalScrollBar()->value();
if (!only_vertical) {
double old_scroll = horizontalScrollBar()->value();
double old_scale = GetScale();
emit ScaleChanged(old_scale * scale_multiplier);
double old_scale = GetScale();
emit ScaleChanged(old_scale * scale_multiplier);
// Use GetScale so that if this value was clamped, we don't erroneously use an unclamped value
int new_x_scroll = qRound((cursor_pos.x() + old_scroll) / old_scale * GetScale() - cursor_pos.x());
horizontalScrollBar()->setValue(new_x_scroll);
}
// Use GetScale so that if this value was clamped, we don't erroneously use an unclamped value
int new_x_scroll =
qRound((cursor_pos.x() + old_scroll) / old_scale * GetScale() -
cursor_pos.x());
horizontalScrollBar()->setValue(new_x_scroll);
}
if (!only_horizontal) {
double old_y_scroll = verticalScrollBar()->value();
if (!only_horizontal) {
double old_y_scroll = verticalScrollBar()->value();
double old_y_scale = GetYScale();
SetYScale(old_y_scale * scale_multiplier);
double old_y_scale = GetYScale();
SetYScale(old_y_scale * scale_multiplier);
// Use GetYScale so that if this value was clamped, we don't erroneously use an unclamped value
int new_y_scroll = qRound((cursor_pos.y() + old_y_scroll) / old_y_scale * GetYScale() - cursor_pos.y());
verticalScrollBar()->setValue(new_y_scroll);
}
// Use GetYScale so that if this value was clamped, we don't erroneously use an unclamped value
int new_y_scroll =
qRound((cursor_pos.y() + old_y_scroll) / old_y_scale * GetYScale() -
cursor_pos.y());
verticalScrollBar()->setValue(new_y_scroll);
}
}
void TimeBasedView::SetYScale(const double &y_scale)
{
Q_ASSERT(y_scale > 0);
Q_ASSERT(y_scale > 0);
y_scale_ = y_scale;
y_scale_ = y_scale;
if (y_axis_enabled_) {
VerticalScaleChangedEvent(y_scale_);
if (y_axis_enabled_) {
VerticalScaleChangedEvent(y_scale_);
viewport()->update();
}
viewport()->update();
}
}
void TimeBasedView::SetViewerNode(ViewerOutput *v)
{
if (viewer_) {
disconnect(viewer_, &ViewerOutput::PlayheadChanged, viewport(), static_cast<void(QWidget::*)()>(&TimeBasedView::update));
}
if (viewer_) {
disconnect(viewer_, &ViewerOutput::PlayheadChanged, viewport(),
static_cast<void (QWidget::*)()>(&TimeBasedView::update));
}
viewer_ = v;
viewer_ = v;
if (viewer_) {
connect(viewer_, &ViewerOutput::PlayheadChanged, viewport(), static_cast<void(QWidget::*)()>(&TimeBasedView::update));
}
if (viewer_) {
connect(viewer_, &ViewerOutput::PlayheadChanged, viewport(),
static_cast<void (QWidget::*)()>(&TimeBasedView::update));
}
}
QPointF TimeBasedView::ScalePoint(const QPointF &p) const
{
return QPointF(p.x() * GetScale(), p.y() * GetYScale());
return QPointF(p.x() * GetScale(), p.y() * GetYScale());
}
QPointF TimeBasedView::UnscalePoint(const QPointF &p) const
{
return QPointF(p.x() / GetScale(), p.y() / GetYScale());
return QPointF(p.x() / GetScale(), p.y() / GetYScale());
}
void TimeBasedView::drawForeground(QPainter *painter, const QRectF &rect)
{
QGraphicsView::drawForeground(painter, rect);
QGraphicsView::drawForeground(painter, rect);
if (!timebase().isNull()) {
double width = TimeToScene(timebase());
if (!timebase().isNull()) {
double width = TimeToScene(timebase());
playhead_scene_left_ = GetPlayheadX();
playhead_scene_right_ = playhead_scene_left_ + width;
playhead_scene_left_ = GetPlayheadX();
playhead_scene_right_ = playhead_scene_left_ + width;
QRectF playhead_rect(playhead_scene_left_, rect.top(), width, rect.height());
QRectF playhead_rect(playhead_scene_left_, rect.top(), width,
rect.height());
// Get playhead highlight color
QColor highlight = palette().text().color();
highlight.setAlpha(32);
painter->setPen(Qt::NoPen);
painter->setBrush(highlight);
painter->drawRect(playhead_rect);
// Get playhead highlight color
QColor highlight = palette().text().color();
highlight.setAlpha(32);
painter->setPen(Qt::NoPen);
painter->setBrush(highlight);
painter->drawRect(playhead_rect);
// FIXME: Hardcoded...
painter->setPen(PLAYHEAD_COLOR);
painter->setBrush(Qt::NoBrush);
painter->drawLine(QLineF(playhead_rect.topLeft(), playhead_rect.bottomLeft()));
}
// FIXME: Hardcoded...
painter->setPen(PLAYHEAD_COLOR);
painter->setBrush(Qt::NoBrush);
painter->drawLine(
QLineF(playhead_rect.topLeft(), playhead_rect.bottomLeft()));
}
if (snapped_) {
painter->setPen(palette().text().color());
if (snapped_) {
painter->setPen(palette().text().color());
foreach (const rational& r, snap_time_) {
double x = TimeToScene(r);
foreach (const rational &r, snap_time_) {
double x = TimeToScene(r);
painter->drawLine(x, rect.top(), x, rect.height());
}
}
painter->drawLine(x, rect.top(), x, rect.height());
}
}
}
bool TimeBasedView::PlayheadPress(QMouseEvent *event)
{
QPointF scene_pos = mapToScene(event->pos());
QPointF scene_pos = mapToScene(event->pos());
dragging_playhead_ = (event->button() == Qt::LeftButton
&& scene_pos.x() >= playhead_scene_left_
&& scene_pos.x() < playhead_scene_right_);
dragging_playhead_ = (event->button() == Qt::LeftButton &&
scene_pos.x() >= playhead_scene_left_ &&
scene_pos.x() < playhead_scene_right_);
return dragging_playhead_;
return dragging_playhead_;
}
bool TimeBasedView::PlayheadMove(QMouseEvent *event)
{
if (!dragging_playhead_) {
return false;
}
if (!dragging_playhead_) {
return false;
}
if (viewer_) {
QPointF scene_pos = mapToScene(event->pos());
rational mouse_time = qMax(rational(0), SceneToTime(scene_pos.x()));
if (viewer_) {
QPointF scene_pos = mapToScene(event->pos());
rational mouse_time = qMax(rational(0), SceneToTime(scene_pos.x()));
if (Core::instance()->snapping() && snap_service_) {
rational movement;
if (Core::instance()->snapping() && snap_service_) {
rational movement;
snap_service_->SnapPoint({mouse_time}, &movement, TimeBasedWidget::kSnapAll & ~TimeBasedWidget::kSnapToPlayhead);
snap_service_->SnapPoint({ mouse_time }, &movement,
TimeBasedWidget::kSnapAll &
~TimeBasedWidget::kSnapToPlayhead);
mouse_time += movement;
}
mouse_time += movement;
}
viewer_->SetPlayhead(mouse_time);
}
viewer_->SetPlayhead(mouse_time);
}
return true;
return true;
}
bool TimeBasedView::PlayheadRelease(QMouseEvent*)
bool TimeBasedView::PlayheadRelease(QMouseEvent *)
{
if (dragging_playhead_) {
dragging_playhead_ = false;
if (dragging_playhead_) {
dragging_playhead_ = false;
if (snap_service_) {
snap_service_->HideSnaps();
}
if (snap_service_) {
snap_service_->HideSnaps();
}
return true;
}
return true;
}
return false;
return false;
}
qreal TimeBasedView::GetPlayheadX()
{
if (viewer_) {
return TimeToScene(viewer_->GetPlayhead());
} else {
return 0;
}
if (viewer_) {
return TimeToScene(viewer_->GetPlayhead());
} else {
return 0;
}
}
void TimeBasedView::SetEndTime(const rational &length)
{
end_time_ = length;
end_time_ = length;
UpdateSceneRect();
UpdateSceneRect();
}
void TimeBasedView::UpdateSceneRect()
{
QRectF bounding_rect = scene_.itemsBoundingRect();
QRectF bounding_rect = scene_.itemsBoundingRect();
// There's no need for a timeline to ever go below 0 on the X scale
bounding_rect.setLeft(0);
// There's no need for a timeline to ever go below 0 on the X scale
bounding_rect.setLeft(0);
// Ensure the scene is always the full length of the timeline with a gap at the end to work with
bounding_rect.setRight(TimeToScene(end_time_) + width());
// Ensure the scene is always the full length of the timeline with a gap at the end to work with
bounding_rect.setRight(TimeToScene(end_time_) + width());
// Any further rect processing from derivatives can be done here
SceneRectUpdateEvent(bounding_rect);
// Any further rect processing from derivatives can be done here
SceneRectUpdateEvent(bounding_rect);
// If the scene is already this rect, do nothing
if (scene_.sceneRect() != bounding_rect) {
scene_.setSceneRect(bounding_rect);
}
// If the scene is already this rect, do nothing
if (scene_.sceneRect() != bounding_rect) {
scene_.setSceneRect(bounding_rect);
}
}
void TimeBasedView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
QGraphicsView::resizeEvent(event);
UpdateSceneRect();
UpdateSceneRect();
}
void TimeBasedView::ScaleChangedEvent(const double &scale)
{
TimeScaledObject::ScaleChangedEvent(scale);
TimeScaledObject::ScaleChangedEvent(scale);
// Update scene rect
UpdateSceneRect();
// Update scene rect
UpdateSceneRect();
// Force redraw for playhead if the above function didn't do it
viewport()->update();
// Force redraw for playhead if the above function didn't do it
viewport()->update();
}
}
+76 -61
View File
@@ -28,108 +28,123 @@
#include "timescaledobject.h"
#include "widget/handmovableview/handmovableview.h"
namespace olive {
namespace olive
{
class TimeBasedWidget;
class TimeBasedView : public HandMovableView, public TimeScaledObject
{
Q_OBJECT
class TimeBasedView : public HandMovableView, public TimeScaledObject {
Q_OBJECT
public:
TimeBasedView(QWidget* parent = nullptr);
TimeBasedView(QWidget *parent = nullptr);
void EnableSnap(const std::vector<rational> &points);
void DisableSnap();
bool IsSnapped() const
{
return snapped_;
}
void EnableSnap(const std::vector<rational> &points);
void DisableSnap();
bool IsSnapped() const
{
return snapped_;
}
TimeBasedWidget *GetSnapService() const { return snap_service_; }
void SetSnapService(TimeBasedWidget* service) { snap_service_ = service; }
TimeBasedWidget *GetSnapService() const
{
return snap_service_;
}
void SetSnapService(TimeBasedWidget *service)
{
snap_service_ = service;
}
const double& GetYScale() const;
void SetYScale(const double& y_scale);
const double &GetYScale() const;
void SetYScale(const double &y_scale);
virtual bool IsDraggingPlayhead() const
{
return dragging_playhead_;
}
virtual bool IsDraggingPlayhead() const
{
return dragging_playhead_;
}
// To be called only by selection managers
virtual void SelectionManagerSelectEvent(void *obj){}
virtual void SelectionManagerDeselectEvent(void *obj){}
// To be called only by selection managers
virtual void SelectionManagerSelectEvent(void *obj)
{
}
virtual void SelectionManagerDeselectEvent(void *obj)
{
}
ViewerOutput *GetViewerNode() const { return viewer_; }
ViewerOutput *GetViewerNode() const
{
return viewer_;
}
void SetViewerNode(ViewerOutput *v);
void SetViewerNode(ViewerOutput *v);
QPointF ScalePoint(const QPointF &p) const;
QPointF UnscalePoint(const QPointF &p) const;
QPointF ScalePoint(const QPointF &p) const;
QPointF UnscalePoint(const QPointF &p) const;
public slots:
void SetEndTime(const rational& length);
void SetEndTime(const rational &length);
/**
/**
* @brief Slot called whenever the view resizes or the scene contents change to enforce minimum scene sizes
*/
void UpdateSceneRect();
void UpdateSceneRect();
signals:
void ScaleChanged(double scale);
void ScaleChanged(double scale);
protected:
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual void ScaleChangedEvent(const double& scale) override;
virtual void ScaleChangedEvent(const double &scale) override;
virtual void SceneRectUpdateEvent(QRectF&){}
virtual void SceneRectUpdateEvent(QRectF &)
{
}
virtual void VerticalScaleChangedEvent(double scale);
virtual void VerticalScaleChangedEvent(double scale);
virtual void ZoomIntoCursorPosition(QWheelEvent *event, double multiplier, const QPointF &cursor_pos) override;
virtual void ZoomIntoCursorPosition(QWheelEvent *event, double multiplier,
const QPointF &cursor_pos) override;
bool PlayheadPress(QMouseEvent* event);
bool PlayheadMove(QMouseEvent* event);
bool PlayheadRelease(QMouseEvent* event);
bool PlayheadPress(QMouseEvent *event);
bool PlayheadMove(QMouseEvent *event);
bool PlayheadRelease(QMouseEvent *event);
virtual void TimebaseChangedEvent(const rational &) override;
virtual void TimebaseChangedEvent(const rational &) override;
bool IsYAxisEnabled() const
{
return y_axis_enabled_;
}
bool IsYAxisEnabled() const
{
return y_axis_enabled_;
}
void SetYAxisEnabled(bool e)
{
y_axis_enabled_ = e;
}
void SetYAxisEnabled(bool e)
{
y_axis_enabled_ = e;
}
private:
qreal GetPlayheadX();
qreal GetPlayheadX();
double playhead_scene_left_;
double playhead_scene_right_;
double playhead_scene_left_;
double playhead_scene_right_;
bool dragging_playhead_;
bool dragging_playhead_;
QGraphicsScene scene_;
QGraphicsScene scene_;
bool snapped_;
std::vector<rational> snap_time_;
bool snapped_;
std::vector<rational> snap_time_;
rational end_time_;
rational end_time_;
TimeBasedWidget* snap_service_;
TimeBasedWidget *snap_service_;
bool y_axis_enabled_;
bool y_axis_enabled_;
double y_scale_;
ViewerOutput *viewer_;
double y_scale_;
ViewerOutput *viewer_;
};
}
@@ -20,6 +20,7 @@
#include "timebasedviewselectionmanager.h"
namespace olive {
namespace olive
{
}
@@ -31,440 +31,459 @@
#include "timebasedwidget.h"
#include "widget/timetarget/timetarget.h"
namespace olive {
template <typename T>
class TimeBasedViewSelectionManager
namespace olive
{
template <typename T> class TimeBasedViewSelectionManager {
public:
TimeBasedViewSelectionManager(TimeBasedView *view) :
view_(view),
rubberband_(nullptr),
snap_mask_(TimeBasedWidget::kSnapAll)
{}
void SetSnapMask(TimeBasedWidget::SnapMask e)
{
snap_mask_ = e;
}
void ClearDrawnObjects()
{
drawn_objects_.clear();
}
void DeclareDrawnObject(T *object, const QRectF &rect)
{
QRectF r(view_->UnscalePoint(rect.topLeft()), view_->UnscalePoint(rect.bottomRight()));
drawn_objects_.push_back({object, r});
}
bool Select(T *key)
{
Q_ASSERT(key);
if (!IsSelected(key)) {
selected_.push_back(key);
return true;
}
return false;
}
bool Deselect(T *key)
{
Q_ASSERT(key);
auto it = std::find(selected_.cbegin(), selected_.cend(), key);
if (it == selected_.cend()) {
return false;
} else {
selected_.erase(it);
return true;
}
}
void ClearSelection()
{
selected_.clear();
}
bool IsSelected(T *key) const
{
return std::find(selected_.cbegin(), selected_.cend(), key) != selected_.cend();
}
const std::vector<T*> &GetSelectedObjects() const
{
return selected_;
}
void SetTimebase(const rational &tb)
{
timebase_ = tb;
}
T *GetObjectAtPoint(const QPointF &scene_pt)
{
// Iterate in reverse order because the objects drawn later will appear on top to the user
QPointF unscaled = view_->UnscalePoint(scene_pt);
for (auto it=drawn_objects_.crbegin(); it!=drawn_objects_.crend(); it++) {
const DrawnObject &kp = *it;
if (kp.second.contains(unscaled)) {
return kp.first;
}
}
return nullptr;
}
T *GetObjectAtPoint(const QPoint &pt)
{
return GetObjectAtPoint(view_->mapToScene(pt));
}
T *MousePress(QMouseEvent *event)
{
T *key_under_cursor = nullptr;
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {
// See if there's a keyframe in this position
key_under_cursor = GetObjectAtPoint(event->pos());
bool holding_shift = event->modifiers() & Qt::ShiftModifier;
if (!key_under_cursor || !IsSelected(key_under_cursor)) {
if (!holding_shift) {
// If not already selecting and not holding shift, clear the current selection
ClearSelection();
}
// Add item to selection, either nothing if shift wasn't held, or the existing selection
if (key_under_cursor) {
Select(key_under_cursor);
view_->SelectionManagerSelectEvent(key_under_cursor);
}
} else if (holding_shift) {
// If selected and holding shift, de-select this item but do nothing else
Deselect(key_under_cursor);
view_->SelectionManagerDeselectEvent(key_under_cursor);
key_under_cursor = nullptr;
}
}
return key_under_cursor;
}
bool IsDragging() const
{
return !dragging_.empty();
}
void DragStart(T *initial_item, QMouseEvent *event, TimeTargetObject *target = nullptr)
{
if (event->button() != Qt::LeftButton) {
return;
}
time_target_ = target;
initial_drag_item_ = initial_item;
dragging_.resize(selected_.size());
if constexpr (std::is_same_v<T, TimelineMarker>) {
snap_points_.resize(selected_.size()*2);
} else {
snap_points_.resize(selected_.size());
}
if (target) {
time_targets_.resize(snap_points_.size());
memset(time_targets_.data(), 0, time_targets_.size() * sizeof(Node*));
} else {
time_targets_.clear();
}
for (size_t i=0; i<selected_.size(); i++) {
T *obj = selected_.at(i);
if constexpr (std::is_same_v<T, TimelineMarker>) {
dragging_[i] = obj->time().in();
snap_points_[i] = obj->time().in();
snap_points_[i+selected_.size()] = obj->time().out();
if (target) {
time_targets_[i] = time_targets_[i+selected_.size()] = QtUtils::GetParentOfType<Node>(obj);
}
} else {
dragging_[i] = obj->time();
snap_points_[i] = obj->time();
if (target) {
time_targets_[i] = QtUtils::GetParentOfType<Node>(obj);
}
}
}
drag_mouse_start_ = view_->UnscalePoint(view_->mapToScene(event->pos()));
}
void SnapPoints(rational *movement)
{
std::vector<rational> copy = snap_points_;
if (time_target_) {
for (size_t i=0; i<copy.size(); i++) {
if (Node *parent = time_targets_[i]) {
copy[i] = time_target_->GetAdjustedTime(parent, time_target_->GetTimeTarget(), copy[i], Node::kTransformTowardsOutput);
}
}
}
if (Core::instance()->snapping() && view_->GetSnapService()) {
view_->GetSnapService()->SnapPoint(copy, movement, snap_mask_);
}
}
void Unsnap()
{
if (view_->GetSnapService()) {
view_->GetSnapService()->HideSnaps();
}
}
void DragMove(const QPoint &local_pos, const QString &tip_format = QString())
{
rational time_diff = view_->SceneToTimeNoGrid(view_->mapToScene(local_pos).x() - view_->ScalePoint(drag_mouse_start_).x());
// Snap points
rational presnap_time_diff = time_diff;
SnapPoints(&time_diff);
// Validate snapping
if (Core::instance()->snapping() && view_->GetSnapService()) {
for (size_t i=0; i<selected_.size(); i++) {
rational proposed_time = dragging_.at(i) + time_diff;
T *sel = selected_.at(i);
if (sel->has_sibling_at_time(proposed_time)) {
// Unsnap
time_diff = presnap_time_diff;
if (view_->GetSnapService()) {
view_->GetSnapService()->HideSnaps();
}
break;
}
}
}
// Validate movement
for (size_t i=0; i<selected_.size(); i++) {
rational proposed_time = dragging_.at(i) + time_diff;
T *sel = selected_.at(i);
// Magic number: use interval of 1ms to avoid collisions
rational adj(1, 1000);
if (dragging_.at(i) < proposed_time) {
// Negate adjustment value if origin is less than proposed time
adj = -adj;
}
bool loop;
do {
loop = false;
while (sel->has_sibling_at_time(proposed_time)) {
proposed_time += adj;
Unsnap();
}
if (proposed_time < 0) {
// Prevent any object from going below zero
proposed_time = 0;
Unsnap();
// Setting our proposed time to zero may (re)introduce a conflict that we just avoided
// with the sibling check above, so we request it to happen again. To avoid a negative
// adj bringing us back below zero, we force adj to positive so it'll only nudge higher
adj = qAbs(adj);
loop = true;
}
} while (loop);
time_diff = proposed_time - dragging_.at(i);
}
// Apply movement
for (size_t i=0; i<selected_.size(); i++) {
selected_.at(i)->set_time(dragging_.at(i) + time_diff);
}
// Show information about this keyframe
rational display_time;
if constexpr (std::is_same_v<T, TimelineMarker>) {
display_time = initial_drag_item_->time().in();
} else {
display_time = initial_drag_item_->time();
}
QString tip = QString::fromStdString(Timecode::time_to_timecode(
display_time, timebase_,
Core::instance()->GetTimecodeDisplay(), false));
last_used_tip_format_ = tip_format;
if (!tip_format.isEmpty()) {
tip = tip_format.arg(tip);
}
QToolTip::hideText();
QToolTip::showText(QCursor::pos(), tip);
}
void DragStop(MultiUndoCommand *command)
{
QToolTip::hideText();
for (size_t i=0; i<selected_.size(); i++) {
rational current;
if constexpr (std::is_same_v<T, TimelineMarker>) {
current = selected_.at(i)->time().in();
} else {
current = selected_.at(i)->time();
}
command->add_child(new SetTimeCommand(selected_.at(i), current, dragging_.at(i)));
}
dragging_.clear();
Unsnap();
}
void RubberBandStart(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {
rubberband_scene_start_ = view_->UnscalePoint(view_->mapToScene(event->pos()));
rubberband_ = new QRubberBand(QRubberBand::Rectangle, view_);
rubberband_->setGeometry(QRect(event->pos().x(), event->pos().y(), 0, 0));
rubberband_->show();
rubberband_preselected_ = selected_;
}
}
void RubberBandMove(const QPoint &pos)
{
if (IsRubberBanding()) {
QRectF band_rect = QRectF(view_->mapFromScene(view_->ScalePoint(rubberband_scene_start_)), pos).normalized();
rubberband_->setGeometry(band_rect.toRect());
QPointF current = view_->UnscalePoint(view_->mapToScene(pos));
QRectF scene_rect = QRectF(rubberband_scene_start_, current).normalized();
selected_ = rubberband_preselected_;
foreach (const DrawnObject &kp, drawn_objects_) {
if (scene_rect.intersects(kp.second)) {
Select(kp.first);
}
}
}
}
void RubberBandStop()
{
if (IsRubberBanding()) {
delete rubberband_;
rubberband_ = nullptr;
}
}
bool IsRubberBanding() const
{
return rubberband_;
}
void ForceDragUpdate()
{
if (IsRubberBanding() || IsDragging()) {
QPoint local_pos = view_->viewport()->mapFromGlobal(QCursor::pos());
if (IsRubberBanding()) {
RubberBandMove(local_pos);
} else {
DragMove(local_pos, last_used_tip_format_);
}
}
}
TimeBasedViewSelectionManager(TimeBasedView *view)
: view_(view)
, rubberband_(nullptr)
, snap_mask_(TimeBasedWidget::kSnapAll)
{
}
void SetSnapMask(TimeBasedWidget::SnapMask e)
{
snap_mask_ = e;
}
void ClearDrawnObjects()
{
drawn_objects_.clear();
}
void DeclareDrawnObject(T *object, const QRectF &rect)
{
QRectF r(view_->UnscalePoint(rect.topLeft()),
view_->UnscalePoint(rect.bottomRight()));
drawn_objects_.push_back({ object, r });
}
bool Select(T *key)
{
Q_ASSERT(key);
if (!IsSelected(key)) {
selected_.push_back(key);
return true;
}
return false;
}
bool Deselect(T *key)
{
Q_ASSERT(key);
auto it = std::find(selected_.cbegin(), selected_.cend(), key);
if (it == selected_.cend()) {
return false;
} else {
selected_.erase(it);
return true;
}
}
void ClearSelection()
{
selected_.clear();
}
bool IsSelected(T *key) const
{
return std::find(selected_.cbegin(), selected_.cend(), key) !=
selected_.cend();
}
const std::vector<T *> &GetSelectedObjects() const
{
return selected_;
}
void SetTimebase(const rational &tb)
{
timebase_ = tb;
}
T *GetObjectAtPoint(const QPointF &scene_pt)
{
// Iterate in reverse order because the objects drawn later will appear on top to the user
QPointF unscaled = view_->UnscalePoint(scene_pt);
for (auto it = drawn_objects_.crbegin(); it != drawn_objects_.crend();
it++) {
const DrawnObject &kp = *it;
if (kp.second.contains(unscaled)) {
return kp.first;
}
}
return nullptr;
}
T *GetObjectAtPoint(const QPoint &pt)
{
return GetObjectAtPoint(view_->mapToScene(pt));
}
T *MousePress(QMouseEvent *event)
{
T *key_under_cursor = nullptr;
if (event->button() == Qt::LeftButton ||
event->button() == Qt::RightButton) {
// See if there's a keyframe in this position
key_under_cursor = GetObjectAtPoint(event->pos());
bool holding_shift = event->modifiers() & Qt::ShiftModifier;
if (!key_under_cursor || !IsSelected(key_under_cursor)) {
if (!holding_shift) {
// If not already selecting and not holding shift, clear the current selection
ClearSelection();
}
// Add item to selection, either nothing if shift wasn't held, or the existing selection
if (key_under_cursor) {
Select(key_under_cursor);
view_->SelectionManagerSelectEvent(key_under_cursor);
}
} else if (holding_shift) {
// If selected and holding shift, de-select this item but do nothing else
Deselect(key_under_cursor);
view_->SelectionManagerDeselectEvent(key_under_cursor);
key_under_cursor = nullptr;
}
}
return key_under_cursor;
}
bool IsDragging() const
{
return !dragging_.empty();
}
void DragStart(T *initial_item, QMouseEvent *event,
TimeTargetObject *target = nullptr)
{
if (event->button() != Qt::LeftButton) {
return;
}
time_target_ = target;
initial_drag_item_ = initial_item;
dragging_.resize(selected_.size());
if constexpr (std::is_same_v<T, TimelineMarker>) {
snap_points_.resize(selected_.size() * 2);
} else {
snap_points_.resize(selected_.size());
}
if (target) {
time_targets_.resize(snap_points_.size());
memset(time_targets_.data(), 0,
time_targets_.size() * sizeof(Node *));
} else {
time_targets_.clear();
}
for (size_t i = 0; i < selected_.size(); i++) {
T *obj = selected_.at(i);
if constexpr (std::is_same_v<T, TimelineMarker>) {
dragging_[i] = obj->time().in();
snap_points_[i] = obj->time().in();
snap_points_[i + selected_.size()] = obj->time().out();
if (target) {
time_targets_[i] = time_targets_[i + selected_.size()] =
QtUtils::GetParentOfType<Node>(obj);
}
} else {
dragging_[i] = obj->time();
snap_points_[i] = obj->time();
if (target) {
time_targets_[i] = QtUtils::GetParentOfType<Node>(obj);
}
}
}
drag_mouse_start_ =
view_->UnscalePoint(view_->mapToScene(event->pos()));
}
void SnapPoints(rational *movement)
{
std::vector<rational> copy = snap_points_;
if (time_target_) {
for (size_t i = 0; i < copy.size(); i++) {
if (Node *parent = time_targets_[i]) {
copy[i] = time_target_->GetAdjustedTime(
parent, time_target_->GetTimeTarget(), copy[i],
Node::kTransformTowardsOutput);
}
}
}
if (Core::instance()->snapping() && view_->GetSnapService()) {
view_->GetSnapService()->SnapPoint(copy, movement, snap_mask_);
}
}
void Unsnap()
{
if (view_->GetSnapService()) {
view_->GetSnapService()->HideSnaps();
}
}
void DragMove(const QPoint &local_pos,
const QString &tip_format = QString())
{
rational time_diff =
view_->SceneToTimeNoGrid(view_->mapToScene(local_pos).x() -
view_->ScalePoint(drag_mouse_start_).x());
// Snap points
rational presnap_time_diff = time_diff;
SnapPoints(&time_diff);
// Validate snapping
if (Core::instance()->snapping() && view_->GetSnapService()) {
for (size_t i = 0; i < selected_.size(); i++) {
rational proposed_time = dragging_.at(i) + time_diff;
T *sel = selected_.at(i);
if (sel->has_sibling_at_time(proposed_time)) {
// Unsnap
time_diff = presnap_time_diff;
if (view_->GetSnapService()) {
view_->GetSnapService()->HideSnaps();
}
break;
}
}
}
// Validate movement
for (size_t i = 0; i < selected_.size(); i++) {
rational proposed_time = dragging_.at(i) + time_diff;
T *sel = selected_.at(i);
// Magic number: use interval of 1ms to avoid collisions
rational adj(1, 1000);
if (dragging_.at(i) < proposed_time) {
// Negate adjustment value if origin is less than proposed time
adj = -adj;
}
bool loop;
do {
loop = false;
while (sel->has_sibling_at_time(proposed_time)) {
proposed_time += adj;
Unsnap();
}
if (proposed_time < 0) {
// Prevent any object from going below zero
proposed_time = 0;
Unsnap();
// Setting our proposed time to zero may (re)introduce a conflict that we just avoided
// with the sibling check above, so we request it to happen again. To avoid a negative
// adj bringing us back below zero, we force adj to positive so it'll only nudge higher
adj = qAbs(adj);
loop = true;
}
} while (loop);
time_diff = proposed_time - dragging_.at(i);
}
// Apply movement
for (size_t i = 0; i < selected_.size(); i++) {
selected_.at(i)->set_time(dragging_.at(i) + time_diff);
}
// Show information about this keyframe
rational display_time;
if constexpr (std::is_same_v<T, TimelineMarker>) {
display_time = initial_drag_item_->time().in();
} else {
display_time = initial_drag_item_->time();
}
QString tip = QString::fromStdString(Timecode::time_to_timecode(
display_time, timebase_, Core::instance()->GetTimecodeDisplay(),
false));
last_used_tip_format_ = tip_format;
if (!tip_format.isEmpty()) {
tip = tip_format.arg(tip);
}
QToolTip::hideText();
QToolTip::showText(QCursor::pos(), tip);
}
void DragStop(MultiUndoCommand *command)
{
QToolTip::hideText();
for (size_t i = 0; i < selected_.size(); i++) {
rational current;
if constexpr (std::is_same_v<T, TimelineMarker>) {
current = selected_.at(i)->time().in();
} else {
current = selected_.at(i)->time();
}
command->add_child(
new SetTimeCommand(selected_.at(i), current, dragging_.at(i)));
}
dragging_.clear();
Unsnap();
}
void RubberBandStart(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton ||
event->button() == Qt::RightButton) {
rubberband_scene_start_ =
view_->UnscalePoint(view_->mapToScene(event->pos()));
rubberband_ = new QRubberBand(QRubberBand::Rectangle, view_);
rubberband_->setGeometry(
QRect(event->pos().x(), event->pos().y(), 0, 0));
rubberband_->show();
rubberband_preselected_ = selected_;
}
}
void RubberBandMove(const QPoint &pos)
{
if (IsRubberBanding()) {
QRectF band_rect = QRectF(view_->mapFromScene(view_->ScalePoint(
rubberband_scene_start_)),
pos)
.normalized();
rubberband_->setGeometry(band_rect.toRect());
QPointF current = view_->UnscalePoint(view_->mapToScene(pos));
QRectF scene_rect =
QRectF(rubberband_scene_start_, current).normalized();
selected_ = rubberband_preselected_;
foreach (const DrawnObject &kp, drawn_objects_) {
if (scene_rect.intersects(kp.second)) {
Select(kp.first);
}
}
}
}
void RubberBandStop()
{
if (IsRubberBanding()) {
delete rubberband_;
rubberband_ = nullptr;
}
}
bool IsRubberBanding() const
{
return rubberband_;
}
void ForceDragUpdate()
{
if (IsRubberBanding() || IsDragging()) {
QPoint local_pos = view_->viewport()->mapFromGlobal(QCursor::pos());
if (IsRubberBanding()) {
RubberBandMove(local_pos);
} else {
DragMove(local_pos, last_used_tip_format_);
}
}
}
private:
class SetTimeCommand : public UndoCommand
{
public:
SetTimeCommand(T* key, const rational& time)
{
key_ = key;
new_time_ = time;
old_time_ = key_->time();
}
class SetTimeCommand : public UndoCommand {
public:
SetTimeCommand(T *key, const rational &time)
{
key_ = key;
new_time_ = time;
old_time_ = key_->time();
}
SetTimeCommand(T* key, const rational& new_time, const rational& old_time)
{
key_ = key;
new_time_ = new_time;
old_time_ = old_time;
}
SetTimeCommand(T *key, const rational &new_time,
const rational &old_time)
{
key_ = key;
new_time_ = new_time;
old_time_ = old_time;
}
virtual Project* GetRelevantProject() const override
{
return Project::GetProjectFromObject(key_);
}
virtual Project *GetRelevantProject() const override
{
return Project::GetProjectFromObject(key_);
}
protected:
virtual void redo() override
{
key_->set_time(new_time_);
}
protected:
virtual void redo() override
{
key_->set_time(new_time_);
}
virtual void undo() override
{
key_->set_time(old_time_);
}
virtual void undo() override
{
key_->set_time(old_time_);
}
private:
T* key_;
private:
T *key_;
rational old_time_;
rational new_time_;
rational old_time_;
rational new_time_;
};
};
TimeBasedView *view_;
TimeBasedView *view_;
using DrawnObject = QPair<T *, QRectF>;
std::vector<DrawnObject> drawn_objects_;
using DrawnObject = QPair<T*, QRectF>;
std::vector<DrawnObject> drawn_objects_;
std::vector<T *> selected_;
std::vector<T*> selected_;
std::vector<rational> dragging_;
std::vector<rational> snap_points_;
std::vector<Node *> time_targets_;
std::vector<rational> dragging_;
std::vector<rational> snap_points_;
std::vector<Node*> time_targets_;
T *initial_drag_item_;
T *initial_drag_item_;
QPointF drag_mouse_start_;
QPointF drag_mouse_start_;
rational timebase_;
rational timebase_;
QRubberBand *rubberband_;
QPointF rubberband_scene_start_;
std::vector<T *> rubberband_preselected_;
QRubberBand *rubberband_;
QPointF rubberband_scene_start_;
std::vector<T*> rubberband_preselected_;
TimeBasedWidget::SnapMask snap_mask_;
TimeBasedWidget::SnapMask snap_mask_;
TimeTargetObject *time_target_;
QString last_used_tip_format_;
TimeTargetObject *time_target_;
QString last_used_tip_format_;
};
}
File diff suppressed because it is too large Load Diff
+157 -120
View File
@@ -31,164 +31,202 @@
#include "widget/timelinewidget/view/timelineview.h"
#include "widget/timetarget/timetarget.h"
namespace olive {
namespace olive
{
class TimeRuler;
class TimeBasedWidget : public TimelineScaledWidget
{
Q_OBJECT
class TimeBasedWidget : public TimelineScaledWidget {
Q_OBJECT
public:
TimeBasedWidget(bool ruler_text_visible = true, bool ruler_cache_status_visible = false, QWidget* parent = nullptr);
TimeBasedWidget(bool ruler_text_visible = true,
bool ruler_cache_status_visible = false,
QWidget *parent = nullptr);
void ZoomIn();
void ZoomIn();
void ZoomOut();
void ZoomOut();
ViewerOutput* GetConnectedNode() const;
ViewerOutput *GetConnectedNode() const;
void ConnectViewerNode(ViewerOutput *node);
void ConnectViewerNode(ViewerOutput *node);
TimelineWorkArea *GetConnectedWorkArea() const { return workarea_; }
TimelineMarkerList *GetConnectedMarkers() const { return markers_; }
void ConnectWorkArea(TimelineWorkArea *workarea);
void ConnectMarkers(TimelineMarkerList *markers);
TimelineWorkArea *GetConnectedWorkArea() const
{
return workarea_;
}
TimelineMarkerList *GetConnectedMarkers() const
{
return markers_;
}
void ConnectWorkArea(TimelineWorkArea *workarea);
void ConnectMarkers(TimelineMarkerList *markers);
void SetScaleAndCenterOnPlayhead(const double& scale);
void SetScaleAndCenterOnPlayhead(const double &scale);
TimeRuler* ruler() const;
TimeRuler *ruler() const;
using SnapMask = uint32_t;
enum SnapPoints {
kSnapToClips = 0x1,
kSnapToPlayhead = 0x2,
kSnapToMarkers = 0x4,
kSnapToKeyframes = 0x8,
kSnapToWorkarea = 0x10,
kSnapAll = UINT32_MAX
};
using SnapMask = uint32_t;
enum SnapPoints {
kSnapToClips = 0x1,
kSnapToPlayhead = 0x2,
kSnapToMarkers = 0x4,
kSnapToKeyframes = 0x8,
kSnapToWorkarea = 0x10,
kSnapAll = UINT32_MAX
};
/**
/**
* @brief Snaps point `start_point` that is moving by `movement` to currently existing clips
*/
bool SnapPoint(const std::vector<rational> &start_times, rational *movement, SnapMask snap_points = kSnapAll);
void ShowSnaps(const std::vector<rational> &times);
void HideSnaps();
bool SnapPoint(const std::vector<rational> &start_times, rational *movement,
SnapMask snap_points = kSnapAll);
void ShowSnaps(const std::vector<rational> &times);
void HideSnaps();
virtual bool CopySelected(bool cut);
virtual bool CopySelected(bool cut);
virtual bool Paste();
virtual bool Paste();
public slots:
void SetTimebase(const rational& timebase);
void SetTimebase(const rational &timebase);
void SetScale(const double& scale);
void SetScale(const double &scale);
void GoToStart();
void GoToStart();
void PrevFrame();
void PrevFrame();
void NextFrame();
void NextFrame();
void GoToEnd();
void GoToEnd();
void GoToPrevCut();
void GoToPrevCut();
void GoToNextCut();
void GoToNextCut();
void SetInAtPlayhead();
void SetInAtPlayhead();
void SetOutAtPlayhead();
void SetOutAtPlayhead();
void ResetIn();
void ResetIn();
void ResetOut();
void ResetOut();
void ClearInOutPoints();
void ClearInOutPoints();
void SetMarker();
void SetMarker();
void ToggleShowAll();
void ToggleShowAll();
void GoToIn();
void GoToIn();
void GoToOut();
void GoToOut();
void DeleteSelected();
void DeleteSelected();
protected:
ResizableTimelineScrollBar* scrollbar() const;
ResizableTimelineScrollBar *scrollbar() const;
virtual void TimebaseChangedEvent(const rational&) override;
virtual void TimebaseChangedEvent(const rational &) override;
virtual void TimeChangedEvent(const rational&){}
virtual void TimeChangedEvent(const rational &)
{
}
virtual void ScaleChangedEvent(const double &) override;
virtual void ScaleChangedEvent(const double &) override;
virtual void ConnectedNodeChangeEvent(ViewerOutput*){}
virtual void ConnectedNodeChangeEvent(ViewerOutput *)
{
}
virtual void ConnectedWorkAreaChangeEvent(TimelineWorkArea *){}
virtual void ConnectedMarkersChangeEvent(TimelineMarkerList *){}
virtual void ConnectedWorkAreaChangeEvent(TimelineWorkArea *)
{
}
virtual void ConnectedMarkersChangeEvent(TimelineMarkerList *)
{
}
virtual void ConnectNodeEvent(ViewerOutput*){}
virtual void ConnectNodeEvent(ViewerOutput *)
{
}
virtual void DisconnectNodeEvent(ViewerOutput*){}
virtual void DisconnectNodeEvent(ViewerOutput *)
{
}
void SetAutoMaxScrollBar(bool e);
void SetAutoMaxScrollBar(bool e);
virtual void resizeEvent(QResizeEvent *event) override;
virtual void resizeEvent(QResizeEvent *event) override;
void ConnectTimelineView(TimeBasedView* base);
void ConnectTimelineView(TimeBasedView *base);
void SetCatchUpScrollValue(QScrollBar *b, int v, int maximum);
void StopCatchUpScrollTimer(QScrollBar *b);
void SetCatchUpScrollValue(QScrollBar *b, int v, int maximum);
void StopCatchUpScrollTimer(QScrollBar *b);
virtual const QVector<Block*> *GetSnapBlocks() const { return nullptr; }
virtual const QVector<KeyframeViewInputConnection*> *GetSnapKeyframes() const { return nullptr; }
virtual const TimeTargetObject *GetKeyframeTimeTarget() const { return nullptr; }
virtual const std::vector<NodeKeyframe*> *GetSnapIgnoreKeyframes() const { return nullptr; }
virtual const std::vector<TimelineMarker*> *GetSnapIgnoreMarkers() const { return nullptr; }
virtual const QVector<Block *> *GetSnapBlocks() const
{
return nullptr;
}
virtual const QVector<KeyframeViewInputConnection *> *
GetSnapKeyframes() const
{
return nullptr;
}
virtual const TimeTargetObject *GetKeyframeTimeTarget() const
{
return nullptr;
}
virtual const std::vector<NodeKeyframe *> *GetSnapIgnoreKeyframes() const
{
return nullptr;
}
virtual const std::vector<TimelineMarker *> *GetSnapIgnoreMarkers() const
{
return nullptr;
}
protected slots:
/**
/**
* @brief Slot to center the horizontal scroll bar on the playhead's current position
*/
void CenterScrollOnPlayhead();
void CenterScrollOnPlayhead();
/**
/**
* @brief By default, TimeBasedWidget will set the timebase to the viewer node's video timebase.
* Set this to false if you want to set your own timebase.
*/
void SetAutoSetTimebase(bool e);
void SetAutoSetTimebase(bool e);
static void PageScrollInternal(QScrollBar* bar, int maximum, int screen_position, bool whole_page_scroll);
static void PageScrollInternal(QScrollBar *bar, int maximum,
int screen_position, bool whole_page_scroll);
void StopCatchUpScrollTimer()
{
StopCatchUpScrollTimer(scrollbar_);
}
void StopCatchUpScrollTimer()
{
StopCatchUpScrollTimer(scrollbar_);
}
void SetCatchUpScrollValue(int v);
void SetCatchUpScrollValue(int v);
signals:
void TimebaseChanged(const rational&);
void TimebaseChanged(const rational &);
void ConnectedNodeChanged(ViewerOutput* old, ViewerOutput* now);
void ConnectedNodeChanged(ViewerOutput *old, ViewerOutput *now);
protected slots:
virtual void SendCatchUpScrollEvent();
virtual void SendCatchUpScrollEvent();
private:
/**
/**
* @brief Set either in or out point to the current playhead
*
* @param m
*
* Set to kTrimIn or kTrimOut for setting the in point or out point respectively.
*/
void SetPoint(Timeline::MovementMode m, const rational &time);
void SetPoint(Timeline::MovementMode m, const rational &time);
/**
/**
* @brief Reset either the in or out point
*
* Sets either the in point to 0 or the out point to `RATIONAL_MAX`.
@@ -197,72 +235,71 @@ private:
*
* Set to kTrimIn or kTrimOut for setting the in point or out point respectively.
*/
void ResetPoint(Timeline::MovementMode m);
void ResetPoint(Timeline::MovementMode m);
void PageScrollInternal(int screen_position, bool whole_page_scroll);
void PageScrollInternal(int screen_position, bool whole_page_scroll);
bool UserIsDraggingPlayhead() const;
bool UserIsDraggingPlayhead() const;
ViewerOutput* viewer_node_;
ViewerOutput *viewer_node_;
TimeRuler* ruler_;
TimeRuler *ruler_;
ResizableTimelineScrollBar* scrollbar_;
ResizableTimelineScrollBar *scrollbar_;
bool auto_max_scrollbar_;
bool auto_max_scrollbar_;
QList<TimeBasedView*> timeline_views_;
QList<TimeBasedView *> timeline_views_;
bool toggle_show_all_;
bool toggle_show_all_;
double toggle_show_all_old_scale_;
int toggle_show_all_old_scroll_;
double toggle_show_all_old_scale_;
int toggle_show_all_old_scroll_;
bool auto_set_timebase_;
bool auto_set_timebase_;
int scrollbar_start_width_;
double scrollbar_start_value_;
double scrollbar_start_scale_;
bool scrollbar_top_handle_;
int scrollbar_start_width_;
double scrollbar_start_value_;
double scrollbar_start_scale_;
bool scrollbar_top_handle_;
TimelineWorkArea *workarea_;
TimelineMarkerList *markers_;
TimelineWorkArea *workarea_;
TimelineMarkerList *markers_;
QTimer *catchup_scroll_timer_;
struct CatchUpScrollData {
qint64 last_forced = 0;
int maximum;
int value;
};
QMap<QScrollBar*, CatchUpScrollData> catchup_scroll_values_;
QTimer *catchup_scroll_timer_;
struct CatchUpScrollData {
qint64 last_forced = 0;
int maximum;
int value;
};
QMap<QScrollBar *, CatchUpScrollData> catchup_scroll_values_;
private slots:
void UpdateMaximumScroll();
void UpdateMaximumScroll();
void ScrollBarResizeBegan(int current_bar_width, bool top_handle);
void ScrollBarResizeBegan(int current_bar_width, bool top_handle);
void ScrollBarResizeMoved(int new_bar_width);
void ScrollBarResizeMoved(int new_bar_width);
/**
/**
* @brief Slot to handle page scrolling of the playhead
*
* If the playhead is outside the current scroll bounds, this function will scroll to where it is. Otherwise it will
* do nothing.
*/
void PageScrollToPlayhead();
void PageScrollToPlayhead();
void CatchUpScrollToPlayhead();
void CatchUpScrollToPlayhead();
void CatchUpScrollToPoint(int point);
void CatchUpScrollToPoint(int point);
void CatchUpTimerTimeout();
void CatchUpTimerTimeout();
void AutoUpdateTimebase();
void AutoUpdateTimebase();
void ConnectedNodeRemovedFromGraph();
void PlayheadTimeChanged(const rational &time);
void ConnectedNodeRemovedFromGraph();
void PlayheadTimeChanged(const rational &time);
};
}
+59 -51
View File
@@ -25,126 +25,134 @@
#include "audio/audiovisualwaveform.h"
namespace olive {
namespace olive
{
const int TimeScaledObject::kCalculateDimensionsPadding = 10;
TimeScaledObject::TimeScaledObject() :
scale_(1.0),
min_scale_(0),
max_scale_(AudioVisualWaveform::kMaximumSampleRate.toDouble())
TimeScaledObject::TimeScaledObject()
: scale_(1.0)
, min_scale_(0)
, max_scale_(AudioVisualWaveform::kMaximumSampleRate.toDouble())
{
}
void TimeScaledObject::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
timebase_dbl_ = timebase_.toDouble();
timebase_ = timebase;
timebase_dbl_ = timebase_.toDouble();
TimebaseChangedEvent(timebase);
TimebaseChangedEvent(timebase);
}
const rational &TimeScaledObject::timebase() const
{
return timebase_;
return timebase_;
}
const double &TimeScaledObject::timebase_dbl() const
{
return timebase_dbl_;
return timebase_dbl_;
}
rational TimeScaledObject::SceneToTime(const double &x, const double &x_scale, const rational &timebase, bool round)
rational TimeScaledObject::SceneToTime(const double &x, const double &x_scale,
const rational &timebase, bool round)
{
double unscaled_time = x / x_scale / timebase.toDouble();
double unscaled_time = x / x_scale / timebase.toDouble();
// Adjust screen point by scale and timebase
qint64 rounded_x_mvmt;
// Adjust screen point by scale and timebase
qint64 rounded_x_mvmt;
if (round) {
rounded_x_mvmt = qRound64(unscaled_time);
} else if (unscaled_time < 0) {
// "floor" to zero
rounded_x_mvmt = qCeil(unscaled_time);
} else {
rounded_x_mvmt = qFloor(unscaled_time);
}
if (round) {
rounded_x_mvmt = qRound64(unscaled_time);
} else if (unscaled_time < 0) {
// "floor" to zero
rounded_x_mvmt = qCeil(unscaled_time);
} else {
rounded_x_mvmt = qFloor(unscaled_time);
}
// Return a time in the timebase
return rational(rounded_x_mvmt * timebase.numerator(), timebase.denominator());
// Return a time in the timebase
return rational(rounded_x_mvmt * timebase.numerator(),
timebase.denominator());
}
rational TimeScaledObject::SceneToTimeNoGrid(const double &x, const double &x_scale)
rational TimeScaledObject::SceneToTimeNoGrid(const double &x,
const double &x_scale)
{
double unscaled_time = x / x_scale;
double unscaled_time = x / x_scale;
return rational::fromDouble(unscaled_time);
return rational::fromDouble(unscaled_time);
}
double TimeScaledObject::TimeToScene(const rational &time) const
{
return time.toDouble() * scale_;
return time.toDouble() * scale_;
}
rational TimeScaledObject::SceneToTime(const double &x, bool round) const
{
return SceneToTime(x, scale_, timebase_, round);
return SceneToTime(x, scale_, timebase_, round);
}
rational TimeScaledObject::SceneToTimeNoGrid(const double &x) const
{
return SceneToTimeNoGrid(x, scale_);
return SceneToTimeNoGrid(x, scale_);
}
void TimeScaledObject::SetMaximumScale(const double &max)
{
max_scale_ = max;
max_scale_ = max;
if (GetScale() > max_scale_) {
SetScale(max_scale_);
}
if (GetScale() > max_scale_) {
SetScale(max_scale_);
}
}
void TimeScaledObject::SetMinimumScale(const double &min)
{
min_scale_ = min;
min_scale_ = min;
if (GetScale() < min_scale_) {
SetScale(min_scale_);
}
if (GetScale() < min_scale_) {
SetScale(min_scale_);
}
}
const double& TimeScaledObject::GetScale() const
const double &TimeScaledObject::GetScale() const
{
return scale_;
return scale_;
}
void TimeScaledObject::SetScale(const double& scale)
void TimeScaledObject::SetScale(const double &scale)
{
Q_ASSERT(scale > 0);
Q_ASSERT(scale > 0);
scale_ = std::clamp(scale, min_scale_, max_scale_);
scale_ = std::clamp(scale, min_scale_, max_scale_);
ScaleChangedEvent(scale_);
ScaleChangedEvent(scale_);
}
void TimeScaledObject::SetScaleFromDimensions(double viewport_width, double content_width)
void TimeScaledObject::SetScaleFromDimensions(double viewport_width,
double content_width)
{
SetScale(CalculateScaleFromDimensions(viewport_width, content_width));
SetScale(CalculateScaleFromDimensions(viewport_width, content_width));
}
double TimeScaledObject::CalculateScaleFromDimensions(double viewport_sz, double content_sz)
double TimeScaledObject::CalculateScaleFromDimensions(double viewport_sz,
double content_sz)
{
return static_cast<double>(viewport_sz / kCalculateDimensionsPadding * (kCalculateDimensionsPadding-1)) / static_cast<double>(content_sz);
return static_cast<double>(viewport_sz / kCalculateDimensionsPadding *
(kCalculateDimensionsPadding - 1)) /
static_cast<double>(content_sz);
}
double TimeScaledObject::CalculatePaddingFromDimensionScale(double viewport_sz)
{
return (viewport_sz / (kCalculateDimensionsPadding * 2));
return (viewport_sz / (kCalculateDimensionsPadding * 2));
}
TimelineScaledWidget::TimelineScaledWidget(QWidget *parent) :
QWidget(parent)
TimelineScaledWidget::TimelineScaledWidget(QWidget *parent)
: QWidget(parent)
{
}
+41 -34
View File
@@ -26,67 +26,74 @@
#include "node/block/block.h"
namespace olive {
namespace olive
{
/**
* @brief Provides base functionality for any object that uses time and scale
*/
class TimeScaledObject
{
class TimeScaledObject {
public:
TimeScaledObject();
virtual ~TimeScaledObject() = default;
TimeScaledObject();
virtual ~TimeScaledObject() = default;
void SetTimebase(const rational &timebase);
void SetTimebase(const rational &timebase);
const rational& timebase() const;
const double& timebase_dbl() const;
const rational &timebase() const;
const double &timebase_dbl() const;
static rational SceneToTime(const double &x, const double& x_scale, const rational& timebase, bool round = false);
static rational SceneToTimeNoGrid(const double &x, const double& x_scale);
static rational SceneToTime(const double &x, const double &x_scale,
const rational &timebase, bool round = false);
static rational SceneToTimeNoGrid(const double &x, const double &x_scale);
const double& GetScale() const;
const double &GetMaximumScale() const { return max_scale_; }
const double &GetScale() const;
const double &GetMaximumScale() const
{
return max_scale_;
}
void SetScale(const double& scale);
void SetScale(const double &scale);
void SetScaleFromDimensions(double viewport_width, double content_width);
static double CalculateScaleFromDimensions(double viewport_sz, double content_sz);
static double CalculatePaddingFromDimensionScale(double viewport_sz);
void SetScaleFromDimensions(double viewport_width, double content_width);
static double CalculateScaleFromDimensions(double viewport_sz,
double content_sz);
static double CalculatePaddingFromDimensionScale(double viewport_sz);
double TimeToScene(const rational& time) const;
rational SceneToTime(const double &x, bool round = false) const;
rational SceneToTimeNoGrid(const double &x) const;
double TimeToScene(const rational &time) const;
rational SceneToTime(const double &x, bool round = false) const;
rational SceneToTimeNoGrid(const double &x) const;
protected:
virtual void TimebaseChangedEvent(const rational&){}
virtual void TimebaseChangedEvent(const rational &)
{
}
virtual void ScaleChangedEvent(const double&){}
virtual void ScaleChangedEvent(const double &)
{
}
void SetMaximumScale(const double& max);
void SetMaximumScale(const double &max);
void SetMinimumScale(const double& min);
void SetMinimumScale(const double &min);
private:
rational timebase_;
rational timebase_;
double timebase_dbl_;
double timebase_dbl_;
double scale_;
double scale_;
double min_scale_;
double min_scale_;
double max_scale_;
static const int kCalculateDimensionsPadding;
double max_scale_;
static const int kCalculateDimensionsPadding;
};
class TimelineScaledWidget : public QWidget, public TimeScaledObject
{
Q_OBJECT
class TimelineScaledWidget : public QWidget, public TimeScaledObject {
Q_OBJECT
public:
TimelineScaledWidget(QWidget* parent = nullptr);
TimelineScaledWidget(QWidget *parent = nullptr);
};
}