Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

KDChartPosition.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002   KDChart - a multi-platform charting engine
00003   */
00004 
00005 /****************************************************************************
00006 ** Copyright (C) 2005-2006 Klarälvdalens Datakonsult AB.  All rights reserved.
00007 **
00008 ** This file is part of the KD Chart library.
00009 **
00010 ** This file may be distributed and/or modified under the terms of the
00011 ** GNU General Public License version 2 as published by the Free Software
00012 ** Foundation and appearing in the file LICENSE.GPL included in the
00013 ** packaging of this file.
00014 **
00015 ** Licensees holding valid commercial KD Chart licenses may use this file in
00016 ** accordance with the KD Chart Commercial License Agreement provided with
00017 ** the Software.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** See http://www.kdab.net/kdchart for
00023 **   information about KD Chart Commercial License Agreements.
00024 **
00025 ** Contact info@kdab.net if any conditions of this
00026 ** licensing are not clear to you.
00027 **
00028 **********************************************************************/
00029 
00030 #ifndef KDCHARTPOSITION_H
00031 #define KDCHARTPOSITION_H
00032 
00033 #include <QDebug>
00034 #include <Qt>
00035 #include <QMetaType>
00036 #include <QCoreApplication>
00037 #include "KDChartGlobal.h"
00038 #include "KDChartEnums.h"
00039 
00040 class QStringList;
00041 class QByteArray;
00042 template <typename T> class QList;
00043 
00044 namespace KDChart {
00045 
00075 class KDCHART_EXPORT Position
00076 {
00077     Q_DECLARE_TR_FUNCTIONS( Position )
00078     Position( int value );
00079 public:
00080     Position();
00081     Position( KDChartEnums::PositionValue value ); // intentionally non-explicit
00082 
00083     KDChartEnums::PositionValue value() const;
00084 
00085     const char * name() const;
00086     QString printableName() const;
00087 
00088     bool isUnknown() const;
00089 
00090     bool isWestSide() const;
00091     bool isNorthSide() const;
00092     bool isEastSide() const;
00093     bool isSouthSide() const;
00094 
00095     bool isCorner() const;
00096     bool isPole() const;
00097 
00098     bool isFloating() const;
00099 
00100     static const Position& Unknown;
00101     static const Position& Center;
00102     static const Position& NorthWest;
00103     static const Position& North;
00104     static const Position& NorthEast;
00105     static const Position& East;
00106     static const Position& SouthEast;
00107     static const Position& South;
00108     static const Position& SouthWest;
00109     static const Position& West;
00110 
00111     static const Position& Floating;
00112 
00113     enum Option { IncludeCenter=0, ExcludeCenter=1 };
00114     Q_DECLARE_FLAGS( Options, Option )
00115 
00116     static QList<QByteArray> names( Options options=IncludeCenter );
00117     static QStringList printableNames( Options options=IncludeCenter );
00118 
00119     static Position fromName(const char * name);
00120     static Position fromName(const QByteArray & name);
00121 
00122     bool operator==( const Position& ) const;
00123     bool operator==( int ) const;
00124     bool operator!=( const Position& ) const;
00125     bool operator!=( int ) const;
00126 
00127 private:
00128     int m_value;
00129 }; // End of class Position
00130 
00131 inline bool Position::operator!=( const Position & other ) const { return !operator==( other ); }
00132 inline bool Position::operator!=( int other ) const { return !operator==( other ); }
00133 
00134 
00135 class KDCHART_EXPORT PositionPoints
00136 {
00137   public:
00138     PositionPoints(){} // all points get initialized with the default automatically
00139 
00140     PositionPoints(
00141         QPointF center,
00142         QPointF northWest,
00143         QPointF north,
00144         QPointF northEast,
00145         QPointF east,
00146         QPointF southEast,
00147         QPointF south,
00148         QPointF southWest,
00149         QPointF west )
00150       : mPositionCenter(    center )
00151       , mPositionNorthWest( northWest )
00152       , mPositionNorth(     north )
00153       , mPositionNorthEast( northEast )
00154       , mPositionEast(      east )
00155       , mPositionSouthEast( southEast )
00156       , mPositionSouth(     south )
00157       , mPositionSouthWest( southWest )
00158       , mPositionWest(      west )
00159         {}
00160     PositionPoints(
00161         const QPointF& onePointForAllPositions )
00162       : mPositionCenter(    onePointForAllPositions )
00163       , mPositionNorthWest( onePointForAllPositions )
00164       , mPositionNorth(     onePointForAllPositions )
00165       , mPositionNorthEast( onePointForAllPositions )
00166       , mPositionEast(      onePointForAllPositions )
00167       , mPositionSouthEast( onePointForAllPositions )
00168       , mPositionSouth(     onePointForAllPositions )
00169       , mPositionSouthWest( onePointForAllPositions )
00170       , mPositionWest(      onePointForAllPositions )
00171         {}
00172     PositionPoints(
00173         const QRectF& rect )
00174     {
00175         const QRectF r( rect.normalized() );
00176         mPositionCenter    = r.center();
00177         mPositionNorthWest = r.topLeft();
00178         mPositionNorth     = QPointF(r.center().x(), r.top());
00179         mPositionNorthEast = r.topRight();
00180         mPositionEast      = QPointF(r.right(), r.center().y());
00181         mPositionSouthEast = r.bottomRight();
00182         mPositionSouth     = QPointF(r.center().x(), r.bottom());
00183         mPositionSouthWest = r.bottomLeft();
00184         mPositionWest      = QPointF(r.left(), r.center().y());
00185     }
00186     PositionPoints(
00187         QPointF northWest,
00188         QPointF northEast,
00189         QPointF southEast,
00190         QPointF southWest )
00191       : mPositionCenter(    (northWest + southEast) / 2.0 )
00192       , mPositionNorthWest( northWest )
00193       , mPositionNorth(     (northWest + northEast) / 2.0 )
00194       , mPositionNorthEast( northEast )
00195       , mPositionEast(      (northEast + southEast) / 2.0 )
00196       , mPositionSouthEast( southEast )
00197       , mPositionSouth(     (southWest + southEast) / 2.0 )
00198       , mPositionSouthWest( southWest )
00199       , mPositionWest(      (northWest + southWest) / 2.0 )
00200         {}
00201 
00202     const QPointF point( Position position ) const
00203     {
00204       //qDebug() << "point( " << position.name() << " )";
00205       if( position ==  Position::Center)
00206         return mPositionCenter;
00207       if( position ==  Position::NorthWest)
00208         return mPositionNorthWest;
00209       if( position ==  Position::North)
00210         return mPositionNorth;
00211       if( position ==  Position::NorthEast)
00212         return mPositionNorthEast;
00213       if( position ==  Position::East)
00214         return mPositionEast;
00215       if( position ==  Position::SouthEast)
00216         return mPositionSouthEast;
00217       if( position ==  Position::South)
00218         return mPositionSouth;
00219       if( position ==  Position::SouthWest)
00220         return mPositionSouthWest;
00221       if( position ==  Position::West)
00222         return mPositionWest;
00223       return mPositionUnknown;
00224     }
00225 
00226     bool isNull() const
00227     {
00228         return
00229             mPositionUnknown.isNull() &&
00230             mPositionCenter.isNull() &&
00231             mPositionNorthWest.isNull() &&
00232             mPositionNorth.isNull() &&
00233             mPositionNorthEast.isNull() &&
00234             mPositionEast.isNull() &&
00235             mPositionSouthEast.isNull() &&
00236             mPositionSouth.isNull() &&
00237             mPositionSouthWest.isNull() &&
00238             mPositionWest.isNull();
00239     }
00240 
00241     QPointF mPositionUnknown;
00242     QPointF mPositionCenter;
00243     QPointF mPositionNorthWest;
00244     QPointF mPositionNorth;
00245     QPointF mPositionNorthEast;
00246     QPointF mPositionEast;
00247     QPointF mPositionSouthEast;
00248     QPointF mPositionSouth;
00249     QPointF mPositionSouthWest;
00250     QPointF mPositionWest;
00251 }; // End of class PositionPoints
00252 
00253 
00254 }
00255 
00256 Q_DECLARE_TYPEINFO( KDChart::Position, Q_MOVABLE_TYPE );
00257 Q_DECLARE_METATYPE( KDChart::Position )
00258 Q_DECLARE_OPERATORS_FOR_FLAGS( KDChart::Position::Options )
00259 
00260 #if !defined(QT_NO_DEBUG_STREAM)
00261 KDCHART_EXPORT QDebug operator<<(QDebug, const KDChart::Position& );
00262 #endif /* QT_NO_DEBUG_STREAM */
00263 
00264 #endif // KDCHARTPOSITION_H

Generated on Thu May 10 11:06:25 2007 for KD Chart 2 by doxygen 1.3.6