]> sigrok.org Git - pulseview.git/blobdiff - pv/view/timemarker.cpp
RowItemOwner: Added list_by_type
[pulseview.git] / pv / view / timemarker.cpp
index 4b8d2b527a5992dc43c4e58f15c68d02dcf0312d..e4ef3c0e1cb5edff4a2765484ca93a3697431369 100644 (file)
@@ -40,14 +40,13 @@ namespace pv {
 namespace view {
 
 const int TimeMarker::ArrowSize = 4;
-const int TimeMarker::Offset = 1;
 
 TimeMarker::TimeMarker(View &view, const QColor &colour, double time) :
        TimeItem(view),
        colour_(colour),
        time_(time),
-       value_action_(NULL),
-       value_widget_(NULL),
+       value_action_(nullptr),
+       value_widget_(nullptr),
        updating_value_widget_(false)
 {
 }
@@ -75,29 +74,30 @@ float TimeMarker::get_x() const
        return (time_ - view_.offset()) / view_.scale();
 }
 
-QPoint TimeMarker::point() const
+QPoint TimeMarker::point(const QRect &rect) const
 {
-       return QPoint(get_x(), 0);
+       return QPoint(get_x(), rect.bottom());
 }
 
 QRectF TimeMarker::label_rect(const QRectF &rect) const
 {
-       const float x = (time_ - view_.offset()) / view_.scale();
-
        QFontMetrics m(QApplication::font());
-       const float text_width =
-               max(m.boundingRect(get_text()).size().width(), ArrowSize);
-       const float text_height = m.height();
-
-       const QSizeF label_size(
-               text_width + View::LabelPadding.width() * 2,
-               text_height + View::LabelPadding.height() * 2);
+       const QSizeF text_size(
+               max(m.boundingRect(get_text()).size().width(), ArrowSize),
+               m.height());
+       const QSizeF label_size(text_size + LabelPadding * 2);
        const float top = rect.height() - label_size.height() -
-               TimeMarker::Offset - TimeMarker::ArrowSize - 0.5f;
-       const float height = label_size.height();
+               TimeMarker::ArrowSize - 0.5f;
+       const float x = get_x();
+
+       return QRectF(QPointF(x - label_size.width() / 2, top), label_size);
+}
 
-       return QRectF(x - label_size.width() / 2, top,
-               label_size.width(), height);
+QRectF TimeMarker::hit_box_rect(const QRectF &rect) const
+{
+       const float x = get_x();
+       const float h = QFontMetrics(QApplication::font()).height();
+       return QRectF(x - h / 2.0f, rect.top(), h, rect.height());
 }
 
 void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover)
@@ -166,6 +166,9 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent)
        using pv::widgets::Popup;
 
        Popup *const popup = new Popup(parent);
+       popup->set_position(parent->mapToGlobal(
+               point(parent->rect())), Popup::Bottom);
+
        QFormLayout *const form = new QFormLayout(popup);
        popup->setLayout(form);