]> sigrok.org Git - pulseview.git/commitdiff
Added context widgets to TimeMarker
authorJoel Holdsworth <redacted>
Sun, 19 May 2013 09:37:31 +0000 (10:37 +0100)
committerJoel Holdsworth <redacted>
Sun, 19 May 2013 11:24:53 +0000 (12:24 +0100)
pv/view/timemarker.cpp
pv/view/timemarker.h

index 5db9e9fe77ae3c0fa4ec2e4e069c9364e704ffbb..03749689cb44aa602f5ce12e68affb55c821d5d9 100644 (file)
@@ -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<QAction*> TimeMarker::get_context_bar_actions()
 {
        list<QAction*> 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
index f12fa2965693b7d7580b3b8638c8c9174f5f8561..63733f7a5c9a4a9040f4660db5b0ebf152c490c0 100644 (file)
 #define PULSEVIEW_PV_VIEW_MARKER_H
 
 #include <QColor>
+#include <QDoubleSpinBox>
 #include <QObject>
 #include <QRectF>
+#include <QWidgetAction>
 
 #include "selectableitem.h"
 
@@ -88,6 +90,9 @@ public:
         */
        const std::list<QAction*> 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