| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/util/qlayoutpolicy.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the Qt Quick Layouts module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | #include "qlayoutpolicy_p.h" | - | ||||||
| 35 | #include <QtCore/qdebug.h> | - | ||||||
| 36 | #include <QtCore/qdatastream.h> | - | ||||||
| 37 | - | |||||||
| 38 | QT_BEGIN_NAMESPACE | - | ||||||
| 39 | - | |||||||
| 40 | void QLayoutPolicy::setControlType(ControlType type) | - | ||||||
| 41 | { | - | ||||||
| 42 | /* | - | ||||||
| 43 | The control type is a flag type, with values 0x1, 0x2, 0x4, 0x8, 0x10, | - | ||||||
| 44 | etc. In memory, we pack it onto the available bits (CTSize) in | - | ||||||
| 45 | setControlType(), and unpack it here. | - | ||||||
| 46 | - | |||||||
| 47 | Example: | - | ||||||
| 48 | - | |||||||
| 49 | 0x00000001 maps to 0 | - | ||||||
| 50 | 0x00000002 maps to 1 | - | ||||||
| 51 | 0x00000004 maps to 2 | - | ||||||
| 52 | 0x00000008 maps to 3 | - | ||||||
| 53 | etc. | - | ||||||
| 54 | */ | - | ||||||
| 55 | - | |||||||
| 56 | int i = 0; | - | ||||||
| 57 | while (true) { | - | ||||||
| 58 | if (type & (0x1 << i)) {
| 0 | ||||||
| 59 | bits.ctype = i; | - | ||||||
| 60 | return; never executed: return; | 0 | ||||||
| 61 | } | - | ||||||
| 62 | ++i; | - | ||||||
| 63 | } never executed: end of block | 0 | ||||||
| 64 | } never executed: end of block | 0 | ||||||
| 65 | - | |||||||
| 66 | QLayoutPolicy::ControlType QLayoutPolicy::controlType() const | - | ||||||
| 67 | { | - | ||||||
| 68 | return QLayoutPolicy::ControlType(1 << bits.ctype); never executed: return QLayoutPolicy::ControlType(1 << bits.ctype); | 0 | ||||||
| 69 | } | - | ||||||
| 70 | - | |||||||
| 71 | #ifndef QT_NO_DATASTREAM | - | ||||||
| 72 | - | |||||||
| 73 | /*! | - | ||||||
| 74 | \relates QLayoutPolicy | - | ||||||
| 75 | - | |||||||
| 76 | Writes the size \a policy to the data stream \a stream. | - | ||||||
| 77 | - | |||||||
| 78 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||
| 79 | */ | - | ||||||
| 80 | QDataStream &operator<<(QDataStream &stream, const QLayoutPolicy &policy) | - | ||||||
| 81 | { | - | ||||||
| 82 | // The order here is for historical reasons. (compatibility with Qt4) | - | ||||||
| 83 | quint32 data = (policy.bits.horPolicy | // [0, 3] | - | ||||||
| 84 | policy.bits.verPolicy << 4 | // [4, 7] | - | ||||||
| 85 | policy.bits.hfw << 8 | // [8] | - | ||||||
| 86 | policy.bits.ctype << 9 | // [9, 13] | - | ||||||
| 87 | policy.bits.wfh << 14 | // [14] | - | ||||||
| 88 | //policy.bits.padding << 15 | // [15] | - | ||||||
| 89 | policy.bits.verStretch << 16 | // [16, 23] | - | ||||||
| 90 | policy.bits.horStretch << 24); // [24, 31] | - | ||||||
| 91 | return stream << data; never executed: return stream << data; | 0 | ||||||
| 92 | } | - | ||||||
| 93 | - | |||||||
| 94 | #define VALUE_OF_BITS(data, bitstart, bitcount) ((data >> bitstart) & ((1 << bitcount) -1)) | - | ||||||
| 95 | - | |||||||
| 96 | /*! | - | ||||||
| 97 | \relates QLayoutPolicy | - | ||||||
| 98 | - | |||||||
| 99 | Reads the size \a policy from the data stream \a stream. | - | ||||||
| 100 | - | |||||||
| 101 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||
| 102 | */ | - | ||||||
| 103 | QDataStream &operator>>(QDataStream &stream, QLayoutPolicy &policy) | - | ||||||
| 104 | { | - | ||||||
| 105 | quint32 data; | - | ||||||
| 106 | stream >> data; | - | ||||||
| 107 | policy.bits.horPolicy = VALUE_OF_BITS(data, 0, 4); | - | ||||||
| 108 | policy.bits.verPolicy = VALUE_OF_BITS(data, 4, 4); | - | ||||||
| 109 | policy.bits.hfw = VALUE_OF_BITS(data, 8, 1); | - | ||||||
| 110 | policy.bits.ctype = VALUE_OF_BITS(data, 9, 5); | - | ||||||
| 111 | policy.bits.wfh = VALUE_OF_BITS(data, 14, 1); | - | ||||||
| 112 | policy.bits.padding = 0; | - | ||||||
| 113 | policy.bits.verStretch = VALUE_OF_BITS(data, 16, 8); | - | ||||||
| 114 | policy.bits.horStretch = VALUE_OF_BITS(data, 24, 8); | - | ||||||
| 115 | return stream; never executed: return stream; | 0 | ||||||
| 116 | } | - | ||||||
| 117 | #endif // QT_NO_DATASTREAM | - | ||||||
| 118 | - | |||||||
| 119 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||
| 120 | QDebug operator<<(QDebug dbg, const QLayoutPolicy &p) | - | ||||||
| 121 | { | - | ||||||
| 122 | QDebugStateSaver saver(dbg); | - | ||||||
| 123 | dbg.nospace() << "QLayoutPolicy(horizontalPolicy = " << p.horizontalPolicy() | - | ||||||
| 124 | << ", verticalPolicy = " << p.verticalPolicy() << ')'; | - | ||||||
| 125 | return dbg; never executed: return dbg; | 0 | ||||||
| 126 | } | - | ||||||
| 127 | #endif | - | ||||||
| 128 | - | |||||||
| 129 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |