00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef HOVERPOINTS_H
00043 #define HOVERPOINTS_H
00044
00045 #include <QtGui>
00046
00047 QT_FORWARD_DECLARE_CLASS(QBypassWidget)
00048
00049 class HoverPoints : public QObject
00050 {
00051 Q_OBJECT
00052 public:
00053 enum PointShape {
00054 CircleShape,
00055 RectangleShape
00056 };
00057
00058 enum LockType {
00059 LockToLeft = 0x01,
00060 LockToRight = 0x02,
00061 LockToTop = 0x04,
00062 LockToBottom = 0x08
00063 };
00064
00065 enum SortType {
00066 NoSort,
00067 XSort,
00068 YSort
00069 };
00070
00071 enum ConnectionType {
00072 NoConnection,
00073 LineConnection,
00074 CurveConnection
00075 };
00076
00077 HoverPoints(QWidget *widget, PointShape shape);
00078
00079 bool eventFilter(QObject *object, QEvent *event);
00080
00081 void paintPoints();
00082
00083 inline QRectF boundingRect() const;
00084 void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
00085
00086 QPolygonF points() const { return m_points; }
00087 void setPoints(const QPolygonF &points);
00088
00089 QSizeF pointSize() const { return m_pointSize; }
00090 void setPointSize(const QSizeF &size) { m_pointSize = size; }
00091
00092 SortType sortType() const { return m_sortType; }
00093 void setSortType(SortType sortType) { m_sortType = sortType; }
00094
00095 ConnectionType connectionType() const { return m_connectionType; }
00096 void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
00097
00098 void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
00099 void setShapePen(const QPen &pen) { m_pointPen = pen; }
00100 void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
00101
00102 void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
00103
00104 void setEditable(bool editable) { m_editable = editable; }
00105 bool editable() const { return m_editable; }
00106
00107 public slots:
00108 void setEnabled(bool enabled);
00109 void setDisabled(bool disabled) { setEnabled(!disabled); }
00110
00111 signals:
00112 void pointsChanged(const QPolygonF &points);
00113
00114 public:
00115 void firePointChange();
00116
00117 private:
00118 inline QRectF pointBoundingRect(int i) const;
00119 void movePoint(int i, const QPointF &newPos, bool emitChange = true);
00120
00121 QWidget *m_widget;
00122
00123 QPolygonF m_points;
00124 QRectF m_bounds;
00125 PointShape m_shape;
00126 SortType m_sortType;
00127 ConnectionType m_connectionType;
00128
00129 QVector<uint> m_locks;
00130
00131 QSizeF m_pointSize;
00132 int m_currentIndex;
00133 bool m_editable;
00134 bool m_enabled;
00135
00136 QHash<int, int> m_fingerPointMapping;
00137
00138 QPen m_pointPen;
00139 QBrush m_pointBrush;
00140 QPen m_connectionPen;
00141 };
00142
00143
00144 inline QRectF HoverPoints::pointBoundingRect(int i) const
00145 {
00146 QPointF p = m_points.at(i);
00147 qreal w = m_pointSize.width();
00148 qreal h = m_pointSize.height();
00149 qreal x = p.x() - w / 2;
00150 qreal y = p.y() - h / 2;
00151 return QRectF(x, y, w, h);
00152 }
00153
00154 inline QRectF HoverPoints::boundingRect() const
00155 {
00156 if (m_bounds.isEmpty())
00157 return m_widget->rect();
00158 else
00159 return m_bounds;
00160 }
00161
00162 #endif // HOVERPOINTS_H