reimplemented rubberband and hand drag routines
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
rubberband_(QRubberBand::Rectangle, this),
|
||||
hand_drag_view_(nullptr),
|
||||
timeline_node_(nullptr),
|
||||
playhead_(0)
|
||||
{
|
||||
@@ -588,7 +589,7 @@ void TimelineWidget::AddGhost(TimelineViewGhostItem *ghost)
|
||||
|
||||
void TimelineWidget::StartRubberBandSelect(bool clear_current_selection)
|
||||
{
|
||||
rubberband_origin_ = QCursor::pos();
|
||||
drag_origin_ = QCursor::pos();
|
||||
rubberband_.show();
|
||||
|
||||
if (!clear_current_selection) {
|
||||
@@ -604,14 +605,14 @@ void TimelineWidget::MoveRubberBandSelect()
|
||||
{
|
||||
QPoint rubberband_now = QCursor::pos();
|
||||
|
||||
rubberband_.setGeometry(QRect(mapFromGlobal(rubberband_origin_), mapFromGlobal(rubberband_now)).normalized());
|
||||
rubberband_.setGeometry(QRect(mapFromGlobal(drag_origin_), mapFromGlobal(rubberband_now)).normalized());
|
||||
|
||||
foreach (TimelineView* view, views_) {
|
||||
view->DeselectAll();
|
||||
|
||||
// Map global mouse coordinates to viewport
|
||||
|
||||
QRect mapped_rect(view->viewport()->mapFromGlobal(rubberband_origin_),
|
||||
QRect mapped_rect(view->viewport()->mapFromGlobal(drag_origin_),
|
||||
view->viewport()->mapFromGlobal(rubberband_now));
|
||||
|
||||
// Normalize and get items in rect
|
||||
@@ -634,3 +635,31 @@ void TimelineWidget::EndRubberBandSelect()
|
||||
rubberband_.hide();
|
||||
rubberband_already_selected_.clear();
|
||||
}
|
||||
|
||||
void TimelineWidget::StartHandDrag()
|
||||
{
|
||||
// Determine which view to hand drag by which is under the cursor now
|
||||
foreach (TimelineView* view, views_) {
|
||||
if (view->underMouse()) {
|
||||
hand_drag_view_ = view;
|
||||
hand_drag_view_origin_ = view->GetScrollCoordinates();
|
||||
drag_origin_ = QCursor::pos();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::MoveHandDrag()
|
||||
{
|
||||
if (hand_drag_view_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Drag the view if we found one in StartHandDrag()
|
||||
hand_drag_view_->SetScrollCoordinates(hand_drag_view_origin_ + (drag_origin_ - QCursor::pos()));
|
||||
}
|
||||
|
||||
void TimelineWidget::EndHandDrag()
|
||||
{
|
||||
hand_drag_view_ = nullptr;
|
||||
}
|
||||
|
||||
@@ -80,11 +80,7 @@ private:
|
||||
|
||||
static olive::timeline::MovementMode FlipTrimMode(const olive::timeline::MovementMode& trim_mode);
|
||||
|
||||
const QGraphicsView::DragMode& drag_mode();
|
||||
|
||||
protected:
|
||||
void set_drag_mode(const QGraphicsView::DragMode& mode);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the QGraphicsItem at a particular scene position
|
||||
*
|
||||
@@ -128,8 +124,6 @@ private:
|
||||
private:
|
||||
TimelineWidget* parent_;
|
||||
|
||||
QGraphicsView::DragMode drag_mode_;
|
||||
|
||||
};
|
||||
|
||||
class PointerTool : public Tool
|
||||
@@ -269,6 +263,9 @@ private:
|
||||
public:
|
||||
HandTool(TimelineWidget* parent);
|
||||
|
||||
virtual void MousePress(TimelineViewMouseEvent *event);
|
||||
virtual void MouseMove(TimelineViewMouseEvent *event);
|
||||
virtual void MouseRelease(TimelineViewMouseEvent *event);
|
||||
private:
|
||||
QPoint screen_drag_start_;
|
||||
QPoint scrollbar_start_;
|
||||
@@ -284,13 +281,20 @@ private:
|
||||
virtual void MouseRelease(TimelineViewMouseEvent *event);
|
||||
};
|
||||
|
||||
QPoint drag_origin_;
|
||||
|
||||
void StartRubberBandSelect(bool clear_current_selection);
|
||||
void MoveRubberBandSelect();
|
||||
void EndRubberBandSelect();
|
||||
QRubberBand rubberband_;
|
||||
QPoint rubberband_origin_;
|
||||
QList<QGraphicsItem*> rubberband_already_selected_;
|
||||
|
||||
void StartHandDrag();
|
||||
void MoveHandDrag();
|
||||
void EndHandDrag();
|
||||
TimelineView* hand_drag_view_;
|
||||
QPoint hand_drag_view_origin_;
|
||||
|
||||
Tool* GetActiveTool();
|
||||
|
||||
QVector< std::shared_ptr<Tool> > tools_;
|
||||
|
||||
@@ -25,5 +25,19 @@
|
||||
TimelineWidget::HandTool::HandTool(TimelineWidget* parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
set_drag_mode(QGraphicsView::ScrollHandDrag);
|
||||
}
|
||||
|
||||
void TimelineWidget::HandTool::MousePress(TimelineViewMouseEvent *)
|
||||
{
|
||||
parent()->StartHandDrag();
|
||||
}
|
||||
|
||||
void TimelineWidget::HandTool::MouseMove(TimelineViewMouseEvent *)
|
||||
{
|
||||
parent()->MoveHandDrag();
|
||||
}
|
||||
|
||||
void TimelineWidget::HandTool::MouseRelease(TimelineViewMouseEvent *)
|
||||
{
|
||||
parent()->EndHandDrag();
|
||||
}
|
||||
|
||||
@@ -237,8 +237,8 @@ void TimelineWidget::ImportTool::DragDrop(TimelineViewMouseEvent *event)
|
||||
if (event->GetModifiers() & Qt::ControlModifier) {
|
||||
//emit parent()->RequestInsertBlockAtTime(clip, ghost->GetAdjustedIn());
|
||||
} else {
|
||||
new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(ghost->Track().type()),
|
||||
ghost->Track().index(),
|
||||
new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(ghost->GetAdjustedTrack().type()),
|
||||
ghost->GetAdjustedTrack().index(),
|
||||
clip,
|
||||
ghost->GetAdjustedIn(),
|
||||
command);
|
||||
|
||||
@@ -38,7 +38,6 @@ TimelineWidget::PointerTool::PointerTool(TimelineWidget *parent) :
|
||||
track_movement_allowed_(true),
|
||||
rubberband_selecting_(false)
|
||||
{
|
||||
set_drag_mode(QGraphicsView::RubberBandDrag);
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::MousePress(TimelineViewMouseEvent *event)
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
|
||||
TimelineWidget::Tool::Tool(TimelineWidget *parent) :
|
||||
dragging_(false),
|
||||
parent_(parent),
|
||||
drag_mode_(QGraphicsView::NoDrag)
|
||||
parent_(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -53,16 +52,6 @@ olive::timeline::MovementMode TimelineWidget::Tool::FlipTrimMode(const olive::ti
|
||||
return trim_mode;
|
||||
}
|
||||
|
||||
const QGraphicsView::DragMode &TimelineWidget::Tool::drag_mode()
|
||||
{
|
||||
return drag_mode_;
|
||||
}
|
||||
|
||||
void TimelineWidget::Tool::set_drag_mode(const QGraphicsView::DragMode &mode)
|
||||
{
|
||||
drag_mode_ = mode;
|
||||
}
|
||||
|
||||
TimelineViewBlockItem *TimelineWidget::Tool::GetItemAtScenePos(const TimelineCoordinate& coord)
|
||||
{
|
||||
QMapIterator<Block*, TimelineViewBlockItem*> iterator(parent()->block_items_);
|
||||
|
||||
@@ -42,7 +42,7 @@ TimelineView::TimelineView(const TrackType &type, Qt::Alignment vertical_alignme
|
||||
setAlignment(Qt::AlignLeft | vertical_alignment);
|
||||
|
||||
setScene(&scene_);
|
||||
setDragMode(RubberBandDrag);
|
||||
setDragMode(NoDrag);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
setBackgroundRole(QPalette::Window);
|
||||
|
||||
@@ -249,6 +249,17 @@ int TimelineView::GetTrackHeight(int track_index)
|
||||
return fontMetrics().height() * 3;
|
||||
}
|
||||
|
||||
QPoint TimelineView::GetScrollCoordinates()
|
||||
{
|
||||
return QPoint(horizontalScrollBar()->value(), verticalScrollBar()->value());
|
||||
}
|
||||
|
||||
void TimelineView::SetScrollCoordinates(const QPoint &pt)
|
||||
{
|
||||
horizontalScrollBar()->setValue(pt.x());
|
||||
verticalScrollBar()->setValue(pt.y());
|
||||
}
|
||||
|
||||
int TimelineView::SceneToTrack(double y)
|
||||
{
|
||||
int track = -1;
|
||||
|
||||
@@ -61,6 +61,9 @@ public:
|
||||
int GetTrackY(int track_index);
|
||||
int GetTrackHeight(int track_index);
|
||||
|
||||
QPoint GetScrollCoordinates();
|
||||
void SetScrollCoordinates(const QPoint& pt);
|
||||
|
||||
public slots:
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user