00001 #ifndef HOVERPOINTS_H
00002 #define HOVERPOINTS_H
00003
00004 #include <QtGui>
00005
00006 QT_FORWARD_DECLARE_CLASS(QBypassWidget)
00007
00008
00011 class HoverPoints : public QObject
00012 {
00013 Q_OBJECT
00014 public:
00018 enum PointShape {
00019 CircleShape,
00020 RectangleShape
00021 };
00025 enum LockType {
00026 LockToLeft = 0x01,
00027 LockToRight = 0x02,
00028 LockToTop = 0x04,
00029 LockToBottom = 0x08
00030 };
00034 enum SortType {
00035 NoSort,
00036 XSort,
00037 YSort
00038 };
00042 enum ConnectionType {
00043 NoConnection,
00044 LineConnection,
00045 CurveConnection
00046 };
00047
00048 HoverPoints(QWidget *widget, PointShape shape);
00049
00050 bool eventFilter(QObject *object, QEvent *event);
00051
00052 void paintPoints();
00053
00057 inline QRectF boundingRect() const;
00062 void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
00063
00067 QPolygonF points() const { return m_points; }
00068 void setPoints(const QPolygonF &points);
00069
00073 QSizeF pointSize() const { return m_pointSize; }
00078 void setPointSize(const QSizeF &size) { m_pointSize = size; }
00079
00083 SortType sortType() const { return m_sortType; }
00088 void setSortType(SortType sortType) { m_sortType = sortType; }
00089
00093 ConnectionType connectionType() const { return m_connectionType; }
00098 void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
00099
00104 void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
00109 void setShapePen(const QPen &pen) { m_pointPen = pen; }
00114 void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
00115
00121 void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
00122
00127 void setEditable(bool editable) { m_editable = editable; }
00131 bool editable() const { return m_editable; }
00132
00133 public slots:
00134 void setEnabled(bool enabled);
00139 void setDisabled(bool disabled) { setEnabled(!disabled); }
00140
00141 signals:
00146 void pointsChanged(const QPolygonF &points);
00152 void chooseColor(int index, QWidget *selectedWidget);
00158 void alphaChanged(int index, qreal newXPos);
00164 void alphaPointCreated(int index, qreal xPos);
00169 void alphaPointDeleted(int index);
00170
00171 public:
00172 void firePointChange();
00173 void movePoint(int i, const QPointF &newPos, bool emitChange = true);
00174
00175 private slots:
00176 void newPoint();
00177 void deletePoint();
00178 void fireChooseColor();
00179
00180 private:
00181 inline QRectF pointBoundingRect(int i) const;
00182
00183 QWidget *m_widget;
00184
00185 QPolygonF m_points;
00186 QRectF m_bounds;
00187 PointShape m_shape;
00188 SortType m_sortType;
00189 ConnectionType m_connectionType;
00190
00191 QVector<uint> m_locks;
00192
00193 QSizeF m_pointSize;
00194 int m_currentIndex;
00195 bool m_editable;
00196 bool m_enabled;
00197
00198 QPen m_pointPen;
00199 QBrush m_pointBrush;
00200 QPen m_connectionPen;
00201
00202 QMenu m_menu;
00203 QAction *a_newPoint;
00204 QAction *a_deletePoint;
00205 QAction *a_chooseColor;
00206 QPointF a_clickPos;
00207 int a_index;
00208 };
00209
00210
00211 inline QRectF HoverPoints::pointBoundingRect(int i) const
00212 {
00213 QPointF p = m_points.at(i);
00214 qreal w = m_pointSize.width();
00215 qreal h = m_pointSize.height();
00216 qreal x = p.x() - w / 2;
00217 qreal y = p.y() - h / 2;
00218 return QRectF(x, y, w, h);
00219 }
00220
00221 inline QRectF HoverPoints::boundingRect() const
00222 {
00223 if (m_bounds.isEmpty())
00224 return m_widget->rect();
00225 else
00226 return m_bounds;
00227 }
00228
00229 #endif // HOVERPOINTS_H