Enable marker snapping

This commit is contained in:
Thomas Wilshaw
2021-11-08 20:51:38 +00:00
parent b4bfee1193
commit 3a5f0134af
2 changed files with 20 additions and 6 deletions
+15 -3
View File
@@ -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();
}
}
+5 -3
View File
@@ -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 {