| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef HOVERPOINTS_H
|
|---|
| 43 | #define HOVERPOINTS_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtGui>
|
|---|
| 46 |
|
|---|
| 47 | QT_FORWARD_DECLARE_CLASS(QBypassWidget)
|
|---|
| 48 |
|
|---|
| 49 | class HoverPoints : public QObject
|
|---|
| 50 | {
|
|---|
| 51 | Q_OBJECT
|
|---|
| 52 | public:
|
|---|
| 53 | enum PointShape {
|
|---|
| 54 | CircleShape,
|
|---|
| 55 | RectangleShape
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | enum LockType {
|
|---|
| 59 | LockToLeft = 0x01,
|
|---|
| 60 | LockToRight = 0x02,
|
|---|
| 61 | LockToTop = 0x04,
|
|---|
| 62 | LockToBottom = 0x08
|
|---|
| 63 | };
|
|---|
| 64 |
|
|---|
| 65 | enum SortType {
|
|---|
| 66 | NoSort,
|
|---|
| 67 | XSort,
|
|---|
| 68 | YSort
|
|---|
| 69 | };
|
|---|
| 70 |
|
|---|
| 71 | enum ConnectionType {
|
|---|
| 72 | NoConnection,
|
|---|
| 73 | LineConnection,
|
|---|
| 74 | CurveConnection
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | HoverPoints(QWidget *widget, PointShape shape);
|
|---|
| 78 |
|
|---|
| 79 | bool eventFilter(QObject *object, QEvent *event);
|
|---|
| 80 |
|
|---|
| 81 | void paintPoints();
|
|---|
| 82 |
|
|---|
| 83 | inline QRectF boundingRect() const;
|
|---|
| 84 | void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
|
|---|
| 85 |
|
|---|
| 86 | QPolygonF points() const { return m_points; }
|
|---|
| 87 | void setPoints(const QPolygonF &points);
|
|---|
| 88 |
|
|---|
| 89 | QSizeF pointSize() const { return m_pointSize; }
|
|---|
| 90 | void setPointSize(const QSizeF &size) { m_pointSize = size; }
|
|---|
| 91 |
|
|---|
| 92 | SortType sortType() const { return m_sortType; }
|
|---|
| 93 | void setSortType(SortType sortType) { m_sortType = sortType; }
|
|---|
| 94 |
|
|---|
| 95 | ConnectionType connectionType() const { return m_connectionType; }
|
|---|
| 96 | void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
|
|---|
| 97 |
|
|---|
| 98 | void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
|
|---|
| 99 | void setShapePen(const QPen &pen) { m_pointPen = pen; }
|
|---|
| 100 | void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
|
|---|
| 101 |
|
|---|
| 102 | void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
|
|---|
| 103 |
|
|---|
| 104 | void setEditable(bool editable) { m_editable = editable; }
|
|---|
| 105 | bool editable() const { return m_editable; }
|
|---|
| 106 |
|
|---|
| 107 | public slots:
|
|---|
| 108 | void setEnabled(bool enabled);
|
|---|
| 109 | void setDisabled(bool disabled) { setEnabled(!disabled); }
|
|---|
| 110 |
|
|---|
| 111 | signals:
|
|---|
| 112 | void pointsChanged(const QPolygonF &points);
|
|---|
| 113 |
|
|---|
| 114 | public:
|
|---|
| 115 | void firePointChange();
|
|---|
| 116 |
|
|---|
| 117 | private:
|
|---|
| 118 | inline QRectF pointBoundingRect(int i) const;
|
|---|
| 119 | void movePoint(int i, const QPointF &newPos, bool emitChange = true);
|
|---|
| 120 |
|
|---|
| 121 | QWidget *m_widget;
|
|---|
| 122 |
|
|---|
| 123 | QPolygonF m_points;
|
|---|
| 124 | QRectF m_bounds;
|
|---|
| 125 | PointShape m_shape;
|
|---|
| 126 | SortType m_sortType;
|
|---|
| 127 | ConnectionType m_connectionType;
|
|---|
| 128 |
|
|---|
| 129 | QVector<uint> m_locks;
|
|---|
| 130 |
|
|---|
| 131 | QSizeF m_pointSize;
|
|---|
| 132 | int m_currentIndex;
|
|---|
| 133 | bool m_editable;
|
|---|
| 134 | bool m_enabled;
|
|---|
| 135 |
|
|---|
| 136 | QPen m_pointPen;
|
|---|
| 137 | QBrush m_pointBrush;
|
|---|
| 138 | QPen m_connectionPen;
|
|---|
| 139 | };
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | inline QRectF HoverPoints::pointBoundingRect(int i) const
|
|---|
| 143 | {
|
|---|
| 144 | QPointF p = m_points.at(i);
|
|---|
| 145 | qreal w = m_pointSize.width();
|
|---|
| 146 | qreal h = m_pointSize.height();
|
|---|
| 147 | qreal x = p.x() - w / 2;
|
|---|
| 148 | qreal y = p.y() - h / 2;
|
|---|
| 149 | return QRectF(x, y, w, h);
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | inline QRectF HoverPoints::boundingRect() const
|
|---|
| 153 | {
|
|---|
| 154 | if (m_bounds.isEmpty())
|
|---|
| 155 | return m_widget->rect();
|
|---|
| 156 | else
|
|---|
| 157 | return m_bounds;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | #endif // HOVERPOINTS_H
|
|---|