~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/kernel/qsizepolicy.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the gui module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef QSIZEPOLICY_H
 
30
#define QSIZEPOLICY_H
 
31
 
 
32
#include "QtCore/qobject.h"
 
33
#include "QtCore/qobjectdefs.h"
 
34
 
 
35
class QVariant;
 
36
 
 
37
class Q_GUI_EXPORT QSizePolicy
 
38
{
 
39
    Q_GADGET
 
40
    Q_ENUMS(Policy)
 
41
private:
 
42
    enum SizePolicyMasks {
 
43
        HSize = 4,
 
44
        HMask = 0x0f,
 
45
        VMask = HMask << HSize
 
46
    };
 
47
public:
 
48
    enum PolicyFlag {
 
49
        GrowFlag = 1,
 
50
        ExpandFlag = 2,
 
51
        ShrinkFlag = 4,
 
52
        IgnoreFlag = 8
 
53
    };
 
54
 
 
55
    enum Policy {
 
56
        Fixed = 0,
 
57
        Minimum = GrowFlag,
 
58
        Maximum = ShrinkFlag,
 
59
        Preferred = GrowFlag | ShrinkFlag,
 
60
        MinimumExpanding = GrowFlag | ExpandFlag,
 
61
        Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
 
62
        Ignored = ShrinkFlag|GrowFlag|IgnoreFlag
 
63
    };
 
64
 
 
65
    QSizePolicy() : data(0) { }
 
66
 
 
67
    QSizePolicy(Policy horizontal, Policy vertical)
 
68
        : data(horizontal | (vertical<<HSize)) { }
 
69
 
 
70
    Policy horizontalPolicy() const { return static_cast<Policy>(data & HMask); }
 
71
    Policy verticalPolicy() const { return static_cast<Policy>((data & VMask) >> HSize); }
 
72
 
 
73
    void setHorizontalPolicy(Policy d) { data = (data & ~HMask) | d; }
 
74
    void setVerticalPolicy(Policy d) { data = (data & ~(HMask << HSize)) | (d << HSize); }
 
75
 
 
76
    Qt::Orientations expandingDirections() const {
 
77
        Qt::Orientations result;
 
78
        if (verticalPolicy() & ExpandFlag)
 
79
            result |= Qt::Vertical;
 
80
        if (horizontalPolicy() & ExpandFlag)
 
81
            result |= Qt::Horizontal;
 
82
        return result;
 
83
    }
 
84
 
 
85
    void setHeightForWidth(bool b) { data = b ? (data | (1 << 2*HSize)) : (data & ~(1 << 2*HSize));  }
 
86
    bool hasHeightForWidth() const { return data & (1 << 2*HSize); }
 
87
 
 
88
    bool operator==(const QSizePolicy& s) const { return data == s.data; }
 
89
    bool operator!=(const QSizePolicy& s) const { return data != s.data; }
 
90
    operator QVariant() const; // implemented in qabstractlayout.cpp
 
91
 
 
92
    int horizontalStretch() const { return data >> 24; }
 
93
    int verticalStretch() const { return (data >> 16) & 0xff; }
 
94
    void setHorizontalStretch(uchar stretchFactor) { data = (data&0x00ffffff) | (uint(stretchFactor)<<24); }
 
95
    void setVerticalStretch(uchar stretchFactor) { data = (data&0xff00ffff) | (uint(stretchFactor)<<16); }
 
96
 
 
97
    void transpose();
 
98
 
 
99
#ifdef QT3_SUPPORT
 
100
    typedef Policy SizeType;
 
101
#ifndef qdoc
 
102
    typedef Qt::Orientations ExpandData;
 
103
    enum {
 
104
        NoDirection = 0,
 
105
        Horizontally = 1,
 
106
        Vertically = 2,
 
107
        BothDirections = Horizontally | Vertically
 
108
    };
 
109
#else
 
110
    enum ExpandData {
 
111
        NoDirection = 0x0,
 
112
        Horizontally = 0x1,
 
113
        Vertically = 0x2,
 
114
        BothDirections = 0x3
 
115
    };
 
116
#endif // qdoc
 
117
 
 
118
    inline QT3_SUPPORT bool mayShrinkHorizontally() const
 
119
        { return horizontalPolicy() & ShrinkFlag; }
 
120
    inline QT3_SUPPORT bool mayShrinkVertically() const { return verticalPolicy() & ShrinkFlag; }
 
121
    inline QT3_SUPPORT bool mayGrowHorizontally() const { return horizontalPolicy() & GrowFlag; }
 
122
    inline QT3_SUPPORT bool mayGrowVertically() const { return verticalPolicy() & GrowFlag; }
 
123
    inline QT3_SUPPORT Qt::Orientations expanding() const { return expandingDirections(); }
 
124
 
 
125
    QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, bool hfw)
 
126
        : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) { }
 
127
 
 
128
    QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, uchar hors, uchar vers, bool hfw = false)
 
129
        : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) {
 
130
        setHorizontalStretch(hors);
 
131
        setVerticalStretch(vers);
 
132
    }
 
133
 
 
134
    inline QT3_SUPPORT Policy horData() const { return static_cast<Policy>(data & HMask); }
 
135
    inline QT3_SUPPORT Policy verData() const { return static_cast<Policy>((data & VMask) >> HSize); }
 
136
    inline QT3_SUPPORT void setHorData(Policy d) { setHorizontalPolicy(d); }
 
137
    inline QT3_SUPPORT void setVerData(Policy d) { setVerticalPolicy(d); }
 
138
 
 
139
    inline QT3_SUPPORT uint horStretch() const { return horizontalStretch(); }
 
140
    inline QT3_SUPPORT uint verStretch() const { return verticalStretch(); }
 
141
    inline QT3_SUPPORT void setHorStretch(uchar sf) { setHorizontalStretch(sf); }
 
142
    inline QT3_SUPPORT void setVerStretch(uchar sf) { setVerticalStretch(sf); }
 
143
#endif
 
144
 
 
145
private:
 
146
    QSizePolicy(int i) : data(i) { }
 
147
 
 
148
    quint32 data;
 
149
};
 
150
 
 
151
inline void QSizePolicy::transpose() {
 
152
    Policy hData = horizontalPolicy();
 
153
    Policy vData = verticalPolicy();
 
154
    uchar hStretch = horizontalStretch();
 
155
    uchar vStretch = verticalStretch();
 
156
    setHorizontalPolicy(vData);
 
157
    setVerticalPolicy(hData);
 
158
    setHorizontalStretch(vStretch);
 
159
    setVerticalStretch(hStretch);
 
160
}
 
161
 
 
162
#endif // QSIZEPOLICY_H