Documents > BPS V2 C++ API
bpsmargins.h
Go to the documentation of this file.
00001 
00004 #ifndef BPSMARGINS_H
00005 #define BPSMARGINS_H
00006 
00007 #include "bpscore_global.h"
00008 #include <QMetaType>
00009 #include <QVariant>
00010 
00014 class BPSCORE_EXPORT BpsMargins
00015 {
00016 public:
00017 
00021     BpsMargins();
00022 
00027     BpsMargins(const BpsMargins& aMargins);
00028 
00033     BpsMargins(qreal aValue);
00034 
00040     BpsMargins(qreal aTopBottom, qreal aLeftRight);
00041 
00049     BpsMargins(qreal aTop, qreal aRight, qreal aBottom, qreal aLeft);
00050 
00054     bool isNull() const;
00055 
00059     bool isValid() const;
00060 
00064     qreal top() const;
00065 
00069     qreal right() const;
00070 
00074     qreal bottom() const;
00075 
00079     qreal left() const;
00080 
00085     void setTop(qreal aValue);
00086 
00091     void setRight(qreal aValue);
00092 
00097     void setBottom(qreal aValue);
00098 
00103     void setLeft(qreal aValue);
00104 
00108     qreal& rtop();
00109 
00113     qreal& rright();
00114 
00118     qreal& rbottom();
00119 
00123     qreal& rleft();
00124 
00128     operator QVariant() const;
00129 
00135     BpsMargins& operator*=(qreal aFactor);
00136 
00142     BpsMargins& operator/=(qreal aDivisor);
00143 
00145     friend inline bool operator==(const BpsMargins& aFirst, const BpsMargins& aSecond);
00146 
00147     friend inline bool operator!=(const BpsMargins& aFirst, const BpsMargins& aSecond);
00148 
00149     friend inline const BpsMargins operator*(qreal aFactor, const BpsMargins& aMargins);
00150 
00151     friend inline const BpsMargins operator*(const BpsMargins& aMargins, qreal aFactor);
00152 
00153     friend inline const BpsMargins operator/(const BpsMargins& aMargins, qreal aDivisor);
00155 
00156 private:
00158     qreal mTop, mRight, mBottom, mLeft;
00160 };
00161 
00163 Q_DECLARE_METATYPE(BpsMargins)
00164 Q_DECLARE_TYPEINFO(BpsMargins, Q_MOVABLE_TYPE);
00166 
00167 /************************************************************************/
00168 /* S T R E A M   F U N C T I O N S                                      */
00169 /************************************************************************/
00170 
00177 BPSCORE_EXPORT QDataStream& operator<<(QDataStream& aStream, const BpsMargins& aMargins);
00178 
00185 BPSCORE_EXPORT QDataStream& operator>>(QDataStream& aStream, BpsMargins& aMargins);
00186 
00193 BPSCORE_EXPORT QDebug operator<<(QDebug aDebug, const BpsMargins& aMargins);
00194 
00195 /************************************************************************/
00196 /* M E M B E R   I N L I N E S                                          */
00197 /************************************************************************/
00198 
00199 inline BpsMargins::BpsMargins()
00200 { 
00201     mTop = mRight = mBottom = mLeft = -1.0; 
00202 } // default constructor
00203 
00204 inline BpsMargins::BpsMargins(const BpsMargins& aMargins)
00205 {
00206     mTop = aMargins.mTop;
00207     mRight = aMargins.mRight;
00208     mBottom = aMargins.mBottom;
00209     mLeft = aMargins.mLeft;
00210 } // copy constructor
00211 
00212 inline BpsMargins::BpsMargins(qreal aValue) 
00213 {
00214     mTop = mRight = mBottom = mLeft = aValue;
00215 } // convenience constructor
00216 
00217 inline BpsMargins::BpsMargins(qreal aTopBottom, qreal aLeftRight)
00218 {
00219     mTop = mBottom = aTopBottom;
00220     mLeft = mRight = aLeftRight;
00221 } // convenience constructor
00222 
00223 inline BpsMargins::BpsMargins(qreal aTop, qreal aRight, qreal aBottom, qreal aLeft)
00224 { 
00225     mTop = aTop;
00226     mRight = aRight;
00227     mBottom = aBottom;
00228     mLeft = aLeft;
00229 } // convenience constructor
00230 
00231 inline bool BpsMargins::isNull() const 
00232 { 
00233     return qIsNull(mTop) && qIsNull(mRight) && qIsNull(mBottom) && qIsNull(mLeft); 
00234 } // isNull 
00235 
00236 inline bool BpsMargins::isValid() const 
00237 { 
00238     return mTop>=0.0 && mRight>=0.0 && mBottom>=0.0 && mLeft>=0.0; 
00239 } // isValid
00240 
00241 inline qreal BpsMargins::top() const { return mTop; }
00242 inline qreal BpsMargins::right() const { return mRight; }
00243 inline qreal BpsMargins::bottom() const { return mBottom; }
00244 inline qreal BpsMargins::left() const { return mLeft; }
00245 
00246 inline void BpsMargins::setTop(qreal aValue) { mTop = aValue; }
00247 inline void BpsMargins::setRight(qreal aValue) { mRight = aValue; }
00248 inline void BpsMargins::setBottom(qreal aValue) { mBottom = aValue; }
00249 inline void BpsMargins::setLeft(qreal aValue) { mLeft = aValue; }
00250 
00251 inline qreal& BpsMargins::rtop() { return mTop; }
00252 inline qreal& BpsMargins::rright() { return mRight; }
00253 inline qreal& BpsMargins::rbottom() { return mBottom; }
00254 inline qreal& BpsMargins::rleft() { return mLeft; }
00255 
00256 inline BpsMargins::operator QVariant() const 
00257 { 
00258     return QVariant::fromValue(*this); 
00259 } // operator QVariant
00260 
00261 inline BpsMargins& BpsMargins::operator*=(qreal aFactor)
00262 { 
00263     mTop *= aFactor;
00264     mRight *= aFactor;
00265     mBottom *= aFactor;
00266     mLeft *= aFactor;
00267     return *this; 
00268 } // operator*=
00269 
00270 inline BpsMargins& BpsMargins::operator/=(qreal aDivisor)
00271 { 
00272     Q_ASSERT(!qIsNull(aDivisor));
00273     mTop /= aDivisor;
00274     mRight /= aDivisor;
00275     mBottom /= aDivisor;
00276     mLeft /= aDivisor;
00277     return *this; 
00278 } // operator/=
00279 
00280 
00281 /************************************************************************/
00282 /* F R I E N D   I N L I N E S                                          */
00283 /************************************************************************/
00284 
00291 inline bool operator==(const BpsMargins& aFirst, const BpsMargins& aSecond)
00292 { 
00293     return 
00294         qFuzzyCompare(aFirst.mTop, aSecond.mTop) &&
00295         qFuzzyCompare(aFirst.mRight, aSecond.mRight) &&
00296         qFuzzyCompare(aFirst.mBottom, aSecond.mBottom) &&
00297         qFuzzyCompare(aFirst.mLeft, aSecond.mLeft);
00298 } // operator==
00299 
00306 inline bool operator!=(const BpsMargins& aFirst, const BpsMargins& aSecond)
00307 { 
00308     return 
00309         !qFuzzyCompare(aFirst.mTop, aSecond.mTop) ||
00310         !qFuzzyCompare(aFirst.mRight, aSecond.mRight) ||
00311         !qFuzzyCompare(aFirst.mBottom, aSecond.mBottom) ||
00312         !qFuzzyCompare(aFirst.mLeft, aSecond.mLeft);
00313 } // operator==
00314 
00321 inline const BpsMargins operator*(const BpsMargins& aMargins, qreal aFactor)
00322 { 
00323     return 
00324         BpsMargins(
00325             aMargins.mTop * aFactor, 
00326             aMargins.mRight * aFactor,
00327             aMargins.mBottom * aFactor,
00328             aMargins.mLeft * aFactor
00329         ); 
00330 } // operator*
00331 
00338 inline const BpsMargins operator*(qreal aFactor, const BpsMargins& aMargins)
00339 { 
00340     return 
00341         BpsMargins(
00342             aMargins.mTop * aFactor, 
00343             aMargins.mRight * aFactor,
00344             aMargins.mBottom * aFactor,
00345             aMargins.mLeft * aFactor
00346         ); 
00347 } // operator*
00348 
00355 inline const BpsMargins operator/(const BpsMargins &aMargins, qreal aDivisor)
00356 {
00357     Q_ASSERT(!qIsNull(aDivisor));
00358     return
00359         BpsMargins(
00360             aMargins.mTop / aDivisor, 
00361             aMargins.mRight / aDivisor,
00362             aMargins.mBottom / aDivisor,
00363             aMargins.mLeft / aDivisor
00364         ); 
00365 } // operator/
00366 
00367 #endif // BPSMARGINS_H