From: Soeren Apel Date: Sun, 23 Jul 2017 07:35:25 +0000 (+0200) Subject: Improve hover point signaling X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=commitdiff_plain;h=873e80357d9622678069fcfe83b010717a68284c Improve hover point signaling Two issues here: 1) it's bad style to have an event handler for an event that was triggered in the same class 2) supplying the current hover point along with the event is a sensible thing to do --- diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index b485733..7bbc5a1 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -710,15 +710,13 @@ const QString DecodeTrace::get_annotation_at_point(const QPoint &point) QString() : annotations[0].annotations().front(); } -void DecodeTrace::hover_point_changed() +void DecodeTrace::hover_point_changed(const QPoint &hp) { assert(owner_); const View *const view = owner_->view(); assert(view); - QPoint hp = view->hover_point(); - if (hp.x() == 0) { QToolTip::hideText(); return; @@ -746,13 +744,14 @@ void DecodeTrace::hover_point_changed() // If it did, the tool tip would constantly hide and re-appear. // We also push it up by one row so that it appears above the // decode trace, not below. - hp.setX(hp.x() - (text_size.width() / 2) - padding); + QPoint p = hp; + p.setX(hp.x() - (text_size.width() / 2) - padding); - hp.setY(get_visual_y() - (row_height_ / 2) + + p.setY(get_visual_y() - (row_height_ / 2) + (hover_row * row_height_) - row_height_ - text_size.height() - padding); - QToolTip::showText(view->viewport()->mapToGlobal(hp), ann); + QToolTip::showText(view->viewport()->mapToGlobal(p), ann); } void DecodeTrace::create_decoder_form(int index, diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index d6a1fbb..fe3503b 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -179,7 +179,7 @@ private: const data::DecodeChannel *ch); public: - void hover_point_changed(); + void hover_point_changed(const QPoint &hp); private Q_SLOTS: void on_new_annotations(); diff --git a/pv/views/trace/rowitem.cpp b/pv/views/trace/rowitem.cpp index 11a02e9..c57043d 100644 --- a/pv/views/trace/rowitem.cpp +++ b/pv/views/trace/rowitem.cpp @@ -23,8 +23,9 @@ namespace pv { namespace views { namespace trace { -void RowItem::hover_point_changed() +void RowItem::hover_point_changed(const QPoint &hp) { + (void)hp; } } // namespace trace diff --git a/pv/views/trace/rowitem.hpp b/pv/views/trace/rowitem.hpp index ae91d4b..d2a205f 100644 --- a/pv/views/trace/rowitem.hpp +++ b/pv/views/trace/rowitem.hpp @@ -31,7 +31,7 @@ class RowItem : public ViewItem Q_OBJECT public: - virtual void hover_point_changed(); + virtual void hover_point_changed(const QPoint &hp); }; } // namespace trace diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index 5455b20..0526bb2 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -46,8 +46,8 @@ Ruler::Ruler(View &parent) : { setMouseTracking(true); - connect(&view_, SIGNAL(hover_point_changed()), - this, SLOT(hover_point_changed())); + connect(&view_, SIGNAL(hover_point_changed(QPoint)), + this, SLOT(hover_point_changed(QPoint))); connect(&view_, SIGNAL(offset_changed()), this, SLOT(invalidate_tick_position_cache())); connect(&view_, SIGNAL(scale_changed()), @@ -256,8 +256,10 @@ int Ruler::calculate_text_height() const return QFontMetrics(font()).ascent(); } -void Ruler::hover_point_changed() +void Ruler::hover_point_changed(const QPoint &hp) { + (void)hp; + update(); } diff --git a/pv/views/trace/ruler.hpp b/pv/views/trace/ruler.hpp index 40aae48..661254a 100644 --- a/pv/views/trace/ruler.hpp +++ b/pv/views/trace/ruler.hpp @@ -171,7 +171,7 @@ protected: void resizeEvent(QResizeEvent*) override; private Q_SLOTS: - void hover_point_changed(); + void hover_point_changed(const QPoint &hp); // Resets the 'tick_position_cache_'. void invalidate_tick_position_cache(); diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index f8378d9..bda056a 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -212,9 +212,6 @@ View::View(Session &session, bool is_main_view, QWidget *parent) : connect(splitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(on_splitter_moved())); - connect(this, SIGNAL(hover_point_changed()), - this, SLOT(on_hover_point_changed())); - connect(&lazy_event_handler_, SIGNAL(timeout()), this, SLOT(process_sticky_events())); lazy_event_handler_.setSingleShot(true); @@ -1005,11 +1002,11 @@ bool View::eventFilter(QObject *object, QEvent *event) else hover_point_ = QPoint(-1, -1); - hover_point_changed(); + update_hover_point(); } else if (type == QEvent::Leave) { hover_point_ = QPoint(-1, -1); - hover_point_changed(); + update_hover_point(); } else if (type == QEvent::Show) { // This is somewhat of a hack, unfortunately. We cannot use @@ -1047,6 +1044,16 @@ void View::resizeEvent(QResizeEvent* event) update_layout(); } +void View::update_hover_point() +{ + const vector> trace_tree_items( + list_by_type()); + for (shared_ptr r : trace_tree_items) + r->hover_point_changed(hover_point_); + + hover_point_changed(hover_point_); +} + void View::row_item_appearance_changed(bool label, bool content) { if (label) @@ -1388,14 +1395,6 @@ void View::process_sticky_events() sticky_events_ = 0; } -void View::on_hover_point_changed() -{ - const vector> trace_tree_items( - list_by_type()); - for (shared_ptr r : trace_tree_items) - r->hover_point_changed(); -} - } // namespace trace } // namespace views } // namespace pv diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index a42f964..f0aa491 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -269,7 +269,7 @@ public: void restack_all_trace_tree_items(); Q_SIGNALS: - void hover_point_changed(); + void hover_point_changed(const QPoint &hp); void selection_changed(); @@ -347,6 +347,8 @@ private: void resizeEvent(QResizeEvent *event); + void update_hover_point(); + public: void row_item_appearance_changed(bool label, bool content); void time_item_appearance_changed(bool label, bool content); @@ -367,8 +369,6 @@ private Q_SLOTS: void process_sticky_events(); - void on_hover_point_changed(); - /** * Sets the 'offset_' member and emits the 'offset_changed' * signal if needed.