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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "tracegroup.hpp"
32 using std::shared_ptr;
38 const int TraceGroup::Padding = 8;
39 const int TraceGroup::Width = 12;
40 const int TraceGroup::LineThickness = 5;
41 const QColor TraceGroup::LineColour(QColor(0x55, 0x57, 0x53));
43 TraceGroup::~TraceGroup()
49 bool TraceGroup::enabled() const
51 return std::any_of(child_items().begin(), child_items().end(),
52 [](const shared_ptr<RowItem> &r) { return r->enabled(); });
55 pv::Session& TraceGroup::session()
58 return owner_->session();
61 const pv::Session& TraceGroup::session() const
64 return owner_->session();
67 pv::view::View* TraceGroup::view()
70 return owner_->view();
73 const pv::view::View* TraceGroup::view() const
76 return owner_->view();
79 pair<int, int> TraceGroup::v_extents() const
81 return RowItemOwner::v_extents();
84 void TraceGroup::paint_label(QPainter &p, const QRect &rect, bool hover)
86 const QRectF r = label_rect(rect).adjusted(
87 LineThickness / 2, LineThickness / 2,
88 -LineThickness / 2, -LineThickness / 2);
91 const QPointF points[] = {
99 const QPen pen(highlight_pen());
100 p.setPen(QPen(pen.brush(), pen.width() + LineThickness,
101 Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
102 p.setBrush(Qt::transparent);
103 p.drawPolyline(points, countof(points));
106 p.setPen(QPen(QBrush(LineColour.darker()), LineThickness,
107 Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
108 p.drawPolyline(points, countof(points));
109 p.setPen(QPen(QBrush(hover ? LineColour.lighter() : LineColour),
110 LineThickness - 2, Qt::SolidLine, Qt::SquareCap,
112 p.drawPolyline(points, countof(points));
115 QRectF TraceGroup::label_rect(const QRectF &rect) const
118 for (const shared_ptr<RowItem> r : child_items())
119 if (r && r->enabled())
120 child_rect = child_rect.united(r->label_rect(rect));
122 return QRectF(child_rect.x() - Width - Padding, child_rect.y(),
123 Width, child_rect.height());
126 bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point)
135 QMenu* TraceGroup::create_context_menu(QWidget *parent)
137 QMenu *const menu = new QMenu(parent);
139 QAction *const ungroup = new QAction(tr("Ungroup"), this);
140 ungroup->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
141 connect(ungroup, SIGNAL(triggered()), this, SLOT(on_ungroup()));
142 menu->addAction(ungroup);
147 pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent)
153 int TraceGroup::owner_visual_v_offset() const
155 return owner_ ? visual_v_offset() + owner_->owner_visual_v_offset() : 0;
158 void TraceGroup::restack_items()
160 vector< shared_ptr<RowItem> > items(
161 child_items().begin(), child_items().end());
163 // Sort by the centre line of the extents
164 stable_sort(items.begin(), items.end(),
165 [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
166 const auto aext = a->v_extents();
167 const auto bext = b->v_extents();
168 return a->layout_v_offset() +
169 (aext.first + aext.second) / 2 <
170 b->layout_v_offset() +
171 (bext.first + bext.second) / 2;
174 int total_offset = 0;
175 for (shared_ptr<RowItem> r : items) {
176 const pair<int, int> extents = r->v_extents();
177 if (extents.first == 0 && extents.second == 0)
180 // We position disabled traces, so that they are close to the
181 // animation target positon should they be re-enabled
183 total_offset += -extents.first;
186 r->set_layout_v_offset(total_offset);
189 total_offset += extents.second;
193 unsigned int TraceGroup::depth() const
195 return owner_ ? owner_->depth() + 1 : 0;
198 void TraceGroup::ungroup()
200 const vector< shared_ptr<RowItem> > items(
201 child_items().begin(), child_items().end());
204 for (shared_ptr<RowItem> r : items)
205 owner_->add_child_item(r);
207 owner_->remove_child_item(shared_from_this());
210 void TraceGroup::on_ungroup()
215 void TraceGroup::row_item_appearance_changed(bool label, bool content)
218 owner_->row_item_appearance_changed(label, content);
221 void TraceGroup::extents_changed(bool horz, bool vert)
224 owner_->extents_changed(horz, vert);