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