X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fview%2Ftracegroup.cpp;h=490f39c5457187a0c808cc32684abb25f8fcb3d9;hb=eb8269e3b5eebdd77e6a82d42bcfdfbc3f7613a9;hp=9d0465fc3c863421f69bec5eaf5740b7629e83f2;hpb=b781f8065271c6ce4b82f06f20dd37464f213d47;p=pulseview.git
diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp
index 9d0465f..490f39c 100644
--- a/pv/view/tracegroup.cpp
+++ b/pv/view/tracegroup.cpp
@@ -14,76 +14,113 @@
* 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, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
-#include
+#include
+#include
#include
-#include "tracegroup.h"
+#include
+#include
+#include "tracegroup.hpp"
+
+using std::pair;
using std::shared_ptr;
+using std::vector;
namespace pv {
-namespace view {
+namespace views {
+namespace TraceView {
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;
+ owner_ = nullptr;
clear_child_items();
}
bool TraceGroup::enabled() const
{
return std::any_of(child_items().begin(), child_items().end(),
- [](const shared_ptr &r) { return r->enabled(); });
+ [](const shared_ptr &r) { return r->enabled(); });
}
-pv::SigSession& TraceGroup::session()
+pv::Session& TraceGroup::session()
{
- assert(_owner);
- return _owner->session();
+ assert(owner_);
+ return owner_->session();
}
-const pv::SigSession& TraceGroup::session() const
+const pv::Session& TraceGroup::session() const
{
- assert(_owner);
- return _owner->session();
+ assert(owner_);
+ return owner_->session();
}
-pv::view::View* TraceGroup::view()
+View* TraceGroup::view()
{
- assert(_owner);
- return _owner->view();
+ assert(owner_);
+ return owner_->view();
}
-const pv::view::View* TraceGroup::view() const
+const View* TraceGroup::view() const
{
- assert(_owner);
- return _owner->view();
+ assert(owner_);
+ return owner_->view();
}
-void TraceGroup::paint_label(QPainter &p, int right, bool hover)
+pair TraceGroup::v_extents() const
{
- (void)p;
- (void)right;
- (void)hover;
+ return TraceTreeItemOwner::v_extents();
}
-QRectF TraceGroup::label_rect(int right) const
+void TraceGroup::paint_label(QPainter &p, const QRect &rect, bool hover)
{
- QRectF rect;
- for (const shared_ptr r : child_items())
- if (r)
- rect = rect.united(r->label_rect(right));
+ const QRectF r = label_rect(rect).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));
+}
- return QRectF(rect.x() - Width - Padding, rect.y(),
- Width, rect.height());
+QRectF TraceGroup::label_rect(const QRectF &rect) const
+{
+ QRectF child_rect;
+ for (const shared_ptr 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)
@@ -97,27 +134,94 @@ 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);
+
+ 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 NULL;
+ return menu;
}
pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent)
{
(void)parent;
- return NULL;
+ return nullptr;
+}
+
+int TraceGroup::owner_visual_v_offset() const
+{
+ return owner_ ? visual_v_offset() + owner_->owner_visual_v_offset() : 0;
+}
+
+void TraceGroup::restack_items()
+{
+ vector> items(trace_tree_child_items());
+
+ // Sort by the centre line of the extents
+ stable_sort(items.begin(), items.end(),
+ [](const shared_ptr &a, const shared_ptr &b) {
+ const auto aext = a->v_extents();
+ const auto bext = b->v_extents();
+ return a->layout_v_offset() +
+ (aext.first + aext.second) / 2 <
+ b->layout_v_offset() +
+ (bext.first + bext.second) / 2;
+ });
+
+ int total_offset = 0;
+ for (shared_ptr r : items) {
+ const pair extents = r->v_extents();
+ if (extents.first == 0 && extents.second == 0)
+ continue;
+
+ // We position disabled traces, so that they are close to the
+ // animation target positon should they be re-enabled
+ if (r->enabled())
+ total_offset += -extents.first;
+
+ if (!r->dragging())
+ r->set_layout_v_offset(total_offset);
+
+ if (r->enabled())
+ total_offset += extents.second;
+ }
+}
+
+unsigned int TraceGroup::depth() const
+{
+ return owner_ ? owner_->depth() + 1 : 0;
+}
+
+void TraceGroup::ungroup()
+{
+ const vector> items(trace_tree_child_items());
+ clear_child_items();
+
+ for (shared_ptr r : items)
+ owner_->add_child_item(r);
+
+ owner_->remove_child_item(shared_from_this());
+}
+
+void TraceGroup::on_ungroup()
+{
+ ungroup();
}
-int TraceGroup::owner_v_offset() const
+void TraceGroup::row_item_appearance_changed(bool label, bool content)
{
- return v_offset() + _owner->owner_v_offset();
+ if (owner_)
+ owner_->row_item_appearance_changed(label, content);
}
-void TraceGroup::update_viewport()
+void TraceGroup::extents_changed(bool horz, bool vert)
{
- if (_owner)
- _owner->update_viewport();
+ if (owner_)
+ owner_->extents_changed(horz, vert);
}
-} // namespace view
+} // namespace TraceView
+} // namespace views
} // namespace pv