2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #include "tracegroup.hpp"
32 using std::shared_ptr;
39 const int TraceGroup::Padding = 8;
40 const int TraceGroup::Width = 12;
41 const int TraceGroup::LineThickness = 5;
42 const QColor TraceGroup::LineColor(QColor(0x55, 0x57, 0x53));
44 TraceGroup::~TraceGroup()
50 bool TraceGroup::enabled() const
52 return any_of(child_items().begin(), child_items().end(),
53 [](const shared_ptr<ViewItem> &r) { return r->enabled(); });
56 pv::Session& TraceGroup::session()
59 return owner_->session();
62 const pv::Session& TraceGroup::session() const
65 return owner_->session();
68 View* TraceGroup::view()
71 return owner_->view();
74 const View* TraceGroup::view() const
77 return owner_->view();
80 pair<int, int> TraceGroup::v_extents() const
82 return TraceTreeItemOwner::v_extents();
85 void TraceGroup::paint_label(QPainter &p, const QRect &rect, bool hover)
87 const QRectF r = label_rect(rect).adjusted(
88 LineThickness / 2.0, LineThickness / 2.0,
89 -LineThickness / 2.0, -LineThickness / 2.0);
92 const QPointF points[] = {
100 const QPen pen(highlight_pen());
101 p.setPen(QPen(pen.brush(), pen.width() + LineThickness,
102 Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
103 p.setBrush(Qt::transparent);
104 p.drawPolyline(points, countof(points));
107 p.setPen(QPen(QBrush(LineColor.darker()), LineThickness,
108 Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
109 p.drawPolyline(points, countof(points));
110 p.setPen(QPen(QBrush(hover ? LineColor.lighter() : LineColor),
111 LineThickness - 2, Qt::SolidLine, Qt::SquareCap,
113 p.drawPolyline(points, countof(points));
116 QRectF TraceGroup::label_rect(const QRectF &rect) const
119 for (const shared_ptr<ViewItem> r : child_items())
120 if (r && r->enabled())
121 child_rect = child_rect.united(r->label_rect(rect));
123 return QRectF(child_rect.x() - Width - Padding, child_rect.y(),
124 Width, child_rect.height());
127 bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point)
136 QMenu* TraceGroup::create_context_menu(QWidget *parent)
138 QMenu *const menu = new QMenu(parent);
140 QAction *const ungroup = new QAction(tr("Ungroup"), this);
141 ungroup->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
142 connect(ungroup, SIGNAL(triggered()), this, SLOT(on_ungroup()));
143 menu->addAction(ungroup);
148 pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent)
154 int TraceGroup::owner_visual_v_offset() const
156 return owner_ ? visual_v_offset() + owner_->owner_visual_v_offset() : 0;
159 unsigned int TraceGroup::depth() const
161 return owner_ ? owner_->depth() + 1 : 0;
164 void TraceGroup::ungroup()
166 const vector<shared_ptr<TraceTreeItem>> items(trace_tree_child_items());
169 for (shared_ptr<TraceTreeItem> r : items)
170 owner_->add_child_item(r);
172 owner_->remove_child_item(shared_from_this());
175 void TraceGroup::on_ungroup()
180 void TraceGroup::row_item_appearance_changed(bool label, bool content)
183 owner_->row_item_appearance_changed(label, content);
186 void TraceGroup::extents_changed(bool horz, bool vert)
189 owner_->extents_changed(horz, vert);