]> sigrok.org Git - pulseview.git/commitdiff
Added signal (multi) selection
authorJoel Holdsworth <redacted>
Sat, 17 Nov 2012 08:13:31 +0000 (08:13 +0000)
committerJoel Holdsworth <redacted>
Sat, 17 Nov 2012 12:34:31 +0000 (12:34 +0000)
pv/view/header.cpp
pv/view/header.h
pv/view/signal.cpp
pv/view/signal.h

index 125d3c2430ba868d95c0f535e162d9279dda9e90..8434e2c8dc9ffb289c676f338d151793367e5a8e 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <boost/foreach.hpp>
 
+#include <QApplication>
 #include <QColorDialog>
 #include <QInputDialog>
 #include <QMenu>
@@ -55,6 +56,29 @@ Header::Header(View &parent) :
                this, SLOT(on_action_set_colour_triggered()));
 }
 
+boost::shared_ptr<pv::view::Signal> Header::get_mouse_over_signal(
+       const QPoint &pt)
+{
+       const int w = width();
+       const vector< shared_ptr<Signal> > &sigs =
+               _view.session().get_signals();
+
+       const int v_offset = _view.v_offset();
+       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+       {
+               assert(s);
+
+               const QRect signal_heading_rect(
+                       0, s->get_v_offset() - v_offset,
+                       w, View::SignalHeight);
+
+               if(s->pt_in_label_rect(signal_heading_rect, pt))
+                       return s;
+       }
+
+       return shared_ptr<Signal>();
+}
+
 void Header::paintEvent(QPaintEvent *event)
 {
        const int w = width();
@@ -80,6 +104,29 @@ void Header::paintEvent(QPaintEvent *event)
        painter.end();
 }
 
+void Header::mousePressEvent(QMouseEvent *event)
+{
+       assert(event);
+
+       const vector< shared_ptr<Signal> > &sigs =
+               _view.session().get_signals();
+
+       if(~QApplication::keyboardModifiers() & Qt::ControlModifier) {
+               // Unselect all other signals because the Ctrl is not
+               // pressed
+               BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+                       s->select(false);
+       }
+
+       // Select the signal if it has been clicked
+       const shared_ptr<Signal> mouse_over_signal =
+               get_mouse_over_signal(event->pos());
+       if(mouse_over_signal)
+               mouse_over_signal->select(!mouse_over_signal->selected());
+
+       update();
+}
+
 void Header::mouseMoveEvent(QMouseEvent *event)
 {
        assert(event);
@@ -95,31 +142,18 @@ void Header::leaveEvent(QEvent *event)
 
 void Header::contextMenuEvent(QContextMenuEvent *event)
 {
-       const int w = width();
-       const vector< shared_ptr<Signal> > &sigs =
-               _view.session().get_signals();
+       const shared_ptr<Signal> s = get_mouse_over_signal(_mouse_point);
 
-       const int v_offset = _view.v_offset();
-       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
-       {
-               assert(s);
-
-               const QRect signal_heading_rect(
-                       0, s->get_v_offset() - v_offset,
-                       w, View::SignalHeight);
-
-               if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) {
-                       QMenu menu(this);
-                       menu.addAction(_action_set_name);
-                       menu.addAction(_action_set_colour);
+       if(!s)
+               return;
 
-                       _context_signal = s;
-                       menu.exec(event->globalPos());
-                       _context_signal.reset();
+       QMenu menu(this);
+       menu.addAction(_action_set_name);
+       menu.addAction(_action_set_colour);
 
-                       break;
-               }
-       }
+       _context_signal = s;
+       menu.exec(event->globalPos());
+       _context_signal.reset();
 }
 
 void Header::on_action_set_name_triggered()
index efc126e9aa36d305bba37a39dd11b10cd5ad10a3..e5cd241f6308bc79a2bc64f6a92b5382eb0993e8 100644 (file)
@@ -38,10 +38,16 @@ class Header : public QWidget
 public:
        Header(View &parent);
 
+private:
+       boost::shared_ptr<pv::view::Signal> get_mouse_over_signal(
+               const QPoint &pt);
+
 private:
        void paintEvent(QPaintEvent *event);
 
 private:
+       void mousePressEvent(QMouseEvent * event);
+
        void mouseMoveEvent(QMouseEvent *event);
 
        void leaveEvent(QEvent *event);
index 02732ffc7a19112d3e6fc236b7beea57ccf6ed8c..8fed4273e86d40beeac77329f60e60f0c6f9ecf7 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <extdef.h>
 
+#include <QApplication>
+
 #include "signal.h"
 #include "view.h"
 
@@ -27,10 +29,12 @@ namespace pv {
 namespace view {
 
 const int Signal::LabelHitPadding = 2;
+const int Signal::LabelHighlightRadius = 6;
 
 Signal::Signal(QString name) :
        _name(name),
-       _v_offset(0)
+       _v_offset(0),
+       _selected(false)
 {
 }
 
@@ -64,6 +68,16 @@ void Signal::set_v_offset(int v_offset)
        _v_offset = v_offset;
 }
 
+bool Signal::selected() const
+{
+       return _selected;
+}
+
+void Signal::select(bool select)
+{
+       _selected = select;
+}
+
 void Signal::paint_label(QPainter &p, const QRect &rect, bool hover)
 {
        p.setBrush(_colour);
@@ -91,6 +105,14 @@ void Signal::paint_label(QPainter &p, const QRect &rect, bool hover)
                QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
        };
 
+       if(_selected) {
+               p.setPen(QPen(QApplication::palette().brush(
+                       QPalette::Highlight), LabelHighlightRadius,
+                       Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+               p.setBrush(Qt::transparent);
+               p.drawPolygon(points, countof(points));
+       }
+
        p.setPen(Qt::transparent);
        p.setBrush(hover ? colour.lighter() : colour);
        p.drawPolygon(points, countof(points));
index b3212394115df5c5b043d27969cb8dcdfd117d84..72d42cc2fd094098a634eea00b77a7cce606e77e 100644 (file)
@@ -40,6 +40,7 @@ class Signal
 {
 private:
        static const int LabelHitPadding;
+       static const int LabelHighlightRadius;
 
 protected:
        Signal(QString name);
@@ -75,6 +76,16 @@ public:
         */
        void set_v_offset(int v_offset);
 
+       /**
+        * Returns true if the signal has been selected by the user.
+        */
+       bool selected() const;
+
+       /**
+        * Selects or deselects the signal.
+        */
+       void select(bool select = true);
+
        /**
         * Paints the signal with a QPainter
         * @param p the QPainter to paint into.
@@ -130,6 +141,8 @@ protected:
        QColor _colour;
        int _v_offset;
 
+       bool _selected;
+
        QSizeF _text_size;
 };