1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PULSEVIEW_PV_VIEWWIDGET_HPP
#define PULSEVIEW_PV_VIEWWIDGET_HPP
#include <memory>
#include <QPoint>
#include <QWidget>
#include <pv/util.hpp>
using std::shared_ptr;
using std::vector;
class QTouchEvent;
namespace pv {
namespace views {
namespace trace {
class View;
class ViewItem;
class ViewWidget : public QWidget
{
Q_OBJECT
protected:
ViewWidget(View &parent);
/**
* Indicates when a view item is being hovered over.
* @param item The item that is being hovered over, or @c nullptr
* if no view item is being hovered over.
* @remarks the default implementation does nothing.
*/
virtual void item_hover(const shared_ptr<ViewItem> &item, QPoint pos);
/**
* Indicates the event an a view item has been clicked.
* @param item the view item that has been clicked.
* @remarks the default implementation does nothing.
*/
virtual void item_clicked(const shared_ptr<ViewItem> &item);
/**
* Returns true if the selection of row items allows dragging.
* @return Returns true if the drag is acceptable.
*/
bool accept_drag() const;
/**
* Returns true if the mouse button is down.
*/
bool mouse_down() const;
/**
* Drag the dragging items by the delta offset.
* @param delta the drag offset in pixels.
*/
void drag_items(const QPoint &delta);
/**
* Sets this item into the dragged state.
*/
virtual void drag();
/**
* Drag the background by the delta offset.
* @param delta the drag offset in pixels.
* @remarks The default implementation does nothing.
*/
virtual void drag_by(const QPoint &delta);
/**
* Sets this item into the un-dragged state.
*/
virtual void drag_release();
/**
* Gets the items in the view widget.
*/
virtual vector< shared_ptr<ViewItem> > items() = 0;
/**
* Gets the first view item which has a hit-box that contains @c pt .
* @param pt the point to search with.
* @return the view item that has been found, or and empty
* @c shared_ptr if no item was found.
*/
virtual shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt) = 0;
/**
* Handles left mouse button press events.
* @param event the mouse event that triggered this handler.
*/
void mouse_left_press_event(QMouseEvent *event);
/**
* Handles left mouse button release events.
* @param event the mouse event that triggered this handler.
*/
void mouse_left_release_event(QMouseEvent *event);
/**
* Handles touch begin update and end events.
* @param e the event that triggered this handler.
*/
virtual bool touch_event(QTouchEvent *event);
protected:
bool event(QEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
void leaveEvent(QEvent *event);
public Q_SLOTS:
void clear_selection();
Q_SIGNALS:
void selection_changed();
protected:
pv::views::trace::View &view_;
QPoint mouse_point_;
QPoint mouse_down_point_;
pv::util::Timestamp mouse_down_offset_;
shared_ptr<ViewItem> mouse_down_item_;
/// Keyboard modifiers that were active when mouse was last moved or clicked
Qt::KeyboardModifiers mouse_modifiers_;
bool item_dragging_;
};
} // namespace trace
} // namespace views
} // namespace pv
#endif // PULSEVIEW_PV_VIEWWIDGET_HPP
|