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