timeline: improved rubberband behavior
Improved rubberband responsiveness and show rubberband if dragging from a gap (or other such immovable block).
This commit is contained in:
@@ -1427,16 +1427,19 @@ void TimelineWidget::RestoreSplitterState(const QByteArray &state)
|
||||
view_splitter_->restoreState(state);
|
||||
}
|
||||
|
||||
void TimelineWidget::StartRubberBandSelect(bool enable_selecting, bool select_links)
|
||||
void TimelineWidget::StartRubberBandSelect(const QPoint &global_cursor_start)
|
||||
{
|
||||
drag_origin_ = QCursor::pos();
|
||||
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));
|
||||
|
||||
rubberband_.show();
|
||||
|
||||
// We don't touch any blocks that are already selected. If you want these to be deselected by
|
||||
// default, call DeselectAll() before calling StartRubberBandSelect()
|
||||
rubberband_old_selections_ = selections_;
|
||||
|
||||
MoveRubberBandSelect(enable_selecting, select_links);
|
||||
}
|
||||
|
||||
void TimelineWidget::MoveRubberBandSelect(bool enable_selecting, bool select_links)
|
||||
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
|
||||
void InsertGapsAt(const rational& time, const rational& length, QUndoCommand* command);
|
||||
|
||||
void StartRubberBandSelect(bool enable_selecting, bool select_links);
|
||||
void StartRubberBandSelect(const QPoint& global_cursor_start);
|
||||
void MoveRubberBandSelect(bool enable_selecting, bool select_links);
|
||||
void EndRubberBandSelect();
|
||||
|
||||
|
||||
@@ -121,21 +121,38 @@ void PointerTool::MousePress(TimelineViewMouseEvent *event)
|
||||
|
||||
parent()->SignalSelectedBlocks(selected_blocks);
|
||||
|
||||
} else if (event->GetButton() == Qt::LeftButton) {
|
||||
}
|
||||
|
||||
// Start rubberband drag
|
||||
parent()->StartRubberBandSelect(true, !(event->GetModifiers() & Qt::AltModifier));
|
||||
|
||||
rubberband_selecting_ = true;
|
||||
can_rubberband_select_ = (event->GetButton() == Qt::LeftButton // Only rubberband select from the primary mouse button
|
||||
&& (!selectable_item || drag_movement_mode_ == Timeline::kNone)); // And if no item was selected OR the item isn't draggable
|
||||
|
||||
if (can_rubberband_select_) {
|
||||
drag_global_start_ = QCursor::pos();
|
||||
}
|
||||
}
|
||||
|
||||
void PointerTool::MouseMove(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (rubberband_selecting_) {
|
||||
if (can_rubberband_select_) {
|
||||
|
||||
if (!rubberband_selecting_) {
|
||||
|
||||
// If we clicked an item but are rubberband selecting anyway, deselect it now
|
||||
if (clicked_item_) {
|
||||
parent()->RemoveSelection(clicked_item_);
|
||||
parent()->SignalDeselectedBlocks({clicked_item_->block()});
|
||||
clicked_item_ = nullptr;
|
||||
}
|
||||
|
||||
parent()->StartRubberBandSelect(drag_global_start_);
|
||||
|
||||
rubberband_selecting_ = true;
|
||||
|
||||
}
|
||||
|
||||
// Process rubberband select
|
||||
parent()->MoveRubberBandSelect(true, !(event->GetModifiers() & Qt::AltModifier));
|
||||
|
||||
} else {
|
||||
// Process drag
|
||||
if (!dragging_) {
|
||||
|
||||
@@ -113,6 +113,7 @@ private:
|
||||
bool trimming_allowed_;
|
||||
bool track_movement_allowed_;
|
||||
bool gap_trimming_allowed_;
|
||||
bool can_rubberband_select_;
|
||||
bool rubberband_selecting_;
|
||||
|
||||
Timeline::TrackType drag_track_type_;
|
||||
@@ -120,6 +121,8 @@ private:
|
||||
|
||||
TimelineViewBlockItem* clicked_item_;
|
||||
|
||||
QPoint drag_global_start_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -31,19 +31,21 @@ ZoomTool::ZoomTool(TimelineWidget *parent) :
|
||||
void ZoomTool::MousePress(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
drag_global_start_ = QCursor::pos();
|
||||
}
|
||||
|
||||
void ZoomTool::MouseMove(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
if (dragging_) {
|
||||
parent()->MoveRubberBandSelect(false, false);
|
||||
} else {
|
||||
parent()->StartRubberBandSelect(false, false);
|
||||
if (!dragging_) {
|
||||
parent()->StartRubberBandSelect(drag_global_start_);
|
||||
|
||||
dragging_ = true;
|
||||
}
|
||||
|
||||
parent()->MoveRubberBandSelect(false, false);
|
||||
}
|
||||
|
||||
void ZoomTool::MouseRelease(TimelineViewMouseEvent *event)
|
||||
|
||||
@@ -34,6 +34,9 @@ public:
|
||||
virtual void MouseMove(TimelineViewMouseEvent *event) override;
|
||||
virtual void MouseRelease(TimelineViewMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
QPoint drag_global_start_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user