| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QMARGINS_H |
| 5 | #define QMARGINS_H |
| 6 | |
| 7 | #include <QtCore/qcheckedint_impl.h> |
| 8 | #include <QtCore/qcompare.h> |
| 9 | #include <QtCore/qnamespace.h> |
| 10 | |
| 11 | #include <QtCore/q20type_traits.h> |
| 12 | #include <QtCore/q23utility.h> |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | QT_ENABLE_P0846_SEMANTICS_FOR(get) |
| 17 | |
| 18 | class QDataStream; |
| 19 | class QMarginsF; |
| 20 | |
| 21 | /***************************************************************************** |
| 22 | QMargins class |
| 23 | *****************************************************************************/ |
| 24 | |
| 25 | class QMargins |
| 26 | { |
| 27 | public: |
| 28 | constexpr QMargins() noexcept; |
| 29 | constexpr QMargins(int left, int top, int right, int bottom) noexcept; |
| 30 | |
| 31 | constexpr bool isNull() const noexcept; |
| 32 | |
| 33 | constexpr int left() const noexcept; |
| 34 | constexpr int top() const noexcept; |
| 35 | constexpr int right() const noexcept; |
| 36 | constexpr int bottom() const noexcept; |
| 37 | |
| 38 | constexpr void setLeft(int left) noexcept; |
| 39 | constexpr void setTop(int top) noexcept; |
| 40 | constexpr void setRight(int right) noexcept; |
| 41 | constexpr void setBottom(int bottom) noexcept; |
| 42 | |
| 43 | constexpr QMargins &operator+=(const QMargins &margins) noexcept; |
| 44 | constexpr QMargins &operator-=(const QMargins &margins) noexcept; |
| 45 | constexpr QMargins &operator+=(int) noexcept; |
| 46 | constexpr QMargins &operator-=(int) noexcept; |
| 47 | constexpr QMargins &operator*=(int) noexcept; |
| 48 | constexpr QMargins &operator/=(int); |
| 49 | constexpr QMargins &operator*=(qreal) noexcept; |
| 50 | constexpr QMargins &operator/=(qreal); |
| 51 | |
| 52 | [[nodiscard]] constexpr inline QMarginsF toMarginsF() const noexcept; |
| 53 | |
| 54 | friend constexpr inline QMargins operator+(const QMargins &m1, const QMargins &m2) noexcept; |
| 55 | friend constexpr inline QMargins operator-(const QMargins &m1, const QMargins &m2) noexcept; |
| 56 | friend constexpr inline QMargins operator+(const QMargins &lhs, int rhs) noexcept; |
| 57 | friend constexpr inline QMargins operator+(int lhs, const QMargins &rhs) noexcept; |
| 58 | friend constexpr inline QMargins operator-(const QMargins &lhs, int rhs) noexcept; |
| 59 | friend constexpr inline QMargins operator*(const QMargins &margins, int factor) noexcept; |
| 60 | friend constexpr inline QMargins operator*(int factor, const QMargins &margins) noexcept; |
| 61 | friend constexpr inline QMargins operator*(const QMargins &margins, qreal factor) noexcept; |
| 62 | friend constexpr inline QMargins operator*(qreal factor, const QMargins &margins) noexcept; |
| 63 | friend constexpr inline QMargins operator/(const QMargins &margins, int divisor); |
| 64 | friend constexpr inline QMargins operator/(const QMargins &margins, qreal divisor); |
| 65 | friend constexpr inline QMargins operator|(const QMargins &m1, const QMargins &m2) noexcept; |
| 66 | |
| 67 | private: |
| 68 | using Representation = QtPrivate::QCheckedIntegers::QCheckedInt<int>; |
| 69 | |
| 70 | constexpr QMargins(Representation left, |
| 71 | Representation top, |
| 72 | Representation right, |
| 73 | Representation bottom) noexcept |
| 74 | : m_left(left), m_top(top), m_right(right), m_bottom(bottom) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | Representation m_left; |
| 79 | Representation m_top; |
| 80 | Representation m_right; |
| 81 | Representation m_bottom; |
| 82 | |
| 83 | friend constexpr bool comparesEqual(const QMargins &lhs, const QMargins &rhs) noexcept |
| 84 | { |
| 85 | return lhs.m_left == rhs.m_left |
| 86 | && lhs.m_top == rhs.m_top |
| 87 | && lhs.m_right == rhs.m_right |
| 88 | && lhs.m_bottom == rhs.m_bottom; |
| 89 | } |
| 90 | Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QMargins) |
| 91 | |
| 92 | template <std::size_t I, |
| 93 | typename M, |
| 94 | std::enable_if_t<(I < 4), bool> = true, |
| 95 | std::enable_if_t<std::is_same_v<q20::remove_cvref_t<M>, QMargins>, bool> = true> |
| 96 | friend constexpr decltype(auto) get(M &&m) noexcept |
| 97 | { |
| 98 | if constexpr (I == 0) |
| 99 | return q23::forward_like<M>(m.m_left).as_underlying(); |
| 100 | else if constexpr (I == 1) |
| 101 | return q23::forward_like<M>(m.m_top).as_underlying(); |
| 102 | else if constexpr (I == 2) |
| 103 | return q23::forward_like<M>(m.m_right).as_underlying(); |
| 104 | else if constexpr (I == 3) |
| 105 | return q23::forward_like<M>(m.m_bottom).as_underlying(); |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | Q_DECLARE_TYPEINFO(QMargins, Q_RELOCATABLE_TYPE); |
| 110 | |
| 111 | /***************************************************************************** |
| 112 | QMargins stream functions |
| 113 | *****************************************************************************/ |
| 114 | #ifndef QT_NO_DATASTREAM |
| 115 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMargins &); |
| 116 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMargins &); |
| 117 | #endif |
| 118 | |
| 119 | /***************************************************************************** |
| 120 | QMargins inline functions |
| 121 | *****************************************************************************/ |
| 122 | |
| 123 | constexpr inline QMargins::QMargins() noexcept : m_left(0), m_top(0), m_right(0), m_bottom(0) {} |
| 124 | |
| 125 | constexpr inline QMargins::QMargins(int aleft, int atop, int aright, int abottom) noexcept |
| 126 | : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {} |
| 127 | |
| 128 | constexpr inline bool QMargins::isNull() const noexcept |
| 129 | { return m_left==0 && m_top==0 && m_right==0 && m_bottom==0; } |
| 130 | |
| 131 | constexpr inline int QMargins::left() const noexcept |
| 132 | { return m_left.value(); } |
| 133 | |
| 134 | constexpr inline int QMargins::top() const noexcept |
| 135 | { return m_top.value(); } |
| 136 | |
| 137 | constexpr inline int QMargins::right() const noexcept |
| 138 | { return m_right.value(); } |
| 139 | |
| 140 | constexpr inline int QMargins::bottom() const noexcept |
| 141 | { return m_bottom.value(); } |
| 142 | |
| 143 | |
| 144 | constexpr inline void QMargins::setLeft(int aleft) noexcept |
| 145 | { m_left.setValue(aleft); } |
| 146 | |
| 147 | constexpr inline void QMargins::setTop(int atop) noexcept |
| 148 | { m_top.setValue(atop); } |
| 149 | |
| 150 | constexpr inline void QMargins::setRight(int aright) noexcept |
| 151 | { m_right.setValue(aright); } |
| 152 | |
| 153 | constexpr inline void QMargins::setBottom(int abottom) noexcept |
| 154 | { m_bottom.setValue(abottom); } |
| 155 | |
| 156 | constexpr inline QMargins operator+(const QMargins &m1, const QMargins &m2) noexcept |
| 157 | { |
| 158 | return QMargins(m1.m_left + m2.m_left, m1.m_top + m2.m_top, |
| 159 | m1.m_right + m2.m_right, m1.m_bottom + m2.m_bottom); |
| 160 | } |
| 161 | |
| 162 | constexpr inline QMargins operator-(const QMargins &m1, const QMargins &m2) noexcept |
| 163 | { |
| 164 | return QMargins(m1.m_left - m2.m_left, m1.m_top - m2.m_top, |
| 165 | m1.m_right - m2.m_right, m1.m_bottom - m2.m_bottom); |
| 166 | } |
| 167 | |
| 168 | constexpr inline QMargins operator+(const QMargins &lhs, int rhs) noexcept |
| 169 | { |
| 170 | return QMargins(lhs.m_left + rhs, lhs.m_top + rhs, |
| 171 | lhs.m_right + rhs, lhs.m_bottom + rhs); |
| 172 | } |
| 173 | |
| 174 | constexpr inline QMargins operator+(int lhs, const QMargins &rhs) noexcept |
| 175 | { |
| 176 | return QMargins(rhs.m_left + lhs, rhs.m_top + lhs, |
| 177 | rhs.m_right + lhs, rhs.m_bottom + lhs); |
| 178 | } |
| 179 | |
| 180 | constexpr inline QMargins operator-(const QMargins &lhs, int rhs) noexcept |
| 181 | { |
| 182 | return QMargins(lhs.m_left - rhs, lhs.m_top - rhs, |
| 183 | lhs.m_right - rhs, lhs.m_bottom - rhs); |
| 184 | } |
| 185 | |
| 186 | constexpr inline QMargins operator*(const QMargins &margins, int factor) noexcept |
| 187 | { |
| 188 | return QMargins(margins.m_left * factor, margins.m_top * factor, |
| 189 | margins.m_right * factor, margins.m_bottom * factor); |
| 190 | } |
| 191 | |
| 192 | constexpr inline QMargins operator*(int factor, const QMargins &margins) noexcept |
| 193 | { |
| 194 | return QMargins(margins.m_left * factor, margins.m_top * factor, |
| 195 | margins.m_right * factor, margins.m_bottom * factor); |
| 196 | } |
| 197 | |
| 198 | constexpr inline QMargins operator*(const QMargins &margins, qreal factor) noexcept |
| 199 | { |
| 200 | // Deliberately using left(), top() etc. (checked ints don't have FP arithmetic) |
| 201 | return QMargins(QtPrivate::qSaturateRound(value: margins.left() * factor), |
| 202 | QtPrivate::qSaturateRound(value: margins.top() * factor), |
| 203 | QtPrivate::qSaturateRound(value: margins.right() * factor), |
| 204 | QtPrivate::qSaturateRound(value: margins.bottom() * factor)); |
| 205 | } |
| 206 | |
| 207 | constexpr inline QMargins operator*(qreal factor, const QMargins &margins) noexcept |
| 208 | { |
| 209 | return QMargins(QtPrivate::qSaturateRound(value: margins.left() * factor), |
| 210 | QtPrivate::qSaturateRound(value: margins.top() * factor), |
| 211 | QtPrivate::qSaturateRound(value: margins.right() * factor), |
| 212 | QtPrivate::qSaturateRound(value: margins.bottom() * factor)); |
| 213 | } |
| 214 | |
| 215 | constexpr inline QMargins operator/(const QMargins &margins, int divisor) |
| 216 | { |
| 217 | return QMargins(margins.m_left / divisor, margins.m_top / divisor, |
| 218 | margins.m_right / divisor, margins.m_bottom / divisor); |
| 219 | } |
| 220 | |
| 221 | constexpr inline QMargins operator/(const QMargins &margins, qreal divisor) |
| 222 | { |
| 223 | Q_ASSERT(!qFuzzyIsNull(divisor)); |
| 224 | return QMargins(QtPrivate::qSaturateRound(value: margins.left() / divisor), |
| 225 | QtPrivate::qSaturateRound(value: margins.top() / divisor), |
| 226 | QtPrivate::qSaturateRound(value: margins.right() / divisor), |
| 227 | QtPrivate::qSaturateRound(value: margins.bottom() / divisor)); |
| 228 | } |
| 229 | |
| 230 | constexpr inline QMargins operator|(const QMargins &m1, const QMargins &m2) noexcept |
| 231 | { |
| 232 | return QMargins(qMax(a: m1.m_left, b: m2.m_left), qMax(a: m1.m_top, b: m2.m_top), |
| 233 | qMax(a: m1.m_right, b: m2.m_right), qMax(a: m1.m_bottom, b: m2.m_bottom)); |
| 234 | } |
| 235 | |
| 236 | constexpr inline QMargins &QMargins::operator+=(const QMargins &margins) noexcept |
| 237 | { |
| 238 | return *this = *this + margins; |
| 239 | } |
| 240 | |
| 241 | constexpr inline QMargins &QMargins::operator-=(const QMargins &margins) noexcept |
| 242 | { |
| 243 | return *this = *this - margins; |
| 244 | } |
| 245 | |
| 246 | constexpr inline QMargins &QMargins::operator+=(int margin) noexcept |
| 247 | { |
| 248 | m_left += margin; |
| 249 | m_top += margin; |
| 250 | m_right += margin; |
| 251 | m_bottom += margin; |
| 252 | return *this; |
| 253 | } |
| 254 | |
| 255 | constexpr inline QMargins &QMargins::operator-=(int margin) noexcept |
| 256 | { |
| 257 | m_left -= margin; |
| 258 | m_top -= margin; |
| 259 | m_right -= margin; |
| 260 | m_bottom -= margin; |
| 261 | return *this; |
| 262 | } |
| 263 | |
| 264 | constexpr inline QMargins &QMargins::operator*=(int factor) noexcept |
| 265 | { |
| 266 | return *this = *this * factor; |
| 267 | } |
| 268 | |
| 269 | constexpr inline QMargins &QMargins::operator/=(int divisor) |
| 270 | { |
| 271 | return *this = *this / divisor; |
| 272 | } |
| 273 | |
| 274 | constexpr inline QMargins &QMargins::operator*=(qreal factor) noexcept |
| 275 | { |
| 276 | return *this = *this * factor; |
| 277 | } |
| 278 | |
| 279 | constexpr inline QMargins &QMargins::operator/=(qreal divisor) |
| 280 | { |
| 281 | return *this = *this / divisor; |
| 282 | } |
| 283 | |
| 284 | constexpr inline QMargins operator+(const QMargins &margins) noexcept |
| 285 | { |
| 286 | return margins; |
| 287 | } |
| 288 | |
| 289 | constexpr inline QMargins operator-(const QMargins &margins) noexcept |
| 290 | { |
| 291 | return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); |
| 292 | } |
| 293 | |
| 294 | #ifndef QT_NO_DEBUG_STREAM |
| 295 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &); |
| 296 | #endif |
| 297 | |
| 298 | /***************************************************************************** |
| 299 | QMarginsF class |
| 300 | *****************************************************************************/ |
| 301 | |
| 302 | class QMarginsF |
| 303 | { |
| 304 | public: |
| 305 | constexpr QMarginsF() noexcept; |
| 306 | constexpr QMarginsF(qreal left, qreal top, qreal right, qreal bottom) noexcept; |
| 307 | constexpr QMarginsF(const QMargins &margins) noexcept; |
| 308 | |
| 309 | constexpr bool isNull() const noexcept; |
| 310 | |
| 311 | constexpr qreal left() const noexcept; |
| 312 | constexpr qreal top() const noexcept; |
| 313 | constexpr qreal right() const noexcept; |
| 314 | constexpr qreal bottom() const noexcept; |
| 315 | |
| 316 | constexpr void setLeft(qreal aleft) noexcept; |
| 317 | constexpr void setTop(qreal atop) noexcept; |
| 318 | constexpr void setRight(qreal aright) noexcept; |
| 319 | constexpr void setBottom(qreal abottom) noexcept; |
| 320 | |
| 321 | constexpr QMarginsF &operator+=(const QMarginsF &margins) noexcept; |
| 322 | constexpr QMarginsF &operator-=(const QMarginsF &margins) noexcept; |
| 323 | constexpr QMarginsF &operator+=(qreal addend) noexcept; |
| 324 | constexpr QMarginsF &operator-=(qreal subtrahend) noexcept; |
| 325 | constexpr QMarginsF &operator*=(qreal factor) noexcept; |
| 326 | constexpr QMarginsF &operator/=(qreal divisor); |
| 327 | |
| 328 | constexpr inline QMargins toMargins() const noexcept; |
| 329 | |
| 330 | private: |
| 331 | qreal m_left; |
| 332 | qreal m_top; |
| 333 | qreal m_right; |
| 334 | qreal m_bottom; |
| 335 | |
| 336 | QT_WARNING_PUSH |
| 337 | QT_WARNING_DISABLE_FLOAT_COMPARE |
| 338 | friend constexpr bool qFuzzyCompare(const QMarginsF &lhs, const QMarginsF &rhs) noexcept |
| 339 | { |
| 340 | return ((!lhs.m_left || !rhs.m_left) ? qFuzzyIsNull(d: lhs.m_left - rhs.m_left) |
| 341 | : qFuzzyCompare(p1: lhs.m_left, p2: rhs.m_left)) |
| 342 | && ((!lhs.m_top || !rhs.m_top) ? qFuzzyIsNull(d: lhs.m_top - rhs.m_top) |
| 343 | : qFuzzyCompare(p1: lhs.m_top, p2: rhs.m_top)) |
| 344 | && ((!lhs.m_right || !rhs.m_right) ? qFuzzyIsNull(d: lhs.m_right - rhs.m_right) |
| 345 | : qFuzzyCompare(p1: lhs.m_right, p2: rhs.m_right)) |
| 346 | && ((!lhs.m_bottom || !rhs.m_bottom) ? qFuzzyIsNull(d: lhs.m_bottom - rhs.m_bottom) |
| 347 | : qFuzzyCompare(p1: lhs.m_bottom, p2: rhs.m_bottom)); |
| 348 | } |
| 349 | QT_WARNING_POP |
| 350 | friend constexpr bool qFuzzyIsNull(const QMarginsF &m) noexcept |
| 351 | { |
| 352 | return qFuzzyIsNull(d: m.m_left) && qFuzzyIsNull(d: m.m_top) |
| 353 | && qFuzzyIsNull(d: m.m_right) && qFuzzyIsNull(d: m.m_bottom); |
| 354 | } |
| 355 | |
| 356 | friend constexpr bool comparesEqual(const QMarginsF &lhs, const QMarginsF &rhs) noexcept |
| 357 | { |
| 358 | return qFuzzyCompare(lhs, rhs); |
| 359 | } |
| 360 | Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QMarginsF) |
| 361 | |
| 362 | friend constexpr bool comparesEqual(const QMarginsF &lhs, const QMargins &rhs) noexcept |
| 363 | { return comparesEqual(lhs, rhs: rhs.toMarginsF()); } |
| 364 | Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QMarginsF, QMargins) |
| 365 | |
| 366 | template <std::size_t I, |
| 367 | typename M, |
| 368 | std::enable_if_t<(I < 4), bool> = true, |
| 369 | std::enable_if_t<std::is_same_v<q20::remove_cvref_t<M>, QMarginsF>, bool> = true> |
| 370 | friend constexpr decltype(auto) get(M &&m) noexcept |
| 371 | { |
| 372 | if constexpr (I == 0) |
| 373 | return q23::forward_like<M>(m.m_left); |
| 374 | else if constexpr (I == 1) |
| 375 | return q23::forward_like<M>(m.m_top); |
| 376 | else if constexpr (I == 2) |
| 377 | return q23::forward_like<M>(m.m_right); |
| 378 | else if constexpr (I == 3) |
| 379 | return q23::forward_like<M>(m.m_bottom); |
| 380 | } |
| 381 | }; |
| 382 | |
| 383 | Q_DECLARE_TYPEINFO(QMarginsF, Q_RELOCATABLE_TYPE); |
| 384 | |
| 385 | /***************************************************************************** |
| 386 | QMarginsF stream functions |
| 387 | *****************************************************************************/ |
| 388 | |
| 389 | #ifndef QT_NO_DATASTREAM |
| 390 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMarginsF &); |
| 391 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &); |
| 392 | #endif |
| 393 | |
| 394 | /***************************************************************************** |
| 395 | QMarginsF inline functions |
| 396 | *****************************************************************************/ |
| 397 | |
| 398 | constexpr inline QMarginsF::QMarginsF() noexcept |
| 399 | : m_left(0), m_top(0), m_right(0), m_bottom(0) {} |
| 400 | |
| 401 | constexpr inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) noexcept |
| 402 | : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {} |
| 403 | |
| 404 | constexpr inline QMarginsF::QMarginsF(const QMargins &margins) noexcept |
| 405 | : m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {} |
| 406 | |
| 407 | constexpr inline bool QMarginsF::isNull() const noexcept |
| 408 | { return qFuzzyIsNull(d: m_left) && qFuzzyIsNull(d: m_top) && qFuzzyIsNull(d: m_right) && qFuzzyIsNull(d: m_bottom); } |
| 409 | |
| 410 | constexpr inline qreal QMarginsF::left() const noexcept |
| 411 | { return m_left; } |
| 412 | |
| 413 | constexpr inline qreal QMarginsF::top() const noexcept |
| 414 | { return m_top; } |
| 415 | |
| 416 | constexpr inline qreal QMarginsF::right() const noexcept |
| 417 | { return m_right; } |
| 418 | |
| 419 | constexpr inline qreal QMarginsF::bottom() const noexcept |
| 420 | { return m_bottom; } |
| 421 | |
| 422 | |
| 423 | constexpr inline void QMarginsF::setLeft(qreal aleft) noexcept |
| 424 | { m_left = aleft; } |
| 425 | |
| 426 | constexpr inline void QMarginsF::setTop(qreal atop) noexcept |
| 427 | { m_top = atop; } |
| 428 | |
| 429 | constexpr inline void QMarginsF::setRight(qreal aright) noexcept |
| 430 | { m_right = aright; } |
| 431 | |
| 432 | constexpr inline void QMarginsF::setBottom(qreal abottom) noexcept |
| 433 | { m_bottom = abottom; } |
| 434 | |
| 435 | constexpr inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) noexcept |
| 436 | { |
| 437 | return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(), |
| 438 | lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom()); |
| 439 | } |
| 440 | |
| 441 | constexpr inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) noexcept |
| 442 | { |
| 443 | return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(), |
| 444 | lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()); |
| 445 | } |
| 446 | |
| 447 | constexpr inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) noexcept |
| 448 | { |
| 449 | return QMarginsF(lhs.left() + rhs, lhs.top() + rhs, |
| 450 | lhs.right() + rhs, lhs.bottom() + rhs); |
| 451 | } |
| 452 | |
| 453 | constexpr inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) noexcept |
| 454 | { |
| 455 | return QMarginsF(rhs.left() + lhs, rhs.top() + lhs, |
| 456 | rhs.right() + lhs, rhs.bottom() + lhs); |
| 457 | } |
| 458 | |
| 459 | constexpr inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) noexcept |
| 460 | { |
| 461 | return QMarginsF(lhs.left() - rhs, lhs.top() - rhs, |
| 462 | lhs.right() - rhs, lhs.bottom() - rhs); |
| 463 | } |
| 464 | |
| 465 | constexpr inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) noexcept |
| 466 | { |
| 467 | return QMarginsF(lhs.left() * rhs, lhs.top() * rhs, |
| 468 | lhs.right() * rhs, lhs.bottom() * rhs); |
| 469 | } |
| 470 | |
| 471 | constexpr inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) noexcept |
| 472 | { |
| 473 | return QMarginsF(rhs.left() * lhs, rhs.top() * lhs, |
| 474 | rhs.right() * lhs, rhs.bottom() * lhs); |
| 475 | } |
| 476 | |
| 477 | constexpr inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor) |
| 478 | { |
| 479 | Q_ASSERT(divisor < 0 || divisor > 0); |
| 480 | return QMarginsF(lhs.left() / divisor, lhs.top() / divisor, |
| 481 | lhs.right() / divisor, lhs.bottom() / divisor); |
| 482 | } |
| 483 | |
| 484 | constexpr inline QMarginsF operator|(const QMarginsF &m1, const QMarginsF &m2) noexcept |
| 485 | { |
| 486 | return QMarginsF(qMax(a: m1.left(), b: m2.left()), qMax(a: m1.top(), b: m2.top()), |
| 487 | qMax(a: m1.right(), b: m2.right()), qMax(a: m1.bottom(), b: m2.bottom())); |
| 488 | } |
| 489 | |
| 490 | constexpr inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) noexcept |
| 491 | { |
| 492 | return *this = *this + margins; |
| 493 | } |
| 494 | |
| 495 | constexpr inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) noexcept |
| 496 | { |
| 497 | return *this = *this - margins; |
| 498 | } |
| 499 | |
| 500 | constexpr inline QMarginsF &QMarginsF::operator+=(qreal addend) noexcept |
| 501 | { |
| 502 | m_left += addend; |
| 503 | m_top += addend; |
| 504 | m_right += addend; |
| 505 | m_bottom += addend; |
| 506 | return *this; |
| 507 | } |
| 508 | |
| 509 | constexpr inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) noexcept |
| 510 | { |
| 511 | m_left -= subtrahend; |
| 512 | m_top -= subtrahend; |
| 513 | m_right -= subtrahend; |
| 514 | m_bottom -= subtrahend; |
| 515 | return *this; |
| 516 | } |
| 517 | |
| 518 | constexpr inline QMarginsF &QMarginsF::operator*=(qreal factor) noexcept |
| 519 | { |
| 520 | return *this = *this * factor; |
| 521 | } |
| 522 | |
| 523 | constexpr inline QMarginsF &QMarginsF::operator/=(qreal divisor) |
| 524 | { |
| 525 | return *this = *this / divisor; |
| 526 | } |
| 527 | |
| 528 | constexpr inline QMarginsF operator+(const QMarginsF &margins) noexcept |
| 529 | { |
| 530 | return margins; |
| 531 | } |
| 532 | |
| 533 | constexpr inline QMarginsF operator-(const QMarginsF &margins) noexcept |
| 534 | { |
| 535 | return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); |
| 536 | } |
| 537 | |
| 538 | constexpr QMarginsF QMargins::toMarginsF() const noexcept { return *this; } |
| 539 | |
| 540 | constexpr inline QMargins QMarginsF::toMargins() const noexcept |
| 541 | { |
| 542 | return QMargins(QtPrivate::qSaturateRound(value: m_left), |
| 543 | QtPrivate::qSaturateRound(value: m_top), |
| 544 | QtPrivate::qSaturateRound(value: m_right), |
| 545 | QtPrivate::qSaturateRound(value: m_bottom)); |
| 546 | } |
| 547 | |
| 548 | #ifndef QT_NO_DEBUG_STREAM |
| 549 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QMarginsF &); |
| 550 | #endif |
| 551 | |
| 552 | QT_END_NAMESPACE |
| 553 | |
| 554 | /***************************************************************************** |
| 555 | QMargins/QMarginsF tuple protocol |
| 556 | *****************************************************************************/ |
| 557 | |
| 558 | namespace std { |
| 559 | template <> |
| 560 | class tuple_size<QT_PREPEND_NAMESPACE(QMargins)> : public integral_constant<size_t, 4> {}; |
| 561 | template <> |
| 562 | class tuple_element<0, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; }; |
| 563 | template <> |
| 564 | class tuple_element<1, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; }; |
| 565 | template <> |
| 566 | class tuple_element<2, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; }; |
| 567 | template <> |
| 568 | class tuple_element<3, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; }; |
| 569 | |
| 570 | template <> |
| 571 | class tuple_size<QT_PREPEND_NAMESPACE(QMarginsF)> : public integral_constant<size_t, 4> {}; |
| 572 | template <> |
| 573 | class tuple_element<0, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); }; |
| 574 | template <> |
| 575 | class tuple_element<1, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); }; |
| 576 | template <> |
| 577 | class tuple_element<2, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); }; |
| 578 | template <> |
| 579 | class tuple_element<3, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); }; |
| 580 | } |
| 581 | |
| 582 | #endif // QMARGINS_H |
| 583 | |