]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | #include "view.hpp" | |
24 | ||
25 | #include "rowitem.hpp" | |
26 | ||
27 | namespace pv { | |
28 | namespace view { | |
29 | ||
30 | RowItem::RowItem() : | |
31 | owner_(NULL), | |
32 | layout_v_offset_(0), | |
33 | visual_v_offset_(0), | |
34 | v_offset_animation_(this, "visual_v_offset") | |
35 | { | |
36 | } | |
37 | ||
38 | int RowItem::layout_v_offset() const | |
39 | { | |
40 | return layout_v_offset_; | |
41 | } | |
42 | ||
43 | void RowItem::set_layout_v_offset(int v_offset) | |
44 | { | |
45 | if (layout_v_offset_ == v_offset) | |
46 | return; | |
47 | ||
48 | layout_v_offset_ = v_offset; | |
49 | ||
50 | if (owner_) | |
51 | owner_->extents_changed(false, true); | |
52 | } | |
53 | ||
54 | int RowItem::visual_v_offset() const | |
55 | { | |
56 | return visual_v_offset_; | |
57 | } | |
58 | ||
59 | void RowItem::set_visual_v_offset(int v_offset) | |
60 | { | |
61 | visual_v_offset_ = v_offset; | |
62 | ||
63 | if (owner_) | |
64 | owner_->row_item_appearance_changed(true, true); | |
65 | } | |
66 | ||
67 | void RowItem::force_to_v_offset(int v_offset) | |
68 | { | |
69 | v_offset_animation_.stop(); | |
70 | layout_v_offset_ = visual_v_offset_ = v_offset; | |
71 | ||
72 | if (owner_) { | |
73 | owner_->row_item_appearance_changed(true, true); | |
74 | owner_->extents_changed(false, true); | |
75 | } | |
76 | } | |
77 | ||
78 | void RowItem::animate_to_layout_v_offset() | |
79 | { | |
80 | if (visual_v_offset_ == layout_v_offset_ || | |
81 | (v_offset_animation_.endValue() == layout_v_offset_ && | |
82 | v_offset_animation_.state() == QAbstractAnimation::Running)) | |
83 | return; | |
84 | ||
85 | v_offset_animation_.setDuration(100); | |
86 | v_offset_animation_.setStartValue(visual_v_offset_); | |
87 | v_offset_animation_.setEndValue(layout_v_offset_); | |
88 | v_offset_animation_.setEasingCurve(QEasingCurve::OutQuad); | |
89 | v_offset_animation_.start(); | |
90 | } | |
91 | ||
92 | RowItemOwner* RowItem::owner() const | |
93 | { | |
94 | return owner_; | |
95 | } | |
96 | ||
97 | void RowItem::set_owner(RowItemOwner *owner) | |
98 | { | |
99 | assert(owner_ || owner); | |
100 | v_offset_animation_.stop(); | |
101 | ||
102 | if (owner_) { | |
103 | const int owner_offset = owner_->owner_visual_v_offset(); | |
104 | layout_v_offset_ += owner_offset; | |
105 | visual_v_offset_ += owner_offset; | |
106 | } | |
107 | ||
108 | owner_ = owner; | |
109 | ||
110 | if (owner_) { | |
111 | const int owner_offset = owner_->owner_visual_v_offset(); | |
112 | layout_v_offset_ -= owner_offset; | |
113 | visual_v_offset_ -= owner_offset; | |
114 | } | |
115 | } | |
116 | ||
117 | int RowItem::get_visual_y() const | |
118 | { | |
119 | assert(owner_); | |
120 | return visual_v_offset_ + owner_->owner_visual_v_offset(); | |
121 | } | |
122 | ||
123 | void RowItem::drag_by(const QPoint &delta) | |
124 | { | |
125 | force_to_v_offset(drag_point_.y() + delta.y() - | |
126 | owner_->owner_visual_v_offset()); | |
127 | } | |
128 | ||
129 | QPoint RowItem::point(const QRect &rect) const | |
130 | { | |
131 | return QPoint(rect.right(), get_visual_y()); | |
132 | } | |
133 | ||
134 | void RowItem::hover_point_changed() | |
135 | { | |
136 | } | |
137 | ||
138 | } // namespace view | |
139 | } // namespace pv |