PulseView  unreleased development snapshot
A Qt-based sigrok GUI
viewitem.cpp
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 #include "viewitem.hpp"
21 
22 #include <climits>
23 
24 #include <QApplication>
25 #include <QMenu>
26 #include <QPalette>
27 
28 namespace pv {
29 namespace views {
30 namespace trace {
31 
32 const QSizeF ViewItem::LabelPadding(4, 0);
33 const int ViewItem::HighlightRadius = 3;
34 
36  context_parent_(nullptr),
37  drag_point_(INT_MIN, INT_MIN),
38  selected_(false)
39 {
40 }
41 
42 bool ViewItem::is_selectable(QPoint pos) const
43 {
44  (void)pos;
45  return true;
46 }
47 
48 bool ViewItem::selected() const
49 {
50  return selected_;
51 }
52 
54 {
55  selected_ = select;
56 }
57 
58 bool ViewItem::is_draggable(QPoint pos) const
59 {
60  (void)pos;
61  return true;
62 }
63 
64 bool ViewItem::dragging() const
65 {
66  return drag_point_.x() != INT_MIN && drag_point_.y() != INT_MIN;
67 }
68 
70 {
71  drag_point_ = drag_point(QRect());
72 }
73 
75 {
76  drag_point_ = QPoint(INT_MIN, INT_MIN);
77 }
78 
79 QRectF ViewItem::label_rect(const QRectF &rect) const
80 {
81  (void)rect;
82  return QRectF();
83 }
84 
86 {
87  (void)pp;
88  return QRectF();
89 }
90 
91 QMenu* ViewItem::create_header_context_menu(QWidget *parent)
92 {
93  context_parent_ = parent;
94  return new QMenu(parent);
95 }
96 
97 QMenu* ViewItem::create_view_context_menu(QWidget *parent, QPoint &click_pos)
98 {
99  (void)parent;
100  (void)click_pos;
101  return nullptr;
102 }
103 
105 {
106  (void)parent;
107  return nullptr;
108 }
109 
111 {
112 }
113 
115 {
116  return QPen(QApplication::palette().brush(
117  QPalette::Highlight), HighlightRadius * 2,
118  Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
119 }
120 
121 void ViewItem::paint_label(QPainter &p, const QRect &rect, bool hover)
122 {
123  (void)p;
124  (void)rect;
125  (void)hover;
126 }
127 
129 {
130  (void)p;
131  (void)pp;
132 }
133 
135 {
136  (void)p;
137  (void)pp;
138 }
139 
141 {
142  (void)p;
143  (void)pp;
144 }
145 
146 QColor ViewItem::select_text_color(QColor background)
147 {
148  return (background.lightness() > 110) ? Qt::black : Qt::white;
149 }
150 
151 void ViewItem::hover_point_changed(const QPoint &hp)
152 {
153  (void)hp;
154 }
155 
156 void ViewItem::mouse_left_press_event(const QMouseEvent* event)
157 {
158  (void)event;
159 }
160 
161 } // namespace trace
162 } // namespace views
163 } // namespace pv
virtual QMenu * create_view_context_menu(QWidget *parent, QPoint &click_pos)
Definition: viewitem.cpp:97
bool dragging() const
Definition: viewitem.cpp:64
static const int HighlightRadius
Definition: viewitem.hpp:52
virtual void delete_pressed()
Definition: viewitem.cpp:110
virtual pv::widgets::Popup * create_popup(QWidget *parent)
Definition: viewitem.cpp:104
virtual QRectF hit_box_rect(const ViewItemPaintParams &pp) const
Definition: viewitem.cpp:85
virtual QRectF label_rect(const QRectF &rect) const
Definition: viewitem.cpp:79
virtual void hover_point_changed(const QPoint &hp)
Definition: viewitem.cpp:151
static QPen highlight_pen()
Definition: viewitem.cpp:114
static const QSizeF LabelPadding
Definition: viewitem.hpp:51
virtual void drag_release()
Definition: viewitem.cpp:74
virtual bool is_draggable(QPoint pos) const
Definition: viewitem.cpp:58
static QColor select_text_color(QColor background)
Definition: viewitem.cpp:146
virtual void mouse_left_press_event(const QMouseEvent *event)
Definition: viewitem.cpp:156
bool selected() const
Definition: viewitem.cpp:48
virtual bool is_selectable(QPoint pos) const
Definition: viewitem.cpp:42
virtual QPoint drag_point(const QRect &rect) const =0
virtual void paint_back(QPainter &p, ViewItemPaintParams &pp)
Definition: viewitem.cpp:128
virtual void paint_mid(QPainter &p, ViewItemPaintParams &pp)
Definition: viewitem.cpp:134
virtual void select(bool select=true)
Definition: viewitem.cpp:53
virtual void paint_label(QPainter &p, const QRect &rect, bool hover)
Definition: viewitem.cpp:121
virtual void paint_fore(QPainter &p, ViewItemPaintParams &pp)
Definition: viewitem.cpp:140
virtual QMenu * create_header_context_menu(QWidget *parent)
Definition: viewitem.cpp:91