File: tracegroup.cpp

package info (click to toggle)
pulseview 0.4.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,092 kB
  • sloc: cpp: 25,958; xml: 215; java: 42; makefile: 2
file content (194 lines) | stat: -rw-r--r-- 4,475 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * This file is part of the PulseView project.
 *
 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <extdef.h>

#include <algorithm>
#include <cassert>

#include <QMenu>
#include <QPainter>

#include "tracegroup.hpp"

using std::any_of;
using std::pair;
using std::shared_ptr;
using std::vector;

namespace pv {
namespace views {
namespace trace {

const int TraceGroup::Padding = 8;
const int TraceGroup::Width = 12;
const int TraceGroup::LineThickness = 5;
const QColor TraceGroup::LineColor(QColor(0x55, 0x57, 0x53));

TraceGroup::~TraceGroup()
{
	owner_ = nullptr;
	clear_child_items();
}

bool TraceGroup::enabled() const
{
	return any_of(child_items().begin(), child_items().end(),
		[](const shared_ptr<ViewItem> &r) { return r->enabled(); });
}

pv::Session& TraceGroup::session()
{
	assert(owner_);
	return owner_->session();
}

const pv::Session& TraceGroup::session() const
{
	assert(owner_);
	return owner_->session();
}

View* TraceGroup::view()
{
	assert(owner_);
	return owner_->view();
}

const View* TraceGroup::view() const
{
	assert(owner_);
	return owner_->view();
}

pair<int, int> TraceGroup::v_extents() const
{
	return TraceTreeItemOwner::v_extents();
}

void TraceGroup::paint_label(QPainter &p, const QRect &rect, bool hover)
{
	const QRectF r = label_rect(rect).adjusted(
		LineThickness / 2.0, LineThickness / 2.0,
		-LineThickness / 2.0, -LineThickness / 2.0);

	// 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(LineColor.darker()), LineThickness,
		Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
	p.drawPolyline(points, countof(points));
	p.setPen(QPen(QBrush(hover ? LineColor.lighter() : LineColor),
		LineThickness - 2, Qt::SolidLine, Qt::SquareCap,
		Qt::RoundJoin));
	p.drawPolyline(points, countof(points));
}

QRectF TraceGroup::label_rect(const QRectF &rect) const
{
	QRectF child_rect;
	for (const shared_ptr<ViewItem>& r : child_items())
		if (r && r->enabled())
			child_rect = child_rect.united(r->label_rect(rect));

	return QRectF(child_rect.x() - Width - Padding, child_rect.y(),
		Width, child_rect.height());
}

bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point)
{
	(void)left;
	(void)right;
	(void)point;

	return false;
}

QMenu* TraceGroup::create_header_context_menu(QWidget *parent)
{
	QMenu *const menu = new QMenu(parent);

	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)
{
	(void)parent;
	return nullptr;
}

int TraceGroup::owner_visual_v_offset() const
{
	return owner_ ? visual_v_offset() + owner_->owner_visual_v_offset() : 0;
}

unsigned int TraceGroup::depth() const
{
	return owner_ ? owner_->depth() + 1 : 0;
}

void TraceGroup::ungroup()
{
	const vector<shared_ptr<TraceTreeItem>> items(trace_tree_child_items());
	clear_child_items();

	for (const shared_ptr<TraceTreeItem>& r : items)
		owner_->add_child_item(r);

	owner_->remove_child_item(shared_from_this());
}

void TraceGroup::on_ungroup()
{
	ungroup();
}

void TraceGroup::row_item_appearance_changed(bool label, bool content)
{
	if (owner_)
		owner_->row_item_appearance_changed(label, content);
}

void TraceGroup::extents_changed(bool horz, bool vert)
{
	if (owner_)
		owner_->extents_changed(horz, vert);
}

} // namespace trace
} // namespace views
} // namespace pv