src/HoverPoints.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the demonstration applications of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://trolltech.com/products/qt/licenses/licensing/opensource/
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
00017 ** or contact the sales department at sales@trolltech.com.
00018 **
00019 ** In addition, as a special exception, Trolltech gives you certain
00020 ** additional rights. These rights are described in the Trolltech GPL
00021 ** Exception version 1.0, which can be found at
00022 ** http://www.trolltech.com/products/qt/gplexception/ and in the file
00023 ** GPL_EXCEPTION.txt in this package.
00024 **
00025 ** In addition, as a special exception, Trolltech, as the sole copyright
00026 ** holder for Qt Designer, grants users of the Qt/Eclipse Integration
00027 ** plug-in the right for the Qt/Eclipse Integration to link to
00028 ** functionality provided by Qt Designer and its related libraries.
00029 **
00030 ** Trolltech reserves all rights not expressly granted herein.
00031 ** 
00032 ** Trolltech ASA (c) 2007
00033 **
00034 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00035 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00036 **
00037 ****************************************************************************/
00038 
00039 #ifndef HOVERPOINTS_H
00040 #define HOVERPOINTS_H
00041 
00042 #include "common.h"
00043 
00044 #include <QtGui>
00045 
00046 class QBypassWidget;
00047 
00048 class HoverPoints : public QObject
00049 {
00050     Q_OBJECT
00051 public:
00052     enum PointShape {
00053         CircleShape,
00054         RectangleShape
00055     };
00056 
00057     enum LockType {
00058         LockToLeft   = 0x01,
00059         LockToRight  = 0x02,
00060         LockToTop    = 0x04,
00061         LockToBottom = 0x08
00062     };
00063 
00064     enum SortType {
00065         NoSort,
00066         XSort,
00067         YSort
00068     };
00069 
00070     enum ConnectionType {
00071         NoConnection,
00072         LineConnection,
00073         CurveConnection
00074     };
00075 
00076     HoverPoints(QWidget *widget, PointShape shape);
00077 
00078     bool eventFilter(QObject *object, QEvent *event);
00079 
00080     void paintPoints();
00081 
00082     inline QRectF boundingRect() const;
00083     void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
00084 
00085     QPolygonF points() const { return m_points; }
00086     void setPoints(const QPolygonF &points);
00087 
00088     QSizeF pointSize() const { return m_pointSize; }
00089     void setPointSize(const QSizeF &size) { m_pointSize = size; }
00090 
00091     SortType sortType() const { return m_sortType; }
00092     void setSortType(SortType sortType) { m_sortType = sortType; }
00093 
00094     ConnectionType connectionType() const { return m_connectionType; }
00095     void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
00096 
00097     void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
00098     void setShapePen(const QPen &pen) { m_pointPen = pen; }
00099     void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
00100 
00101     void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
00102 
00103     void setEditable(bool editable) { m_editable = editable; }
00104     bool editable() const { return m_editable; }
00105 
00106 public slots:
00107     void setEnabled(bool enabled);
00108     void setDisabled(bool disabled) { setEnabled(!disabled); }
00109 
00110 signals:
00111     void pointsChanged(const QPolygonF &points);
00112 
00113 public:
00114     void firePointChange();
00115 
00116 private:
00117     inline QRectF pointBoundingRect(int i) const;
00118     void movePoint(int i, const QPointF &newPos, bool emitChange = true);
00119 
00120     QWidget *m_widget;
00121 
00122     QPolygonF m_points;
00123     QRectF m_bounds;
00124     PointShape m_shape;
00125     SortType m_sortType;
00126     ConnectionType m_connectionType;
00127 
00128     QVector<uint> m_locks;
00129 
00130     QSizeF m_pointSize;
00131     int m_currentIndex;
00132     bool m_editable;
00133     bool m_enabled;
00134 
00135     QPen m_pointPen;
00136     QBrush m_pointBrush;
00137     QPen m_connectionPen;
00138 };
00139 
00140 
00141 inline QRectF HoverPoints::pointBoundingRect(int i) const
00142 {
00143     QPointF p = m_points.at(i);
00144     double w = m_pointSize.width();
00145     double h = m_pointSize.height();
00146     double x = p.x() - w / 2;
00147     double y = p.y() - h / 2;
00148     return QRectF(x, y, w, h);
00149 }
00150 
00151 inline QRectF HoverPoints::boundingRect() const
00152 {
00153     if (m_bounds.isEmpty())
00154         return m_widget->rect();
00155     else
00156         return m_bounds;
00157 }
00158 
00159 #endif // HOVERPOINTS_H

Generated on Mon Dec 10 18:18:11 2007 for VisLU by  doxygen 1.5.4