]> sigrok.org Git - pulseview.git/commitdiff
Added a context menu for set name
authorJoel Holdsworth <redacted>
Sat, 20 Oct 2012 10:10:54 +0000 (11:10 +0100)
committerJoel Holdsworth <redacted>
Sat, 20 Oct 2012 17:29:25 +0000 (18:29 +0100)
pv/signal.cpp
pv/signal.h
pv/view/header.cpp
pv/view/header.h

index 091dd8d4406ef62dfc56b325c96f770890342323..aeb693b77d043a670556fd1889e40395211d931e 100644 (file)
@@ -37,6 +37,11 @@ QString Signal::get_name() const
        return _name;
 }
 
+void Signal::set_name(QString name)
+{
+       _name = name;
+}
+
 void Signal::paint_label(QPainter &p, const QRect &rect, bool hover)
 {
        p.setBrush(get_colour());
index b4c4244ca3fc438f7a71441bfc0a7de80fec0674..18ff4b4d619239b233bc3bbad5f92b67efc0874a 100644 (file)
@@ -40,8 +40,16 @@ protected:
        Signal(QString name);
 
 public:
+       /**
+        * Gets the name of this signal.
+        */
        QString get_name() const;
 
+       /**
+        * Sets the name of the signal.
+        */
+       void set_name(QString name);
+
        /**
         * Paints the signal with a QPainter
         * @param p the QPainter to paint into.
index 8fe9d485b761c5874625836b1aa469669bf135ba..1c7903dbc372d38d55366b771c49fe3854de9bdf 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <boost/foreach.hpp>
 
+#include <QInputDialog>
+#include <QMenu>
 #include <QMouseEvent>
 #include <QPainter>
 #include <QRect>
@@ -40,9 +42,13 @@ namespace view {
 
 Header::Header(View &parent) :
        QWidget(&parent),
-       _view(parent)
+       _view(parent),
+       _action_set_name(new QAction(tr("Set &Name..."), this))
 {
        setMouseTracking(true);
+
+       connect(_action_set_name, SIGNAL(triggered()),
+               this, SLOT(on_action_set_name_triggered()));
 }
 
 void Header::paintEvent(QPaintEvent *event)
@@ -84,5 +90,47 @@ void Header::leaveEvent(QEvent *event)
        update();
 }
 
+void Header::contextMenuEvent(QContextMenuEvent *event)
+{
+       const int w = width();
+       const vector< shared_ptr<Signal> > &sigs =
+               _view.session().get_signals();
+
+       int offset = -_view.v_offset();
+       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+       {
+               assert(s);
+
+               const QRect signal_heading_rect(
+                       0, offset, w, View::SignalHeight);
+
+               if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) {
+                       QMenu menu(this);
+                       menu.addAction(_action_set_name);
+
+                       _context_signal = s;
+                       menu.exec(event->globalPos());
+                       _context_signal.reset();
+
+                       break;
+               }
+
+               offset += View::SignalHeight;
+       }
+}
+
+void Header::on_action_set_name_triggered()
+{
+       boost::shared_ptr<Signal> context_signal = _context_signal;
+       if(!context_signal)
+               return;
+
+       const QString new_label = QInputDialog::getText(this, tr("Set Name"),
+               tr("Name"), QLineEdit::Normal, context_signal->get_name());
+
+       if(!new_label.isEmpty())
+               context_signal->set_name(new_label);
+}
+
 } // namespace view
 } // namespace pv
index 5693a8a0d4f1bfc0d5a16e294d4f6d745e3c1a7b..a92d11737873806f61f3092858ee9afc1cf619c1 100644 (file)
 #ifndef PV_VIEW_HEADER_H
 #define PV_VIEW_HEADER_H
 
+#include <boost/shared_ptr.hpp>
+
 #include <QWidget>
 
 namespace pv {
+
+class Signal;
+
 namespace view {
 
 class View;
@@ -43,10 +48,18 @@ private:
 
        void leaveEvent(QEvent *event);
 
+       void contextMenuEvent(QContextMenuEvent *event);
+
+private slots:
+       void on_action_set_name_triggered();
+
 private:
        View &_view;
 
        QPoint _mouse_point;
+
+       boost::shared_ptr<pv::Signal> _context_signal;
+       QAction *_action_set_name;
 };
 
 } // namespace view