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