MathSignal: Add config dialog
[pulseview.git] / pv / views / trace / tracetreeitem.cpp
blob31b43ca1bd253c9cb51c28ad5b9593ed6c377d86
1 /*
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/>.
20 #include <cassert>
22 #include "view.hpp"
24 #include "tracetreeitem.hpp"
26 namespace pv {
27 namespace views {
28 namespace trace {
30 TraceTreeItem::TraceTreeItem() :
31 owner_(nullptr),
32 layout_v_offset_(0),
33 visual_v_offset_(0),
34 v_offset_animation_(this, "visual_v_offset")
38 void TraceTreeItem::select(bool select)
40 ViewItem::select(select);
41 owner_->row_item_appearance_changed(true, true);
44 int TraceTreeItem::layout_v_offset() const
46 return layout_v_offset_;
49 void TraceTreeItem::set_layout_v_offset(int v_offset)
51 if (layout_v_offset_ == v_offset)
52 return;
54 layout_v_offset_ = v_offset;
56 if (owner_)
57 owner_->extents_changed(false, true);
60 int TraceTreeItem::visual_v_offset() const
62 return visual_v_offset_;
65 void TraceTreeItem::set_visual_v_offset(int v_offset)
67 visual_v_offset_ = v_offset;
69 if (owner_)
70 owner_->row_item_appearance_changed(true, true);
73 void TraceTreeItem::force_to_v_offset(int v_offset)
75 v_offset_animation_.stop();
76 layout_v_offset_ = visual_v_offset_ = v_offset;
78 if (owner_) {
79 owner_->row_item_appearance_changed(true, true);
80 owner_->extents_changed(false, true);
84 void TraceTreeItem::animate_to_layout_v_offset()
86 if (visual_v_offset_ == layout_v_offset_ ||
87 (v_offset_animation_.endValue() == layout_v_offset_ &&
88 v_offset_animation_.state() == QAbstractAnimation::Running))
89 return;
91 v_offset_animation_.setDuration(100);
92 v_offset_animation_.setStartValue(visual_v_offset_);
93 v_offset_animation_.setEndValue(layout_v_offset_);
94 v_offset_animation_.setEasingCurve(QEasingCurve::OutQuad);
95 v_offset_animation_.start();
98 TraceTreeItemOwner* TraceTreeItem::owner() const
100 return owner_;
103 void TraceTreeItem::set_owner(TraceTreeItemOwner *owner)
105 assert(owner_ || owner);
106 v_offset_animation_.stop();
108 if (owner_) {
109 const int owner_offset = owner_->owner_visual_v_offset();
110 layout_v_offset_ += owner_offset;
111 visual_v_offset_ += owner_offset;
114 owner_ = owner;
116 if (owner_) {
117 const int owner_offset = owner_->owner_visual_v_offset();
118 layout_v_offset_ -= owner_offset;
119 visual_v_offset_ -= owner_offset;
123 int TraceTreeItem::get_visual_y() const
125 assert(owner_);
126 return visual_v_offset_ + owner_->owner_visual_v_offset();
129 void TraceTreeItem::drag_by(const QPoint &delta)
131 assert(owner_);
132 force_to_v_offset(drag_point_.y() + delta.y() -
133 owner_->owner_visual_v_offset());
136 QPoint TraceTreeItem::drag_point(const QRect &rect) const
138 return QPoint(rect.right(), get_visual_y());
141 } // namespace trace
142 } // namespace views
143 } // namespace pv