PulseView  0.3.0
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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef PULSEVIEW_PV_VIEWITEM_HPP
22 #define PULSEVIEW_PV_VIEWITEM_HPP
23 
24 #include <list>
25 
26 #include <QPen>
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 view {
41 
42 class ViewItemOwner;
43 
44 class ViewItem : public QObject
45 {
46  Q_OBJECT
47 
48 public:
49  static const QSizeF LabelPadding;
50  static const int HighlightRadius;
51 
52 public:
53  ViewItem();
54 
55 public:
59  virtual bool enabled() const = 0;
60 
64  bool selected() const;
65 
69  virtual void select(bool select = true);
70 
74  virtual bool is_draggable() const;
75 
79  bool dragging() const;
80 
84  void drag();
85 
89  virtual void drag_release();
90 
95  virtual void drag_by(const QPoint &delta) = 0;
96 
101  virtual QPoint point(const QRect &rect) const = 0;
102 
109  virtual QRectF label_rect(const QRectF &rect) const;
110 
117  virtual QRectF hit_box_rect(const ViewItemPaintParams &pp) const;
118 
125  virtual void paint_label(QPainter &p, const QRect &rect, bool hover);
126 
132  virtual void paint_back(QPainter &p, const ViewItemPaintParams &pp);
133 
139  virtual void paint_mid(QPainter &p, const ViewItemPaintParams &pp);
140 
146  virtual void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
147 
148 public:
155  static QColor select_text_colour(QColor background);
156 
157 public:
158  virtual QMenu* create_context_menu(QWidget *parent);
159 
160  virtual pv::widgets::Popup* create_popup(QWidget *parent);
161 
162  virtual void delete_pressed();
163 
164 protected:
165  static QPen highlight_pen();
166 
167 protected:
168  QWidget *context_parent_;
169  QPoint drag_point_;
170 
171 private:
172  bool selected_;
173 };
174 
175 } // namespace view
176 } // namespace pv
177 
178 #endif // PULSEVIEW_PV_VIEWITEM_HPP
virtual void drag_release()
Definition: viewitem.cpp:68
static const QSizeF LabelPadding
Definition: viewitem.hpp:49
virtual QMenu * create_context_menu(QWidget *parent)
Definition: viewitem.cpp:85
virtual bool enabled() const =0
virtual bool is_draggable() const
Definition: viewitem.cpp:52
virtual void paint_fore(QPainter &p, const ViewItemPaintParams &pp)
Definition: viewitem.cpp:127
QWidget * context_parent_
Definition: viewitem.hpp:168
virtual pv::widgets::Popup * create_popup(QWidget *parent)
Definition: viewitem.cpp:91
virtual void paint_label(QPainter &p, const QRect &rect, bool hover)
Definition: viewitem.cpp:108
static QColor select_text_colour(QColor background)
Definition: viewitem.cpp:133
virtual void delete_pressed()
Definition: viewitem.cpp:97
virtual void paint_mid(QPainter &p, const ViewItemPaintParams &pp)
Definition: viewitem.cpp:121
virtual void select(bool select=true)
Definition: viewitem.cpp:47
virtual QRectF label_rect(const QRectF &rect) const
Definition: viewitem.cpp:73
static const int HighlightRadius
Definition: viewitem.hpp:50
bool selected() const
Definition: viewitem.cpp:42
virtual void paint_back(QPainter &p, const ViewItemPaintParams &pp)
Definition: viewitem.cpp:115
virtual QRectF hit_box_rect(const ViewItemPaintParams &pp) const
Definition: viewitem.cpp:79
bool dragging() const
Definition: viewitem.cpp:57
virtual QPoint point(const QRect &rect) const =0
static QPen highlight_pen()
Definition: viewitem.cpp:101
virtual void drag_by(const QPoint &delta)=0