|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef HOVERPOINTS_H |
|
43 #define HOVERPOINTS_H |
|
44 |
|
45 #include <QtGui> |
|
46 |
|
47 QT_FORWARD_DECLARE_CLASS(QBypassWidget) |
|
48 |
|
49 class HoverPoints : public QObject |
|
50 { |
|
51 Q_OBJECT |
|
52 public: |
|
53 enum PointShape { |
|
54 CircleShape, |
|
55 RectangleShape |
|
56 }; |
|
57 |
|
58 enum LockType { |
|
59 LockToLeft = 0x01, |
|
60 LockToRight = 0x02, |
|
61 LockToTop = 0x04, |
|
62 LockToBottom = 0x08 |
|
63 }; |
|
64 |
|
65 enum SortType { |
|
66 NoSort, |
|
67 XSort, |
|
68 YSort |
|
69 }; |
|
70 |
|
71 enum ConnectionType { |
|
72 NoConnection, |
|
73 LineConnection, |
|
74 CurveConnection |
|
75 }; |
|
76 |
|
77 HoverPoints(QWidget *widget, PointShape shape); |
|
78 |
|
79 bool eventFilter(QObject *object, QEvent *event); |
|
80 |
|
81 void paintPoints(); |
|
82 |
|
83 inline QRectF boundingRect() const; |
|
84 void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; } |
|
85 |
|
86 QPolygonF points() const { return m_points; } |
|
87 void setPoints(const QPolygonF &points); |
|
88 |
|
89 QSizeF pointSize() const { return m_pointSize; } |
|
90 void setPointSize(const QSizeF &size) { m_pointSize = size; } |
|
91 |
|
92 SortType sortType() const { return m_sortType; } |
|
93 void setSortType(SortType sortType) { m_sortType = sortType; } |
|
94 |
|
95 ConnectionType connectionType() const { return m_connectionType; } |
|
96 void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; } |
|
97 |
|
98 void setConnectionPen(const QPen &pen) { m_connectionPen = pen; } |
|
99 void setShapePen(const QPen &pen) { m_pointPen = pen; } |
|
100 void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; } |
|
101 |
|
102 void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; } |
|
103 |
|
104 void setEditable(bool editable) { m_editable = editable; } |
|
105 bool editable() const { return m_editable; } |
|
106 |
|
107 public slots: |
|
108 void setEnabled(bool enabled); |
|
109 void setDisabled(bool disabled) { setEnabled(!disabled); } |
|
110 |
|
111 signals: |
|
112 void pointsChanged(const QPolygonF &points); |
|
113 |
|
114 public: |
|
115 void firePointChange(); |
|
116 |
|
117 private: |
|
118 inline QRectF pointBoundingRect(int i) const; |
|
119 void movePoint(int i, const QPointF &newPos, bool emitChange = true); |
|
120 |
|
121 QWidget *m_widget; |
|
122 |
|
123 QPolygonF m_points; |
|
124 QRectF m_bounds; |
|
125 PointShape m_shape; |
|
126 SortType m_sortType; |
|
127 ConnectionType m_connectionType; |
|
128 |
|
129 QVector<uint> m_locks; |
|
130 |
|
131 QSizeF m_pointSize; |
|
132 int m_currentIndex; |
|
133 bool m_editable; |
|
134 bool m_enabled; |
|
135 |
|
136 QHash<int, int> m_fingerPointMapping; |
|
137 |
|
138 QPen m_pointPen; |
|
139 QBrush m_pointBrush; |
|
140 QPen m_connectionPen; |
|
141 }; |
|
142 |
|
143 |
|
144 inline QRectF HoverPoints::pointBoundingRect(int i) const |
|
145 { |
|
146 QPointF p = m_points.at(i); |
|
147 qreal w = m_pointSize.width(); |
|
148 qreal h = m_pointSize.height(); |
|
149 qreal x = p.x() - w / 2; |
|
150 qreal y = p.y() - h / 2; |
|
151 return QRectF(x, y, w, h); |
|
152 } |
|
153 |
|
154 inline QRectF HoverPoints::boundingRect() const |
|
155 { |
|
156 if (m_bounds.isEmpty()) |
|
157 return m_widget->rect(); |
|
158 else |
|
159 return m_bounds; |
|
160 } |
|
161 |
|
162 #endif // HOVERPOINTS_H |