Trace: Introduce hover_point_changed()
[pulseview.git] / pv / view / trace.cpp
index 250376ebb8828d931300a8a1a9ba5fc96ca4b749..61a002bb80f422a042f300c9d01526b04d810730 100644 (file)
@@ -42,6 +42,7 @@ const QPen Trace::AxisPen(QColor(128, 128, 128, 64));
 const int Trace::LabelHitPadding = 2;
 
 Trace::Trace(QString name) :
+       _view(NULL),
        _name(name),
        _v_offset(0),
        _popup(NULL),
@@ -82,7 +83,15 @@ void Trace::set_v_offset(int v_offset)
 void Trace::set_view(pv::view::View *view)
 {
        assert(view);
+
+       if (_view)
+               disconnect(_view, SIGNAL(hover_point_changed()),
+                       this, SLOT(on_hover_point_changed()));
+
        _view = view;
+
+       connect(view, SIGNAL(hover_point_changed()),
+               this, SLOT(on_hover_point_changed()));
 }
 
 void Trace::paint_back(QPainter &p, int left, int right)
@@ -219,24 +228,6 @@ QRectF Trace::get_label_rect(int right)
                label_size.width(), label_size.height());
 }
 
-bool Trace::eventFilter(QObject *obj, QEvent *evt)
-{
-       QKeyEvent *keyEvent;
-
-       (void)obj;
-
-       if (evt->type() == QEvent::KeyPress) {
-               keyEvent = static_cast<QKeyEvent*>(evt);
-               if (keyEvent->key() == Qt::Key_Enter ||
-                   keyEvent->key() == Qt::Key_Return) {
-                       close_popup();
-                       return true;
-               }
-       }
-
-       return false;
-}
-
 QColor Trace::get_text_colour() const
 {
        return (_colour.lightness() > 64) ? Qt::black : Qt::white;
@@ -282,21 +273,15 @@ void Trace::populate_popup_form(QWidget *parent, QFormLayout *form)
 {
        QLineEdit *const name_edit = new QLineEdit(parent);
        name_edit->setText(_name);
-       name_edit->selectAll();
-       name_edit->setFocus();
        connect(name_edit, SIGNAL(textChanged(const QString&)),
                this, SLOT(on_text_changed(const QString&)));
        form->addRow(tr("Name"), name_edit);
 
-       // We want to close the popup when the Enter key was pressed.
-       name_edit->installEventFilter(this);
-
        add_colour_option(parent, form);
 }
 
-void Trace::close_popup()
+void Trace::hover_point_changed()
 {
-       _popup->close();
 }
 
 void Trace::on_popup_closed()
@@ -317,5 +302,10 @@ void Trace::on_colour_changed(const QColor &colour)
        colour_changed();
 }
 
+void Trace::on_hover_point_changed()
+{
+       hover_point_changed();
+}
+
 } // namespace view
 } // namespace pv