source: trunk/src/gui/graphicsview/qgridlayoutengine_p.h@ 256

Last change on this file since 256 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 15.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QGRIDLAYOUTENGINE_P_H
43#define QGRIDLAYOUTENGINE_P_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists for the convenience
50// of the graphics view layout classes. This header
51// file may change from version to version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include "qalgorithms.h"
57#include "qbitarray.h"
58#include "qlist.h"
59#include "qmap.h"
60#include "qpair.h"
61#include "qvector.h"
62
63#include <float.h>
64
65QT_BEGIN_NAMESPACE
66
67class QGraphicsLayoutItem;
68class QStyle;
69class QWidget;
70
71// ### deal with Descent in a similar way
72enum {
73 MinimumSize = Qt::MinimumSize,
74 PreferredSize = Qt::PreferredSize,
75 MaximumSize = Qt::MaximumSize,
76 NSizes
77};
78
79// do not reorder
80enum {
81 Hor,
82 Ver,
83 NOrientations
84};
85
86// do not reorder
87enum LayoutSide {
88 Left,
89 Top,
90 Right,
91 Bottom
92};
93
94template <typename T>
95class QLayoutParameter
96{
97public:
98 enum State { Default, User, Cached };
99
100 inline QLayoutParameter() : q_value(T()), q_state(Default) {}
101 inline QLayoutParameter(T value, State state = Default) : q_value(value), q_state(state) {}
102
103 inline void setUserValue(T value) {
104 q_value = value;
105 q_state = User;
106 }
107 inline void setCachedValue(T value) const {
108 if (q_state != User) {
109 q_value = value;
110 q_state = Cached;
111 }
112 }
113 inline T value() const { return q_value; }
114 inline T value(T defaultValue) const { return isUser() ? q_value : defaultValue; }
115 inline bool isDefault() const { return q_state == Default; }
116 inline bool isUser() const { return q_state == User; }
117 inline bool isCached() const { return q_state == Cached; }
118
119private:
120 mutable T q_value;
121 mutable State q_state;
122};
123
124class QStretchParameter : public QLayoutParameter<int>
125{
126public:
127 QStretchParameter() : QLayoutParameter<int>(-1) {}
128
129};
130
131class QLayoutStyleInfo
132{
133public:
134 inline QLayoutStyleInfo() { invalidate(); }
135 inline QLayoutStyleInfo(QStyle *style, QWidget *widget)
136 : q_valid(true), q_style(style), q_widget(widget) {}
137
138 inline void invalidate() { q_valid = false; q_style = 0; q_widget = 0; }
139
140 inline QStyle *style() const { return q_style; }
141 inline QWidget *widget() const { return q_widget; }
142
143 inline bool operator==(const QLayoutStyleInfo &other)
144 { return q_style == other.q_style && q_widget == other.q_widget; }
145 inline bool operator!=(const QLayoutStyleInfo &other)
146 { return !(*this == other); }
147
148private:
149 bool q_valid;
150 QStyle *q_style;
151 QWidget *q_widget;
152};
153
154class QGridLayoutBox
155{
156public:
157 inline QGridLayoutBox()
158 : q_minimumSize(0), q_preferredSize(0), q_maximumSize(FLT_MAX),
159 q_minimumDescent(-1), q_minimumAscent(-1) {}
160
161 void add(const QGridLayoutBox &other, int stretch, qreal spacing);
162 void combine(const QGridLayoutBox &other);
163 void normalize();