Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsize.cpp
Go to the documentation of this file.
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#include "qsize.h"
5#include "qdatastream.h"
6
7#include <private/qdebug_p.h>
8
10
44/*****************************************************************************
45 QSize member functions
46 *****************************************************************************/
47
130void QSize::transpose() noexcept
131{
132 qSwap(wd, ht);
133}
134
190{
191 if (mode == Qt::IgnoreAspectRatio || wd == 0 || ht == 0) {
192 return s;
193 } else {
194 bool useHeight;
195 qint64 rw = qint64(s.ht) * qint64(wd) / qint64(ht);
196
197 if (mode == Qt::KeepAspectRatio) {
198 useHeight = (rw <= s.wd);
199 } else { // mode == Qt::KeepAspectRatioByExpanding
200 useHeight = (rw >= s.wd);
201 }
202
203 if (useHeight) {
204 return QSize(rw, s.ht);
205 } else {
206 return QSize(s.wd,
207 qint32(qint64(s.wd) * qint64(ht) / qint64(wd)));
208 }
209 }
210}
211
379/*****************************************************************************
380 QSize stream functions
381 *****************************************************************************/
382#ifndef QT_NO_DATASTREAM
394{
395 if (s.version() == 1)
396 s << (qint16)sz.width() << (qint16)sz.height();
397 else
398 s << (qint32)sz.width() << (qint32)sz.height();
399 return s;
400}
401
413{
414 if (s.version() == 1) {
415 qint16 w, h;
416 s >> w; sz.rwidth() = w;
417 s >> h; sz.rheight() = h;
418 }
419 else {
420 qint32 w, h;
421 s >> w; sz.rwidth() = w;
422 s >> h; sz.rheight() = h;
423 }
424 return s;
425}
426#endif // QT_NO_DATASTREAM
427
428#ifndef QT_NO_DEBUG_STREAM
430{
431 QDebugStateSaver saver(dbg);
432 dbg.nospace();
433 dbg << "QSize(";
435 dbg << ')';
436 return dbg;
437}
438#endif
439
440
441
478/*****************************************************************************
479 QSizeF member functions
480 *****************************************************************************/
481
581void QSizeF::transpose() noexcept
582{
583 qSwap(wd, ht);
584}
585
641{
642 if (mode == Qt::IgnoreAspectRatio || qIsNull(wd) || qIsNull(ht)) {
643 return s;
644 } else {
645 bool useHeight;
646 qreal rw = s.ht * wd / ht;
647
648 if (mode == Qt::KeepAspectRatio) {
649 useHeight = (rw <= s.wd);
650 } else { // mode == Qt::KeepAspectRatioByExpanding
651 useHeight = (rw >= s.wd);
652 }
653
654 if (useHeight) {
655 return QSizeF(rw, s.ht);
656 } else {
657 return QSizeF(s.wd, s.wd * ht / wd);
658 }
659 }
660}
661
830/*****************************************************************************
831 QSizeF stream functions
832 *****************************************************************************/
833#ifndef QT_NO_DATASTREAM
845{
846 s << double(sz.width()) << double(sz.height());
847 return s;
848}
849
861{
862 double w, h;
863 s >> w;
864 s >> h;
865 sz.setWidth(qreal(w));
866 sz.setHeight(qreal(h));
867 return s;
868}
869#endif // QT_NO_DATASTREAM
870
871#ifndef QT_NO_DEBUG_STREAM
873{
874 QDebugStateSaver saver(dbg);
875 dbg.nospace();
876 dbg << "QSizeF(";
878 dbg << ')';
879 return dbg;
880}
881#endif
882
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qsize.h:208
constexpr void setHeight(qreal h) noexcept
Sets the height to the given finite height.
Definition qsize.h:341
constexpr void setWidth(qreal w) noexcept
Sets the width to the given finite width.
Definition qsize.h:338
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const noexcept
Definition qsize.h:353
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
void transpose() noexcept
Swaps the width and height values.
Definition qsize.cpp:581
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr int & rheight() noexcept
Returns a reference to the height.
Definition qsize.h:157
QSize scaled(int w, int h, Qt::AspectRatioMode mode) const noexcept
Definition qsize.h:151
constexpr int & rwidth() noexcept
Returns a reference to the width.
Definition qsize.h:154
void transpose() noexcept
Swaps the width and height values.
Definition qsize.cpp:130
Combined button and popup list for selecting options.
static void formatQSize(QDebug &debug, const Size &size)
Definition qdebug_p.h:39
AspectRatioMode
@ KeepAspectRatio
@ IgnoreAspectRatio
bool qIsNull(qfloat16 f) noexcept
Definition qfloat16.h:354
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
QDataStream & operator<<(QDataStream &s, const QSize &sz)
Definition qsize.cpp:393
QDataStream & operator>>(QDataStream &s, QSize &sz)
Definition qsize.cpp:412
QT_BEGIN_NAMESPACE constexpr void qSwap(T &value1, T &value2) noexcept(std::is_nothrow_swappable_v< T >)
Definition qswap.h:20
short qint16
Definition qtypes.h:47
int qint32
Definition qtypes.h:49
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187