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