source: trunk/demos/shared/hoverpoints.h@ 858

Last change on this file since 858 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 4.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the demonstration applications of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef HOVERPOINTS_H
43#define HOVERPOINTS_H
44
45#include <QtGui>
46
47QT_FORWARD_DECLARE_CLASS(QBypassWidget)
48
49class HoverPoints : public QObject
50{
51 Q_OBJECT
52public:
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
107public slots:
108 void setEnabled(bool enabled);
109 void setDisabled(bool disabled) { setEnabled(!disabled); }
110
111signals:
112 void pointsChanged(const QPolygonF &points);
113
114public:
115 void firePointChange();
116
117private:
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
144inline 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
154inline 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
Note: See TracBrowser for help on using the repository browser.