]> sigrok.org Git - pulseview.git/blob - pv/view/rowitem.hpp
39c6f04030d1d214b688aa7ffedbbb0a8530f023
[pulseview.git] / pv / view / rowitem.hpp
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 #ifndef PULSEVIEW_PV_VIEW_HEADERITEM_H
22 #define PULSEVIEW_PV_VIEW_HEADERITEM_H
23
24 #include <memory>
25
26 #include <QPropertyAnimation>
27
28 #include "rowitempaintparams.hpp"
29 #include "selectableitem.hpp"
30
31 namespace pv {
32 namespace view {
33
34 class RowItemOwner;
35
36 class RowItem : public SelectableItem,
37         public std::enable_shared_from_this<pv::view::RowItem>
38 {
39         Q_OBJECT
40         Q_PROPERTY(int visual_v_offset
41                 READ visual_v_offset
42                 WRITE set_visual_v_offset)
43
44 public:
45         /**
46          * Constructor.
47          */
48         RowItem();
49
50         /**
51          * Returns true if the item is visible and enabled.
52          */
53         virtual bool enabled() const = 0;
54
55         /**
56          * Gets the vertical layout offset of this signal.
57          */
58         int layout_v_offset() const;
59
60         /**
61          * Sets the vertical layout offset of this signal.
62          */
63         void set_layout_v_offset(int v_offset);
64
65         /**
66          * Gets the vertical visual offset of this signal.
67          */
68         int visual_v_offset() const;
69
70         /**
71          * Sets the vertical visual offset of this signal.
72          */
73         void set_visual_v_offset(int v_offset);
74
75         /**
76          * Sets the visual and layout offset of this signal.
77          */
78         void force_to_v_offset(int v_offset);
79
80         /**
81          * Begins an animation that will animate the visual offset toward
82          * the layout offset.
83          */
84         void animate_to_layout_v_offset();
85
86         /**
87          * Gets the owner this trace in the view trace hierachy.
88          */
89         pv::view::RowItemOwner* owner() const;
90
91         /**
92          * Sets the owner this trace in the view trace hierachy.
93          * @param The new owner of the trace.
94          */
95         void set_owner(pv::view::RowItemOwner *owner);
96
97         /**
98          * Gets the visual y-offset of the axis.
99          */
100         int get_visual_y() const;
101
102         /**
103          * Gets the drag point of the row item.
104          */
105         QPoint point() const;
106
107         /**
108          * Computes the vertical extents of the contents of this row item.
109          * @return A pair containing the minimum and maximum y-values.
110          */
111         virtual std::pair<int, int> v_extents() const = 0;
112
113         /**
114          * Paints the background layer of the trace with a QPainter
115          * @param p the QPainter to paint into.
116          * @param pp the painting parameters object to paint with.
117          **/
118         virtual void paint_back(QPainter &p, const RowItemPaintParams &pp);
119
120         /**
121          * Paints the mid-layer of the trace with a QPainter
122          * @param p the QPainter to paint into.
123          * @param pp the painting parameters object to paint with.
124          **/
125         virtual void paint_mid(QPainter &p, const RowItemPaintParams &pp);
126
127         /**
128          * Paints the foreground layer of the trace with a QPainter
129          * @param p the QPainter to paint into.
130          * @param pp the painting parameters object to paint with.
131          **/
132         virtual void paint_fore(QPainter &p, const RowItemPaintParams &pp);
133
134         /**
135          * Paints the signal label.
136          * @param p the QPainter to paint into.
137          * @param right the x-coordinate of the right edge of the header
138          *      area.
139          * @param hover true if the label is being hovered over by the mouse.
140          */
141         virtual void paint_label(QPainter &p, int right, bool hover) = 0;
142
143         /**
144          * Computes the outline rectangle of a label.
145          * @param right the x-coordinate of the right edge of the header
146          *      area.
147          * @return Returns the rectangle of the signal label.
148          */
149         virtual QRectF label_rect(int right) const = 0;
150
151 public:
152         virtual void hover_point_changed();
153
154 protected:
155         pv::view::RowItemOwner *owner_;
156
157         int layout_v_offset_;
158         int visual_v_offset_;
159
160 private:
161         QPropertyAnimation v_offset_animation_;
162 };
163
164 } // namespace view
165 } // namespace pv
166
167 #endif // PULSEVIEW_PV_VIEW_HEADERITEM_H