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-2007 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 
00138 class KDCHART_EXPORT PositionPoints
00139 {
00140   public:
00141     PositionPoints(){} // all points get initialized with the default automatically
00142 
00143     PositionPoints(
00144         QPointF center,
00145         QPointF northWest,
00146         QPointF north,
00147         QPointF northEast,
00148         QPointF east,
00149         QPointF southEast,
00150         QPointF south,
00151         QPointF southWest,
00152         QPointF west )
00153       : mPositionCenter(    center )
00154       , mPositionNorthWest( northWest )
00155       , mPositionNorth(     north )
00156       , mPositionNorthEast( northEast )
00157       , mPositionEast(      east )
00158       , mPositionSouthEast( southEast )
00159       , mPositionSouth(     south )
00160       , mPositionSouthWest( southWest )
00161       , mPositionWest(      west )
00162         {}
00163     PositionPoints(
00164         const QPointF& onePointForAllPositions )
00165       : mPositionCenter(    onePointForAllPositions )
00166       , mPositionNorthWest( onePointForAllPositions )
00167       , mPositionNorth(     onePointForAllPositions )
00168       , mPositionNorthEast( onePointForAllPositions )
00169       , mPositionEast(      onePointForAllPositions )
00170       , mPositionSouthEast( onePointForAllPositions )
00171       , mPositionSouth(     onePointForAllPositions )
00172       , mPositionSouthWest( onePointForAllPositions )
00173       , mPositionWest(      onePointForAllPositions )
00174         {}
00175     PositionPoints(
00176         const QRectF& rect )
00177     {
00178         const QRectF r( rect.normalized() );
00179         mPositionCenter    = r.center();
00180         mPositionNorthWest = r.topLeft();
00181         mPositionNorth     = QPointF(r.center().x(), r.top());
00182         mPositionNorthEast = r.topRight();
00183         mPositionEast      = QPointF(r.right(), r.center().y());
00184         mPositionSouthEast = r.bottomRight();
00185         mPositionSouth     = QPointF(r.center().x(), r.bottom());
00186         mPositionSouthWest = r.bottomLeft();
00187         mPositionWest      = QPointF(r.left(), r.center().y());
00188     }
00189     PositionPoints(
00190         QPointF northWest,
00191         QPointF northEast,
00192         QPointF southEast,
00193         QPointF southWest )
00194       : mPositionCenter(    (northWest + southEast) / 2.0 )
00195       , mPositionNorthWest( northWest )
00196       , mPositionNorth(     (northWest + northEast) / 2.0 )
00197       , mPositionNorthEast( northEast )
00198       , mPositionEast(      (northEast + southEast) / 2.0 )
00199       , mPositionSouthEast( southEast )
00200       , mPositionSouth(     (southWest + southEast) / 2.0 )
00201       , mPositionSouthWest( southWest )
00202       , mPositionWest(      (northWest + southWest) / 2.0 )
00203         {}
00204 
00205     const QPointF point( Position position ) const
00206     {
00207       //qDebug() << "point( " << position.name() << " )";
00208       if( position ==  Position::Center)
00209         return mPositionCenter;
00210       if( position ==  Position::NorthWest)
00211         return mPositionNorthWest;
00212       if( position ==  Position::North)
00213         return mPositionNorth;
00214       if( position ==  Position::NorthEast)
00215         return mPositionNorthEast;
00216       if( position ==  Position::East)
00217         return mPositionEast;
00218       if( position ==  Position::SouthEast)
00219         return mPositionSouthEast;
00220       if( position ==  Position::South)
00221         return mPositionSouth;
00222       if( position ==  Position::SouthWest)
00223         return mPositionSouthWest;
00224       if( position ==  Position::West)
00225         return mPositionWest;
00226       return mPositionUnknown;
00227     }
00228 
00229     bool isNull() const
00230     {
00231         return
00232             mPositionUnknown.isNull() &&
00233             mPositionCenter.isNull() &&
00234             mPositionNorthWest.isNull() &&
00235             mPositionNorth.isNull() &&
00236             mPositionNorthEast.isNull() &&
00237             mPositionEast.isNull() &&
00238             mPositionSouthEast.isNull() &&
00239             mPositionSouth.isNull() &&
00240             mPositionSouthWest.isNull() &&
00241             mPositionWest.isNull();
00242     }
00243 
00244     QPointF mPositionUnknown;
00245     QPointF mPositionCenter;
00246     QPointF mPositionNorthWest;
00247     QPointF mPositionNorth;
00248     QPointF mPositionNorthEast;
00249     QPointF mPositionEast;
00250     QPointF mPositionSouthEast;
00251     QPointF mPositionSouth;
00252     QPointF mPositionSouthWest;
00253     QPointF mPositionWest;
00254 }; // End of class PositionPoints
00255 
00256 
00257 }
00258 
00259 Q_DECLARE_TYPEINFO( KDChart::Position, Q_MOVABLE_TYPE );
00260 Q_DECLARE_METATYPE( KDChart::Position )
00261 Q_DECLARE_OPERATORS_FOR_FLAGS( KDChart::Position::Options )
00262 
00263 #if !defined(QT_NO_DEBUG_STREAM)
00264 KDCHART_EXPORT QDebug operator<<(QDebug, const KDChart::Position& );
00265 #endif /* QT_NO_DEBUG_STREAM */
00266 
00267 #endif // KDCHARTPOSITION_H

Generated on Mon Sep 17 16:16:50 2007 for KD Chart 2 by  doxygen 1.5.1