From 569d1e41fbc1be584efdbcdc2c8a01e7af3353ed Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Wed, 25 Sep 2013 16:19:03 +0900 Subject: [PATCH] Integration Popup into Trace --- pv/view/header.cpp | 21 ++++++++++++++++++++- pv/view/trace.cpp | 17 +++++++++++++++++ pv/view/trace.h | 10 +++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 549b7191..f8f5b638 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -34,6 +34,8 @@ #include #include +#include + 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 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(); } } diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index e9424750..28084544 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -29,6 +29,8 @@ #include "trace.h" #include "view.h" +#include + 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( diff --git a/pv/view/trace.h b/pv/view/trace.h index 631c8d9c..ff65a213 100644 --- a/pv/view/trace.h +++ b/pv/view/trace.h @@ -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: /** -- 2.30.2