Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qtoolbararealayout.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 QtWidgets 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 <QWidgetItem> | - | ||||||||||||||||||||||||
35 | #include <QToolBar> | - | ||||||||||||||||||||||||
36 | #include <QStyleOption> | - | ||||||||||||||||||||||||
37 | #include <QApplication> | - | ||||||||||||||||||||||||
38 | #include <qdebug.h> | - | ||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||
40 | #include "qtoolbararealayout_p.h" | - | ||||||||||||||||||||||||
41 | #include "qmainwindowlayout_p.h" | - | ||||||||||||||||||||||||
42 | #include "qwidgetanimator_p.h" | - | ||||||||||||||||||||||||
43 | #include "qtoolbarlayout_p.h" | - | ||||||||||||||||||||||||
44 | #include "qtoolbar_p.h" | - | ||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||
46 | /****************************************************************************** | - | ||||||||||||||||||||||||
47 | ** QToolBarAreaLayoutItem | - | ||||||||||||||||||||||||
48 | */ | - | ||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||
50 | #ifndef QT_NO_TOOLBAR | - | ||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | // qmainwindow.cpp | - | ||||||||||||||||||||||||
55 | extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *mainWindow); | - | ||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | QSize QToolBarAreaLayoutItem::minimumSize() const | - | ||||||||||||||||||||||||
58 | { | - | ||||||||||||||||||||||||
59 | if (skip())
| 0 | ||||||||||||||||||||||||
60 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||||||||
61 | return qSmartMinSize(static_cast<QWidgetItem*>(widgetItem)); never executed: return qSmartMinSize(static_cast<QWidgetItem*>(widgetItem)); | 0 | ||||||||||||||||||||||||
62 | } | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | QSize QToolBarAreaLayoutItem::sizeHint() const | - | ||||||||||||||||||||||||
65 | { | - | ||||||||||||||||||||||||
66 | if (skip())
| 0 | ||||||||||||||||||||||||
67 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||
69 | return realSizeHint(); never executed: return realSizeHint(); | 0 | ||||||||||||||||||||||||
70 | } | - | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | //returns the real size hint not taking into account the visibility of the widget | - | ||||||||||||||||||||||||
73 | QSize QToolBarAreaLayoutItem::realSizeHint() const | - | ||||||||||||||||||||||||
74 | { | - | ||||||||||||||||||||||||
75 | QWidget *wid = widgetItem->widget(); | - | ||||||||||||||||||||||||
76 | QSize s = wid->sizeHint().expandedTo(wid->minimumSizeHint()); | - | ||||||||||||||||||||||||
77 | if (wid->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||||||||
78 | s.setWidth(0); never executed: s.setWidth(0); | 0 | ||||||||||||||||||||||||
79 | if (wid->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||||||||
80 | s.setHeight(0); never executed: s.setHeight(0); | 0 | ||||||||||||||||||||||||
81 | s = s.boundedTo(wid->maximumSize()) | - | ||||||||||||||||||||||||
82 | .expandedTo(wid->minimumSize()); | - | ||||||||||||||||||||||||
83 | return s; never executed: return s; | 0 | ||||||||||||||||||||||||
84 | } | - | ||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||
86 | bool QToolBarAreaLayoutItem::skip() const | - | ||||||||||||||||||||||||
87 | { | - | ||||||||||||||||||||||||
88 | if (gap)
| 0 | ||||||||||||||||||||||||
89 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
90 | return widgetItem == 0 || widgetItem->isEmpty(); never executed: return widgetItem == 0 || widgetItem->isEmpty();
| 0 | ||||||||||||||||||||||||
91 | } | - | ||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||
93 | /****************************************************************************** | - | ||||||||||||||||||||||||
94 | ** QToolBarAreaLayoutLine | - | ||||||||||||||||||||||||
95 | */ | - | ||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | QToolBarAreaLayoutLine::QToolBarAreaLayoutLine(Qt::Orientation orientation) | - | ||||||||||||||||||||||||
98 | : o(orientation) | - | ||||||||||||||||||||||||
99 | { | - | ||||||||||||||||||||||||
100 | } never executed: end of block | 0 | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | QSize QToolBarAreaLayoutLine::sizeHint() const | - | ||||||||||||||||||||||||
103 | { | - | ||||||||||||||||||||||||
104 | int a = 0, b = 0; | - | ||||||||||||||||||||||||
105 | for (int i = 0; i < toolBarItems.count(); ++i) {
| 0 | ||||||||||||||||||||||||
106 | const QToolBarAreaLayoutItem &item = toolBarItems.at(i); | - | ||||||||||||||||||||||||
107 | if (item.skip())
| 0 | ||||||||||||||||||||||||
108 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||
110 | QSize sh = item.sizeHint(); | - | ||||||||||||||||||||||||
111 | a += item.preferredSize > 0 ? item.preferredSize : pick(o, sh);
| 0 | ||||||||||||||||||||||||
112 | b = qMax(b, perp(o, sh)); | - | ||||||||||||||||||||||||
113 | } never executed: end of block | 0 | ||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||
115 | QSize result; | - | ||||||||||||||||||||||||
116 | rpick(o, result) = a; | - | ||||||||||||||||||||||||
117 | rperp(o, result) = b; | - | ||||||||||||||||||||||||
118 | - | |||||||||||||||||||||||||
119 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
120 | } | - | ||||||||||||||||||||||||
121 | - | |||||||||||||||||||||||||
122 | QSize QToolBarAreaLayoutLine::minimumSize() const | - | ||||||||||||||||||||||||
123 | { | - | ||||||||||||||||||||||||
124 | int a = 0, b = 0; | - | ||||||||||||||||||||||||
125 | for (int i = 0; i < toolBarItems.count(); ++i) {
| 0 | ||||||||||||||||||||||||
126 | const QToolBarAreaLayoutItem &item = toolBarItems[i]; | - | ||||||||||||||||||||||||
127 | if (item.skip())
| 0 | ||||||||||||||||||||||||
128 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||
130 | QSize ms = item.minimumSize(); | - | ||||||||||||||||||||||||
131 | a += pick(o, ms); | - | ||||||||||||||||||||||||
132 | b = qMax(b, perp(o, ms)); | - | ||||||||||||||||||||||||
133 | } never executed: end of block | 0 | ||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||
135 | QSize result; | - | ||||||||||||||||||||||||
136 | rpick(o, result) = a; | - | ||||||||||||||||||||||||
137 | rperp(o, result) = b; | - | ||||||||||||||||||||||||
138 | - | |||||||||||||||||||||||||
139 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
140 | } | - | ||||||||||||||||||||||||
141 | - | |||||||||||||||||||||||||
142 | void QToolBarAreaLayoutLine::fitLayout() | - | ||||||||||||||||||||||||
143 | { | - | ||||||||||||||||||||||||
144 | int last = -1; | - | ||||||||||||||||||||||||
145 | int min = pick(o, minimumSize()); | - | ||||||||||||||||||||||||
146 | int space = pick(o, rect.size()); | - | ||||||||||||||||||||||||
147 | int extra = qMax(0, space - min); | - | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | for (int i = 0; i < toolBarItems.count(); ++i) {
| 0 | ||||||||||||||||||||||||
150 | QToolBarAreaLayoutItem &item = toolBarItems[i]; | - | ||||||||||||||||||||||||
151 | if (item.skip())
| 0 | ||||||||||||||||||||||||
152 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | if (QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout()))
| 0 | ||||||||||||||||||||||||
155 | tblayout->checkUsePopupMenu(); never executed: tblayout->checkUsePopupMenu(); | 0 | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | const int itemMin = pick(o, item.minimumSize()); | - | ||||||||||||||||||||||||
158 | //preferredSize is the default if it is set, otherwise, we take the sizehint | - | ||||||||||||||||||||||||
159 | item.size = item.preferredSize > 0 ? item.preferredSize : pick(o, item.sizeHint());
| 0 | ||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | //the extraspace is the space above the item minimum sizehint | - | ||||||||||||||||||||||||
162 | const int extraSpace = qMin(item.size - itemMin, extra); | - | ||||||||||||||||||||||||
163 | item.size = itemMin + extraSpace; //that is the real size | - | ||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||
165 | extra -= extraSpace; | - | ||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||
167 | last = i; | - | ||||||||||||||||||||||||
168 | } never executed: end of block | 0 | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | // calculate the positions from the sizes | - | ||||||||||||||||||||||||
171 | int pos = 0; | - | ||||||||||||||||||||||||
172 | for (int i = 0; i < toolBarItems.count(); ++i) {
| 0 | ||||||||||||||||||||||||
173 | QToolBarAreaLayoutItem &item = toolBarItems[i]; | - | ||||||||||||||||||||||||
174 | if (item.skip())
| 0 | ||||||||||||||||||||||||
175 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | item.pos = pos; | - | ||||||||||||||||||||||||
178 | if (i == last) // stretch the last item to the end of the line
| 0 | ||||||||||||||||||||||||
179 | item.size = qMax(0, pick(o, rect.size()) - item.pos); never executed: item.size = qMax(0, pick(o, rect.size()) - item.pos); | 0 | ||||||||||||||||||||||||
180 | pos += item.size; | - | ||||||||||||||||||||||||
181 | } never executed: end of block | 0 | ||||||||||||||||||||||||
182 | } never executed: end of block | 0 | ||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||
184 | bool QToolBarAreaLayoutLine::skip() const | - | ||||||||||||||||||||||||
185 | { | - | ||||||||||||||||||||||||
186 | for (int i = 0; i < toolBarItems.count(); ++i) {
| 0 | ||||||||||||||||||||||||
187 | if (!toolBarItems.at(i).skip())
| 0 | ||||||||||||||||||||||||
188 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
189 | } never executed: end of block | 0 | ||||||||||||||||||||||||
190 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
191 | } | - | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | /****************************************************************************** | - | ||||||||||||||||||||||||
194 | ** QToolBarAreaLayoutInfo | - | ||||||||||||||||||||||||
195 | */ | - | ||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||
197 | QToolBarAreaLayoutInfo::QToolBarAreaLayoutInfo(QInternal::DockPosition pos) | - | ||||||||||||||||||||||||
198 | : dockPos(pos), dirty(false) | - | ||||||||||||||||||||||||
199 | { | - | ||||||||||||||||||||||||
200 | switch (pos) { | - | ||||||||||||||||||||||||
201 | case QInternal::LeftDock: never executed: case QInternal::LeftDock: | 0 | ||||||||||||||||||||||||
202 | case QInternal::RightDock: never executed: case QInternal::RightDock: | 0 | ||||||||||||||||||||||||
203 | o = Qt::Vertical; | - | ||||||||||||||||||||||||
204 | break; never executed: break; | 0 | ||||||||||||||||||||||||
205 | case QInternal::TopDock: never executed: case QInternal::TopDock: | 0 | ||||||||||||||||||||||||
206 | case QInternal::BottomDock: never executed: case QInternal::BottomDock: | 0 | ||||||||||||||||||||||||
207 | o = Qt::Horizontal; | - | ||||||||||||||||||||||||
208 | break; never executed: break; | 0 | ||||||||||||||||||||||||
209 | default: never executed: default: | 0 | ||||||||||||||||||||||||
210 | o = Qt::Horizontal; | - | ||||||||||||||||||||||||
211 | break; never executed: break; | 0 | ||||||||||||||||||||||||
212 | } | - | ||||||||||||||||||||||||
213 | } | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | QSize QToolBarAreaLayoutInfo::sizeHint() const | - | ||||||||||||||||||||||||
216 | { | - | ||||||||||||||||||||||||
217 | int a = 0, b = 0; | - | ||||||||||||||||||||||||
218 | for (int i = 0; i < lines.count(); ++i) {
| 0 | ||||||||||||||||||||||||
219 | const QToolBarAreaLayoutLine &l = lines.at(i); | - | ||||||||||||||||||||||||
220 | if (l.skip())
| 0 | ||||||||||||||||||||||||
221 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
222 | - | |||||||||||||||||||||||||
223 | QSize hint = l.sizeHint(); | - | ||||||||||||||||||||||||
224 | a = qMax(a, pick(o, hint)); | - | ||||||||||||||||||||||||
225 | b += perp(o, hint); | - | ||||||||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||
228 | QSize result; | - | ||||||||||||||||||||||||
229 | rpick(o, result) = a; | - | ||||||||||||||||||||||||
230 | rperp(o, result) = b; | - | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
233 | } | - | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | QSize QToolBarAreaLayoutInfo::minimumSize() const | - | ||||||||||||||||||||||||
236 | { | - | ||||||||||||||||||||||||
237 | int a = 0, b = 0; | - | ||||||||||||||||||||||||
238 | for (int i = 0; i < lines.count(); ++i) {
| 0 | ||||||||||||||||||||||||
239 | const QToolBarAreaLayoutLine &l = lines.at(i); | - | ||||||||||||||||||||||||
240 | if (l.skip())
| 0 | ||||||||||||||||||||||||
241 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||
243 | QSize m = l.minimumSize(); | - | ||||||||||||||||||||||||
244 | a = qMax(a, pick(o, m)); | - | ||||||||||||||||||||||||
245 | b += perp(o, m); | - | ||||||||||||||||||||||||
246 | } never executed: end of block | 0 | ||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||
248 | QSize result; | - | ||||||||||||||||||||||||
249 | rpick(o, result) = a; | - | ||||||||||||||||||||||||
250 | rperp(o, result) = b; | - | ||||||||||||||||||||||||
251 | - | |||||||||||||||||||||||||
252 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
253 | } | - | ||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||
255 | void QToolBarAreaLayoutInfo::fitLayout() | - | ||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||
257 | dirty = false; | - | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | int b = 0; | - | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | bool reverse = dockPos == QInternal::RightDock || dockPos == QInternal::BottomDock;
| 0 | ||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||
263 | int i = reverse ? lines.count() - 1 : 0;
| 0 | ||||||||||||||||||||||||
264 | for (;;) { | - | ||||||||||||||||||||||||
265 | if ((reverse && i < 0) || (!reverse && i == lines.count()))
| 0 | ||||||||||||||||||||||||
266 | break; never executed: break; | 0 | ||||||||||||||||||||||||
267 | - | |||||||||||||||||||||||||
268 | QToolBarAreaLayoutLine &l = lines[i]; | - | ||||||||||||||||||||||||
269 | if (!l.skip()) {
| 0 | ||||||||||||||||||||||||
270 | if (o == Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
271 | l.rect.setLeft(rect.left()); | - | ||||||||||||||||||||||||
272 | l.rect.setRight(rect.right()); | - | ||||||||||||||||||||||||
273 | l.rect.setTop(b + rect.top()); | - | ||||||||||||||||||||||||
274 | b += l.sizeHint().height(); | - | ||||||||||||||||||||||||
275 | l.rect.setBottom(b - 1 + rect.top()); | - | ||||||||||||||||||||||||
276 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
277 | l.rect.setTop(rect.top()); | - | ||||||||||||||||||||||||
278 | l.rect.setBottom(rect.bottom()); | - | ||||||||||||||||||||||||
279 | l.rect.setLeft(b + rect.left()); | - | ||||||||||||||||||||||||
280 | b += l.sizeHint().width(); | - | ||||||||||||||||||||||||
281 | l.rect.setRight(b - 1 + rect.left()); | - | ||||||||||||||||||||||||
282 | } never executed: end of block | 0 | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | l.fitLayout(); | - | ||||||||||||||||||||||||
285 | } never executed: end of block | 0 | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | i += reverse ? -1 : 1;
| 0 | ||||||||||||||||||||||||
288 | } never executed: end of block | 0 | ||||||||||||||||||||||||
289 | } never executed: end of block | 0 | ||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||
291 | QLayoutItem *QToolBarAreaLayoutInfo::insertToolBar(QToolBar *before, QToolBar *toolBar) | - | ||||||||||||||||||||||||
292 | { | - | ||||||||||||||||||||||||
293 | toolBar->setOrientation(o); | - | ||||||||||||||||||||||||
294 | QLayoutItem *item = new QWidgetItemV2(toolBar); | - | ||||||||||||||||||||||||
295 | insertItem(before, item); | - | ||||||||||||||||||||||||
296 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||
297 | } | - | ||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||
299 | void QToolBarAreaLayoutInfo::insertItem(QToolBar *before, QLayoutItem *item) | - | ||||||||||||||||||||||||
300 | { | - | ||||||||||||||||||||||||
301 | if (before == 0) {
| 0 | ||||||||||||||||||||||||
302 | if (lines.isEmpty())
| 0 | ||||||||||||||||||||||||
303 | lines.append(QToolBarAreaLayoutLine(o)); never executed: lines.append(QToolBarAreaLayoutLine(o)); | 0 | ||||||||||||||||||||||||
304 | lines.last().toolBarItems.append(item); | - | ||||||||||||||||||||||||
305 | return; never executed: return; | 0 | ||||||||||||||||||||||||
306 | } | - | ||||||||||||||||||||||||
307 | - | |||||||||||||||||||||||||
308 | for (int j = 0; j < lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
309 | QToolBarAreaLayoutLine &line = lines[j]; | - | ||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
312 | if (line.toolBarItems.at(k).widgetItem->widget() == before) {
| 0 | ||||||||||||||||||||||||
313 | line.toolBarItems.insert(k, item); | - | ||||||||||||||||||||||||
314 | return; never executed: return; | 0 | ||||||||||||||||||||||||
315 | } | - | ||||||||||||||||||||||||
316 | } never executed: end of block | 0 | ||||||||||||||||||||||||
317 | } never executed: end of block | 0 | ||||||||||||||||||||||||
318 | } never executed: end of block | 0 | ||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||
320 | void QToolBarAreaLayoutInfo::removeToolBar(QToolBar *toolBar) | - | ||||||||||||||||||||||||
321 | { | - | ||||||||||||||||||||||||
322 | for (int j = 0; j < lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
323 | QToolBarAreaLayoutLine &line = lines[j]; | - | ||||||||||||||||||||||||
324 | - | |||||||||||||||||||||||||
325 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
326 | QToolBarAreaLayoutItem &item = line.toolBarItems[k]; | - | ||||||||||||||||||||||||
327 | if (item.widgetItem->widget() == toolBar) {
| 0 | ||||||||||||||||||||||||
328 | delete item.widgetItem; | - | ||||||||||||||||||||||||
329 | item.widgetItem = 0; | - | ||||||||||||||||||||||||
330 | line.toolBarItems.removeAt(k); | - | ||||||||||||||||||||||||
331 | - | |||||||||||||||||||||||||
332 | if (line.toolBarItems.isEmpty() && j < lines.count() - 1)
| 0 | ||||||||||||||||||||||||
333 | lines.removeAt(j); never executed: lines.removeAt(j); | 0 | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | return; never executed: return; | 0 | ||||||||||||||||||||||||
336 | } | - | ||||||||||||||||||||||||
337 | } never executed: end of block | 0 | ||||||||||||||||||||||||
338 | } never executed: end of block | 0 | ||||||||||||||||||||||||
339 | } never executed: end of block | 0 | ||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||
341 | void QToolBarAreaLayoutInfo::insertToolBarBreak(QToolBar *before) | - | ||||||||||||||||||||||||
342 | { | - | ||||||||||||||||||||||||
343 | if (before == 0) {
| 0 | ||||||||||||||||||||||||
344 | if (!lines.isEmpty() && lines.last().toolBarItems.isEmpty())
| 0 | ||||||||||||||||||||||||
345 | return; never executed: return; | 0 | ||||||||||||||||||||||||
346 | lines.append(QToolBarAreaLayoutLine(o)); | - | ||||||||||||||||||||||||
347 | return; never executed: return; | 0 | ||||||||||||||||||||||||
348 | } | - | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | for (int j = 0; j < lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
351 | QToolBarAreaLayoutLine &line = lines[j]; | - | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
354 | if (line.toolBarItems.at(k).widgetItem->widget() == before) {
| 0 | ||||||||||||||||||||||||
355 | if (k == 0)
| 0 | ||||||||||||||||||||||||
356 | return; never executed: return; | 0 | ||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||
358 | QToolBarAreaLayoutLine newLine(o); | - | ||||||||||||||||||||||||
359 | newLine.toolBarItems = line.toolBarItems.mid(k); | - | ||||||||||||||||||||||||
360 | line.toolBarItems = line.toolBarItems.mid(0, k); | - | ||||||||||||||||||||||||
361 | lines.insert(j + 1, newLine); | - | ||||||||||||||||||||||||
362 | - | |||||||||||||||||||||||||
363 | return; never executed: return; | 0 | ||||||||||||||||||||||||
364 | } | - | ||||||||||||||||||||||||
365 | } never executed: end of block | 0 | ||||||||||||||||||||||||
366 | } never executed: end of block | 0 | ||||||||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | void QToolBarAreaLayoutInfo::removeToolBarBreak(QToolBar *before) | - | ||||||||||||||||||||||||
370 | { | - | ||||||||||||||||||||||||
371 | for (int j = 0; j < lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
372 | const QToolBarAreaLayoutLine &line = lines.at(j); | - | ||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||
374 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
375 | if (line.toolBarItems.at(k).widgetItem->widget() == before) {
| 0 | ||||||||||||||||||||||||
376 | if (k != 0)
| 0 | ||||||||||||||||||||||||
377 | return; never executed: return; | 0 | ||||||||||||||||||||||||
378 | if (j == 0)
| 0 | ||||||||||||||||||||||||
379 | return; never executed: return; | 0 | ||||||||||||||||||||||||
380 | - | |||||||||||||||||||||||||
381 | lines[j - 1].toolBarItems += lines[j].toolBarItems; | - | ||||||||||||||||||||||||
382 | lines.removeAt(j); | - | ||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||
384 | return; never executed: return; | 0 | ||||||||||||||||||||||||
385 | } | - | ||||||||||||||||||||||||
386 | } never executed: end of block | 0 | ||||||||||||||||||||||||
387 | } never executed: end of block | 0 | ||||||||||||||||||||||||
388 | } never executed: end of block | 0 | ||||||||||||||||||||||||
389 | - | |||||||||||||||||||||||||
390 | void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos) | - | ||||||||||||||||||||||||
391 | { | - | ||||||||||||||||||||||||
392 | if (dirty)
| 0 | ||||||||||||||||||||||||
393 | fitLayout(); never executed: fitLayout(); | 0 | ||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||
395 | dirty = true; | - | ||||||||||||||||||||||||
396 | - | |||||||||||||||||||||||||
397 | if (o == Qt::Vertical)
| 0 | ||||||||||||||||||||||||
398 | pos -= rect.top(); never executed: pos -= rect.top(); | 0 | ||||||||||||||||||||||||
399 | - | |||||||||||||||||||||||||
400 | //here we actually update the preferredSize for the line containing the toolbar so that we move it | - | ||||||||||||||||||||||||
401 | for (int j = 0; j < lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
402 | QToolBarAreaLayoutLine &line = lines[j]; | - | ||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||
404 | int previousIndex = -1; | - | ||||||||||||||||||||||||
405 | int minPos = 0; | - | ||||||||||||||||||||||||
406 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
407 | QToolBarAreaLayoutItem ¤t = line.toolBarItems[k]; | - | ||||||||||||||||||||||||
408 | if (current.widgetItem->widget() == toolbar) {
| 0 | ||||||||||||||||||||||||
409 | int newPos = current.pos; | - | ||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||
411 | if (previousIndex >= 0) {
| 0 | ||||||||||||||||||||||||
412 | QToolBarAreaLayoutItem &previous = line.toolBarItems[previousIndex]; | - | ||||||||||||||||||||||||
413 | if (pos < current.pos) {
| 0 | ||||||||||||||||||||||||
414 | newPos = qMax(pos, minPos); | - | ||||||||||||||||||||||||
415 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
416 | //we check the max value for the position (until everything at the right is "compressed") | - | ||||||||||||||||||||||||
417 | int maxPos = pick(o, rect.size()); | - | ||||||||||||||||||||||||
418 | for(int l = k; l < line.toolBarItems.count(); ++l) {
| 0 | ||||||||||||||||||||||||
419 | const QToolBarAreaLayoutItem &item = line.toolBarItems.at(l); | - | ||||||||||||||||||||||||
420 | if (!item.skip()) {
| 0 | ||||||||||||||||||||||||
421 | maxPos -= pick(o, item.minimumSize()); | - | ||||||||||||||||||||||||
422 | } never executed: end of block | 0 | ||||||||||||||||||||||||
423 | } never executed: end of block | 0 | ||||||||||||||||||||||||
424 | newPos = qMin(pos, maxPos); | - | ||||||||||||||||||||||||
425 | } never executed: end of block | 0 | ||||||||||||||||||||||||
426 | - | |||||||||||||||||||||||||
427 | //extra is the number of pixels to add to the previous toolbar | - | ||||||||||||||||||||||||
428 | int extra = newPos - current.pos; | - | ||||||||||||||||||||||||
429 | - | |||||||||||||||||||||||||
430 | //we check if the previous is near its size hint | - | ||||||||||||||||||||||||
431 | //in which case we try to stick to it | - | ||||||||||||||||||||||||
432 | const int diff = pick(o, previous.sizeHint()) - (previous.size + extra); | - | ||||||||||||||||||||||||
433 | if (qAbs(diff) < QApplication::startDragDistance()) {
| 0 | ||||||||||||||||||||||||
434 | //we stick to the default place and size | - | ||||||||||||||||||||||||
435 | extra += diff; | - | ||||||||||||||||||||||||
436 | } never executed: end of block | 0 | ||||||||||||||||||||||||
437 | - | |||||||||||||||||||||||||
438 | //update for the current item | - | ||||||||||||||||||||||||
439 | current.extendSize(line.o, -extra); | - | ||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||
441 | if (extra >= 0) {
| 0 | ||||||||||||||||||||||||
442 | previous.extendSize(line.o, extra); | - | ||||||||||||||||||||||||
443 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
444 | //we need to push the toolbars on the left starting with previous | - | ||||||||||||||||||||||||
445 | extra = -extra; // we just need to know the number of pixels | - | ||||||||||||||||||||||||
446 | ///at this point we need to get extra pixels from the toolbars at the left | - | ||||||||||||||||||||||||
447 | for(int l = previousIndex; l >=0; --l) {
| 0 | ||||||||||||||||||||||||
448 | QToolBarAreaLayoutItem &item = line.toolBarItems[l]; | - | ||||||||||||||||||||||||
449 | if (!item.skip()) {
| 0 | ||||||||||||||||||||||||
450 | const int minPreferredSize = pick(o, item.minimumSize()); | - | ||||||||||||||||||||||||
451 | const int margin = item.size - minPreferredSize; | - | ||||||||||||||||||||||||
452 | if (margin < extra) {
| 0 | ||||||||||||||||||||||||
453 | item.resize(line.o, minPreferredSize); | - | ||||||||||||||||||||||||
454 | extra -= margin; | - | ||||||||||||||||||||||||
455 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
456 | item.extendSize(line.o, -extra); | - | ||||||||||||||||||||||||
457 | extra = 0; | - | ||||||||||||||||||||||||
458 | } never executed: end of block | 0 | ||||||||||||||||||||||||
459 | } | - | ||||||||||||||||||||||||
460 | } never executed: end of block | 0 | ||||||||||||||||||||||||
461 | Q_ASSERT(extra == 0); | - | ||||||||||||||||||||||||
462 | } never executed: end of block | 0 | ||||||||||||||||||||||||
463 | } else { | - | ||||||||||||||||||||||||
464 | //the item is the first one, it should be at position 0 | - | ||||||||||||||||||||||||
465 | } never executed: end of block | 0 | ||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||
467 | return; never executed: return; | 0 | ||||||||||||||||||||||||
468 | - | |||||||||||||||||||||||||
469 | } else if (!current.skip()) {
| 0 | ||||||||||||||||||||||||
470 | previousIndex = k; | - | ||||||||||||||||||||||||
471 | minPos += pick(o, current.minimumSize()); | - | ||||||||||||||||||||||||
472 | } never executed: end of block | 0 | ||||||||||||||||||||||||
473 | } never executed: end of block | 0 | ||||||||||||||||||||||||
474 | } never executed: end of block | 0 | ||||||||||||||||||||||||
475 | } never executed: end of block | 0 | ||||||||||||||||||||||||
476 | - | |||||||||||||||||||||||||
477 | - | |||||||||||||||||||||||||
478 | QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const | - | ||||||||||||||||||||||||
479 | { | - | ||||||||||||||||||||||||
480 | if (rect.contains(pos)) {
| 0 | ||||||||||||||||||||||||
481 | // <pos> is in QToolBarAreaLayout coordinates. | - | ||||||||||||||||||||||||
482 | // <item.pos> is in local dockarea coordinates (see ~20 lines below) | - | ||||||||||||||||||||||||
483 | // Since we're comparing p with item.pos, we put them in the same coordinate system. | - | ||||||||||||||||||||||||
484 | const int p = pick(o, pos - rect.topLeft()); | - | ||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||
486 | for (int j = 0; j < lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
487 | const QToolBarAreaLayoutLine &line = lines.at(j); | - | ||||||||||||||||||||||||
488 | if (line.skip())
| 0 | ||||||||||||||||||||||||
489 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
490 | if (!line.rect.contains(pos))
| 0 | ||||||||||||||||||||||||
491 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
492 | - | |||||||||||||||||||||||||
493 | int k = 0; | - | ||||||||||||||||||||||||
494 | for (; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
495 | const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); | - | ||||||||||||||||||||||||
496 | if (item.skip())
| 0 | ||||||||||||||||||||||||
497 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||
499 | int size = qMin(item.size, pick(o, item.sizeHint())); | - | ||||||||||||||||||||||||
500 | - | |||||||||||||||||||||||||
501 | if (p > item.pos + size)
| 0 | ||||||||||||||||||||||||
502 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
503 | if (p > item.pos + size/2)
| 0 | ||||||||||||||||||||||||
504 | ++k; never executed: ++k; | 0 | ||||||||||||||||||||||||
505 | break; never executed: break; | 0 | ||||||||||||||||||||||||
506 | } | - | ||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | QList<int> result; | - | ||||||||||||||||||||||||
509 | result << j << k; | - | ||||||||||||||||||||||||
510 | *minDistance = 0; //we found a perfect match | - | ||||||||||||||||||||||||
511 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
512 | } | - | ||||||||||||||||||||||||
513 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
514 | const int dist = distance(pos); | - | ||||||||||||||||||||||||
515 | //it will only return a path if the minDistance is higher than the current distance | - | ||||||||||||||||||||||||
516 | if (dist >= 0 && *minDistance > dist) {
| 0 | ||||||||||||||||||||||||
517 | *minDistance = dist; | - | ||||||||||||||||||||||||
518 | - | |||||||||||||||||||||||||
519 | QList<int> result; | - | ||||||||||||||||||||||||
520 | result << lines.count() << 0; | - | ||||||||||||||||||||||||
521 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
522 | } | - | ||||||||||||||||||||||||
523 | } never executed: end of block | 0 | ||||||||||||||||||||||||
524 | - | |||||||||||||||||||||||||
525 | return QList<int>(); never executed: return QList<int>(); | 0 | ||||||||||||||||||||||||
526 | } | - | ||||||||||||||||||||||||
527 | - | |||||||||||||||||||||||||
528 | bool QToolBarAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *item) | - | ||||||||||||||||||||||||
529 | { | - | ||||||||||||||||||||||||
530 | Q_ASSERT(path.count() == 2); | - | ||||||||||||||||||||||||
531 | int j = path.first(); | - | ||||||||||||||||||||||||
532 | if (j == lines.count())
| 0 | ||||||||||||||||||||||||
533 | lines.append(QToolBarAreaLayoutLine(o)); never executed: lines.append(QToolBarAreaLayoutLine(o)); | 0 | ||||||||||||||||||||||||
534 | - | |||||||||||||||||||||||||
535 | QToolBarAreaLayoutLine &line = lines[j]; | - | ||||||||||||||||||||||||
536 | const int k = path.at(1); | - | ||||||||||||||||||||||||
537 | - | |||||||||||||||||||||||||
538 | QToolBarAreaLayoutItem gap_item; | - | ||||||||||||||||||||||||
539 | gap_item.gap = true; | - | ||||||||||||||||||||||||
540 | gap_item.widgetItem = item; | - | ||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||
542 | //update the previous item's preferred size | - | ||||||||||||||||||||||||
543 | for(int p = k - 1 ; p >= 0; --p) {
| 0 | ||||||||||||||||||||||||
544 | QToolBarAreaLayoutItem &previous = line.toolBarItems[p]; | - | ||||||||||||||||||||||||
545 | if (!previous.skip()) {
| 0 | ||||||||||||||||||||||||
546 | //we found the previous one | - | ||||||||||||||||||||||||
547 | int previousSizeHint = pick(line.o, previous.sizeHint()); | - | ||||||||||||||||||||||||
548 | int previousExtraSpace = previous.size - previousSizeHint; | - | ||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||
550 | if (previousExtraSpace > 0) {
| 0 | ||||||||||||||||||||||||
551 | //in this case we reset the space | - | ||||||||||||||||||||||||
552 | previous.preferredSize = -1; | - | ||||||||||||||||||||||||
553 | previous.size = previousSizeHint; | - | ||||||||||||||||||||||||
554 | - | |||||||||||||||||||||||||
555 | gap_item.resize(o, previousExtraSpace); | - | ||||||||||||||||||||||||
556 | } never executed: end of block | 0 | ||||||||||||||||||||||||
557 | - | |||||||||||||||||||||||||
558 | break; never executed: break; | 0 | ||||||||||||||||||||||||
559 | } | - | ||||||||||||||||||||||||
560 | } never executed: end of block | 0 | ||||||||||||||||||||||||
561 | - | |||||||||||||||||||||||||
562 | line.toolBarItems.insert(k, gap_item); | - | ||||||||||||||||||||||||
563 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
564 | - | |||||||||||||||||||||||||
565 | } | - | ||||||||||||||||||||||||
566 | - | |||||||||||||||||||||||||
567 | void QToolBarAreaLayoutInfo::clear() | - | ||||||||||||||||||||||||
568 | { | - | ||||||||||||||||||||||||
569 | lines.clear(); | - | ||||||||||||||||||||||||
570 | rect = QRect(); | - | ||||||||||||||||||||||||
571 | } never executed: end of block | 0 | ||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||
573 | QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const | - | ||||||||||||||||||||||||
574 | { | - | ||||||||||||||||||||||||
575 | Q_ASSERT(path.count() == 2); | - | ||||||||||||||||||||||||
576 | int j = path.at(0); | - | ||||||||||||||||||||||||
577 | int k = path.at(1); | - | ||||||||||||||||||||||||
578 | - | |||||||||||||||||||||||||
579 | const QToolBarAreaLayoutLine &line = lines.at(j); | - | ||||||||||||||||||||||||
580 | const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); | - | ||||||||||||||||||||||||
581 | - | |||||||||||||||||||||||||
582 | QRect result = line.rect; | - | ||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||
584 | if (o == Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
585 | result.setLeft(item.pos + line.rect.left()); | - | ||||||||||||||||||||||||
586 | result.setWidth(item.size); | - | ||||||||||||||||||||||||
587 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
588 | result.setTop(item.pos + line.rect.top()); | - | ||||||||||||||||||||||||
589 | result.setHeight(item.size); | - | ||||||||||||||||||||||||
590 | } never executed: end of block | 0 | ||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||
592 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
593 | } | - | ||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||
595 | int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const | - | ||||||||||||||||||||||||
596 | { | - | ||||||||||||||||||||||||
597 | switch (dockPos) { | - | ||||||||||||||||||||||||
598 | case QInternal::LeftDock: never executed: case QInternal::LeftDock: | 0 | ||||||||||||||||||||||||
599 | if (pos.y() < rect.bottom())
| 0 | ||||||||||||||||||||||||
600 | return pos.x() - rect.right(); never executed: return pos.x() - rect.right(); | 0 | ||||||||||||||||||||||||
601 | break; never executed: break; | 0 | ||||||||||||||||||||||||
602 | case QInternal::RightDock: never executed: case QInternal::RightDock: | 0 | ||||||||||||||||||||||||
603 | if (pos.y() < rect.bottom())
| 0 | ||||||||||||||||||||||||
604 | return rect.left() - pos.x(); never executed: return rect.left() - pos.x(); | 0 | ||||||||||||||||||||||||
605 | break; never executed: break; | 0 | ||||||||||||||||||||||||
606 | case QInternal::TopDock: never executed: case QInternal::TopDock: | 0 | ||||||||||||||||||||||||
607 | if (pos.x() < rect.right())
| 0 | ||||||||||||||||||||||||
608 | return pos.y() - rect.bottom(); never executed: return pos.y() - rect.bottom(); | 0 | ||||||||||||||||||||||||
609 | break; never executed: break; | 0 | ||||||||||||||||||||||||
610 | case QInternal::BottomDock: never executed: case QInternal::BottomDock: | 0 | ||||||||||||||||||||||||
611 | if (pos.x() < rect.right())
| 0 | ||||||||||||||||||||||||
612 | return rect.top() - pos.y(); never executed: return rect.top() - pos.y(); | 0 | ||||||||||||||||||||||||
613 | break; never executed: break; | 0 | ||||||||||||||||||||||||
614 | - | |||||||||||||||||||||||||
615 | case QInternal::DockCount: never executed: case QInternal::DockCount: | 0 | ||||||||||||||||||||||||
616 | break; never executed: break; | 0 | ||||||||||||||||||||||||
617 | } | - | ||||||||||||||||||||||||
618 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
619 | } | - | ||||||||||||||||||||||||
620 | - | |||||||||||||||||||||||||
621 | /****************************************************************************** | - | ||||||||||||||||||||||||
622 | ** QToolBarAreaLayout | - | ||||||||||||||||||||||||
623 | */ | - | ||||||||||||||||||||||||
624 | - | |||||||||||||||||||||||||
625 | QToolBarAreaLayout::QToolBarAreaLayout(const QMainWindow *win) : mainWindow(win), visible(true) | - | ||||||||||||||||||||||||
626 | { | - | ||||||||||||||||||||||||
627 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
628 | QInternal::DockPosition pos = static_cast<QInternal::DockPosition>(i); | - | ||||||||||||||||||||||||
629 | docks[i] = QToolBarAreaLayoutInfo(pos); | - | ||||||||||||||||||||||||
630 | } never executed: end of block | 0 | ||||||||||||||||||||||||
631 | } never executed: end of block | 0 | ||||||||||||||||||||||||
632 | - | |||||||||||||||||||||||||
633 | QRect QToolBarAreaLayout::fitLayout() | - | ||||||||||||||||||||||||
634 | { | - | ||||||||||||||||||||||||
635 | if (!visible)
| 0 | ||||||||||||||||||||||||
636 | return rect; never executed: return rect; | 0 | ||||||||||||||||||||||||
637 | - | |||||||||||||||||||||||||
638 | QSize left_hint = docks[QInternal::LeftDock].sizeHint(); | - | ||||||||||||||||||||||||
639 | QSize right_hint = docks[QInternal::RightDock].sizeHint(); | - | ||||||||||||||||||||||||
640 | QSize top_hint = docks[QInternal::TopDock].sizeHint(); | - | ||||||||||||||||||||||||
641 | QSize bottom_hint = docks[QInternal::BottomDock].sizeHint(); | - | ||||||||||||||||||||||||
642 | - | |||||||||||||||||||||||||
643 | QRect center = rect.adjusted(left_hint.width(), top_hint.height(), | - | ||||||||||||||||||||||||
644 | -right_hint.width(), -bottom_hint.height()); | - | ||||||||||||||||||||||||
645 | - | |||||||||||||||||||||||||
646 | docks[QInternal::TopDock].rect = QRect(rect.left(), rect.top(), | - | ||||||||||||||||||||||||
647 | rect.width(), top_hint.height()); | - | ||||||||||||||||||||||||
648 | docks[QInternal::LeftDock].rect = QRect(rect.left(), center.top(), | - | ||||||||||||||||||||||||
649 | left_hint.width(), center.height()); | - | ||||||||||||||||||||||||
650 | docks[QInternal::RightDock].rect = QRect(center.right() + 1, center.top(), | - | ||||||||||||||||||||||||
651 | right_hint.width(), center.height()); | - | ||||||||||||||||||||||||
652 | docks[QInternal::BottomDock].rect = QRect(rect.left(), center.bottom() + 1, | - | ||||||||||||||||||||||||
653 | rect.width(), bottom_hint.height()); | - | ||||||||||||||||||||||||
654 | - | |||||||||||||||||||||||||
655 | docks[QInternal::TopDock].fitLayout(); | - | ||||||||||||||||||||||||
656 | docks[QInternal::LeftDock].fitLayout(); | - | ||||||||||||||||||||||||
657 | docks[QInternal::RightDock].fitLayout(); | - | ||||||||||||||||||||||||
658 | docks[QInternal::BottomDock].fitLayout(); | - | ||||||||||||||||||||||||
659 | - | |||||||||||||||||||||||||
660 | return center; never executed: return center; | 0 | ||||||||||||||||||||||||
661 | } | - | ||||||||||||||||||||||||
662 | - | |||||||||||||||||||||||||
663 | QSize QToolBarAreaLayout::minimumSize(const QSize ¢erMin) const | - | ||||||||||||||||||||||||
664 | { | - | ||||||||||||||||||||||||
665 | if (!visible)
| 0 | ||||||||||||||||||||||||
666 | return centerMin; never executed: return centerMin; | 0 | ||||||||||||||||||||||||
667 | - | |||||||||||||||||||||||||
668 | QSize result = centerMin; | - | ||||||||||||||||||||||||
669 | - | |||||||||||||||||||||||||
670 | QSize left_min = docks[QInternal::LeftDock].minimumSize(); | - | ||||||||||||||||||||||||
671 | QSize right_min = docks[QInternal::RightDock].minimumSize(); | - | ||||||||||||||||||||||||
672 | QSize top_min = docks[QInternal::TopDock].minimumSize(); | - | ||||||||||||||||||||||||
673 | QSize bottom_min = docks[QInternal::BottomDock].minimumSize(); | - | ||||||||||||||||||||||||
674 | - | |||||||||||||||||||||||||
675 | result.setWidth(qMax(top_min.width(), result.width())); | - | ||||||||||||||||||||||||
676 | result.setWidth(qMax(bottom_min.width(), result.width())); | - | ||||||||||||||||||||||||
677 | result.setHeight(qMax(left_min.height(), result.height())); | - | ||||||||||||||||||||||||
678 | result.setHeight(qMax(right_min.height(), result.height())); | - | ||||||||||||||||||||||||
679 | - | |||||||||||||||||||||||||
680 | result.rwidth() += left_min.width() + right_min.width(); | - | ||||||||||||||||||||||||
681 | result.rheight() += top_min.height() + bottom_min.height(); | - | ||||||||||||||||||||||||
682 | - | |||||||||||||||||||||||||
683 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
684 | } | - | ||||||||||||||||||||||||
685 | - | |||||||||||||||||||||||||
686 | QSize QToolBarAreaLayout::sizeHint(const QSize ¢erHint) const | - | ||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||
688 | if (!visible)
| 0 | ||||||||||||||||||||||||
689 | return centerHint; never executed: return centerHint; | 0 | ||||||||||||||||||||||||
690 | - | |||||||||||||||||||||||||
691 | QSize result = centerHint; | - | ||||||||||||||||||||||||
692 | - | |||||||||||||||||||||||||
693 | QSize left_hint = docks[QInternal::LeftDock].sizeHint(); | - | ||||||||||||||||||||||||
694 | QSize right_hint = docks[QInternal::RightDock].sizeHint(); | - | ||||||||||||||||||||||||
695 | QSize top_hint = docks[QInternal::TopDock].sizeHint(); | - | ||||||||||||||||||||||||
696 | QSize bottom_hint = docks[QInternal::BottomDock].sizeHint(); | - | ||||||||||||||||||||||||
697 | - | |||||||||||||||||||||||||
698 | result.setWidth(qMax(top_hint.width(), result.width())); | - | ||||||||||||||||||||||||
699 | result.setWidth(qMax(bottom_hint.width(), result.width())); | - | ||||||||||||||||||||||||
700 | result.setHeight(qMax(left_hint.height(), result.height())); | - | ||||||||||||||||||||||||
701 | result.setHeight(qMax(right_hint.height(), result.height())); | - | ||||||||||||||||||||||||
702 | - | |||||||||||||||||||||||||
703 | result.rwidth() += left_hint.width() + right_hint.width(); | - | ||||||||||||||||||||||||
704 | result.rheight() += top_hint.height() + bottom_hint.height(); | - | ||||||||||||||||||||||||
705 | - | |||||||||||||||||||||||||
706 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
707 | } | - | ||||||||||||||||||||||||
708 | - | |||||||||||||||||||||||||
709 | QRect QToolBarAreaLayout::rectHint(const QRect &r) const | - | ||||||||||||||||||||||||
710 | { | - | ||||||||||||||||||||||||
711 | int coef = visible ? 1 : -1;
| 0 | ||||||||||||||||||||||||
712 | - | |||||||||||||||||||||||||
713 | QRect result = r; | - | ||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||
715 | QSize left_hint = docks[QInternal::LeftDock].sizeHint(); | - | ||||||||||||||||||||||||
716 | QSize right_hint = docks[QInternal::RightDock].sizeHint(); | - | ||||||||||||||||||||||||
717 | QSize top_hint = docks[QInternal::TopDock].sizeHint(); | - | ||||||||||||||||||||||||
718 | QSize bottom_hint = docks[QInternal::BottomDock].sizeHint(); | - | ||||||||||||||||||||||||
719 | - | |||||||||||||||||||||||||
720 | result.adjust(-left_hint.width()*coef, -top_hint.height()*coef, | - | ||||||||||||||||||||||||
721 | right_hint.width()*coef, bottom_hint.height()*coef); | - | ||||||||||||||||||||||||
722 | - | |||||||||||||||||||||||||
723 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
724 | } | - | ||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | QLayoutItem *QToolBarAreaLayout::itemAt(int *x, int index) const | - | ||||||||||||||||||||||||
727 | { | - | ||||||||||||||||||||||||
728 | Q_ASSERT(x != 0); | - | ||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||
730 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
731 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
732 | - | |||||||||||||||||||||||||
733 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
734 | const QToolBarAreaLayoutLine &line = dock.lines.at(j); | - | ||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||
736 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
737 | if ((*x)++ == index)
| 0 | ||||||||||||||||||||||||
738 | return line.toolBarItems.at(k).widgetItem; never executed: return line.toolBarItems.at(k).widgetItem; | 0 | ||||||||||||||||||||||||
739 | } never executed: end of block | 0 | ||||||||||||||||||||||||
740 | } never executed: end of block | 0 | ||||||||||||||||||||||||
741 | } never executed: end of block | 0 | ||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||
743 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
744 | } | - | ||||||||||||||||||||||||
745 | - | |||||||||||||||||||||||||
746 | QLayoutItem *QToolBarAreaLayout::takeAt(int *x, int index) | - | ||||||||||||||||||||||||
747 | { | - | ||||||||||||||||||||||||
748 | Q_ASSERT(x != 0); | - | ||||||||||||||||||||||||
749 | - | |||||||||||||||||||||||||
750 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
751 | QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||
753 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
754 | QToolBarAreaLayoutLine &line = dock.lines[j]; | - | ||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||
756 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
757 | if ((*x)++ == index) {
| 0 | ||||||||||||||||||||||||
758 | QLayoutItem *result = line.toolBarItems.takeAt(k).widgetItem; | - | ||||||||||||||||||||||||
759 | if (line.toolBarItems.isEmpty())
| 0 | ||||||||||||||||||||||||
760 | dock.lines.removeAt(j); never executed: dock.lines.removeAt(j); | 0 | ||||||||||||||||||||||||
761 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
762 | } | - | ||||||||||||||||||||||||
763 | } never executed: end of block | 0 | ||||||||||||||||||||||||
764 | } never executed: end of block | 0 | ||||||||||||||||||||||||
765 | } never executed: end of block | 0 | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
768 | } | - | ||||||||||||||||||||||||
769 | - | |||||||||||||||||||||||||
770 | void QToolBarAreaLayout::deleteAllLayoutItems() | - | ||||||||||||||||||||||||
771 | { | - | ||||||||||||||||||||||||
772 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
773 | QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
775 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
776 | QToolBarAreaLayoutLine &line = dock.lines[j]; | - | ||||||||||||||||||||||||
777 | - | |||||||||||||||||||||||||
778 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
779 | QToolBarAreaLayoutItem &item = line.toolBarItems[k]; | - | ||||||||||||||||||||||||
780 | if (!item.gap)
| 0 | ||||||||||||||||||||||||
781 | delete item.widgetItem; never executed: delete item.widgetItem; | 0 | ||||||||||||||||||||||||
782 | item.widgetItem = 0; | - | ||||||||||||||||||||||||
783 | } never executed: end of block | 0 | ||||||||||||||||||||||||
784 | } never executed: end of block | 0 | ||||||||||||||||||||||||
785 | } never executed: end of block | 0 | ||||||||||||||||||||||||
786 | } never executed: end of block | 0 | ||||||||||||||||||||||||
787 | - | |||||||||||||||||||||||||
788 | QInternal::DockPosition QToolBarAreaLayout::findToolBar(QToolBar *toolBar) const | - | ||||||||||||||||||||||||
789 | { | - | ||||||||||||||||||||||||
790 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
791 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
792 | - | |||||||||||||||||||||||||
793 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
794 | const QToolBarAreaLayoutLine &line = dock.lines.at(j); | - | ||||||||||||||||||||||||
795 | - | |||||||||||||||||||||||||
796 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
797 | if (line.toolBarItems.at(k).widgetItem->widget() == toolBar)
| 0 | ||||||||||||||||||||||||
798 | return static_cast<QInternal::DockPosition>(i); never executed: return static_cast<QInternal::DockPosition>(i); | 0 | ||||||||||||||||||||||||
799 | } never executed: end of block | 0 | ||||||||||||||||||||||||
800 | } never executed: end of block | 0 | ||||||||||||||||||||||||
801 | } never executed: end of block | 0 | ||||||||||||||||||||||||
802 | - | |||||||||||||||||||||||||
803 | return QInternal::DockCount; never executed: return QInternal::DockCount; | 0 | ||||||||||||||||||||||||
804 | } | - | ||||||||||||||||||||||||
805 | - | |||||||||||||||||||||||||
806 | QLayoutItem *QToolBarAreaLayout::insertToolBar(QToolBar *before, QToolBar *toolBar) | - | ||||||||||||||||||||||||
807 | { | - | ||||||||||||||||||||||||
808 | QInternal::DockPosition pos = findToolBar(before); | - | ||||||||||||||||||||||||
809 | if (pos == QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
810 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
811 | - | |||||||||||||||||||||||||
812 | return docks[pos].insertToolBar(before, toolBar); never executed: return docks[pos].insertToolBar(before, toolBar); | 0 | ||||||||||||||||||||||||
813 | } | - | ||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||
815 | void QToolBarAreaLayout::removeToolBar(QToolBar *toolBar) | - | ||||||||||||||||||||||||
816 | { | - | ||||||||||||||||||||||||
817 | QInternal::DockPosition pos = findToolBar(toolBar); | - | ||||||||||||||||||||||||
818 | if (pos == QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
819 | return; never executed: return; | 0 | ||||||||||||||||||||||||
820 | docks[pos].removeToolBar(toolBar); | - | ||||||||||||||||||||||||
821 | } never executed: end of block | 0 | ||||||||||||||||||||||||
822 | - | |||||||||||||||||||||||||
823 | QLayoutItem *QToolBarAreaLayout::addToolBar(QInternal::DockPosition pos, QToolBar *toolBar) | - | ||||||||||||||||||||||||
824 | { | - | ||||||||||||||||||||||||
825 | return docks[pos].insertToolBar(0, toolBar); never executed: return docks[pos].insertToolBar(0, toolBar); | 0 | ||||||||||||||||||||||||
826 | } | - | ||||||||||||||||||||||||
827 | - | |||||||||||||||||||||||||
828 | void QToolBarAreaLayout::insertToolBarBreak(QToolBar *before) | - | ||||||||||||||||||||||||
829 | { | - | ||||||||||||||||||||||||
830 | QInternal::DockPosition pos = findToolBar(before); | - | ||||||||||||||||||||||||
831 | if (pos == QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
832 | return; never executed: return; | 0 | ||||||||||||||||||||||||
833 | docks[pos].insertToolBarBreak(before); | - | ||||||||||||||||||||||||
834 | } never executed: end of block | 0 | ||||||||||||||||||||||||
835 | - | |||||||||||||||||||||||||
836 | void QToolBarAreaLayout::removeToolBarBreak(QToolBar *before) | - | ||||||||||||||||||||||||
837 | { | - | ||||||||||||||||||||||||
838 | QInternal::DockPosition pos = findToolBar(before); | - | ||||||||||||||||||||||||
839 | if (pos == QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
840 | return; never executed: return; | 0 | ||||||||||||||||||||||||
841 | docks[pos].removeToolBarBreak(before); | - | ||||||||||||||||||||||||
842 | } never executed: end of block | 0 | ||||||||||||||||||||||||
843 | - | |||||||||||||||||||||||||
844 | void QToolBarAreaLayout::addToolBarBreak(QInternal::DockPosition pos) | - | ||||||||||||||||||||||||
845 | { | - | ||||||||||||||||||||||||
846 | docks[pos].insertToolBarBreak(0); | - | ||||||||||||||||||||||||
847 | } never executed: end of block | 0 | ||||||||||||||||||||||||
848 | - | |||||||||||||||||||||||||
849 | void QToolBarAreaLayout::moveToolBar(QToolBar *toolbar, int p) | - | ||||||||||||||||||||||||
850 | { | - | ||||||||||||||||||||||||
851 | QInternal::DockPosition pos = findToolBar(toolbar); | - | ||||||||||||||||||||||||
852 | if (pos == QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
853 | return; never executed: return; | 0 | ||||||||||||||||||||||||
854 | docks[pos].moveToolBar(toolbar, p); | - | ||||||||||||||||||||||||
855 | } never executed: end of block | 0 | ||||||||||||||||||||||||
856 | - | |||||||||||||||||||||||||
857 | - | |||||||||||||||||||||||||
858 | void QToolBarAreaLayout::insertItem(QInternal::DockPosition pos, QLayoutItem *item) | - | ||||||||||||||||||||||||
859 | { | - | ||||||||||||||||||||||||
860 | if (docks[pos].lines.isEmpty())
| 0 | ||||||||||||||||||||||||
861 | docks[pos].lines.append(QToolBarAreaLayoutLine(docks[pos].o)); never executed: docks[pos].lines.append(QToolBarAreaLayoutLine(docks[pos].o)); | 0 | ||||||||||||||||||||||||
862 | docks[pos].lines.last().toolBarItems.append(item); | - | ||||||||||||||||||||||||
863 | } never executed: end of block | 0 | ||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||
865 | void QToolBarAreaLayout::insertItem(QToolBar *before, QLayoutItem *item) | - | ||||||||||||||||||||||||
866 | { | - | ||||||||||||||||||||||||
867 | QInternal::DockPosition pos = findToolBar(before); | - | ||||||||||||||||||||||||
868 | if (pos == QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
869 | return; never executed: return; | 0 | ||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||
871 | docks[pos].insertItem(before, item); | - | ||||||||||||||||||||||||
872 | } never executed: end of block | 0 | ||||||||||||||||||||||||
873 | - | |||||||||||||||||||||||||
874 | void QToolBarAreaLayout::apply(bool animate) | - | ||||||||||||||||||||||||
875 | { | - | ||||||||||||||||||||||||
876 | QMainWindowLayout *layout = qt_mainwindow_layout(mainWindow); | - | ||||||||||||||||||||||||
877 | Q_ASSERT(layout != 0); | - | ||||||||||||||||||||||||
878 | - | |||||||||||||||||||||||||
879 | Qt::LayoutDirection dir = mainWindow->layoutDirection(); | - | ||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||
881 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
882 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
883 | - | |||||||||||||||||||||||||
884 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
885 | const QToolBarAreaLayoutLine &line = dock.lines.at(j); | - | ||||||||||||||||||||||||
886 | if (line.skip())
| 0 | ||||||||||||||||||||||||
887 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
890 | const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); | - | ||||||||||||||||||||||||
891 | if (item.skip() || item.gap)
| 0 | ||||||||||||||||||||||||
892 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
893 | - | |||||||||||||||||||||||||
894 | QRect geo; | - | ||||||||||||||||||||||||
895 | if (visible) {
| 0 | ||||||||||||||||||||||||
896 | if (line.o == Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
897 | geo.setTop(line.rect.top()); | - | ||||||||||||||||||||||||
898 | geo.setBottom(line.rect.bottom()); | - | ||||||||||||||||||||||||
899 | geo.setLeft(line.rect.left() + item.pos); | - | ||||||||||||||||||||||||
900 | geo.setRight(line.rect.left() + item.pos + item.size - 1); | - | ||||||||||||||||||||||||
901 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
902 | geo.setLeft(line.rect.left()); | - | ||||||||||||||||||||||||
903 | geo.setRight(line.rect.right()); | - | ||||||||||||||||||||||||
904 | geo.setTop(line.rect.top() + item.pos); | - | ||||||||||||||||||||||||
905 | geo.setBottom(line.rect.top() + item.pos + item.size - 1); | - | ||||||||||||||||||||||||
906 | } never executed: end of block | 0 | ||||||||||||||||||||||||
907 | } | - | ||||||||||||||||||||||||
908 | - | |||||||||||||||||||||||||
909 | QWidget *widget = item.widgetItem->widget(); | - | ||||||||||||||||||||||||
910 | if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) {
| 0 | ||||||||||||||||||||||||
911 | QToolBarLayout *tbl = qobject_cast<QToolBarLayout*>(toolBar->layout()); | - | ||||||||||||||||||||||||
912 | if (tbl->expanded) {
| 0 | ||||||||||||||||||||||||
913 | QPoint tr = geo.topRight(); | - | ||||||||||||||||||||||||
914 | QSize size = tbl->expandedSize(geo.size()); | - | ||||||||||||||||||||||||
915 | geo.setSize(size); | - | ||||||||||||||||||||||||
916 | geo.moveTopRight(tr); | - | ||||||||||||||||||||||||
917 | if (geo.bottom() > rect.bottom())
| 0 | ||||||||||||||||||||||||
918 | geo.moveBottom(rect.bottom()); never executed: geo.moveBottom(rect.bottom()); | 0 | ||||||||||||||||||||||||
919 | if (geo.right() > rect.right())
| 0 | ||||||||||||||||||||||||
920 | geo.moveRight(rect.right()); never executed: geo.moveRight(rect.right()); | 0 | ||||||||||||||||||||||||
921 | if (geo.left() < 0)
| 0 | ||||||||||||||||||||||||
922 | geo.moveLeft(0); never executed: geo.moveLeft(0); | 0 | ||||||||||||||||||||||||
923 | if (geo.top() < 0)
| 0 | ||||||||||||||||||||||||
924 | geo.moveTop(0); never executed: geo.moveTop(0); | 0 | ||||||||||||||||||||||||
925 | } never executed: end of block | 0 | ||||||||||||||||||||||||
926 | } never executed: end of block | 0 | ||||||||||||||||||||||||
927 | - | |||||||||||||||||||||||||
928 | if (visible && dock.o == Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
929 | geo = QStyle::visualRect(dir, line.rect, geo); never executed: geo = QStyle::visualRect(dir, line.rect, geo); | 0 | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | layout->widgetAnimator.animate(widget, geo, animate); | - | ||||||||||||||||||||||||
932 | } never executed: end of block | 0 | ||||||||||||||||||||||||
933 | } never executed: end of block | 0 | ||||||||||||||||||||||||
934 | } never executed: end of block | 0 | ||||||||||||||||||||||||
935 | } never executed: end of block | 0 | ||||||||||||||||||||||||
936 | - | |||||||||||||||||||||||||
937 | bool QToolBarAreaLayout::toolBarBreak(QToolBar *toolBar) const | - | ||||||||||||||||||||||||
938 | { | - | ||||||||||||||||||||||||
939 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
940 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
941 | - | |||||||||||||||||||||||||
942 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
943 | const QToolBarAreaLayoutLine &line = dock.lines.at(j); | - | ||||||||||||||||||||||||
944 | - | |||||||||||||||||||||||||
945 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
946 | if (line.toolBarItems.at(k).widgetItem->widget() == toolBar)
| 0 | ||||||||||||||||||||||||
947 | return j > 0 && k == 0; never executed: return j > 0 && k == 0;
| 0 | ||||||||||||||||||||||||
948 | } never executed: end of block | 0 | ||||||||||||||||||||||||
949 | } never executed: end of block | 0 | ||||||||||||||||||||||||
950 | } never executed: end of block | 0 | ||||||||||||||||||||||||
951 | - | |||||||||||||||||||||||||
952 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
953 | } | - | ||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||
955 | void QToolBarAreaLayout::getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const | - | ||||||||||||||||||||||||
956 | { | - | ||||||||||||||||||||||||
957 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
958 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
959 | - | |||||||||||||||||||||||||
960 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
961 | const QToolBarAreaLayoutLine &line = dock.lines.at(j); | - | ||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||
963 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
964 | if (line.toolBarItems.at(k).widgetItem->widget() == toolBar) {
| 0 | ||||||||||||||||||||||||
965 | if (line.toolBarItems.count() == 1)
| 0 | ||||||||||||||||||||||||
966 | option->positionWithinLine = QStyleOptionToolBar::OnlyOne; never executed: option->positionWithinLine = QStyleOptionToolBar::OnlyOne; | 0 | ||||||||||||||||||||||||
967 | else if (k == 0)
| 0 | ||||||||||||||||||||||||
968 | option->positionWithinLine = QStyleOptionToolBar::Beginning; never executed: option->positionWithinLine = QStyleOptionToolBar::Beginning; | 0 | ||||||||||||||||||||||||
969 | else if (k == line.toolBarItems.count() - 1)
| 0 | ||||||||||||||||||||||||
970 | option->positionWithinLine = QStyleOptionToolBar::End; never executed: option->positionWithinLine = QStyleOptionToolBar::End; | 0 | ||||||||||||||||||||||||
971 | else | - | ||||||||||||||||||||||||
972 | option->positionWithinLine = QStyleOptionToolBar::Middle; never executed: option->positionWithinLine = QStyleOptionToolBar::Middle; | 0 | ||||||||||||||||||||||||
973 | - | |||||||||||||||||||||||||
974 | if (dock.lines.count() == 1)
| 0 | ||||||||||||||||||||||||
975 | option->positionOfLine = QStyleOptionToolBar::OnlyOne; never executed: option->positionOfLine = QStyleOptionToolBar::OnlyOne; | 0 | ||||||||||||||||||||||||
976 | else if (j == 0)
| 0 | ||||||||||||||||||||||||
977 | option->positionOfLine = QStyleOptionToolBar::Beginning; never executed: option->positionOfLine = QStyleOptionToolBar::Beginning; | 0 | ||||||||||||||||||||||||
978 | else if (j == dock.lines.count() - 1)
| 0 | ||||||||||||||||||||||||
979 | option->positionOfLine = QStyleOptionToolBar::End; never executed: option->positionOfLine = QStyleOptionToolBar::End; | 0 | ||||||||||||||||||||||||
980 | else | - | ||||||||||||||||||||||||
981 | option->positionOfLine = QStyleOptionToolBar::Middle; never executed: option->positionOfLine = QStyleOptionToolBar::Middle; | 0 | ||||||||||||||||||||||||
982 | - | |||||||||||||||||||||||||
983 | return; never executed: return; | 0 | ||||||||||||||||||||||||
984 | } | - | ||||||||||||||||||||||||
985 | } never executed: end of block | 0 | ||||||||||||||||||||||||
986 | } never executed: end of block | 0 | ||||||||||||||||||||||||
987 | } never executed: end of block | 0 | ||||||||||||||||||||||||
988 | } never executed: end of block | 0 | ||||||||||||||||||||||||
989 | - | |||||||||||||||||||||||||
990 | QList<int> QToolBarAreaLayout::indexOf(QWidget *toolBar) const | - | ||||||||||||||||||||||||
991 | { | - | ||||||||||||||||||||||||
992 | QList<int> result; | - | ||||||||||||||||||||||||
993 | - | |||||||||||||||||||||||||
994 | bool found = false; | - | ||||||||||||||||||||||||
995 | - | |||||||||||||||||||||||||
996 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
997 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
998 | - | |||||||||||||||||||||||||
999 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
1000 | const QToolBarAreaLayoutLine &line = dock.lines.at(j); | - | ||||||||||||||||||||||||
1001 | - | |||||||||||||||||||||||||
1002 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
1003 | const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); | - | ||||||||||||||||||||||||
1004 | if (!item.gap && item.widgetItem->widget() == toolBar) {
| 0 | ||||||||||||||||||||||||
1005 | found = true; | - | ||||||||||||||||||||||||
1006 | result.prepend(k); | - | ||||||||||||||||||||||||
1007 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1008 | } | - | ||||||||||||||||||||||||
1009 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1010 | - | |||||||||||||||||||||||||
1011 | if (found) {
| 0 | ||||||||||||||||||||||||
1012 | result.prepend(j); | - | ||||||||||||||||||||||||
1013 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1014 | } | - | ||||||||||||||||||||||||
1015 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1016 | - | |||||||||||||||||||||||||
1017 | if (found) {
| 0 | ||||||||||||||||||||||||
1018 | result.prepend(i); | - | ||||||||||||||||||||||||
1019 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1020 | } | - | ||||||||||||||||||||||||
1021 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1022 | - | |||||||||||||||||||||||||
1023 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
1024 | } | - | ||||||||||||||||||||||||
1025 | - | |||||||||||||||||||||||||
1026 | //this functions returns the path to the possible gapindex for the position pos | - | ||||||||||||||||||||||||
1027 | QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const | - | ||||||||||||||||||||||||
1028 | { | - | ||||||||||||||||||||||||
1029 | Qt::LayoutDirection dir = mainWindow->layoutDirection(); | - | ||||||||||||||||||||||||
1030 | int minDistance = 80; // when a dock area is empty, how "wide" is it? | - | ||||||||||||||||||||||||
1031 | QList<int> ret; //return value | - | ||||||||||||||||||||||||
1032 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
1033 | QPoint p = pos; | - | ||||||||||||||||||||||||
1034 | if (docks[i].o == Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
1035 | p = QStyle::visualPos(dir, docks[i].rect, p); never executed: p = QStyle::visualPos(dir, docks[i].rect, p); | 0 | ||||||||||||||||||||||||
1036 | QList<int> result = docks[i].gapIndex(p, &minDistance); | - | ||||||||||||||||||||||||
1037 | if (!result.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1038 | result.prepend(i); | - | ||||||||||||||||||||||||
1039 | ret = result; | - | ||||||||||||||||||||||||
1040 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1041 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1042 | - | |||||||||||||||||||||||||
1043 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
1044 | } | - | ||||||||||||||||||||||||
1045 | - | |||||||||||||||||||||||||
1046 | QList<int> QToolBarAreaLayout::currentGapIndex() const | - | ||||||||||||||||||||||||
1047 | { | - | ||||||||||||||||||||||||
1048 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
1049 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
1050 | - | |||||||||||||||||||||||||
1051 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
1052 | const QToolBarAreaLayoutLine &line = dock.lines[j]; | - | ||||||||||||||||||||||||
1053 | - | |||||||||||||||||||||||||
1054 | for (int k = 0; k < line.toolBarItems.count(); k++) {
| 0 | ||||||||||||||||||||||||
1055 | if (line.toolBarItems[k].gap) {
| 0 | ||||||||||||||||||||||||
1056 | QList<int> result; | - | ||||||||||||||||||||||||
1057 | result << i << j << k; | - | ||||||||||||||||||||||||
1058 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
1059 | } | - | ||||||||||||||||||||||||
1060 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1061 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1062 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1063 | return QList<int>(); never executed: return QList<int>(); | 0 | ||||||||||||||||||||||||
1064 | } | - | ||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item) | - | ||||||||||||||||||||||||
1067 | { | - | ||||||||||||||||||||||||
1068 | Q_ASSERT(path.count() == 3); | - | ||||||||||||||||||||||||
1069 | const int i = path.first(); | - | ||||||||||||||||||||||||
1070 | Q_ASSERT(i >= 0 && i < QInternal::DockCount); | - | ||||||||||||||||||||||||
1071 | return docks[i].insertGap(path.mid(1), item); never executed: return docks[i].insertGap(path.mid(1), item); | 0 | ||||||||||||||||||||||||
1072 | } | - | ||||||||||||||||||||||||
1073 | - | |||||||||||||||||||||||||
1074 | void QToolBarAreaLayout::remove(const QList<int> &path) | - | ||||||||||||||||||||||||
1075 | { | - | ||||||||||||||||||||||||
1076 | Q_ASSERT(path.count() == 3); | - | ||||||||||||||||||||||||
1077 | docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2)); | - | ||||||||||||||||||||||||
1078 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1079 | - | |||||||||||||||||||||||||
1080 | void QToolBarAreaLayout::remove(QLayoutItem *item) | - | ||||||||||||||||||||||||
1081 | { | - | ||||||||||||||||||||||||
1082 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
1083 | QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
1084 | - | |||||||||||||||||||||||||
1085 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
1086 | QToolBarAreaLayoutLine &line = dock.lines[j]; | - | ||||||||||||||||||||||||
1087 | - | |||||||||||||||||||||||||
1088 | for (int k = 0; k < line.toolBarItems.count(); k++) {
| 0 | ||||||||||||||||||||||||
1089 | if (line.toolBarItems[k].widgetItem == item) {
| 0 | ||||||||||||||||||||||||
1090 | line.toolBarItems.removeAt(k); | - | ||||||||||||||||||||||||
1091 | if (line.toolBarItems.isEmpty())
| 0 | ||||||||||||||||||||||||
1092 | dock.lines.removeAt(j); never executed: dock.lines.removeAt(j); | 0 | ||||||||||||||||||||||||
1093 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1094 | } | - | ||||||||||||||||||||||||
1095 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1096 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1097 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1098 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1099 | - | |||||||||||||||||||||||||
1100 | void QToolBarAreaLayout::clear() | - | ||||||||||||||||||||||||
1101 | { | - | ||||||||||||||||||||||||
1102 | for (int i = 0; i < QInternal::DockCount; ++i)
| 0 | ||||||||||||||||||||||||
1103 | docks[i].clear(); never executed: docks[i].clear(); | 0 | ||||||||||||||||||||||||
1104 | rect = QRect(); | - | ||||||||||||||||||||||||
1105 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1106 | - | |||||||||||||||||||||||||
1107 | QToolBarAreaLayoutItem *QToolBarAreaLayout::item(const QList<int> &path) | - | ||||||||||||||||||||||||
1108 | { | - | ||||||||||||||||||||||||
1109 | Q_ASSERT(path.count() == 3); | - | ||||||||||||||||||||||||
1110 | - | |||||||||||||||||||||||||
1111 | if (path.at(0) < 0 || path.at(0) >= QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
1112 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1113 | QToolBarAreaLayoutInfo &info = docks[path.at(0)]; | - | ||||||||||||||||||||||||
1114 | if (path.at(1) < 0 || path.at(1) >= info.lines.count())
| 0 | ||||||||||||||||||||||||
1115 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1116 | QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; | - | ||||||||||||||||||||||||
1117 | if (path.at(2) < 0 || path.at(2) >= line.toolBarItems.count())
| 0 | ||||||||||||||||||||||||
1118 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1119 | return &(line.toolBarItems[path.at(2)]); never executed: return &(line.toolBarItems[path.at(2)]); | 0 | ||||||||||||||||||||||||
1120 | } | - | ||||||||||||||||||||||||
1121 | - | |||||||||||||||||||||||||
1122 | QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const | - | ||||||||||||||||||||||||
1123 | { | - | ||||||||||||||||||||||||
1124 | const int i = path.first(); | - | ||||||||||||||||||||||||
1125 | - | |||||||||||||||||||||||||
1126 | QRect r = docks[i].itemRect(path.mid(1)); | - | ||||||||||||||||||||||||
1127 | if (docks[i].o == Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
1128 | r = QStyle::visualRect(mainWindow->layoutDirection(), never executed: r = QStyle::visualRect(mainWindow->layoutDirection(), docks[i].rect, r); | 0 | ||||||||||||||||||||||||
1129 | docks[i].rect, r); never executed: r = QStyle::visualRect(mainWindow->layoutDirection(), docks[i].rect, r); | 0 | ||||||||||||||||||||||||
1130 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
1131 | } | - | ||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||
1133 | QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path) | - | ||||||||||||||||||||||||
1134 | { | - | ||||||||||||||||||||||||
1135 | QToolBarAreaLayoutItem *item = this->item(path); | - | ||||||||||||||||||||||||
1136 | if (!item) {
| 0 | ||||||||||||||||||||||||
1137 | qWarning() << "No item at" << path; | - | ||||||||||||||||||||||||
1138 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1139 | } | - | ||||||||||||||||||||||||
1140 | Q_ASSERT(item->gap); | - | ||||||||||||||||||||||||
1141 | Q_ASSERT(item->widgetItem != 0); | - | ||||||||||||||||||||||||
1142 | item->gap = false; | - | ||||||||||||||||||||||||
1143 | return item->widgetItem; never executed: return item->widgetItem; | 0 | ||||||||||||||||||||||||
1144 | } | - | ||||||||||||||||||||||||
1145 | - | |||||||||||||||||||||||||
1146 | QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other) | - | ||||||||||||||||||||||||
1147 | { | - | ||||||||||||||||||||||||
1148 | //other needs to be update as well | - | ||||||||||||||||||||||||
1149 | Q_ASSERT(path.count() == 3); | - | ||||||||||||||||||||||||
1150 | QToolBarAreaLayoutItem *item = this->item(path); | - | ||||||||||||||||||||||||
1151 | Q_ASSERT(item); | - | ||||||||||||||||||||||||
1152 | - | |||||||||||||||||||||||||
1153 | //update the leading space here | - | ||||||||||||||||||||||||
1154 | QToolBarAreaLayoutInfo &info = docks[path.at(0)]; | - | ||||||||||||||||||||||||
1155 | QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; | - | ||||||||||||||||||||||||
1156 | if (item->size != pick(line.o, item->realSizeHint())) {
| 0 | ||||||||||||||||||||||||
1157 | //the item doesn't have its default size | - | ||||||||||||||||||||||||
1158 | //so we'll give this to the next item | - | ||||||||||||||||||||||||
1159 | int newExtraSpace = 0; | - | ||||||||||||||||||||||||
1160 | //let's iterate over the siblings of the current item that pare placed before it | - | ||||||||||||||||||||||||
1161 | //we need to find just the one before | - | ||||||||||||||||||||||||
1162 | for (int i = path.at(2) - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
1163 | QToolBarAreaLayoutItem &previous = line.toolBarItems[i]; | - | ||||||||||||||||||||||||
1164 | if (!previous.skip()) {
| 0 | ||||||||||||||||||||||||
1165 | //we need to check if it has a previous element and a next one | - | ||||||||||||||||||||||||
1166 | //the previous will get its size changed | - | ||||||||||||||||||||||||
1167 | for (int j = path.at(2) + 1; j < line.toolBarItems.count(); ++j) {
| 0 | ||||||||||||||||||||||||
1168 | const QToolBarAreaLayoutItem &next = line.toolBarItems.at(j); | - | ||||||||||||||||||||||||
1169 | if (!next.skip()) {
| 0 | ||||||||||||||||||||||||
1170 | newExtraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint()); | - | ||||||||||||||||||||||||
1171 | previous.resize(line.o, next.pos - previous.pos); | - | ||||||||||||||||||||||||
1172 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1173 | } | - | ||||||||||||||||||||||||
1174 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1175 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1176 | } | - | ||||||||||||||||||||||||
1177 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1178 | - | |||||||||||||||||||||||||
1179 | if (other) {
| 0 | ||||||||||||||||||||||||
1180 | QToolBarAreaLayoutInfo &info = other->docks[path.at(0)]; | - | ||||||||||||||||||||||||
1181 | QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; | - | ||||||||||||||||||||||||
1182 | for (int i = path.at(2) - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
1183 | QToolBarAreaLayoutItem &previous = line.toolBarItems[i]; | - | ||||||||||||||||||||||||
1184 | if (!previous.skip()) {
| 0 | ||||||||||||||||||||||||
1185 | previous.resize(line.o, pick(line.o, previous.sizeHint()) + newExtraSpace); | - | ||||||||||||||||||||||||
1186 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1187 | } | - | ||||||||||||||||||||||||
1188 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1189 | - | |||||||||||||||||||||||||
1190 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1191 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1192 | - | |||||||||||||||||||||||||
1193 | Q_ASSERT(!item->gap); | - | ||||||||||||||||||||||||
1194 | item->gap = true; | - | ||||||||||||||||||||||||
1195 | return item->widgetItem; never executed: return item->widgetItem; | 0 | ||||||||||||||||||||||||
1196 | } | - | ||||||||||||||||||||||||
1197 | - | |||||||||||||||||||||||||
1198 | static QRect unpackRect(uint geom0, uint geom1, bool *floating) | - | ||||||||||||||||||||||||
1199 | { | - | ||||||||||||||||||||||||
1200 | *floating = geom0 & 1; | - | ||||||||||||||||||||||||
1201 | if (!*floating)
| 0 | ||||||||||||||||||||||||
1202 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||||||||
1203 | - | |||||||||||||||||||||||||
1204 | geom0 >>= 1; | - | ||||||||||||||||||||||||
1205 | - | |||||||||||||||||||||||||
1206 | int x = (int)(geom0 & 0x0000ffff) - 0x7FFF; | - | ||||||||||||||||||||||||
1207 | int y = (int)(geom1 & 0x0000ffff) - 0x7FFF; | - | ||||||||||||||||||||||||
1208 | - | |||||||||||||||||||||||||
1209 | geom0 >>= 16; | - | ||||||||||||||||||||||||
1210 | geom1 >>= 16; | - | ||||||||||||||||||||||||
1211 | - | |||||||||||||||||||||||||
1212 | int w = geom0 & 0x0000ffff; | - | ||||||||||||||||||||||||
1213 | int h = geom1 & 0x0000ffff; | - | ||||||||||||||||||||||||
1214 | - | |||||||||||||||||||||||||
1215 | return QRect(x, y, w, h); never executed: return QRect(x, y, w, h); | 0 | ||||||||||||||||||||||||
1216 | } | - | ||||||||||||||||||||||||
1217 | - | |||||||||||||||||||||||||
1218 | static void packRect(uint *geom0, uint *geom1, const QRect &rect, bool floating) | - | ||||||||||||||||||||||||
1219 | { | - | ||||||||||||||||||||||||
1220 | *geom0 = 0; | - | ||||||||||||||||||||||||
1221 | *geom1 = 0; | - | ||||||||||||||||||||||||
1222 | - | |||||||||||||||||||||||||
1223 | if (!floating)
| 0 | ||||||||||||||||||||||||
1224 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1225 | - | |||||||||||||||||||||||||
1226 | // The 0x7FFF is half of 0xFFFF. We add it so we can handle negative coordinates on | - | ||||||||||||||||||||||||
1227 | // dual monitors. It's subtracted when unpacking. | - | ||||||||||||||||||||||||
1228 | - | |||||||||||||||||||||||||
1229 | *geom0 |= qMax(0, rect.width()) & 0x0000ffff; | - | ||||||||||||||||||||||||
1230 | *geom1 |= qMax(0, rect.height()) & 0x0000ffff; | - | ||||||||||||||||||||||||
1231 | - | |||||||||||||||||||||||||
1232 | *geom0 <<= 16; | - | ||||||||||||||||||||||||
1233 | *geom1 <<= 16; | - | ||||||||||||||||||||||||
1234 | - | |||||||||||||||||||||||||
1235 | *geom0 |= qMax(0, rect.x() + 0x7FFF) & 0x0000ffff; | - | ||||||||||||||||||||||||
1236 | *geom1 |= qMax(0, rect.y() + 0x7FFF) & 0x0000ffff; | - | ||||||||||||||||||||||||
1237 | - | |||||||||||||||||||||||||
1238 | // yeah, we chop one bit off the width, but it still has a range up to 32512 | - | ||||||||||||||||||||||||
1239 | - | |||||||||||||||||||||||||
1240 | *geom0 <<= 1; | - | ||||||||||||||||||||||||
1241 | *geom0 |= 1; | - | ||||||||||||||||||||||||
1242 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1243 | - | |||||||||||||||||||||||||
1244 | - | |||||||||||||||||||||||||
1245 | void QToolBarAreaLayout::saveState(QDataStream &stream) const | - | ||||||||||||||||||||||||
1246 | { | - | ||||||||||||||||||||||||
1247 | // save toolbar state | - | ||||||||||||||||||||||||
1248 | stream << (uchar) ToolBarStateMarkerEx; | - | ||||||||||||||||||||||||
1249 | - | |||||||||||||||||||||||||
1250 | int lineCount = 0; | - | ||||||||||||||||||||||||
1251 | for (int i = 0; i < QInternal::DockCount; ++i)
| 0 | ||||||||||||||||||||||||
1252 | lineCount += docks[i].lines.count(); never executed: lineCount += docks[i].lines.count(); | 0 | ||||||||||||||||||||||||
1253 | - | |||||||||||||||||||||||||
1254 | stream << lineCount; | - | ||||||||||||||||||||||||
1255 | - | |||||||||||||||||||||||||
1256 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
1257 | const QToolBarAreaLayoutInfo &dock = docks[i]; | - | ||||||||||||||||||||||||
1258 | - | |||||||||||||||||||||||||
1259 | for (int j = 0; j < dock.lines.count(); ++j) {
| 0 | ||||||||||||||||||||||||
1260 | const QToolBarAreaLayoutLine &line = dock.lines.at(j); | - | ||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||
1262 | stream << i << line.toolBarItems.count(); | - | ||||||||||||||||||||||||
1263 | - | |||||||||||||||||||||||||
1264 | for (int k = 0; k < line.toolBarItems.count(); ++k) {
| 0 | ||||||||||||||||||||||||
1265 | const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); | - | ||||||||||||||||||||||||
1266 | QWidget *widget = const_cast<QLayoutItem*>(item.widgetItem)->widget(); | - | ||||||||||||||||||||||||
1267 | QString objectName = widget->objectName(); | - | ||||||||||||||||||||||||
1268 | if (objectName.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1269 | qWarning("QMainWindow::saveState(): 'objectName' not set for QToolBar %p '%s'", | - | ||||||||||||||||||||||||
1270 | widget, widget->windowTitle().toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
1271 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1272 | stream << objectName; | - | ||||||||||||||||||||||||
1273 | // we store information as: | - | ||||||||||||||||||||||||
1274 | // 1st bit: 1 if shown | - | ||||||||||||||||||||||||
1275 | // 2nd bit: 1 if orientation is vertical (default is horizontal) | - | ||||||||||||||||||||||||
1276 | uchar shownOrientation = (uchar)!widget->isHidden(); | - | ||||||||||||||||||||||||
1277 | if (QToolBar * tb= qobject_cast<QToolBar*>(widget)) {
| 0 | ||||||||||||||||||||||||
1278 | if (tb->orientation() == Qt::Vertical)
| 0 | ||||||||||||||||||||||||
1279 | shownOrientation |= 2; never executed: shownOrientation |= 2; | 0 | ||||||||||||||||||||||||
1280 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1281 | stream << shownOrientation; | - | ||||||||||||||||||||||||
1282 | stream << item.pos; | - | ||||||||||||||||||||||||
1283 | //we store the preferred size. If the use rdidn't resize the toolbars it will be -1 | - | ||||||||||||||||||||||||
1284 | stream << item.preferredSize; | - | ||||||||||||||||||||||||
1285 | - | |||||||||||||||||||||||||
1286 | uint geom0, geom1; | - | ||||||||||||||||||||||||
1287 | packRect(&geom0, &geom1, widget->geometry(), widget->isWindow()); | - | ||||||||||||||||||||||||
1288 | stream << geom0 << geom1; | - | ||||||||||||||||||||||||
1289 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1290 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1291 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1292 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1293 | - | |||||||||||||||||||||||||
1294 | static inline int getInt(QDataStream &stream) | - | ||||||||||||||||||||||||
1295 | { | - | ||||||||||||||||||||||||
1296 | int x; | - | ||||||||||||||||||||||||
1297 | stream >> x; | - | ||||||||||||||||||||||||
1298 | return x; never executed: return x; | 0 | ||||||||||||||||||||||||
1299 | } | - | ||||||||||||||||||||||||
1300 | - | |||||||||||||||||||||||||
1301 | - | |||||||||||||||||||||||||
1302 | bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*> &_toolBars, uchar tmarker, bool testing) | - | ||||||||||||||||||||||||
1303 | { | - | ||||||||||||||||||||||||
1304 | QList<QToolBar*> toolBars = _toolBars; | - | ||||||||||||||||||||||||
1305 | int lines; | - | ||||||||||||||||||||||||
1306 | stream >> lines; | - | ||||||||||||||||||||||||
1307 | - | |||||||||||||||||||||||||
1308 | for (int j = 0; j < lines; ++j) {
| 0 | ||||||||||||||||||||||||
1309 | int pos; | - | ||||||||||||||||||||||||
1310 | stream >> pos; | - | ||||||||||||||||||||||||
1311 | if (pos < 0 || pos >= QInternal::DockCount)
| 0 | ||||||||||||||||||||||||
1312 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1313 | int cnt; | - | ||||||||||||||||||||||||
1314 | stream >> cnt; | - | ||||||||||||||||||||||||
1315 | - | |||||||||||||||||||||||||
1316 | QToolBarAreaLayoutInfo &dock = docks[pos]; | - | ||||||||||||||||||||||||
1317 | const bool applyingLayout = !testing; | - | ||||||||||||||||||||||||
1318 | QToolBarAreaLayoutLine line(dock.o); | - | ||||||||||||||||||||||||
1319 | - | |||||||||||||||||||||||||
1320 | for (int k = 0; k < cnt; ++k) {
| 0 | ||||||||||||||||||||||||
1321 | QToolBarAreaLayoutItem item; | - | ||||||||||||||||||||||||
1322 | - | |||||||||||||||||||||||||
1323 | QString objectName; | - | ||||||||||||||||||||||||
1324 | stream >> objectName; | - | ||||||||||||||||||||||||
1325 | uchar shown; | - | ||||||||||||||||||||||||
1326 | stream >> shown; | - | ||||||||||||||||||||||||
1327 | item.pos = getInt(stream); | - | ||||||||||||||||||||||||
1328 | item.size = getInt(stream); | - | ||||||||||||||||||||||||
1329 | - | |||||||||||||||||||||||||
1330 | /* | - | ||||||||||||||||||||||||
1331 | 4.3.0 added floating toolbars, but failed to add the ability to restore them. | - | ||||||||||||||||||||||||
1332 | We need to store there geometry (four ints). We cannot change the format in a | - | ||||||||||||||||||||||||
1333 | patch release (4.3.1) by adding ToolBarStateMarkerEx2 to signal extra data. So | - | ||||||||||||||||||||||||
1334 | for now we'll pack it in the two legacy ints we no longer used in Qt4.3.0. | - | ||||||||||||||||||||||||
1335 | In 4.4, we should add ToolBarStateMarkerEx2 and fix this properly. | - | ||||||||||||||||||||||||
1336 | */ | - | ||||||||||||||||||||||||
1337 | - | |||||||||||||||||||||||||
1338 | QRect rect; | - | ||||||||||||||||||||||||
1339 | bool floating = false; | - | ||||||||||||||||||||||||
1340 | uint geom0, geom1; | - | ||||||||||||||||||||||||
1341 | geom0 = getInt(stream); | - | ||||||||||||||||||||||||
1342 | if (tmarker == ToolBarStateMarkerEx) {
| 0 | ||||||||||||||||||||||||
1343 | geom1 = getInt(stream); | - | ||||||||||||||||||||||||
1344 | rect = unpackRect(geom0, geom1, &floating); | - | ||||||||||||||||||||||||
1345 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1346 | - | |||||||||||||||||||||||||
1347 | QToolBar *toolBar = 0; | - | ||||||||||||||||||||||||
1348 | for (int x = 0; x < toolBars.count(); ++x) {
| 0 | ||||||||||||||||||||||||
1349 | if (toolBars.at(x)->objectName() == objectName) {
| 0 | ||||||||||||||||||||||||
1350 | toolBar = toolBars.takeAt(x); | - | ||||||||||||||||||||||||
1351 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1352 | } | - | ||||||||||||||||||||||||
1353 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1354 | if (toolBar == 0) {
| 0 | ||||||||||||||||||||||||
1355 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
1356 | } | - | ||||||||||||||||||||||||
1357 | - | |||||||||||||||||||||||||
1358 | if (applyingLayout) {
| 0 | ||||||||||||||||||||||||
1359 | item.widgetItem = new QWidgetItemV2(toolBar); | - | ||||||||||||||||||||||||
1360 | toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o); | - | ||||||||||||||||||||||||
1361 | toolBar->setVisible(shown & 1); | - | ||||||||||||||||||||||||
1362 | toolBar->d_func()->setWindowState(floating, true, rect); | - | ||||||||||||||||||||||||
1363 | - | |||||||||||||||||||||||||
1364 | item.preferredSize = item.size; | - | ||||||||||||||||||||||||
1365 | line.toolBarItems.append(item); | - | ||||||||||||||||||||||||
1366 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1367 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1368 | - | |||||||||||||||||||||||||
1369 | if (applyingLayout) {
| 0 | ||||||||||||||||||||||||
1370 | dock.lines.append(line); | - | ||||||||||||||||||||||||
1371 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1372 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1373 | - | |||||||||||||||||||||||||
1374 | - | |||||||||||||||||||||||||
1375 | return stream.status() == QDataStream::Ok; never executed: return stream.status() == QDataStream::Ok; | 0 | ||||||||||||||||||||||||
1376 | } | - | ||||||||||||||||||||||||
1377 | - | |||||||||||||||||||||||||
1378 | bool QToolBarAreaLayout::isEmpty() const | - | ||||||||||||||||||||||||
1379 | { | - | ||||||||||||||||||||||||
1380 | for (int i = 0; i < QInternal::DockCount; ++i) {
| 0 | ||||||||||||||||||||||||
1381 | if (!docks[i].lines.isEmpty())
| 0 | ||||||||||||||||||||||||
1382 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1383 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1384 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
1385 | } | - | ||||||||||||||||||||||||
1386 | - | |||||||||||||||||||||||||
1387 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
1388 | - | |||||||||||||||||||||||||
1389 | #endif // QT_NO_TOOLBAR | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |