GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hoverpoints.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 ** 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 qt-info@nokia.com.
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 /*=========================================================================
43  Modifications were made by the GoFigure Dev. Team.
44  while at Megason Lab, Systems biology, Harvard Medical school, 2009-11
45 
46  Copyright (c) 2009-11, President and Fellows of Harvard College.
47  All rights reserved.
48 
49  Redistribution and use in source and binary forms, with or without
50  modification, are permitted provided that the following conditions are met:
51 
52  Redistributions of source code must retain the above copyright notice,
53  this list of conditions and the following disclaimer.
54  Redistributions in binary form must reproduce the above copyright notice,
55  this list of conditions and the following disclaimer in the documentation
56 // and/or other materials provided with the distribution.
57  Neither the name of the President and Fellows of Harvard College
58  nor the names of its contributors may be used to endorse or promote
59  products derived from this software without specific prior written
60  permission.
61 
62  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
63  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
64  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
65  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
66  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
67  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
68  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
69  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
70  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
71  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
72  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 
74  =========================================================================*/
75 
76 #ifndef HOVERPOINTS_H
77 #define HOVERPOINTS_H
78 
79 #include <QtGui>
80 
81 QT_FORWARD_DECLARE_CLASS(QBypassWidget)
82 
83 class HoverPoints : public QObject
84 {
85  Q_OBJECT
86 public:
87  enum PointShape {
89  RectangleShape
90  };
91 
92  enum LockType {
93  LockToLeft = 0x01,
94  LockToRight = 0x02,
95  LockToTop = 0x04,
96  LockToBottom = 0x08
97  };
98 
99  enum SortType {
102  YSort
103  };
104 
108  CurveConnection
109  };
110 
111  HoverPoints(QWidget *widget, PointShape shape);
112 
113  bool eventFilter(QObject *object, QEvent *event);
114 
115  void paintPoints();
116 
117  inline QRectF boundingRect() const;
118  void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
119 
120  QPolygonF points() const { return m_points; }
121  void setPoints(const QPolygonF &points);
122 
123  QSizeF pointSize() const { return m_pointSize; }
124  void setPointSize(const QSizeF &size) { m_pointSize = size; }
125 
126  SortType sortType() const { return m_sortType; }
127  void setSortType(SortType sortType) { m_sortType = sortType; }
128 
129  ConnectionType connectionType() const { return m_connectionType; }
130  void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
131 
132  void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
133  void setShapePen(const QPen &pen) { m_pointPen = pen; }
134  void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
135 
136  void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
137 
138  void setEditable(bool editable) { m_editable = editable; }
139  bool editable() const { return m_editable; }
140 
141 public slots:
142  void setEnabled(bool enabled);
143 
144 signals:
145  void pointsChanged(const QPolygonF &points);
146 
147 public:
148  void firePointChange();
149 
150 private:
151  inline QRectF pointBoundingRect(int i) const;
152  void movePoint(int i, const QPointF &newPos, bool emitChange = true);
153 
155 
161 
163 
167  bool m_enabled;
168 
170 
174 
175  double m_oldSize[2];
176 };
177 
178 
180 {
181  QPointF p = m_points.at(i);
182  qreal w = m_pointSize.width();
183  qreal h = m_pointSize.height();
184  qreal x = p.x() - w / 2;
185  qreal y = p.y() - h / 2;
186  return QRectF(x, y, w, h);
187 }
188 
190 {
191  if (m_bounds.isEmpty())
192  return m_widget->rect();
193  else
194  return m_bounds;
195 }
196 
197 #endif // HOVERPOINTS_H
void setShapeBrush(const QBrush &brush)
Definition: hoverpoints.h:134
QVector< uint > m_locks
Definition: hoverpoints.h:162
QRectF m_bounds
Definition: hoverpoints.h:157
QPolygonF points() const
Definition: hoverpoints.h:120
SortType m_sortType
Definition: hoverpoints.h:159
void setPointLock(int pos, LockType lock)
Definition: hoverpoints.h:136
PointShape m_shape
Definition: hoverpoints.h:158
QSizeF pointSize() const
Definition: hoverpoints.h:123
void setSortType(SortType sortType)
Definition: hoverpoints.h:127
void setBoundingRect(const QRectF &boundingRect)
Definition: hoverpoints.h:118
bool m_enabled
Definition: hoverpoints.h:167
bool editable() const
Definition: hoverpoints.h:139
SortType sortType() const
Definition: hoverpoints.h:126
QPen m_pointPen
Definition: hoverpoints.h:171
bool m_editable
Definition: hoverpoints.h:166
void setEditable(bool editable)
Definition: hoverpoints.h:138
qreal x() const
qreal y() const
QRectF pointBoundingRect(int i) const
Definition: hoverpoints.h:179
QRectF boundingRect() const
Definition: hoverpoints.h:189
QBrush m_pointBrush
Definition: hoverpoints.h:172
void setConnectionPen(const QPen &pen)
Definition: hoverpoints.h:132
ConnectionType m_connectionType
Definition: hoverpoints.h:160
QWidget * m_widget
Definition: hoverpoints.h:154
ConnectionType connectionType() const
Definition: hoverpoints.h:129
QPolygonF m_points
Definition: hoverpoints.h:156
bool isEmpty() const
QSizeF m_pointSize
Definition: hoverpoints.h:164
const T & at(int i) const
QPen m_connectionPen
Definition: hoverpoints.h:173
int m_currentIndex
Definition: hoverpoints.h:165
void setShapePen(const QPen &pen)
Definition: hoverpoints.h:133
void setConnectionType(ConnectionType connectionType)
Definition: hoverpoints.h:130
void setPointSize(const QSizeF &size)
Definition: hoverpoints.h:124
qreal height() const
QHash< int, int > m_fingerPointMapping
Definition: hoverpoints.h:169
qreal width() const