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