source: trunk/include/qsizepolicy.h@ 8

Last change on this file since 8 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1/****************************************************************************
2** $Id: qsizepolicy.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of the QSizePolicy class
5**
6** Created : 980929
7**
8** Copyright (C) 1998-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QSIZEPOLICY_H
39#define QSIZEPOLICY_H
40
41#ifndef QT_H
42#include "qglobal.h"
43#endif // QT_H
44
45// Documentation is in qabstractlayout.cpp.
46
47class Q_EXPORT QSizePolicy
48{
49private:
50 enum { HSize = 6, HMask = 0x3f, VMask = HMask << HSize,
51 MayGrow = 1, ExpMask = 2, MayShrink = 4 };
52public:
53 enum SizeType { Fixed = 0,
54 Minimum = MayGrow,
55 Maximum = MayShrink,
56 Preferred = MayGrow | MayShrink,
57 MinimumExpanding = MayGrow | ExpMask,
58 Expanding = MayGrow | MayShrink | ExpMask,
59 Ignored = ExpMask /* magic value */ };
60
61 enum ExpandData { NoDirection = 0,
62 Horizontally = 1,
63 Vertically = 2,
64#ifndef QT_NO_COMPAT
65 Horizontal = Horizontally,
66 Vertical = Vertically,
67#endif
68 BothDirections = Horizontally | Vertically };
69
70 QSizePolicy() : data( 0 ) { }
71
72 QSizePolicy( SizeType hor, SizeType ver, bool hfw = FALSE )
73 : data( hor | (ver<<HSize) | (hfw ? (Q_UINT32)(1<<2*HSize) : 0) ) { }
74 QSizePolicy( SizeType hor, SizeType ver, uchar hors, uchar vers, bool hfw = FALSE );
75
76 SizeType horData() const { return (SizeType)( data & HMask ); }
77 SizeType verData() const { return (SizeType)( (data & VMask) >> HSize ); }
78
79 bool mayShrinkHorizontally() const { return horData() & MayShrink || horData() == Ignored; }
80 bool mayShrinkVertically() const { return verData() & MayShrink || verData() == Ignored; }
81 bool mayGrowHorizontally() const { return horData() & MayGrow || horData() == Ignored; }
82 bool mayGrowVertically() const { return verData() & MayGrow || verData() == Ignored; }
83
84 ExpandData expanding() const
85 {
86 return (ExpandData)( (int)(verData() & ExpMask ? Vertically : 0) |
87 (int)(horData() & ExpMask ? Horizontally : 0) );
88 }
89
90 void setHorData( SizeType d ) { data = (Q_UINT32)(data & ~HMask) | d; }
91 void setVerData( SizeType d ) { data = (Q_UINT32)(data & ~(HMask << HSize)) |
92 (d << HSize); }
93
94 void setHeightForWidth( bool b ) { data = b ? (Q_UINT32)( data | ( 1 << 2*HSize ) )
95 : (Q_UINT32)( data & ~( 1 << 2*HSize ) ); }
96 bool hasHeightForWidth() const { return data & ( 1 << 2*HSize ); }
97
98 bool operator==( const QSizePolicy& s ) const { return data == s.data; }
99 bool operator!=( const QSizePolicy& s ) const { return data != s.data; }
100
101
102 uint horStretch() const { return data >> 24; }
103 uint verStretch() const { return (data >> 16) & 0xff; }
104 void setHorStretch( uchar sf ) { data = (data&0x00ffffff) | (uint(sf)<<24); }
105 void setVerStretch( uchar sf ) { data = (data&0xff00ffff) | (uint(sf)<<16); }
106 inline void transpose();
107
108private:
109 QSizePolicy( int i ) : data( (Q_UINT32)i ) { }
110
111 Q_UINT32 data;
112};
113
114inline QSizePolicy::QSizePolicy( SizeType hor, SizeType ver, uchar hors, uchar vers, bool hfw )
115 : data( hor | (ver<<HSize) | (hfw ? (Q_UINT32)(1<<2*HSize) : 0) ) {
116 setHorStretch( hors );
117 setVerStretch( vers );
118}
119
120inline void QSizePolicy::transpose() {
121 *this = QSizePolicy( verData(), horData(), verStretch(), horStretch(),
122 hasHeightForWidth() );
123}
124
125#endif // QSIZEPOLICY_H
Note: See TracBrowser for help on using the repository browser.