]>
Commit | Line | Data |
---|---|---|
23935421 JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | */ | |
20 | ||
21 | #include <assert.h> | |
22 | ||
2acdb232 | 23 | #include "view.hpp" |
23935421 | 24 | |
af503b10 | 25 | #include "tracetreeitem.hpp" |
23935421 JH |
26 | |
27 | namespace pv { | |
28 | namespace view { | |
29 | ||
af503b10 | 30 | TraceTreeItem::TraceTreeItem() : |
4c60462b | 31 | owner_(nullptr), |
8dbbc7f0 JH |
32 | layout_v_offset_(0), |
33 | visual_v_offset_(0), | |
34 | v_offset_animation_(this, "visual_v_offset") | |
23935421 JH |
35 | { |
36 | } | |
37 | ||
75663e3a JH |
38 | void TraceTreeItem::select(bool select) |
39 | { | |
40 | ViewItem::select(select); | |
41 | owner_->row_item_appearance_changed(true, true); | |
42 | } | |
43 | ||
af503b10 | 44 | int TraceTreeItem::layout_v_offset() const |
23935421 | 45 | { |
8dbbc7f0 | 46 | return layout_v_offset_; |
23935421 JH |
47 | } |
48 | ||
af503b10 | 49 | void TraceTreeItem::set_layout_v_offset(int v_offset) |
23935421 | 50 | { |
8dbbc7f0 | 51 | if (layout_v_offset_ == v_offset) |
be9e7b4b JH |
52 | return; |
53 | ||
8dbbc7f0 | 54 | layout_v_offset_ = v_offset; |
32218d3e | 55 | |
8dbbc7f0 JH |
56 | if (owner_) |
57 | owner_->extents_changed(false, true); | |
be9e7b4b JH |
58 | } |
59 | ||
af503b10 | 60 | int TraceTreeItem::visual_v_offset() const |
be9e7b4b | 61 | { |
8dbbc7f0 | 62 | return visual_v_offset_; |
be9e7b4b JH |
63 | } |
64 | ||
af503b10 | 65 | void TraceTreeItem::set_visual_v_offset(int v_offset) |
be9e7b4b | 66 | { |
8dbbc7f0 | 67 | visual_v_offset_ = v_offset; |
32218d3e | 68 | |
8dbbc7f0 | 69 | if (owner_) |
6e2c3c85 | 70 | owner_->row_item_appearance_changed(true, true); |
be9e7b4b JH |
71 | } |
72 | ||
af503b10 | 73 | void TraceTreeItem::force_to_v_offset(int v_offset) |
be9e7b4b | 74 | { |
8dbbc7f0 JH |
75 | v_offset_animation_.stop(); |
76 | layout_v_offset_ = visual_v_offset_ = v_offset; | |
f15bb3bc JH |
77 | |
78 | if (owner_) { | |
79 | owner_->row_item_appearance_changed(true, true); | |
80 | owner_->extents_changed(false, true); | |
81 | } | |
23935421 JH |
82 | } |
83 | ||
af503b10 | 84 | void TraceTreeItem::animate_to_layout_v_offset() |
7ff0145f | 85 | { |
8dbbc7f0 JH |
86 | if (visual_v_offset_ == layout_v_offset_ || |
87 | (v_offset_animation_.endValue() == layout_v_offset_ && | |
88 | v_offset_animation_.state() == QAbstractAnimation::Running)) | |
7ff0145f JH |
89 | return; |
90 | ||
8dbbc7f0 JH |
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(); | |
7ff0145f JH |
96 | } |
97 | ||
af503b10 | 98 | TraceTreeItemOwner* TraceTreeItem::owner() const |
bd9a1f17 | 99 | { |
8dbbc7f0 | 100 | return owner_; |
bd9a1f17 JH |
101 | } |
102 | ||
af503b10 | 103 | void TraceTreeItem::set_owner(TraceTreeItemOwner *owner) |
23935421 | 104 | { |
8dbbc7f0 JH |
105 | assert(owner_ || owner); |
106 | v_offset_animation_.stop(); | |
7ff0145f | 107 | |
8dbbc7f0 JH |
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; | |
7ff0145f | 112 | } |
be9e7b4b | 113 | |
8dbbc7f0 | 114 | owner_ = owner; |
7ff0145f | 115 | |
8dbbc7f0 JH |
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; | |
7ff0145f | 120 | } |
23935421 JH |
121 | } |
122 | ||
af503b10 | 123 | int TraceTreeItem::get_visual_y() const |
23935421 | 124 | { |
8dbbc7f0 JH |
125 | assert(owner_); |
126 | return visual_v_offset_ + owner_->owner_visual_v_offset(); | |
23935421 JH |
127 | } |
128 | ||
af503b10 | 129 | void TraceTreeItem::drag_by(const QPoint &delta) |
23e75650 | 130 | { |
f1a73116 | 131 | assert(owner_); |
23e75650 JH |
132 | force_to_v_offset(drag_point_.y() + delta.y() - |
133 | owner_->owner_visual_v_offset()); | |
134 | } | |
135 | ||
af503b10 | 136 | QPoint TraceTreeItem::point(const QRect &rect) const |
0dda6fe5 | 137 | { |
c3bb03ff | 138 | return QPoint(rect.right(), get_visual_y()); |
0dda6fe5 JH |
139 | } |
140 | ||
23935421 JH |
141 | } // namespace view |
142 | } // namespace pv |