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); 00151 void chooseColor(int index); 00157 void alphaChanged(int index, qreal newXPos); 00163 void alphaPointCreated(int index, qreal xPos); 00168 void alphaPointDeleted(int index); 00169 00170 public: 00171 void firePointChange(); 00172 void movePoint(int i, const QPointF &newPos); 00173 00174 private slots: 00175 void newPoint(); 00176 void deletePoint(); 00177 void fireChooseColor(); 00178 00179 private: 00180 inline QRectF pointBoundingRect(int i) const; 00181 00182 QWidget *m_widget; 00183 00184 QPolygonF m_points; 00185 QRectF m_bounds; 00186 PointShape m_shape; 00187 SortType m_sortType; 00188 ConnectionType m_connectionType; 00189 00190 QVector<uint> m_locks; 00191 00192 QSizeF m_pointSize; 00193 int m_currentIndex; 00194 bool m_editable; 00195 bool m_enabled; 00196 00197 QPen m_pointPen; 00198 QBrush m_pointBrush; 00199 QPen m_connectionPen; 00200 00201 QMenu m_menu; 00202 QAction *a_newPoint; 00203 QAction *a_deletePoint; 00204 QAction *a_chooseColor; 00205 QPointF a_clickPos; 00206 int a_index; 00207 }; 00208 00209 00210 inline QRectF HoverPoints::pointBoundingRect(int i) const 00211 { 00212 QPointF p = m_points.at(i); 00213 qreal w = m_pointSize.width(); 00214 qreal h = m_pointSize.height(); 00215 qreal x = p.x() - w / 2; 00216 qreal y = p.y() - h / 2; 00217 return QRectF(x, y, w, h); 00218 } 00219 00220 inline QRectF HoverPoints::boundingRect() const 00221 { 00222 if (m_bounds.isEmpty()) 00223 return m_widget->rect(); 00224 else 00225 return m_bounds; 00226 } 00227 00228 #endif // HOVERPOINTS_H