RowItem: Split appart visual and layout v offsets
[pulseview.git] / pv / view / tracegroup.cpp
index 9d0465fc3c863421f69bec5eaf5740b7629e83f2..4404b1cd866fe9e160e05a676b9fd3423c3fddd4 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <extdef.h>
 #include <assert.h>
 
 #include <algorithm>
 
+#include <QMenu>
+#include <QPainter>
+
 #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()
 {
@@ -68,11 +76,40 @@ const pv::view::View* TraceGroup::view() const
        return _owner->view();
 }
 
+pair<int, int> 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
@@ -97,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)
@@ -110,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()
@@ -119,5 +161,18 @@ void TraceGroup::update_viewport()
                _owner->update_viewport();
 }
 
+void TraceGroup::on_ungroup()
+{
+       const vector< shared_ptr<RowItem> > items(
+               child_items().begin(), child_items().end());
+       clear_child_items();
+
+       for (shared_ptr<RowItem> r : items)
+               _owner->add_child_item(r);
+
+       _owner->remove_child_item(shared_from_this());
+       appearance_changed();
+}
+
 } // namespace view
 } // namespace pv