]> sigrok.org Git - pulseview.git/blame_incremental - pv/views/trace/viewitem.hpp
Fix #1525 by increasing the allowed unit/div range
[pulseview.git] / pv / views / trace / viewitem.hpp
... / ...
CommitLineData
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, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PULSEVIEW_PV_VIEWITEM_HPP
21#define PULSEVIEW_PV_VIEWITEM_HPP
22
23#include <list>
24
25#include <QMouseEvent>
26#include <QPen>
27#include <QPoint>
28
29#include "viewitempaintparams.hpp"
30
31class QAction;
32class QMenu;
33class QWidget;
34
35namespace pv {
36
37namespace widgets {
38class Popup;
39}
40
41namespace views {
42namespace trace {
43
44class ViewItemOwner;
45
46class ViewItem : public QObject
47{
48 Q_OBJECT
49
50public:
51 static const QSizeF LabelPadding;
52 static const int HighlightRadius;
53
54public:
55 ViewItem();
56
57 /**
58 * Returns true if the item is visible and enabled.
59 */
60 virtual bool enabled() const = 0;
61
62 /**
63 * Returns true if the item may be selected.
64 */
65 virtual bool is_selectable(QPoint pos) const;
66
67 /**
68 * Returns true if the item has been selected by the user.
69 */
70 bool selected() const;
71
72 /**
73 * Selects or deselects the signal.
74 */
75 virtual void select(bool select = true);
76
77 /**
78 * Returns true if the item may be dragged/moved.
79 */
80 virtual bool is_draggable(QPoint pos) const;
81
82 /**
83 * Returns true if the item is being dragged.
84 */
85 bool dragging() const;
86
87 /**
88 * Sets this item into the dragged state.
89 */
90 void drag();
91
92 /**
93 * Sets this item into the un-dragged state.
94 */
95 virtual void drag_release();
96
97 /**
98 * Drags the item to a delta relative to the drag point.
99 * @param delta the offset from the drag point.
100 */
101 virtual void drag_by(const QPoint &delta) = 0;
102
103 /**
104 * Get the drag point.
105 * @param rect the rectangle of the widget area.
106 */
107 virtual QPoint drag_point(const QRect &rect) const = 0;
108
109 /**
110 * Computes the outline rectangle of a label.
111 * @param rect the rectangle of the header area.
112 * @return Returns the rectangle of the signal label.
113 * @remarks The default implementation returns an empty rectangle.
114 */
115 virtual QRectF label_rect(const QRectF &rect) const;
116
117 /**
118 * Computes the outline rectangle of the viewport hit-box.
119 * @param rect the rectangle of the viewport area.
120 * @return Returns the rectangle of the hit-box.
121 * @remarks The default implementation returns an empty hit-box.
122 */
123 virtual QRectF hit_box_rect(const ViewItemPaintParams &pp) const;
124
125 /**
126 * Paints the signal label.
127 * @param p the QPainter to paint into.
128 * @param rect the rectangle of the header area.
129 * @param hover true if the label is being hovered over by the mouse.
130 */
131 virtual void paint_label(QPainter &p, const QRect &rect, bool hover);
132
133 /**
134 * Paints the background layer of the item with a QPainter
135 * @param p the QPainter to paint into.
136 * @param pp the painting parameters object to paint with.
137 */
138 virtual void paint_back(QPainter &p, ViewItemPaintParams &pp);
139
140 /**
141 * Paints the mid-layer of the item with a QPainter
142 * @param p the QPainter to paint into.
143 * @param pp the painting parameters object to paint with.
144 */
145 virtual void paint_mid(QPainter &p, ViewItemPaintParams &pp);
146
147 /**
148 * Paints the foreground layer of the item with a QPainter
149 * @param p the QPainter to paint into.
150 * @param pp the painting parameters object to paint with.
151 */
152 virtual void paint_fore(QPainter &p, ViewItemPaintParams &pp);
153
154 /**
155 * Gets the text color.
156 * @remarks This color is computed by comparing the lightness
157 * of the trace color against a threshold to determine whether
158 * white or black would be more visible.
159 */
160 static QColor select_text_color(QColor background);
161
162public:
163 virtual QMenu* create_header_context_menu(QWidget *parent);
164
165 virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
166
167 virtual pv::widgets::Popup* create_popup(QWidget *parent);
168
169 virtual void delete_pressed();
170
171 virtual void hover_point_changed(const QPoint &hp);
172
173 /**
174 * Handles left mouse button press events.
175 * @param event the mouse event that triggered this handler.
176 */
177 virtual void mouse_left_press_event(const QMouseEvent* event);
178
179protected:
180 static QPen highlight_pen();
181
182protected:
183 QWidget *context_parent_;
184 QPoint drag_point_;
185
186private:
187 bool selected_;
188};
189
190} // namespace trace
191} // namespace views
192} // namespace pv
193
194#endif // PULSEVIEW_PV_VIEWITEM_HPP