]>
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 { | |
f4e57597 SA |
28 | namespace views { |
29 | namespace TraceView { | |
23935421 | 30 | |
af503b10 | 31 | TraceTreeItem::TraceTreeItem() : |
4c60462b | 32 | owner_(nullptr), |
8dbbc7f0 JH |
33 | layout_v_offset_(0), |
34 | visual_v_offset_(0), | |
35 | v_offset_animation_(this, "visual_v_offset") | |
23935421 JH |
36 | { |
37 | } | |
38 | ||
75663e3a JH |
39 | void TraceTreeItem::select(bool select) |
40 | { | |
41 | ViewItem::select(select); | |
42 | owner_->row_item_appearance_changed(true, true); | |
43 | } | |
44 | ||
af503b10 | 45 | int TraceTreeItem::layout_v_offset() const |
23935421 | 46 | { |
8dbbc7f0 | 47 | return layout_v_offset_; |
23935421 JH |
48 | } |
49 | ||
af503b10 | 50 | void TraceTreeItem::set_layout_v_offset(int v_offset) |
23935421 | 51 | { |
8dbbc7f0 | 52 | if (layout_v_offset_ == v_offset) |
be9e7b4b JH |
53 | return; |
54 | ||
8dbbc7f0 | 55 | layout_v_offset_ = v_offset; |
32218d3e | 56 | |
8dbbc7f0 JH |
57 | if (owner_) |
58 | owner_->extents_changed(false, true); | |
be9e7b4b JH |
59 | } |
60 | ||
af503b10 | 61 | int TraceTreeItem::visual_v_offset() const |
be9e7b4b | 62 | { |
8dbbc7f0 | 63 | return visual_v_offset_; |
be9e7b4b JH |
64 | } |
65 | ||
af503b10 | 66 | void TraceTreeItem::set_visual_v_offset(int v_offset) |
be9e7b4b | 67 | { |
8dbbc7f0 | 68 | visual_v_offset_ = v_offset; |
32218d3e | 69 | |
8dbbc7f0 | 70 | if (owner_) |
6e2c3c85 | 71 | owner_->row_item_appearance_changed(true, true); |
be9e7b4b JH |
72 | } |
73 | ||
af503b10 | 74 | void TraceTreeItem::force_to_v_offset(int v_offset) |
be9e7b4b | 75 | { |
8dbbc7f0 JH |
76 | v_offset_animation_.stop(); |
77 | layout_v_offset_ = visual_v_offset_ = v_offset; | |
f15bb3bc JH |
78 | |
79 | if (owner_) { | |
80 | owner_->row_item_appearance_changed(true, true); | |
81 | owner_->extents_changed(false, true); | |
82 | } | |
23935421 JH |
83 | } |
84 | ||
af503b10 | 85 | void TraceTreeItem::animate_to_layout_v_offset() |
7ff0145f | 86 | { |
8dbbc7f0 JH |
87 | if (visual_v_offset_ == layout_v_offset_ || |
88 | (v_offset_animation_.endValue() == layout_v_offset_ && | |
89 | v_offset_animation_.state() == QAbstractAnimation::Running)) | |
7ff0145f JH |
90 | return; |
91 | ||
8dbbc7f0 JH |
92 | v_offset_animation_.setDuration(100); |
93 | v_offset_animation_.setStartValue(visual_v_offset_); | |
94 | v_offset_animation_.setEndValue(layout_v_offset_); | |
95 | v_offset_animation_.setEasingCurve(QEasingCurve::OutQuad); | |
96 | v_offset_animation_.start(); | |
7ff0145f JH |
97 | } |
98 | ||
af503b10 | 99 | TraceTreeItemOwner* TraceTreeItem::owner() const |
bd9a1f17 | 100 | { |
8dbbc7f0 | 101 | return owner_; |
bd9a1f17 JH |
102 | } |
103 | ||
af503b10 | 104 | void TraceTreeItem::set_owner(TraceTreeItemOwner *owner) |
23935421 | 105 | { |
8dbbc7f0 JH |
106 | assert(owner_ || owner); |
107 | v_offset_animation_.stop(); | |
7ff0145f | 108 | |
8dbbc7f0 JH |
109 | if (owner_) { |
110 | const int owner_offset = owner_->owner_visual_v_offset(); | |
111 | layout_v_offset_ += owner_offset; | |
112 | visual_v_offset_ += owner_offset; | |
7ff0145f | 113 | } |
be9e7b4b | 114 | |
8dbbc7f0 | 115 | owner_ = owner; |
7ff0145f | 116 | |
8dbbc7f0 JH |
117 | if (owner_) { |
118 | const int owner_offset = owner_->owner_visual_v_offset(); | |
119 | layout_v_offset_ -= owner_offset; | |
120 | visual_v_offset_ -= owner_offset; | |
7ff0145f | 121 | } |
23935421 JH |
122 | } |
123 | ||
af503b10 | 124 | int TraceTreeItem::get_visual_y() const |
23935421 | 125 | { |
8dbbc7f0 JH |
126 | assert(owner_); |
127 | return visual_v_offset_ + owner_->owner_visual_v_offset(); | |
23935421 JH |
128 | } |
129 | ||
af503b10 | 130 | void TraceTreeItem::drag_by(const QPoint &delta) |
23e75650 | 131 | { |
f1a73116 | 132 | assert(owner_); |
23e75650 JH |
133 | force_to_v_offset(drag_point_.y() + delta.y() - |
134 | owner_->owner_visual_v_offset()); | |
135 | } | |
136 | ||
af503b10 | 137 | QPoint TraceTreeItem::point(const QRect &rect) const |
0dda6fe5 | 138 | { |
c3bb03ff | 139 | return QPoint(rect.right(), get_visual_y()); |
0dda6fe5 JH |
140 | } |
141 | ||
ac0708fb SA |
142 | void TraceTreeItem::set_bgcolour_state(bool state) |
143 | { | |
144 | bgcolour_state_ = state; | |
145 | } | |
146 | ||
f4e57597 SA |
147 | } // namespace TraceView |
148 | } // namespace views | |
23935421 | 149 | } // namespace pv |