source: trunk/src/qt3support/widgets/q3mainwindow.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 71.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt3Support module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "q3mainwindow.h"
43#ifndef QT_NO_MAINWINDOW
44
45#include "qapplication.h"
46#include "qbitmap.h"
47#include "qcursor.h"
48#include "qdatetime.h"
49#include "q3dockarea.h"
50#include "qevent.h"
51#include "qlayout.h"
52#include "qmap.h"
53#include "qmenubar.h"
54#include "qpainter.h"
55#include "q3popupmenu.h"
56#include "q3scrollview.h"
57#include "qstatusbar.h"
58#include "qstringlist.h"
59#include "qstyle.h"
60#include "qstyleoption.h"
61#include "qtimer.h"
62#include "q3toolbar.h"
63#include "qtooltip.h"
64#include "qwhatsthis.h"
65#ifdef Q_WS_MAC
66# include <private/qt_mac_p.h>
67#endif
68
69#include <private/q3mainwindow_p.h>
70
71QT_BEGIN_NAMESPACE
72
73class QHideDock;
74
75/* Q3MainWindowLayout, respects widthForHeight layouts (like the left
76 and right docks are)
77*/
78
79class Q3MainWindowLayout : public QLayout
80{
81 Q_OBJECT
82
83public:
84 Q3MainWindowLayout(Q3MainWindow *mw);
85 ~Q3MainWindowLayout() {}
86
87 void addItem(QLayoutItem *);
88 void setLeftDock(Q3DockArea *l);
89 void setRightDock(Q3DockArea *r);
90 void setCentralWidget(QWidget *w);
91 bool hasHeightForWidth() const { return false; }
92 QSize sizeHint() const;
93 QSize minimumSize() const;
94 QLayoutItem *itemAt(int) const { return 0; } //###
95 QLayoutItem *takeAt(int) { return 0; } //###
96 int count() const { return 0; } //###
97
98protected:
99 void setGeometry(const QRect &r) {
100 QLayout::setGeometry(r);
101 layoutItems(r);
102 }
103
104private:
105 int layoutItems(const QRect&, bool testonly = false);
106 int extraPixels() const;
107
108 Q3DockArea *left, *right;
109 QWidget *central;
110 Q3MainWindow *mainWindow;
111
112};
113
114QSize Q3MainWindowLayout::sizeHint() const
115{
116 int w = 0;
117 int h = 0;
118
119 if (left) {
120 w += left->sizeHint().width();
121 h = qMax(h, left->sizeHint().height());
122 }
123 if (right) {
124 w += right->sizeHint().width();
125 h = qMax(h, right->sizeHint().height());
126 }
127 if (central) {
128 w += central->sizeHint().width();
129 int diff = extraPixels();
130 h = qMax(h, central->sizeHint().height() + diff);
131 }
132 return QSize(w, h);
133}
134
135QSize Q3MainWindowLayout::minimumSize() const
136{
137 int w = 0;
138 int h = 0;
139
140 if (left) {
141 QSize ms = left->minimumSizeHint().expandedTo(left->minimumSize());
142 w += ms.width();
143 h = qMax(h, ms.height());
144 }
145 if (right) {
146 QSize ms = right->minimumSizeHint().expandedTo(right->minimumSize());
147 w += ms.width();
148 h = qMax(h, ms.height());
149 }
150 if (central) {
151 QSize min = central->minimumSize().isNull() ?
152 central->minimumSizeHint() : central->minimumSize();
153 w += min.width();
154 int diff = extraPixels();
155 h = qMax(h, min.height() + diff);
156 }
157 return QSize(w, h);
158}
159
160Q3MainWindowLayout::Q3MainWindowLayout(Q3MainWindow *mw)
161 : left(0), right(0), central(0)
162{
163 mainWindow = mw;
164}
165
166void Q3MainWindowLayout::setLeftDock(Q3DockArea *l)
167{
168 left = l;