X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Ftracegroup.cpp;h=af756d49be6bea0a4877433223773d0b3bbc84c2;hb=0a51d1c122784a9052058c79ec2099b1ed104a22;hp=2c49ae430642ba965f634fc1cc1c36355eba4350;hpb=722930c167711a4b59b4f4d5a9bab20d88b3f535;p=pulseview.git diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index 2c49ae43..af756d49 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -22,13 +22,20 @@ #include +#include + #include "tracegroup.h" +using std::pair; using std::shared_ptr; +using std::vector; namespace pv { namespace view { +const int TraceGroup::Padding = 8; +const int TraceGroup::Width = 12; + TraceGroup::~TraceGroup() { _owner = nullptr; @@ -65,6 +72,11 @@ const pv::view::View* TraceGroup::view() const return _owner->view(); } +pair TraceGroup::v_extents() const +{ + return RowItemOwner::v_extents(); +} + void TraceGroup::paint_label(QPainter &p, int right, bool hover) { (void)p; @@ -72,10 +84,15 @@ void TraceGroup::paint_label(QPainter &p, int right, bool hover) (void)hover; } -QRectF TraceGroup::label_rect(int right) +QRectF TraceGroup::label_rect(int right) const { - (void)right; - return QRectF(); + QRectF rect; + for (const shared_ptr r : child_items()) + if (r) + rect = rect.united(r->label_rect(right)); + + return QRectF(rect.x() - Width - Padding, rect.y(), + Width, rect.height()); } bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point) @@ -89,9 +106,14 @@ bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point) QMenu* TraceGroup::create_context_menu(QWidget *parent) { - (void)parent; + QMenu *const menu = new QMenu(parent); - return NULL; + QAction *const ungroup = new QAction(tr("Ungroup"), this); + ungroup->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); + connect(ungroup, SIGNAL(triggered()), this, SLOT(on_ungroup())); + menu->addAction(ungroup); + + return menu; } pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent) @@ -111,5 +133,20 @@ void TraceGroup::update_viewport() _owner->update_viewport(); } +void TraceGroup::on_ungroup() +{ + const vector< shared_ptr > items( + child_items().begin(), child_items().end()); + clear_child_items(); + + for (shared_ptr r : items) { + _owner->add_child_item(r); + r->set_v_offset(r->v_offset() + v_offset()); + } + + _owner->remove_child_item(shared_from_this()); + appearance_changed(); +} + } // namespace view } // namespace pv