Integration Popup into Trace
authorJoel Holdsworth <joel@airwebreahe.org.uk>
Wed, 25 Sep 2013 07:19:03 +0000 (16:19 +0900)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Sun, 13 Oct 2013 10:05:22 +0000 (11:05 +0100)
pv/view/header.cpp
pv/view/trace.cpp
pv/view/trace.h

index 549b71918627b4bd1a6d0e01f2e20f6fe17994f6..f8f5b6380514ac2604730ce0a687c0c469fff04a 100644 (file)
@@ -34,6 +34,8 @@
 #include <QPainter>
 #include <QRect>
 
+#include <pv/widgets/popup.h>
+
 using namespace boost;
 using namespace std;
 
@@ -151,11 +153,28 @@ void Header::mousePressEvent(QMouseEvent *event)
 
 void Header::mouseReleaseEvent(QMouseEvent *event)
 {
+       using pv::widgets::Popup;
+
        assert(event);
        if (event->button() == Qt::LeftButton) {
+               if (_dragging)
+                       _view.normalize_layout();
+               else
+               {
+                       const shared_ptr<Trace> mouse_over_trace =
+                               get_mouse_over_trace(event->pos());
+                       if (mouse_over_trace) {
+                               Popup *const p =
+                                       mouse_over_trace->create_popup(&_view);
+                               p->set_position(mapToGlobal(QPoint(width(),
+                                       mouse_over_trace->get_y())),
+                                       Popup::Right);
+                               p->show();
+                       }
+               }
+
                _dragging = false;
                _drag_traces.clear();
-               _view.normalize_layout();
        }
 }
 
index e9424750c997237ff1f5623387d286f6145f97dd..28084544f6f4247aee1798e4081302f0f22d5b27 100644 (file)
@@ -29,6 +29,8 @@
 #include "trace.h"
 #include "view.h"
 
+#include <pv/widgets/popup.h>
+
 namespace pv {
 namespace view {
 
@@ -183,6 +185,16 @@ QMenu* Trace::create_context_menu(QWidget *parent)
        return menu;
 }
 
+pv::widgets::Popup* Trace::create_popup(QWidget *parent)
+{
+       using pv::widgets::Popup;
+       Popup *const popup = new Popup(parent);
+       QFormLayout *const form = new QFormLayout(popup);
+       popup->setLayout(form);
+       populate_popup_form(popup, form);
+       return popup;
+}
+
 int Trace::get_y() const
 {
        return _v_offset - _view->v_offset();
@@ -199,6 +211,11 @@ void Trace::paint_axis(QPainter &p, int y, int left, int right)
        p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
 }
 
+void Trace::populate_popup_form(QWidget *parent, QFormLayout *form)
+{
+       form->addRow("Name", new QLineEdit(parent));
+}
+
 void Trace::compute_text_size(QPainter &p)
 {
        _text_size = QSize(
index 631c8d9cb6a7435343ef806d2ed1eb6566cb7e02..ff65a2138536945d2f95115ffbfc38738331862c 100644 (file)
@@ -35,6 +35,10 @@ namespace pv {
 
 class SigSession;
 
+namespace widgets {
+class Popup;
+}
+
 namespace view {
 
 class View;
@@ -133,12 +137,14 @@ public:
 
        virtual QMenu* create_context_menu(QWidget *parent);
 
-protected:
+       pv::widgets::Popup* create_popup(QWidget *parent);
+
        /**
         * Gets the y-offset of the axis.
         */
        int get_y() const;
 
+protected:
        /**
         * Gets the text colour.
         * @remarks This colour is computed by comparing the lightness
@@ -156,6 +162,8 @@ protected:
         */
        void paint_axis(QPainter &p, int y, int left, int right);
 
+       virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
+
 private:
 
        /**