]> sigrok.org Git - pulseview.git/blobdiff - pv/view/timemarker.cpp
ViewPort: Make ViewItemPaintParams mutable
[pulseview.git] / pv / view / timemarker.cpp
index 3014b4a65a8e6d67adbfaa12d685766d4035302f..eaa03b942294e62c4500f7b59bdbccb1a4b3ef8d 100644 (file)
  */
 
 #include <algorithm>
+#include <cmath>
 
 #include <extdef.h>
 
 #include "timemarker.hpp"
 
-#include "view.hpp"
 #include "pv/widgets/timestampspinbox.hpp"
+#include "view.hpp"
 
 #include <QApplication>
-#include <QFormLayout>
 #include <QFontMetrics>
+#include <QFormLayout>
 #include <QPainter>
 
 #include <pv/widgets/popup.hpp>
@@ -73,7 +74,7 @@ void TimeMarker::set_time(const pv::util::Timestamp& time)
 
 float TimeMarker::get_x() const
 {
-       return ((time_ - view_.offset()) / view_.scale()).convert_to<float>();
+       return std::roundf(((time_ - view_.offset()) / view_.scale()).convert_to<float>()) + 0.5f;
 }
 
 QPoint TimeMarker::point(const QRect &rect) const
@@ -107,7 +108,7 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover)
        if (!enabled())
                return;
 
-       const qreal x = ((time_ - view_.offset()) / view_.scale()).convert_to<qreal>();
+       const qreal x = get_x();
        const QRectF r(label_rect(rect));
 
        const QPointF points[] = {
@@ -153,7 +154,7 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover)
        p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, get_text());
 }
 
-void TimeMarker::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void TimeMarker::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        if (!enabled())
                return;