Flow Visualization 1.0

hoverpoints.h

00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the demonstration applications of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef HOVERPOINTS_H
00043 #define HOVERPOINTS_H
00044 
00045 #include <QtGui>
00046 
00047 QT_FORWARD_DECLARE_CLASS(QBypassWidget)
00048 
00049 class HoverPoints : public QObject
00050 {
00051     Q_OBJECT
00052 public:
00053     enum PointShape {
00054         CircleShape,
00055         RectangleShape
00056     };
00057 
00058     enum LockType {
00059         LockToLeft   = 0x01,
00060         LockToRight  = 0x02,
00061         LockToTop    = 0x04,
00062         LockToBottom = 0x08
00063     };
00064 
00065     enum SortType {
00066         NoSort,
00067         XSort,
00068         YSort
00069     };
00070 
00071     enum ConnectionType {
00072         NoConnection,
00073         LineConnection,
00074         CurveConnection
00075     };
00076 
00077     HoverPoints(QWidget *widget, PointShape shape);
00078 
00079     bool eventFilter(QObject *object, QEvent *event);
00080 
00081     void paintPoints();
00082 
00083     inline QRectF boundingRect() const;
00084     void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
00085 
00086     QPolygonF points() const { return m_points; }
00087     void setPoints(const QPolygonF &points);
00088 
00089     QSizeF pointSize() const { return m_pointSize; }
00090     void setPointSize(const QSizeF &size) { m_pointSize = size; }
00091 
00092     SortType sortType() const { return m_sortType; }
00093     void setSortType(SortType sortType) { m_sortType = sortType; }
00094 
00095     ConnectionType connectionType() const { return m_connectionType; }
00096     void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
00097 
00098     void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
00099     void setShapePen(const QPen &pen) { m_pointPen = pen; }
00100     void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
00101 
00102     void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
00103 
00104     void setEditable(bool editable) { m_editable = editable; }
00105     bool editable() const { return m_editable; }
00106 
00107 public slots:
00108     void setEnabled(bool enabled);
00109     void setDisabled(bool disabled) { setEnabled(!disabled); }
00110 
00111 signals:
00112     void pointsChanged(const QPolygonF &points);
00113 
00114 public:
00115     void firePointChange();
00116 
00117 private:
00118     inline QRectF pointBoundingRect(int i) const;
00119     void movePoint(int i, const QPointF &newPos, bool emitChange = true);
00120 
00121     QWidget *m_widget;
00122 
00123     QPolygonF m_points;
00124     QRectF m_bounds;
00125     PointShape m_shape;
00126     SortType m_sortType;
00127     ConnectionType m_connectionType;
00128 
00129     QVector<uint> m_locks;
00130 
00131     QSizeF m_pointSize;
00132     int m_currentIndex;
00133     bool m_editable;
00134     bool m_enabled;
00135 
00136     QHash<int, int> m_fingerPointMapping;
00137 
00138     QPen m_pointPen;
00139     QBrush m_pointBrush;
00140     QPen m_connectionPen;
00141 };
00142 
00143 
00144 inline QRectF HoverPoints::pointBoundingRect(int i) const
00145 {
00146     QPointF p = m_points.at(i);
00147     qreal w = m_pointSize.width();
00148     qreal h = m_pointSize.height();
00149     qreal x = p.x() - w / 2;
00150     qreal y = p.y() - h / 2;
00151     return QRectF(x, y, w, h);
00152 }
00153 
00154 inline QRectF HoverPoints::boundingRect() const
00155 {
00156     if (m_bounds.isEmpty())
00157         return m_widget->rect();
00158     else
00159         return m_bounds;
00160 }
00161 
00162 #endif // HOVERPOINTS_H