FlowVis 1.0
|
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 #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