Enable marker snapping
This commit is contained in:
@@ -158,10 +158,22 @@ void Marker::mouseMoveEvent(QMouseEvent* e)
|
||||
if (drag_allowed_) {
|
||||
dragging_ = true;
|
||||
|
||||
int new_pos = marker_start_x_ + e->globalPos().x() - click_position_.x();
|
||||
int new_position = marker_start_x_ + e->globalPos().x() - click_position_.x();
|
||||
|
||||
if (new_pos > -marker_width_ / 2 && new_pos < static_cast<SeekableWidget *>(parent())->width() - marker_width_ / 2) {
|
||||
this->move(new_pos-2, this->pos().y());
|
||||
rational marker_time = static_cast<SeekableWidget *>(parent())->ScreenToTime(new_position);
|
||||
|
||||
if (Core::instance()->snapping()) {
|
||||
rational movement;
|
||||
static_cast<SeekableWidget *>(parent())->GetSnapService()->SnapPoint({marker_time}, &movement);
|
||||
if (!movement.isNull()) {
|
||||
marker_time += movement;
|
||||
}
|
||||
|
||||
new_position = static_cast<SeekableWidget *>(parent())->TimeToScene(marker_time);
|
||||
}
|
||||
|
||||
if (new_position > -marker_width_ / 2 && new_position < static_cast<SeekableWidget *>(parent())->width() - marker_width_ / 2) {
|
||||
this->move(new_position-2, this->pos().y());
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
|
||||
void SetSnapService(SnapService* service);
|
||||
|
||||
SnapService* GetSnapService() { return snap_service_; };
|
||||
|
||||
bool IsDraggingPlayhead() const
|
||||
{
|
||||
return dragging_;
|
||||
@@ -66,6 +68,9 @@ public:
|
||||
|
||||
void SeekToScreenPoint(int screen);
|
||||
|
||||
int TimeToScreen(const rational& time) const;
|
||||
rational ScreenToTime(int x) const;
|
||||
|
||||
public slots:
|
||||
void SetTime(const rational &r);
|
||||
|
||||
@@ -91,9 +96,6 @@ protected:
|
||||
|
||||
TimelinePoints* timeline_points() const;
|
||||
|
||||
int TimeToScreen(const rational& time) const;
|
||||
rational ScreenToTime(int x) const;
|
||||
|
||||
void DrawPlayhead(QPainter* p, int x, int y);
|
||||
|
||||
inline const int& text_height() const {
|
||||
|
||||
Reference in New Issue
Block a user