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 <QWidget>
00043 #include <QCheckBox>
00044 #include <QComboBox>
00045 #include <QLabel>
00046 #include <QRadioButton>
00047 #include <QButtonGroup>
00048 #include <QPushButton>
00049 #include <QLineEdit>
00050 #include <QSlider>
00051 #include <QDomDocument>
00052 #include <QDomElement>
00053 #include <QPen>
00054 #include <QColorDialog>
00055
00056 #include <iostream>
00057
00058 #include "../renderer/Renderer.h"
00059
00060 struct TFPnt
00061 {
00062 QPointF pos;
00063 QColor col;
00064 };
00065
00069 class HoverPoints : public QObject
00070 {
00071 Q_OBJECT
00072 public:
00073 enum PointShape {
00074 CircleShape,
00075 RectangleShape
00076 };
00077
00078 enum LockType {
00079 LockToLeft = 0x01,
00080 LockToRight = 0x02,
00081 LockToTop = 0x04,
00082 LockToBottom = 0x08
00083 };
00084
00085 enum SortType {
00086 NoSort,
00087 XSort,
00088 YSort
00089 };
00090
00091 enum ConnectionType {
00092 NoConnection,
00093 LineConnection,
00094 CurveConnection
00095 };
00096
00097 HoverPoints(QWidget *widget, PointShape shape);
00098
00100 bool eventFilter(QObject *object, QEvent *event);
00101
00103 void paintPoints();
00104
00106 inline QRectF boundingRect() const;
00108 void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
00109
00110 QVector<TFPnt> points() const { return m_points; }
00111 void setPoints(const QVector<TFPnt> &points);
00112
00113 QSizeF pointSize() const { return m_pointSize; }
00114 void setPointSize(const QSizeF &size) { m_pointSize = size; }
00115
00117 SortType sortType() const { return m_sortType; }
00119 void setSortType(SortType sortType) { m_sortType = sortType; }
00120
00122 ConnectionType connectionType() const { return m_connectionType; }
00124 void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
00125
00127 void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
00129 void setShapePen(const QPen &pen) { m_pointPen = pen; }
00131 void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
00132
00134 void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
00135
00136 void setEditable(bool editable) { m_editable = editable; }
00137 bool editable() const { return m_editable; }
00138
00139
00140 signals:
00142 void pointsChanged(const QVector<TFPnt> &points);
00143
00144 public slots:
00145 void setEnabled(bool enabled);
00146 void setDisabled(bool disabled) { setEnabled(!disabled); }
00147
00148 public:
00149 void firePointChange();
00150
00151 private:
00152 inline QRectF pointBoundingRect(int i) const;
00153 void movePoint(int i, const QPointF &newPos, bool emitChange = true);
00154
00155 QWidget *m_widget;
00156
00157
00158 QVector<TFPnt> m_points;
00159 QRectF m_bounds;
00160 PointShape m_shape;
00161 SortType m_sortType;
00162 ConnectionType m_connectionType;
00163
00164 QVector<uint> m_locks;
00165 QVector<QColor> m_colors;
00166
00167 QSizeF m_pointSize;
00168 int m_currentIndex;
00169 bool m_editable;
00170 bool m_enabled;
00171
00172 QPen m_pointPen;
00173 QBrush m_pointBrush;
00174 QPen m_connectionPen;
00175 };
00176
00177
00178 inline QRectF HoverPoints::pointBoundingRect(int i) const
00179 {
00180 QPointF p = m_points.at(i).pos;
00181 double w = m_pointSize.width();
00182 double h = m_pointSize.height();
00183 double x = p.x() - w / 2;
00184 double y = p.y() - h / 2;
00185 return QRectF(x, y, w, h);
00186 }
00187
00188 inline QRectF HoverPoints::boundingRect() const
00189 {
00190 if (m_bounds.isEmpty())
00191 {
00192 return m_widget->rect();
00193
00194 }
00195 else
00196 return m_bounds;
00197 }
00198
00199 #endif