From: Joel Holdsworth Date: Sun, 19 May 2013 09:37:31 +0000 (+0100) Subject: Added context widgets to TimeMarker X-Git-Tag: pulseview-0.2.0~343 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1e256e16a17271fab3c9c57de3558b3b1c8184f4;p=pulseview.git Added context widgets to TimeMarker --- diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 5db9e9fe..03749689 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -32,8 +32,20 @@ namespace view { TimeMarker::TimeMarker(View &view, const QColor &colour, double time) : _view(view), _colour(colour), - _time(time) + _time(time), + _value_action(&view), + _value_widget(&view), + _updating_value_widget(false) { + _value_action.setDefaultWidget(&_value_widget); + + _value_widget.setValue(time); + _value_widget.setDecimals(6); + _value_widget.setSuffix("s"); + _value_widget.setSingleStep(1e-6); + + connect(&_value_widget, SIGNAL(valueChanged(double)), + this, SLOT(on_value_changed(double))); } double TimeMarker::time() const @@ -44,6 +56,9 @@ double TimeMarker::time() const void TimeMarker::set_time(double time) { _time = time; + _updating_value_widget = true; + _value_widget.setValue(time); + _updating_value_widget = false; time_changed(); } @@ -57,8 +72,17 @@ void TimeMarker::paint(QPainter &p, const QRect &rect) const list TimeMarker::get_context_bar_actions() { list actions; + actions.push_back(&_value_action); return actions; } +void TimeMarker::on_value_changed(double value) +{ + if (!_updating_value_widget) { + _time = value; + time_changed(); + } +} + } // namespace view } // namespace pv diff --git a/pv/view/timemarker.h b/pv/view/timemarker.h index f12fa296..63733f7a 100644 --- a/pv/view/timemarker.h +++ b/pv/view/timemarker.h @@ -22,8 +22,10 @@ #define PULSEVIEW_PV_VIEW_MARKER_H #include +#include #include #include +#include #include "selectableitem.h" @@ -88,6 +90,9 @@ public: */ const std::list get_context_bar_actions(); +private slots: + void on_value_changed(double value); + signals: void time_changed(); @@ -98,6 +103,10 @@ protected: double _time; QSizeF _text_size; + + QWidgetAction _value_action; + QDoubleSpinBox _value_widget; + bool _updating_value_widget; }; } // namespace view