00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef KDCHARTPOSITION_H
00024 #define KDCHARTPOSITION_H
00025
00026 #include <QDebug>
00027 #include <Qt>
00028 #include <QMetaType>
00029 #include <QCoreApplication>
00030 #include "KDChartGlobal.h"
00031 #include "KDChartEnums.h"
00032
00033 class QStringList;
00034 class QByteArray;
00035 template <typename T> class QList;
00036
00037 namespace KDChart {
00038
00067 class KDCHART_EXPORT Position
00068 {
00069 Q_DECLARE_TR_FUNCTIONS( Position )
00070 Position( int value );
00071 public:
00072 Position();
00073 Position( KDChartEnums::PositionValue value );
00074
00075 KDChartEnums::PositionValue value() const;
00076
00077 const char * name() const;
00078 QString printableName() const;
00079
00080 bool isUnknown() const;
00081
00082 bool isWestSide() const;
00083 bool isNorthSide() const;
00084 bool isEastSide() const;
00085 bool isSouthSide() const;
00086
00087 bool isCorner() const;
00088 bool isPole() const;
00089
00090 bool isFloating() const;
00091
00092 static const Position& Unknown;
00093 static const Position& Center;
00094 static const Position& NorthWest;
00095 static const Position& North;
00096 static const Position& NorthEast;
00097 static const Position& East;
00098 static const Position& SouthEast;
00099 static const Position& South;
00100 static const Position& SouthWest;
00101 static const Position& West;
00102
00103 static const Position& Floating;
00104
00105
00106 enum Option {
00107 IncludeCenter = 0x1,
00108 IncludeFloating = 0x2 };
00109 Q_DECLARE_FLAGS( Options, Option )
00110
00111
00112
00113
00114
00115 static QList<QByteArray> names( Options options = Options(IncludeCenter | IncludeFloating) );
00116 static QStringList printableNames( Options options = Options(IncludeCenter | IncludeFloating) );
00117
00118 static Position fromName(const char * name);
00119 static Position fromName(const QByteArray & name);
00120
00121 bool operator==( const Position& ) const;
00122 bool operator==( int ) const;
00123 bool operator!=( const Position& ) const;
00124 bool operator!=( int ) const;
00125
00126 private:
00127 int m_value;
00128 };
00129
00130 inline bool Position::operator!=( const Position & other ) const { return !operator==( other ); }
00131 inline bool Position::operator!=( int other ) const { return !operator==( other ); }
00132
00137 class KDCHART_EXPORT PositionPoints
00138 {
00139 public:
00140 PositionPoints(){}
00141
00142 PositionPoints(
00143 QPointF center,
00144 QPointF northWest,
00145 QPointF north,
00146 QPointF northEast,
00147 QPointF east,
00148 QPointF southEast,
00149 QPointF south,
00150 QPointF southWest,
00151 QPointF west )
00152 : mPositionCenter( center )
00153 , mPositionNorthWest( northWest )
00154 , mPositionNorth( north )
00155 , mPositionNorthEast( northEast )
00156 , mPositionEast( east )
00157 , mPositionSouthEast( southEast )
00158 , mPositionSouth( south )
00159 , mPositionSouthWest( southWest )
00160 , mPositionWest( west )
00161 {}
00162 PositionPoints(
00163 const QPointF& onePointForAllPositions )
00164 : mPositionCenter( onePointForAllPositions )
00165 , mPositionNorthWest( onePointForAllPositions )
00166 , mPositionNorth( onePointForAllPositions )
00167 , mPositionNorthEast( onePointForAllPositions )
00168 , mPositionEast( onePointForAllPositions )
00169 , mPositionSouthEast( onePointForAllPositions )
00170 , mPositionSouth( onePointForAllPositions )
00171 , mPositionSouthWest( onePointForAllPositions )
00172 , mPositionWest( onePointForAllPositions )
00173 {}
00174 PositionPoints(
00175 const QRectF& rect )
00176 {
00177 const QRectF r( rect.normalized() );
00178 mPositionCenter = r.center();
00179 mPositionNorthWest = r.topLeft();
00180 mPositionNorth = QPointF(r.center().x(), r.top());
00181 mPositionNorthEast = r.topRight();
00182 mPositionEast = QPointF(r.right(), r.center().y());
00183 mPositionSouthEast = r.bottomRight();
00184 mPositionSouth = QPointF(r.center().x(), r.bottom());
00185 mPositionSouthWest = r.bottomLeft();
00186 mPositionWest = QPointF(r.left(), r.center().y());
00187 }
00188 PositionPoints(
00189 QPointF northWest,
00190 QPointF northEast,
00191 QPointF southEast,
00192 QPointF southWest )
00193 : mPositionCenter( (northWest + southEast) / 2.0 )
00194 , mPositionNorthWest( northWest )
00195 , mPositionNorth( (northWest + northEast) / 2.0 )
00196 , mPositionNorthEast( northEast )
00197 , mPositionEast( (northEast + southEast) / 2.0 )
00198 , mPositionSouthEast( southEast )
00199 , mPositionSouth( (southWest + southEast) / 2.0 )
00200 , mPositionSouthWest( southWest )
00201 , mPositionWest( (northWest + southWest) / 2.0 )
00202 {}
00203
00204 void setDegrees( KDChartEnums::PositionValue pos, qreal degrees )
00205 {
00206 mapOfDegrees[pos] = degrees;
00207 }
00208
00209 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
00210 const qreal degrees( KDChartEnums::PositionValue pos ) const
00211 #else
00212 qreal degrees( KDChartEnums::PositionValue pos ) const
00213 #endif
00214 {
00215 if( mapOfDegrees.contains(pos) )
00216 return mapOfDegrees[pos];
00217 return 0.0;
00218 }
00219
00220 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
00221 const QPointF point( Position position ) const
00222 #else
00223 QPointF point( Position position ) const
00224 #endif
00225 {
00226
00227 if( position == Position::Center)
00228 return mPositionCenter;
00229 if( position == Position::NorthWest)
00230 return mPositionNorthWest;
00231 if( position == Position::North)
00232 return mPositionNorth;
00233 if( position == Position::NorthEast)
00234 return mPositionNorthEast;
00235 if( position == Position::East)
00236 return mPositionEast;
00237 if( position == Position::SouthEast)
00238 return mPositionSouthEast;
00239 if( position == Position::South)
00240 return mPositionSouth;
00241 if( position == Position::SouthWest)
00242 return mPositionSouthWest;
00243 if( position == Position::West)
00244 return mPositionWest;
00245 return mPositionUnknown;
00246 }
00247
00248 bool isNull() const
00249 {
00250 return
00251 mPositionUnknown.isNull() &&
00252 mPositionCenter.isNull() &&
00253 mPositionNorthWest.isNull() &&
00254 mPositionNorth.isNull() &&
00255 mPositionNorthEast.isNull() &&
00256 mPositionEast.isNull() &&
00257 mPositionSouthEast.isNull() &&
00258 mPositionSouth.isNull() &&
00259 mPositionSouthWest.isNull() &&
00260 mPositionWest.isNull();
00261 }
00262
00263 QPointF mPositionUnknown;
00264 QPointF mPositionCenter;
00265 QPointF mPositionNorthWest;
00266 QPointF mPositionNorth;
00267 QPointF mPositionNorthEast;
00268 QPointF mPositionEast;
00269 QPointF mPositionSouthEast;
00270 QPointF mPositionSouth;
00271 QPointF mPositionSouthWest;
00272 QPointF mPositionWest;
00273 QMap<KDChartEnums::PositionValue, qreal> mapOfDegrees;
00274
00275 };
00276
00277
00278 }
00279
00280 Q_DECLARE_TYPEINFO( KDChart::Position, Q_MOVABLE_TYPE );
00281 Q_DECLARE_METATYPE( KDChart::Position )
00282 Q_DECLARE_OPERATORS_FOR_FLAGS( KDChart::Position::Options )
00283
00284 #if !defined(QT_NO_DEBUG_STREAM)
00285 KDCHART_EXPORT QDebug operator<<(QDebug, const KDChart::Position& );
00286 #endif
00287
00288 #endif // KDCHARTPOSITION_H