VideoVis  0.9
Generates a volume visualisation of a video
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
hoverpoints.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the demonstration applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef HOVERPOINTS_H
43 #define HOVERPOINTS_H
44 
45 #include <QtWidgets>
46 #include <QColorDialog>
47 
48 QT_FORWARD_DECLARE_CLASS(QBypassWidget)
49 
50 
56 class HoverPoints : public QObject
57 {
58  Q_OBJECT
59 public:
60  enum PointShape {
62  RectangleShape
63  };
64 
65  enum LockType {
66  LockToLeft = 0x01,
67  LockToRight = 0x02,
68  LockToTop = 0x04,
69  LockToBottom = 0x08
70  };
71 
72  enum SortType {
75  YSort
76  };
77 
81  CurveConnection
82  };
83 
84  HoverPoints(QWidget *widget, PointShape shape);
85 
86  bool eventFilter(QObject *object, QEvent *event);
87 
88  void paintPoints();
89 
90  inline QRectF boundingRect() const;
91 
92  void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
93 
94  QPolygonF points() const { return m_points; }
95  void setPoints(const QPolygonF &points);
96 
97  QSizeF pointSize() const { return m_pointSize; }
98  void setPointSize(const QSizeF &size) { m_pointSize = size; }
99 
100  SortType sortType() const { return m_sortType; }
101  void setSortType(SortType sortType) { m_sortType = sortType; }
102 
103  ConnectionType connectionType() const { return m_connectionType; }
104  void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
105 
106  void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
107  void setShapePen(const QPen &pen) { m_pointPen = pen; }
108  void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
109 
110  void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
111 
112  void setEditable(bool editable) { m_editable = editable; }
113  bool editable() const { return m_editable; }
114 
115 public slots:
116  void setEnabled(bool enabled);
117  void setDisabled(bool disabled) { setEnabled(!disabled); }
118 
119 signals:
120  void pointsChanged(const QPolygonF &points);
121 
122 public:
123  void firePointChange();
124 
125 private:
126  inline QRectF pointBoundingRect(int i) const;
127  void movePoint(int i, const QPointF &newPos, bool emitChange = true);
128 
129  QWidget *m_widget;
130 
131  QPolygonF m_points;
132  QRectF m_bounds;
133  PointShape m_shape;
134  SortType m_sortType;
135  ConnectionType m_connectionType;
136 
137  QVector<uint> m_locks;
138 
139  QSizeF m_pointSize;
140  int m_currentIndex;
141  bool m_editable;
142  bool m_enabled;
143 
144  QHash<int, int> m_fingerPointMapping;
145 
146  QPen m_pointPen;
147  QBrush m_pointBrush;
148  QPen m_connectionPen;
149 
150  QColorDialog *m_dialog;
151 };
152 
153 
154 inline QRectF HoverPoints::pointBoundingRect(int i) const
155 {
156  QPointF p = m_points.at(i);
157  qreal w = m_pointSize.width();
158  qreal h = m_pointSize.height();
159  qreal x = p.x() - w / 2;
160  qreal y = p.y() - h / 2;
161  return QRectF(x, y, w, h);
162 }
163 
164 inline QRectF HoverPoints::boundingRect() const
165 {
166  if (m_bounds.isEmpty())
167  return m_widget->rect();
168  else
169  return m_bounds;
170 }
171 
172 #endif // HOVERPOINTS_H