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