X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fview%2Ftracegroup.cpp;h=4404b1cd866fe9e160e05a676b9fd3423c3fddd4;hb=be9e7b4bb29b6594ec2b64442748ab135b684bf8;hp=f99b19666ba27892902a97fde42801a47a8ddca2;hpb=0067d80499d36944277e6fed2d7ad5394c85c03f;p=pulseview.git diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index f99b196..4404b1c 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -18,17 +18,28 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include +#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; +const int TraceGroup::LineThickness = 5; +const QColor TraceGroup::LineColour(QColor(0x55, 0x57, 0x53)); + TraceGroup::~TraceGroup() { _owner = nullptr; @@ -65,17 +76,51 @@ 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; - (void)right; - (void)hover; + const QRectF r = label_rect(right).adjusted( + LineThickness / 2, LineThickness / 2, + -LineThickness / 2, -LineThickness / 2); + + // Paint the label + const QPointF points[] = { + r.topRight(), + r.topLeft(), + r.bottomLeft(), + r.bottomRight() + }; + + if (selected()) { + const QPen pen(highlight_pen()); + p.setPen(QPen(pen.brush(), pen.width() + LineThickness, + Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin)); + p.setBrush(Qt::transparent); + p.drawPolyline(points, countof(points)); + } + + p.setPen(QPen(QBrush(LineColour.darker()), LineThickness, + Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin)); + p.drawPolyline(points, countof(points)); + p.setPen(QPen(QBrush(hover ? LineColour.lighter() : LineColour), + LineThickness - 2, Qt::SolidLine, Qt::SquareCap, + Qt::RoundJoin)); + p.drawPolyline(points, countof(points)); } 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 +134,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) @@ -102,7 +152,7 @@ pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent) int TraceGroup::owner_v_offset() const { - return v_offset() + _owner->owner_v_offset(); + return _owner ? layout_v_offset() + _owner->owner_v_offset() : 0; } void TraceGroup::update_viewport() @@ -111,5 +161,18 @@ 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); + + _owner->remove_child_item(shared_from_this()); + appearance_changed(); +} + } // namespace view } // namespace pv