Added a label context bar action
[pulseview.git] / pv / view / signal.cpp
index dd50243a7095c468f4a424ca0e46f9251919c1dc..bb86d8cb6d0add9c3585c8690dee22c60d06579a 100644 (file)
@@ -32,16 +32,45 @@ namespace pv {
 namespace view {
 
 const int Signal::LabelHitPadding = 2;
-const int Signal::LabelHighlightRadius = 6;
 
 const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64));
 
+const char *const ProbeNames[] = {
+       "CLK",
+       "DATA",
+       "IN",
+       "OUT",
+       "RST",
+       "Tx",
+       "Rx",
+       "EN",
+       "SCLK",
+       "MOSI",
+       "MISO",
+       "/SS",
+       "SDA",
+       "SCL"
+};
+
 Signal::Signal(const sr_probe *const probe) :
        _probe(probe),
        _name(probe->name),
-       _v_offset(0)
+       _v_offset(0),
+       _name_action(NULL),
+       _name_widget(),
+       _updating_name_widget(false)
 {
        assert(_probe);
+
+       _name_action.setDefaultWidget(&_name_widget);
+
+       _name_widget.setEditable(true);
+       for(unsigned int i = 0; i < countof(ProbeNames); i++)
+               _name_widget.insertItem(i, ProbeNames[i]);
+       _name_widget.setEditText(probe->name);
+
+       connect(&_name_widget, SIGNAL(editTextChanged(const QString&)),
+               this, SLOT(on_text_changed(const QString&)));
 }
 
 QString Signal::get_name() const
@@ -52,6 +81,9 @@ QString Signal::get_name() const
 void Signal::set_name(QString name)
 {
        _name = name;
+       _updating_name_widget = true;
+       _name_widget.setEditText(name);
+       _updating_name_widget = false;
 }
 
 QColor Signal::get_colour() const
@@ -104,9 +136,7 @@ void Signal::paint_label(QPainter &p, int y, int right, bool hover)
        };
 
        if (selected()) {
-               p.setPen(QPen(QApplication::palette().brush(
-                       QPalette::Highlight), LabelHighlightRadius,
-                       Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+               p.setPen(highlight_pen());
                p.setBrush(Qt::transparent);
                p.drawPolygon(points, countof(points));
        }
@@ -168,5 +198,11 @@ QRectF Signal::get_label_rect(int y, int right)
                label_size.width(), label_size.height());
 }
 
+void Signal::on_text_changed(const QString &text)
+{
+       _name = text;
+       text_changed();
+}
+
 } // namespace view
 } // namespace pv