]> sigrok.org Git - pulseview.git/blob - pv/view/rowitem.hpp
aca4fa83ecbb24bc4f372f25311e643b9a14c13c
[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          * Gets the vertical layout offset of this signal.
52          */
53         int layout_v_offset() const;
54
55         /**
56          * Sets the vertical layout offset of this signal.
57          */
58         void set_layout_v_offset(int v_offset);
59
60         /**
61          * Gets the vertical visual offset of this signal.
62          */
63         int visual_v_offset() const;
64
65         /**
66          * Sets the vertical visual offset of this signal.
67          */
68         void set_visual_v_offset(int v_offset);
69
70         /**
71          * Sets the visual and layout offset of this signal.
72          */
73         void force_to_v_offset(int v_offset);
74
75         /**
76          * Begins an animation that will animate the visual offset toward
77          * the layout offset.
78          */
79         void animate_to_layout_v_offset();
80
81         /**
82          * Gets the owner this trace in the view trace hierachy.
83          */
84         pv::view::RowItemOwner* owner() const;
85
86         /**
87          * Sets the owner this trace in the view trace hierachy.
88          * @param The new owner of the trace.
89          */
90         void set_owner(pv::view::RowItemOwner *owner);
91
92         /**
93          * Gets the visual y-offset of the axis.
94          */
95         int get_visual_y() const;
96
97         /**
98          * Gets the drag point of the row item.
99          */
100         QPoint point() const;
101
102         /**
103          * Computes the vertical extents of the contents of this row item.
104          * @return A pair containing the minimum and maximum y-values.
105          */
106         virtual std::pair<int, int> v_extents() const = 0;
107
108         /**
109          * Paints the background layer of the trace with a QPainter
110          * @param p the QPainter to paint into.
111          * @param pp the painting parameters object to paint with.
112          **/
113         virtual void paint_back(QPainter &p, const RowItemPaintParams &pp);
114
115         /**
116          * Paints the mid-layer of the trace with a QPainter
117          * @param p the QPainter to paint into.
118          * @param pp the painting parameters object to paint with.
119          **/
120         virtual void paint_mid(QPainter &p, const RowItemPaintParams &pp);
121
122         /**
123          * Paints the foreground layer of the trace with a QPainter
124          * @param p the QPainter to paint into.
125          * @param pp the painting parameters object to paint with.
126          **/
127         virtual void paint_fore(QPainter &p, const RowItemPaintParams &pp);
128
129         /**
130          * Paints the signal label.
131          * @param p the QPainter to paint into.
132          * @param rect the rectangle of the header area.
133          * @param hover true if the label is being hovered over by the mouse.
134          */
135         virtual void paint_label(QPainter &p, const QRect &rect, bool hover) = 0;
136
137         /**
138          * Computes the outline rectangle of a label.
139          * @param rect the rectangle of the header area.
140          * @return Returns the rectangle of the signal label.
141          */
142         virtual QRectF label_rect(const QRectF &rect) const = 0;
143
144 public:
145         virtual void hover_point_changed();
146
147 protected:
148         pv::view::RowItemOwner *owner_;
149
150         int layout_v_offset_;
151         int visual_v_offset_;
152
153 private:
154         QPropertyAnimation v_offset_animation_;
155 };
156
157 } // namespace view
158 } // namespace pv
159
160 #endif // PULSEVIEW_PV_VIEW_HEADERITEM_H