PulseView  unreleased development snapshot
A Qt-based sigrok GUI
viewitem.hpp
Go to the documentation of this file.
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_VIEWS_TRACE_VIEWITEM_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACE_VIEWITEM_HPP
22 
23 #include <list>
24 
25 #include <QMouseEvent>
26 #include <QPen>
27 #include <QPoint>
28 
29 #include "viewitempaintparams.hpp"
30 
31 class QAction;
32 class QMenu;
33 class QWidget;
34 
35 namespace pv {
36 
37 namespace widgets {
38 class Popup;
39 }
40 
41 namespace views {
42 namespace trace {
43 
44 class ViewItemOwner;
45 
46 class ViewItem : public QObject
47 {
48  Q_OBJECT
49 
50 public:
51  static const QSizeF LabelPadding;
52  static const int HighlightRadius;
53 
54 public:
55  ViewItem();
56 
60  virtual bool enabled() const = 0;
61 
65  virtual bool is_selectable(QPoint pos) const;
66 
70  bool selected() const;
71 
75  virtual void select(bool select = true);
76 
80  virtual bool is_draggable(QPoint pos) const;
81 
85  bool dragging() const;
86 
90  void drag();
91 
95  virtual void drag_release();
96 
101  virtual void drag_by(const QPoint &delta) = 0;
102 
107  virtual QPoint drag_point(const QRect &rect) const = 0;
108 
115  virtual QRectF label_rect(const QRectF &rect) const;
116 
123  virtual QRectF hit_box_rect(const ViewItemPaintParams &pp) const;
124 
131  virtual void paint_label(QPainter &p, const QRect &rect, bool hover);
132 
138  virtual void paint_back(QPainter &p, ViewItemPaintParams &pp);
139 
145  virtual void paint_mid(QPainter &p, ViewItemPaintParams &pp);
146 
152  virtual void paint_fore(QPainter &p, ViewItemPaintParams &pp);
153 
160  static QColor select_text_color(QColor background);
161 
162 public:
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 
177  virtual void mouse_left_press_event(const QMouseEvent* event);
178 
179 protected:
180  static QPen highlight_pen();
181 
182 protected:
183  QWidget *context_parent_;
184  QPoint drag_point_;
185 
186 private:
187  bool selected_;
188 };
189 
190 } // namespace trace
191 } // namespace views
192 } // namespace pv
193 
194 #endif // PULSEVIEW_PV_VIEWS_TRACE_VIEWITEM_HPP
static const int HighlightRadius
Definition: viewitem.hpp:52
static const QSizeF LabelPadding
Definition: viewitem.hpp:51