X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Ftimemarker.cpp;h=1e5b8206e54165ebc3cc36e20181eef686c422ce;hp=8eed6e7e2b6240c91c9cef368e3873df100b392b;hb=6454b1e960c85b17ec9590b78bc0387dc348ae9b;hpb=70a4886c67e381302d904d1d867abb9d8eac7053 diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 8eed6e7e..1e5b8206 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -40,7 +40,6 @@ 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), @@ -67,7 +66,7 @@ void TimeMarker::set_time(double time) updating_value_widget_ = false; } - time_changed(); + view_.time_item_appearance_changed(true, true); } float TimeMarker::get_x() const @@ -75,32 +74,33 @@ 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.boundingRect("Tg").size().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(x - label_size.width() / 2, top, - label_size.width(), height); + return QRectF(QPointF(x - label_size.width() / 2, top), label_size); } -void TimeMarker::paint_label(QPainter &p, const QRect &rect) +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) { if (!enabled()) return; @@ -136,7 +136,7 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect) } p.setPen(Qt::transparent); - p.setBrush(colour_); + p.setBrush(hover ? colour_.lighter() : colour_); p.drawPolygon(points, countof(points)); p.setPen(colour_.lighter()); @@ -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); @@ -186,10 +189,8 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent) void TimeMarker::on_value_changed(double value) { - if (!updating_value_widget_) { - time_ = value; - time_changed(); - } + if (!updating_value_widget_) + set_time(value); } } // namespace view