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
00043
00044 #ifndef HOVERPOINTS_H
00045 #define HOVERPOINTS_H
00046
00047 #include <QtGui>
00048
00049 class QBypassWidget;
00050
00051 class HoverPoints : public QObject
00052 {
00053 Q_OBJECT
00054 public:
00055 enum PointShape {
00056 CircleShape,
00057 RectangleShape
00058 };
00059
00060 enum LockType {
00061 LockToLeft = 0x01,
00062 LockToRight = 0x02,
00063 LockToTop = 0x04,
00064 LockToBottom = 0x08
00065 };
00066
00067 enum SortType {
00068 NoSort,
00069 XSort,
00070 YSort
00071 };
00072
00073 enum ConnectionType {
00074 NoConnection,
00075 LineConnection,
00076 CurveConnection
00077 };
00078
00079 HoverPoints(QWidget *widget, PointShape shape);
00080
00081 bool eventFilter(QObject *object, QEvent *event);
00082
00083 void paintPoints();
00084
00085 inline QRectF boundingRect() const;
00086 void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
00087
00088 QPolygonF points() const { return m_points; }
00089 void setPoints(const QPolygonF &points);
00090
00091 QSizeF pointSize() const { return m_pointSize; }
00092 void setPointSize(const QSizeF &size) { m_pointSize = size; }
00093
00094 SortType sortType() const { return m_sortType; }
00095 void setSortType(SortType sortType) { m_sortType = sortType; }
00096
00097 ConnectionType connectionType() const { return m_connectionType; }
00098 void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
00099
00100 void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
00101 void setShapePen(const QPen &pen) { m_pointPen = pen; }
00102 void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
00103
00104 void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
00105
00106 void setEditable(bool editable) { m_editable = editable; }
00107 bool editable() const { return m_editable; }
00108
00109 public slots:
00110 void setEnabled(bool enabled);
00111 void setDisabled(bool disabled) { setEnabled(!disabled); }
00112
00113 signals:
00114 void pointsChanged(const QPolygonF &points);
00115
00116 public:
00117 void firePointChange();
00118
00119 private:
00120 inline QRectF pointBoundingRect(int i) const;
00121 void movePoint(int i, const QPointF &newPos, bool emitChange = true);
00122
00123 QWidget *m_widget;
00124
00125 QPolygonF m_points;
00126 QRectF m_bounds;
00127 PointShape m_shape;
00128 SortType m_sortType;
00129 ConnectionType m_connectionType;
00130
00131 QVector<uint> m_locks;
00132
00133 QSizeF m_pointSize;
00134 int m_currentIndex;
00135 bool m_editable;
00136 bool m_enabled;
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 double w = m_pointSize.width();
00148 double h = m_pointSize.height();
00149 double x = p.x() - w / 2;
00150 double 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