Skip to content

Commit

Permalink
Merge branch 'master' into move-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Mar 1, 2023
2 parents b091ed8 + d0f16ef commit 9824760
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 81 deletions.
2 changes: 2 additions & 0 deletions app/widget/handmovableview/handmovableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class HandMovableView : public QGraphicsView

static qreal GetScrollZoomMultiplier(QWheelEvent* event);

virtual void CatchUpScrollEvent(){}

protected:
virtual void ToolChangedEvent(Tool::Item tool){Q_UNUSED(tool)}

Expand Down
21 changes: 19 additions & 2 deletions app/widget/keyframeview/keyframeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ bool KeyframeView::Paste(std::function<Node *(const QString &)> find_node_functi
return false;
}

void KeyframeView::CatchUpScrollEvent()
{
super::CatchUpScrollEvent();

if (this->selection_manager_.IsRubberBanding()) {
this->selection_manager_.RubberBandMove(this->viewport()->mapFromGlobal(QCursor::pos()));
}
}

void KeyframeView::mousePressEvent(QMouseEvent *event)
{
NodeKeyframe *key_under_cursor = selection_manager_.GetObjectAtPoint(event->pos());
Expand Down Expand Up @@ -289,7 +298,7 @@ void KeyframeView::mouseMoveEvent(QMouseEvent *event)
KeyframeDragMove(event, tip);
selection_manager_.DragMove(event, tip);
} else if (selection_manager_.IsRubberBanding()) {
selection_manager_.RubberBandMove(event);
selection_manager_.RubberBandMove(event->pos());
Redraw();
}

Expand All @@ -313,12 +322,13 @@ void KeyframeView::mouseReleaseEvent(QMouseEvent *event)
selection_manager_.DragStop(command);
KeyframeDragRelease(event, command);
Core::instance()->undo_stack()->push(command);
emit Released();
} else if (selection_manager_.IsRubberBanding()) {
selection_manager_.RubberBandStop();
Redraw();
emit SelectionChanged();
}

emit Released();
}

int BinarySearchFirstKeyframeAfterOrAt(const QVector<NodeKeyframe*> &keys, const rational &time)
Expand Down Expand Up @@ -617,6 +627,13 @@ void KeyframeView::ShowKeyframePropertiesDialog()
}
}

void KeyframeView::UpdateRubberBandForScroll()
{
if (this->selection_manager_.IsRubberBanding()) {
this->selection_manager_.RubberBandMove(this->viewport()->mapFromGlobal(QCursor::pos()));
}
}

void KeyframeView::Redraw()
{
viewport()->update();
Expand Down
4 changes: 4 additions & 0 deletions app/widget/keyframeview/keyframeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class KeyframeView : public TimeBasedView, public TimeTargetObject

bool Paste(std::function<Node *(const QString &)> find_node_function);

virtual void CatchUpScrollEvent() override;

signals:
void Dragged(int current_x, int current_y);

Expand Down Expand Up @@ -164,6 +166,8 @@ private slots:

void ShowKeyframePropertiesDialog();

void UpdateRubberBandForScroll();

};

}
Expand Down
16 changes: 2 additions & 14 deletions app/widget/nodeparamview/nodeparamview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ NodeParamView::NodeParamView(bool create_keyframe_view, QWidget *parent) :
keyframe_area_layout->addWidget(keyframe_view_);

// Connect ruler and keyframe view together
connect(keyframe_view_, &KeyframeView::Dragged, this, &NodeParamView::KeyframeViewDragged);
connect(keyframe_view_, &KeyframeView::Released, this, &NodeParamView::KeyframeViewReleased);
connect(keyframe_view_, &KeyframeView::Dragged, this, static_cast<void(NodeParamView::*)(int)>(&NodeParamView::SetCatchUpScrollValue));
connect(keyframe_view_, &KeyframeView::Released, this, static_cast<void(NodeParamView::*)()>(&NodeParamView::StopCatchUpScrollTimer));

splitter->addWidget(keyframe_area);

Expand Down Expand Up @@ -898,18 +898,6 @@ void NodeParamView::PinNode(bool pin)
}
}*/

void NodeParamView::KeyframeViewDragged(int x, int y)
{
Q_UNUSED(y)

SetCatchUpScrollValue(x);
}

void NodeParamView::KeyframeViewReleased()
{
StopCatchUpScrollTimer();
}

void NodeParamView::UpdateElementY()
{
for (NodeParamViewContext *ctx : context_items_) {
Expand Down
3 changes: 0 additions & 3 deletions app/widget/nodeparamview/nodeparamview.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ private slots:

//void FocusChanged(QWidget *old, QWidget *now);

void KeyframeViewDragged(int x, int y);
void KeyframeViewReleased();

void NodeAddedToContext(Node *n);

void NodeRemovedFromContext(Node *n);
Expand Down
10 changes: 10 additions & 0 deletions app/widget/timebased/timebasedview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ void TimeBasedView::SetViewerNode(ViewerOutput *v)
}
}

QPointF TimeBasedView::ScalePoint(const QPointF &p) const
{
return QPointF(p.x() * GetScale(), p.y() * GetYScale());
}

QPointF TimeBasedView::UnscalePoint(const QPointF &p) const
{
return QPointF(p.x() / GetScale(), p.y() / GetYScale());
}

void TimeBasedView::drawForeground(QPainter *painter, const QRectF &rect)
{
QGraphicsView::drawForeground(painter, rect);
Expand Down
3 changes: 3 additions & 0 deletions app/widget/timebased/timebasedview.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class TimeBasedView : public HandMovableView, public TimeScaledObject

void SetViewerNode(ViewerOutput *v);

QPointF ScalePoint(const QPointF &p) const;
QPointF UnscalePoint(const QPointF &p) const;

public slots:
void SetEndTime(const rational& length);

Expand Down
20 changes: 11 additions & 9 deletions app/widget/timebased/timebasedviewselectionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ class TimeBasedViewSelectionManager
drawn_objects_.clear();
}

void DeclareDrawnObject(T *object, const QRectF &pos)
void DeclareDrawnObject(T *object, const QRectF &rect)
{
drawn_objects_.push_back({object, pos});
QRectF r(view_->UnscalePoint(rect.topLeft()), view_->UnscalePoint(rect.bottomRight()));
drawn_objects_.push_back({object, r});
}

bool Select(T *key)
Expand Down Expand Up @@ -345,23 +346,24 @@ class TimeBasedViewSelectionManager
void RubberBandStart(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {
rubberband_start_ = event->pos();
rubberband_scene_start_ = view_->UnscalePoint(view_->mapToScene(event->pos()));

rubberband_ = new QRubberBand(QRubberBand::Rectangle, view_);
rubberband_->setGeometry(QRect(rubberband_start_.x(), rubberband_start_.y(), 0, 0));
rubberband_->setGeometry(QRect(event->pos().x(), event->pos().y(), 0, 0));
rubberband_->show();

rubberband_preselected_ = selected_;
}
}

void RubberBandMove(QMouseEvent *event)
void RubberBandMove(const QPoint &pos)
{
if (IsRubberBanding()) {
QRect band_rect = QRect(rubberband_start_, event->pos()).normalized();
rubberband_->setGeometry(band_rect);
QRectF band_rect = QRectF(view_->mapFromScene(view_->ScalePoint(rubberband_scene_start_)), pos).normalized();
rubberband_->setGeometry(band_rect.toRect());

QRectF scene_rect = view_->mapToScene(band_rect).boundingRect();
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_) {
Expand Down Expand Up @@ -445,7 +447,7 @@ class TimeBasedViewSelectionManager
rational timebase_;

QRubberBand *rubberband_;
QPoint rubberband_start_;
QPointF rubberband_scene_start_;
std::vector<T*> rubberband_preselected_;

TimeBasedWidget::SnapMask snap_mask_;
Expand Down
12 changes: 12 additions & 0 deletions app/widget/timebased/timebasedwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ TimeBasedWidget::TimeBasedWidget(bool ruler_text_visible, bool ruler_cache_statu
ruler_ = new TimeRuler(ruler_text_visible, ruler_cache_status_visible, this);
ConnectTimelineView(ruler_);
ruler()->SetSnapService(this);
connect(ruler(), &TimeRuler::DragMoved, this, static_cast<void(TimeBasedWidget::*)(int)>(&TimeBasedWidget::SetCatchUpScrollValue));
connect(ruler(), &TimeRuler::DragReleased, this, static_cast<void(TimeBasedWidget::*)()>(&TimeBasedWidget::StopCatchUpScrollTimer));

catchup_scroll_timer_ = new QTimer(this);
Expand Down Expand Up @@ -230,6 +231,15 @@ void TimeBasedWidget::CatchUpTimerTimeout()
const CatchUpScrollData &d = it.value();
PageScrollInternal(sb, d.maximum, sb->value() + d.value, false);
}

SendCatchUpScrollEvent();
}

void TimeBasedWidget::SendCatchUpScrollEvent()
{
for (auto v : this->timeline_views_) {
v->CatchUpScrollEvent();
}
}

void TimeBasedWidget::AutoUpdateTimebase()
Expand Down Expand Up @@ -283,6 +293,8 @@ void TimeBasedWidget::ScaleChangedEvent(const double &scale)

UpdateMaximumScroll();

QMetaObject::invokeMethod(this, &TimeBasedWidget::SendCatchUpScrollEvent, Qt::QueuedConnection);

toggle_show_all_ = false;
}

Expand Down
6 changes: 5 additions & 1 deletion app/widget/timebased/timebasedwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public slots:
void ConnectTimelineView(TimeBasedView* base);

void SetCatchUpScrollValue(QScrollBar *b, int v, int maximum);
void SetCatchUpScrollValue(int v);
void StopCatchUpScrollTimer(QScrollBar *b);

virtual const QVector<Block*> *GetSnapBlocks() const { return nullptr; }
Expand Down Expand Up @@ -169,11 +168,16 @@ protected slots:
StopCatchUpScrollTimer(scrollbar_);
}

void SetCatchUpScrollValue(int v);

signals:
void TimebaseChanged(const rational&);

void ConnectedNodeChanged(ViewerOutput* old, ViewerOutput* now);

protected slots:
virtual void SendCatchUpScrollEvent();

private:
/**
* @brief Set either in or out point to the current playhead
Expand Down
91 changes: 44 additions & 47 deletions app/widget/timelinewidget/timelinewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ void TimelineWidget::ScaleChangedEvent(const double &scale)
foreach (TimelineAndTrackView* view, views_) {
view->view()->SetScale(scale);
}

if (rubberband_.isVisible()) {
QMetaObject::invokeMethod(this, &TimelineWidget::ForceUpdateRubberBand, Qt::QueuedConnection);
}
}

void TimelineWidget::ConnectNodeEvent(ViewerOutput *n)
Expand Down Expand Up @@ -339,6 +343,15 @@ void TimelineWidget::DisconnectNodeEvent(ViewerOutput *n)
}
}

void TimelineWidget::SendCatchUpScrollEvent()
{
super::SendCatchUpScrollEvent();

if (rubberband_.isVisible()) {
this->ForceUpdateRubberBand();
}
}

void TimelineWidget::SelectAll()
{
QVector<Block*> newly_selected_blocks;
Expand Down Expand Up @@ -1564,6 +1577,13 @@ void TimelineWidget::MulticamEnabledTriggered(bool e)
Core::instance()->undo_stack()->pushIfHasChildren(command);
}

void TimelineWidget::ForceUpdateRubberBand()
{
if (rubberband_.isVisible()) {
this->MoveRubberBandSelect(rubberband_enable_selecting_, rubberband_select_links_);
}
}

void TimelineWidget::AddGhost(TimelineViewGhostItem *ghost)
{
ghost_items_.append(ghost);
Expand Down Expand Up @@ -1912,46 +1932,6 @@ void TimelineWidget::UpdateViewports(const Track::Type &type)
}
}

QVector<Block *> TimelineWidget::GetBlocksInGlobalRect(const QPoint &p1, const QPoint& p2)
{
QVector<Block*> blocks_in_rect;

// Determine which tracks are in the rect
for (int i=0; i<views_.size(); i++) {
TimelineView* view = views_.at(i)->view();

// Map global mouse coordinates to viewport
QRectF mapped_rect(view->mapToScene(view->viewport()->mapFromGlobal(p1)),
view->mapToScene(view->viewport()->mapFromGlobal(p2)));

// Normalize
mapped_rect = mapped_rect.normalized();

// Get tracks
TrackList* track_list = sequence()->track_list(static_cast<Track::Type>(i));

for (int j=0; j<track_list->GetTrackCount(); j++) {
int track_top = view->GetTrackY(j);
int track_bottom = track_top + view->GetTrackHeight(j);

if (!(track_bottom < mapped_rect.top() || track_top > mapped_rect.bottom())) {
// This track is in the rect, so we'll iterate through its blocks and see where they start
rational left_time = SceneToTime(mapped_rect.left());
rational right_time = SceneToTime(mapped_rect.right(), true);

Track* track = track_list->GetTrackAt(j);
foreach (Block* b, track->Blocks()) {
if (!(b->out() < left_time || b->in() > right_time)) {
blocks_in_rect.append(b);
}
}
}
}
}

return blocks_in_rect;
}

bool TimelineWidget::PasteInternal(bool insert)
{
if (!GetConnectedNode()) {
Expand Down Expand Up @@ -2039,11 +2019,12 @@ void TimelineWidget::RestoreSplitterState(const QByteArray &state)

void TimelineWidget::StartRubberBandSelect(const QPoint &global_cursor_start)
{
drag_origin_ = global_cursor_start;

// Start rubberband at origin
QPoint local_origin = mapFromGlobal(drag_origin_);
rubberband_.setGeometry(QRect(local_origin.x(), local_origin.y(), 0, 0));
// Store scene positions for each view
rubberband_scene_pos_.resize(views_.size());
for (int i = 0; i < rubberband_scene_pos_.size(); i++) {
TimelineView *v = views_.at(i)->view();
rubberband_scene_pos_[i] = v->UnscalePoint(v->mapToScene(v->mapFromGlobal(global_cursor_start)));
}

rubberband_.show();

Expand All @@ -2056,14 +2037,30 @@ void TimelineWidget::MoveRubberBandSelect(bool enable_selecting, bool select_lin
{
QPoint rubberband_now = QCursor::pos();

rubberband_.setGeometry(QRect(mapFromGlobal(drag_origin_), mapFromGlobal(rubberband_now)).normalized());
TimelineView *fv = views_.first()->view();
const QPointF &rubberband_scene_start = rubberband_scene_pos_.at(0);
QPointF rubberband_now_scaled = fv->UnscalePoint(fv->mapToScene(fv->mapFromGlobal(rubberband_now)));

QPoint rubberband_local_start = fv->mapTo(this, fv->mapFromScene(fv->ScalePoint(rubberband_scene_start)));
QPoint rubberband_local_now = fv->mapTo(this, fv->mapFromScene(fv->ScalePoint(rubberband_now_scaled)));

rubberband_.setGeometry(QRect(rubberband_local_start, rubberband_local_now).normalized());

rubberband_enable_selecting_ = enable_selecting;
rubberband_select_links_ = select_links;

if (!enable_selecting) {
return;
}

// Get current items in rubberband
QVector<Block*> items_in_rubberband = GetBlocksInGlobalRect(drag_origin_, rubberband_now);
QVector<Block*> items_in_rubberband;

for (int i = 0; i < views_.size(); i++) {
TimelineView *v = views_.at(i)->view();
QRectF r = QRectF(v->ScalePoint(rubberband_scene_pos_.at(i)), v->mapToScene(v->mapFromGlobal(rubberband_now))).normalized();
items_in_rubberband.append(v->GetItemsAtSceneRect(r));
}

// Reset selection to whatever it was before
SetSelections(rubberband_old_selections_, false);
Expand Down
Loading

0 comments on commit 9824760

Please sign in to comment.