Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qmargins.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2022 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QMARGINS_H
0005 #define QMARGINS_H
0006 
0007 #include <QtCore/qnamespace.h>
0008 
0009 #include <QtCore/q20type_traits.h>
0010 #include <QtCore/q23utility.h>
0011 
0012 QT_BEGIN_NAMESPACE
0013 
0014 QT_ENABLE_P0846_SEMANTICS_FOR(get)
0015 
0016 class QMarginsF;
0017 
0018 /*****************************************************************************
0019   QMargins class
0020  *****************************************************************************/
0021 
0022 class QMargins
0023 {
0024 public:
0025     constexpr QMargins() noexcept;
0026     constexpr QMargins(int left, int top, int right, int bottom) noexcept;
0027 
0028     constexpr bool isNull() const noexcept;
0029 
0030     constexpr int left() const noexcept;
0031     constexpr int top() const noexcept;
0032     constexpr int right() const noexcept;
0033     constexpr int bottom() const noexcept;
0034 
0035     constexpr void setLeft(int left) noexcept;
0036     constexpr void setTop(int top) noexcept;
0037     constexpr void setRight(int right) noexcept;
0038     constexpr void setBottom(int bottom) noexcept;
0039 
0040     constexpr QMargins &operator+=(const QMargins &margins) noexcept;
0041     constexpr QMargins &operator-=(const QMargins &margins) noexcept;
0042     constexpr QMargins &operator+=(int) noexcept;
0043     constexpr QMargins &operator-=(int) noexcept;
0044     constexpr QMargins &operator*=(int) noexcept;
0045     constexpr QMargins &operator/=(int);
0046     constexpr QMargins &operator*=(qreal) noexcept;
0047     constexpr QMargins &operator/=(qreal);
0048 
0049     [[nodiscard]] constexpr inline QMarginsF toMarginsF() const noexcept;
0050 
0051 private:
0052     int m_left;
0053     int m_top;
0054     int m_right;
0055     int m_bottom;
0056 
0057     friend constexpr inline bool operator==(const QMargins &m1, const QMargins &m2) noexcept
0058     {
0059         return
0060                 m1.m_left == m2.m_left &&
0061                 m1.m_top == m2.m_top &&
0062                 m1.m_right == m2.m_right &&
0063                 m1.m_bottom == m2.m_bottom;
0064     }
0065 
0066     friend constexpr inline bool operator!=(const QMargins &m1, const QMargins &m2) noexcept
0067     {
0068         return !(m1 == m2);
0069     }
0070 
0071     template <std::size_t I,
0072               typename M,
0073               std::enable_if_t<(I < 4), bool> = true,
0074               std::enable_if_t<std::is_same_v<q20::remove_cvref_t<M>, QMargins>, bool> = true>
0075     friend constexpr decltype(auto) get(M &&m) noexcept
0076     {
0077         if constexpr (I == 0)
0078             return q23::forward_like<M>(m.m_left);
0079         else if constexpr (I == 1)
0080             return q23::forward_like<M>(m.m_top);
0081         else if constexpr (I == 2)
0082             return q23::forward_like<M>(m.m_right);
0083         else if constexpr (I == 3)
0084             return q23::forward_like<M>(m.m_bottom);
0085     }
0086 };
0087 
0088 Q_DECLARE_TYPEINFO(QMargins, Q_RELOCATABLE_TYPE);
0089 
0090 /*****************************************************************************
0091   QMargins stream functions
0092  *****************************************************************************/
0093 #ifndef QT_NO_DATASTREAM
0094 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMargins &);
0095 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMargins &);
0096 #endif
0097 
0098 /*****************************************************************************
0099   QMargins inline functions
0100  *****************************************************************************/
0101 
0102 constexpr inline QMargins::QMargins() noexcept : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
0103 
0104 constexpr inline QMargins::QMargins(int aleft, int atop, int aright, int abottom) noexcept
0105     : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
0106 
0107 constexpr inline bool QMargins::isNull() const noexcept
0108 { return m_left==0 && m_top==0 && m_right==0 && m_bottom==0; }
0109 
0110 constexpr inline int QMargins::left() const noexcept
0111 { return m_left; }
0112 
0113 constexpr inline int QMargins::top() const noexcept
0114 { return m_top; }
0115 
0116 constexpr inline int QMargins::right() const noexcept
0117 { return m_right; }
0118 
0119 constexpr inline int QMargins::bottom() const noexcept
0120 { return m_bottom; }
0121 
0122 
0123 constexpr inline void QMargins::setLeft(int aleft) noexcept
0124 { m_left = aleft; }
0125 
0126 constexpr inline void QMargins::setTop(int atop) noexcept
0127 { m_top = atop; }
0128 
0129 constexpr inline void QMargins::setRight(int aright) noexcept
0130 { m_right = aright; }
0131 
0132 constexpr inline void QMargins::setBottom(int abottom) noexcept
0133 { m_bottom = abottom; }
0134 
0135 constexpr inline QMargins operator+(const QMargins &m1, const QMargins &m2) noexcept
0136 {
0137     return QMargins(m1.left() + m2.left(), m1.top() + m2.top(),
0138                     m1.right() + m2.right(), m1.bottom() + m2.bottom());
0139 }
0140 
0141 constexpr inline QMargins operator-(const QMargins &m1, const QMargins &m2) noexcept
0142 {
0143     return QMargins(m1.left() - m2.left(), m1.top() - m2.top(),
0144                     m1.right() - m2.right(), m1.bottom() - m2.bottom());
0145 }
0146 
0147 constexpr inline QMargins operator+(const QMargins &lhs, int rhs) noexcept
0148 {
0149     return QMargins(lhs.left() + rhs, lhs.top() + rhs,
0150                     lhs.right() + rhs, lhs.bottom() + rhs);
0151 }
0152 
0153 constexpr inline QMargins operator+(int lhs, const QMargins &rhs) noexcept
0154 {
0155     return QMargins(rhs.left() + lhs, rhs.top() + lhs,
0156                     rhs.right() + lhs, rhs.bottom() + lhs);
0157 }
0158 
0159 constexpr inline QMargins operator-(const QMargins &lhs, int rhs) noexcept
0160 {
0161     return QMargins(lhs.left() - rhs, lhs.top() - rhs,
0162                     lhs.right() - rhs, lhs.bottom() - rhs);
0163 }
0164 
0165 constexpr inline QMargins operator*(const QMargins &margins, int factor) noexcept
0166 {
0167     return QMargins(margins.left() * factor, margins.top() * factor,
0168                     margins.right() * factor, margins.bottom() * factor);
0169 }
0170 
0171 constexpr inline QMargins operator*(int factor, const QMargins &margins) noexcept
0172 {
0173     return QMargins(margins.left() * factor, margins.top() * factor,
0174                     margins.right() * factor, margins.bottom() * factor);
0175 }
0176 
0177 constexpr inline QMargins operator*(const QMargins &margins, qreal factor) noexcept
0178 {
0179     return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
0180                     qRound(margins.right() * factor), qRound(margins.bottom() * factor));
0181 }
0182 
0183 constexpr inline QMargins operator*(qreal factor, const QMargins &margins) noexcept
0184 {
0185     return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
0186                     qRound(margins.right() * factor), qRound(margins.bottom() * factor));
0187 }
0188 
0189 constexpr inline QMargins operator/(const QMargins &margins, int divisor)
0190 {
0191     return QMargins(margins.left() / divisor, margins.top() / divisor,
0192                     margins.right() / divisor, margins.bottom() / divisor);
0193 }
0194 
0195 constexpr inline QMargins operator/(const QMargins &margins, qreal divisor)
0196 {
0197     return QMargins(qRound(margins.left() / divisor), qRound(margins.top() / divisor),
0198                     qRound(margins.right() / divisor), qRound(margins.bottom() / divisor));
0199 }
0200 
0201 constexpr inline QMargins operator|(const QMargins &m1, const QMargins &m2) noexcept
0202 {
0203     return QMargins(qMax(m1.left(), m2.left()), qMax(m1.top(), m2.top()),
0204                     qMax(m1.right(), m2.right()), qMax(m1.bottom(), m2.bottom()));
0205 }
0206 
0207 constexpr inline QMargins &QMargins::operator+=(const QMargins &margins) noexcept
0208 {
0209     return *this = *this + margins;
0210 }
0211 
0212 constexpr inline QMargins &QMargins::operator-=(const QMargins &margins) noexcept
0213 {
0214     return *this = *this - margins;
0215 }
0216 
0217 constexpr inline QMargins &QMargins::operator+=(int margin) noexcept
0218 {
0219     m_left += margin;
0220     m_top += margin;
0221     m_right += margin;
0222     m_bottom += margin;
0223     return *this;
0224 }
0225 
0226 constexpr inline QMargins &QMargins::operator-=(int margin) noexcept
0227 {
0228     m_left -= margin;
0229     m_top -= margin;
0230     m_right -= margin;
0231     m_bottom -= margin;
0232     return *this;
0233 }
0234 
0235 constexpr inline QMargins &QMargins::operator*=(int factor) noexcept
0236 {
0237     return *this = *this * factor;
0238 }
0239 
0240 constexpr inline QMargins &QMargins::operator/=(int divisor)
0241 {
0242     return *this = *this / divisor;
0243 }
0244 
0245 constexpr inline QMargins &QMargins::operator*=(qreal factor) noexcept
0246 {
0247     return *this = *this * factor;
0248 }
0249 
0250 constexpr inline QMargins &QMargins::operator/=(qreal divisor)
0251 {
0252     return *this = *this / divisor;
0253 }
0254 
0255 constexpr inline QMargins operator+(const QMargins &margins) noexcept
0256 {
0257     return margins;
0258 }
0259 
0260 constexpr inline QMargins operator-(const QMargins &margins) noexcept
0261 {
0262     return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
0263 }
0264 
0265 #ifndef QT_NO_DEBUG_STREAM
0266 Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &);
0267 #endif
0268 
0269 /*****************************************************************************
0270   QMarginsF class
0271  *****************************************************************************/
0272 
0273 class QMarginsF
0274 {
0275 public:
0276     constexpr QMarginsF() noexcept;
0277     constexpr QMarginsF(qreal left, qreal top, qreal right, qreal bottom) noexcept;
0278     constexpr QMarginsF(const QMargins &margins) noexcept;
0279 
0280     constexpr bool isNull() const noexcept;
0281 
0282     constexpr qreal left() const noexcept;
0283     constexpr qreal top() const noexcept;
0284     constexpr qreal right() const noexcept;
0285     constexpr qreal bottom() const noexcept;
0286 
0287     constexpr void setLeft(qreal aleft) noexcept;
0288     constexpr void setTop(qreal atop) noexcept;
0289     constexpr void setRight(qreal aright) noexcept;
0290     constexpr void setBottom(qreal abottom) noexcept;
0291 
0292     constexpr QMarginsF &operator+=(const QMarginsF &margins) noexcept;
0293     constexpr QMarginsF &operator-=(const QMarginsF &margins) noexcept;
0294     constexpr QMarginsF &operator+=(qreal addend) noexcept;
0295     constexpr QMarginsF &operator-=(qreal subtrahend) noexcept;
0296     constexpr QMarginsF &operator*=(qreal factor) noexcept;
0297     constexpr QMarginsF &operator/=(qreal divisor);
0298 
0299     constexpr inline QMargins toMargins() const noexcept;
0300 
0301 private:
0302     qreal m_left;
0303     qreal m_top;
0304     qreal m_right;
0305     qreal m_bottom;
0306 
0307     friend constexpr inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
0308     {
0309         return qFuzzyCompare(lhs.left(), rhs.left())
0310             && qFuzzyCompare(lhs.top(), rhs.top())
0311             && qFuzzyCompare(lhs.right(), rhs.right())
0312             && qFuzzyCompare(lhs.bottom(), rhs.bottom());
0313     }
0314 
0315     friend constexpr inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
0316     {
0317         return !(lhs == rhs);
0318     }
0319 
0320     template <std::size_t I,
0321               typename M,
0322               std::enable_if_t<(I < 4), bool> = true,
0323               std::enable_if_t<std::is_same_v<q20::remove_cvref_t<M>, QMarginsF>, bool> = true>
0324     friend constexpr decltype(auto) get(M &&m) noexcept
0325     {
0326         if constexpr (I == 0)
0327             return q23::forward_like<M>(m.m_left);
0328         else if constexpr (I == 1)
0329             return q23::forward_like<M>(m.m_top);
0330         else if constexpr (I == 2)
0331             return q23::forward_like<M>(m.m_right);
0332         else if constexpr (I == 3)
0333             return q23::forward_like<M>(m.m_bottom);
0334     }
0335 };
0336 
0337 Q_DECLARE_TYPEINFO(QMarginsF, Q_RELOCATABLE_TYPE);
0338 
0339 /*****************************************************************************
0340   QMarginsF stream functions
0341  *****************************************************************************/
0342 
0343 #ifndef QT_NO_DATASTREAM
0344 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMarginsF &);
0345 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &);
0346 #endif
0347 
0348 /*****************************************************************************
0349   QMarginsF inline functions
0350  *****************************************************************************/
0351 
0352 constexpr inline QMarginsF::QMarginsF() noexcept
0353     : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
0354 
0355 constexpr inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) noexcept
0356     : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
0357 
0358 constexpr inline QMarginsF::QMarginsF(const QMargins &margins) noexcept
0359     : m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {}
0360 
0361 constexpr inline bool QMarginsF::isNull() const noexcept
0362 { return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); }
0363 
0364 constexpr inline qreal QMarginsF::left() const noexcept
0365 { return m_left; }
0366 
0367 constexpr inline qreal QMarginsF::top() const noexcept
0368 { return m_top; }
0369 
0370 constexpr inline qreal QMarginsF::right() const noexcept
0371 { return m_right; }
0372 
0373 constexpr inline qreal QMarginsF::bottom() const noexcept
0374 { return m_bottom; }
0375 
0376 
0377 constexpr inline void QMarginsF::setLeft(qreal aleft) noexcept
0378 { m_left = aleft; }
0379 
0380 constexpr inline void QMarginsF::setTop(qreal atop) noexcept
0381 { m_top = atop; }
0382 
0383 constexpr inline void QMarginsF::setRight(qreal aright) noexcept
0384 { m_right = aright; }
0385 
0386 constexpr inline void QMarginsF::setBottom(qreal abottom) noexcept
0387 { m_bottom = abottom; }
0388 
0389 constexpr inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
0390 {
0391     return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
0392                      lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom());
0393 }
0394 
0395 constexpr inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
0396 {
0397     return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(),
0398                      lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom());
0399 }
0400 
0401 constexpr inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) noexcept
0402 {
0403     return QMarginsF(lhs.left() + rhs, lhs.top() + rhs,
0404                      lhs.right() + rhs, lhs.bottom() + rhs);
0405 }
0406 
0407 constexpr inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) noexcept
0408 {
0409     return QMarginsF(rhs.left() + lhs, rhs.top() + lhs,
0410                      rhs.right() + lhs, rhs.bottom() + lhs);
0411 }
0412 
0413 constexpr inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) noexcept
0414 {
0415     return QMarginsF(lhs.left() - rhs, lhs.top() - rhs,
0416                      lhs.right() - rhs, lhs.bottom() - rhs);
0417 }
0418 
0419 constexpr inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) noexcept
0420 {
0421     return QMarginsF(lhs.left() * rhs, lhs.top() * rhs,
0422                      lhs.right() * rhs, lhs.bottom() * rhs);
0423 }
0424 
0425 constexpr inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) noexcept
0426 {
0427     return QMarginsF(rhs.left() * lhs, rhs.top() * lhs,
0428                      rhs.right() * lhs, rhs.bottom() * lhs);
0429 }
0430 
0431 constexpr inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor)
0432 {
0433     Q_ASSERT(divisor < 0 || divisor > 0);
0434     return QMarginsF(lhs.left() / divisor, lhs.top() / divisor,
0435                      lhs.right() / divisor, lhs.bottom() / divisor);
0436 }
0437 
0438 constexpr inline QMarginsF operator|(const QMarginsF &m1, const QMarginsF &m2) noexcept
0439 {
0440     return QMarginsF(qMax(m1.left(), m2.left()), qMax(m1.top(), m2.top()),
0441                      qMax(m1.right(), m2.right()), qMax(m1.bottom(), m2.bottom()));
0442 }
0443 
0444 constexpr inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) noexcept
0445 {
0446     return *this = *this + margins;
0447 }
0448 
0449 constexpr inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) noexcept
0450 {
0451     return *this = *this - margins;
0452 }
0453 
0454 constexpr inline QMarginsF &QMarginsF::operator+=(qreal addend) noexcept
0455 {
0456     m_left += addend;
0457     m_top += addend;
0458     m_right += addend;
0459     m_bottom += addend;
0460     return *this;
0461 }
0462 
0463 constexpr inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) noexcept
0464 {
0465     m_left -= subtrahend;
0466     m_top -= subtrahend;
0467     m_right -= subtrahend;
0468     m_bottom -= subtrahend;
0469     return *this;
0470 }
0471 
0472 constexpr inline QMarginsF &QMarginsF::operator*=(qreal factor) noexcept
0473 {
0474     return *this = *this * factor;
0475 }
0476 
0477 constexpr inline QMarginsF &QMarginsF::operator/=(qreal divisor)
0478 {
0479     return *this = *this / divisor;
0480 }
0481 
0482 constexpr inline QMarginsF operator+(const QMarginsF &margins) noexcept
0483 {
0484     return margins;
0485 }
0486 
0487 constexpr inline QMarginsF operator-(const QMarginsF &margins) noexcept
0488 {
0489     return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
0490 }
0491 
0492 constexpr QMarginsF QMargins::toMarginsF() const noexcept { return *this; }
0493 
0494 constexpr inline QMargins QMarginsF::toMargins() const noexcept
0495 {
0496     return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
0497 }
0498 
0499 #ifndef QT_NO_DEBUG_STREAM
0500 Q_CORE_EXPORT QDebug operator<<(QDebug, const QMarginsF &);
0501 #endif
0502 
0503 QT_END_NAMESPACE
0504 
0505 /*****************************************************************************
0506   QMargins/QMarginsF tuple protocol
0507  *****************************************************************************/
0508 
0509 namespace std {
0510     template <>
0511     class tuple_size<QT_PREPEND_NAMESPACE(QMargins)> : public integral_constant<size_t, 4> {};
0512     template <>
0513     class tuple_element<0, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
0514     template <>
0515     class tuple_element<1, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
0516     template <>
0517     class tuple_element<2, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
0518     template <>
0519     class tuple_element<3, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
0520 
0521     template <>
0522     class tuple_size<QT_PREPEND_NAMESPACE(QMarginsF)> : public integral_constant<size_t, 4> {};
0523     template <>
0524     class tuple_element<0, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
0525     template <>
0526     class tuple_element<1, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
0527     template <>
0528     class tuple_element<2, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
0529     template <>
0530     class tuple_element<3, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
0531 }
0532 
0533 #endif // QMARGINS_H