qtoolbarlayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qtoolbarlayout.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 <qapplication.h>-
35#include <qaction.h>-
36#include <qwidgetaction.h>-
37#include <qtoolbar.h>-
38#include <qstyleoption.h>-
39#include <qtoolbutton.h>-
40#include <qmenu.h>-
41#include <qdebug.h>-
42#include <qmath.h>-
43#ifdef Q_OS_OSX-
44#include <qpa/qplatformnativeinterface.h>-
45#endif-
46-
47#include "qmainwindowlayout_p.h"-
48#include "qtoolbarextension_p.h"-
49#include "qtoolbarlayout_p.h"-
50#include "qtoolbarseparator_p.h"-
51-
52#ifndef QT_NO_TOOLBAR-
53-
54QT_BEGIN_NAMESPACE-
55-
56// qmainwindow.cpp-
57extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);-
58-
59/******************************************************************************-
60** QToolBarItem-
61*/-
62-
63QToolBarItem::QToolBarItem(QWidget *widget)-
64 : QWidgetItem(widget), action(0), customWidget(false)-
65{-
66}
never executed: end of block
0
67-
68bool QToolBarItem::isEmpty() const-
69{-
70 return action == 0 || !action->isVisible();
never executed: return action == 0 || !action->isVisible();
action == 0Description
TRUEnever evaluated
FALSEnever evaluated
!action->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
71}-
72-
73/******************************************************************************-
74** QToolBarLayout-
75*/-
76-
77QToolBarLayout::QToolBarLayout(QWidget *parent)-
78 : QLayout(parent), expanded(false), animating(false), dirty(true),-
79 expanding(false), empty(true), expandFlag(false), popupMenu(0)-
80{-
81 QToolBar *tb = qobject_cast<QToolBar*>(parent);-
82 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
83 return;
never executed: return;
0
84-
85 extension = new QToolBarExtension(tb);-
86 extension->setFocusPolicy(Qt::NoFocus);-
87 extension->hide();-
88 QObject::connect(tb, SIGNAL(orientationChanged(Qt::Orientation)),-
89 extension, SLOT(setOrientation(Qt::Orientation)));-
90-
91 setUsePopupMenu(qobject_cast<QMainWindow*>(tb->parentWidget()) == 0);-
92}
never executed: end of block
0
93-
94QToolBarLayout::~QToolBarLayout()-
95{-
96 while (!items.isEmpty()) {
!items.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
97 QToolBarItem *item = items.takeFirst();-
98 if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction*>(item->action)) {
QWidgetAction ...(item->action)Description
TRUEnever evaluated
FALSEnever evaluated
0
99 if (item->customWidget)
item->customWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
100 widgetAction->releaseWidget(item->widget());
never executed: widgetAction->releaseWidget(item->widget());
0
101 }
never executed: end of block
0
102 delete item;-
103 }
never executed: end of block
0
104}
never executed: end of block
0
105-
106void QToolBarLayout::updateMarginAndSpacing()-
107{-
108 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
109 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
110 return;
never executed: return;
0
111 QStyle *style = tb->style();-
112 QStyleOptionToolBar opt;-
113 tb->initStyleOption(&opt);-
114 setMargin(style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb)-
115 + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb));-
116 setSpacing(style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, tb));-
117}
never executed: end of block
0
118-
119bool QToolBarLayout::hasExpandFlag() const-
120{-
121 return expandFlag;
never executed: return expandFlag;
0
122}-
123-
124void QToolBarLayout::setUsePopupMenu(bool set)-
125{-
126 if (!dirty && ((popupMenu == 0) == set))
!dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
((popupMenu == 0) == set)Description
TRUEnever evaluated
FALSEnever evaluated
0
127 invalidate();
never executed: invalidate();
0
128 if (!set) {
!setDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 QObject::connect(extension, SIGNAL(clicked(bool)),-
130 this, SLOT(setExpanded(bool)), Qt::UniqueConnection);-
131 extension->setPopupMode(QToolButton::DelayedPopup);-
132 extension->setMenu(0);-
133 delete popupMenu;-
134 popupMenu = 0;-
135 } else {
never executed: end of block
0
136 QObject::disconnect(extension, SIGNAL(clicked(bool)),-
137 this, SLOT(setExpanded(bool)));-
138 extension->setPopupMode(QToolButton::InstantPopup);-
139 if (!popupMenu) {
!popupMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
140 popupMenu = new QMenu(extension);-
141 }
never executed: end of block
0
142 extension->setMenu(popupMenu);-
143 }
never executed: end of block
0
144}-
145-
146void QToolBarLayout::checkUsePopupMenu()-
147{-
148 QToolBar *tb = static_cast<QToolBar *>(parent());-
149 QMainWindow *mw = qobject_cast<QMainWindow *>(tb->parent());-
150 Qt::Orientation o = tb->orientation();-
151 setUsePopupMenu(!mw || tb->isFloating() || perp(o, expandedSize(mw->size())) >= perp(o, mw->size()));-
152}
never executed: end of block
0
153-
154void QToolBarLayout::addItem(QLayoutItem*)-
155{-
156 qWarning("QToolBarLayout::addItem(): please use addAction() instead");-
157 return;
never executed: return;
0
158}-
159-
160QLayoutItem *QToolBarLayout::itemAt(int index) const-
161{-
162 if (index < 0 || index >= items.count())
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
163 return 0;
never executed: return 0;
0
164 return items.at(index);
never executed: return items.at(index);
0
165}-
166-
167QLayoutItem *QToolBarLayout::takeAt(int index)-
168{-
169 if (index < 0 || index >= items.count())
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
170 return 0;
never executed: return 0;
0
171 QToolBarItem *item = items.takeAt(index);-
172-
173 if (popupMenu)
popupMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
174 popupMenu->removeAction(item->action);
never executed: popupMenu->removeAction(item->action);
0
175-
176 QWidgetAction *widgetAction = qobject_cast<QWidgetAction*>(item->action);-
177 if (widgetAction != 0 && item->customWidget) {
widgetAction != 0Description
TRUEnever evaluated
FALSEnever evaluated
item->customWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
178 widgetAction->releaseWidget(item->widget());-
179 } else {
never executed: end of block
0
180 // destroy the QToolButton/QToolBarSeparator-
181 item->widget()->hide();-
182 item->widget()->deleteLater();-
183 }
never executed: end of block
0
184-
185 invalidate();-
186 return item;
never executed: return item;
0
187}-
188-
189void QToolBarLayout::insertAction(int index, QAction *action)-
190{-
191 index = qMax(0, index);-
192 index = qMin(items.count(), index);-
193-
194 QToolBarItem *item = createItem(action);-
195 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
196 items.insert(index, item);-
197 invalidate();-
198 }
never executed: end of block
0
199}
never executed: end of block
0
200-
201int QToolBarLayout::indexOf(QAction *action) const-
202{-
203 for (int i = 0; i < items.count(); ++i) {
i < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
204 if (items.at(i)->action == action)
items.at(i)->action == actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
205 return i;
never executed: return i;
0
206 }
never executed: end of block
0
207 return -1;
never executed: return -1;
0
208}-
209-
210int QToolBarLayout::count() const-
211{-
212 return items.count();
never executed: return items.count();
0
213}-
214-
215bool QToolBarLayout::isEmpty() const-
216{-
217 if (dirty)
dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
218 updateGeomArray();
never executed: updateGeomArray();
0
219 return empty;
never executed: return empty;
0
220}-
221-
222void QToolBarLayout::invalidate()-
223{-
224 dirty = true;-
225 QLayout::invalidate();-
226}
never executed: end of block
0
227-
228Qt::Orientations QToolBarLayout::expandingDirections() const-
229{-
230 if (dirty)
dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
231 updateGeomArray();
never executed: updateGeomArray();
0
232 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
233 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
234 return Qt::Orientations(0);
never executed: return Qt::Orientations(0);
0
235 Qt::Orientation o = tb->orientation();-
236 return expanding ? Qt::Orientations(o) : Qt::Orientations(0);
never executed: return expanding ? Qt::Orientations(o) : Qt::Orientations(0);
expandingDescription
TRUEnever evaluated
FALSEnever evaluated
0
237}-
238-
239bool QToolBarLayout::movable() const-
240{-
241 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
242 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
243 return false;
never executed: return false;
0
244 QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget());-
245 return tb->isMovable() && win != 0;
never executed: return tb->isMovable() && win != 0;
tb->isMovable()Description
TRUEnever evaluated
FALSEnever evaluated
win != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
246}-
247-
248void QToolBarLayout::updateGeomArray() const-
249{-
250 if (!dirty)
!dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
251 return;
never executed: return;
0
252-
253 QToolBarLayout *that = const_cast<QToolBarLayout*>(this);-
254-
255 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
256 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
257 return;
never executed: return;
0
258 QStyle *style = tb->style();-
259 QStyleOptionToolBar opt;-
260 tb->initStyleOption(&opt);-
261 const int handleExtent = movable()
movable()Description
TRUEnever evaluated
FALSEnever evaluated
0
262 ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;-
263 const int margin = this->margin();-
264 const int spacing = this->spacing();-
265 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);-
266 Qt::Orientation o = tb->orientation();-
267-
268 that->minSize = QSize(0, 0);-
269 that->hint = QSize(0, 0);-
270 rperp(o, that->minSize) = style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb);-
271 rperp(o, that->hint) = style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb);-
272-
273 that->expanding = false;-
274 that->empty = false;-
275-
276 QVector<QLayoutStruct> a(items.count() + 1); // + 1 for the stretch-
277-
278 int count = 0;-
279 for (int i = 0; i < items.count(); ++i) {
i < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
280 QToolBarItem *item = items.at(i);-
281-
282 QSize max = item->maximumSize();-
283 QSize min = item->minimumSize();-
284 QSize hint = item->sizeHint();-
285 Qt::Orientations exp = item->expandingDirections();-
286 bool empty = item->isEmpty();-
287-
288 that->expanding = expanding || exp & o;
expandingDescription
TRUEnever evaluated
FALSEnever evaluated
exp & oDescription
TRUEnever evaluated
FALSEnever evaluated
0
289-
290-
291 if (item->widget()) {
item->widget()Description
TRUEnever evaluated
FALSEnever evaluated
0
292 if ((item->widget()->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag)) {
(item->widget(...y::ExpandFlag)Description
TRUEnever evaluated
FALSEnever evaluated
0
293 that->expandFlag = true;-
294 }
never executed: end of block
0
295 }
never executed: end of block
0
296-
297 if (!empty) {
!emptyDescription
TRUEnever evaluated
FALSEnever evaluated
0
298 if (count == 0) // the minimum size only displays one widget
count == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
299 rpick(o, that->minSize) += pick(o, min);
never executed: rpick(o, that->minSize) += pick(o, min);
0
300 int s = perp(o, minSize);-
301 rperp(o, that->minSize) = qMax(s, perp(o, min));-
302-
303 //we only add spacing before item (ie never before the first one)-
304 rpick(o, that->hint) += (count == 0 ? 0 : spacing) + pick(o, hint);
count == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
305 s = perp(o, that->hint);-
306 rperp(o, that->hint) = qMax(s, perp(o, hint));-
307 ++count;-
308 }
never executed: end of block
0
309-
310 a[i].sizeHint = pick(o, hint);-
311 a[i].maximumSize = pick(o, max);-
312 a[i].minimumSize = pick(o, min);-
313 a[i].expansive = exp & o;-
314 if (o == Qt::Horizontal)
o == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
315 a[i].stretch = item->widget()->sizePolicy().horizontalStretch();
never executed: a[i].stretch = item->widget()->sizePolicy().horizontalStretch();
0
316 else-
317 a[i].stretch = item->widget()->sizePolicy().verticalStretch();
never executed: a[i].stretch = item->widget()->sizePolicy().verticalStretch();
0
318 a[i].empty = empty;-
319 }
never executed: end of block
0
320-
321 that->geomArray = a;-
322 that->empty = count == 0;-
323-
324 rpick(o, that->minSize) += handleExtent;-
325 that->minSize += QSize(2*margin, 2*margin);-
326 if (items.count() > 1)
items.count() > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
327 rpick(o, that->minSize) += spacing + extensionExtent;
never executed: rpick(o, that->minSize) += spacing + extensionExtent;
0
328-
329 rpick(o, that->hint) += handleExtent;-
330 that->hint += QSize(2*margin, 2*margin);-
331 that->dirty = false;-
332}
never executed: end of block
0
333-
334static bool defaultWidgetAction(QToolBarItem *item)-
335{-
336 QWidgetAction *a = qobject_cast<QWidgetAction*>(item->action);-
337 return a != 0 && a->defaultWidget() == item->widget();
never executed: return a != 0 && a->defaultWidget() == item->widget();
a != 0Description
TRUEnever evaluated
FALSEnever evaluated
a->defaultWidg...item->widget()Description
TRUEnever evaluated
FALSEnever evaluated
0
338}-
339-
340void QToolBarLayout::updateMacBorderMetrics()-
341{-
342#ifdef Q_OS_OSX-
343 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
344 if (!tb)-
345 return;-
346-
347 QRect rect = geometry();-
348-
349 QMainWindow *mainWindow = qobject_cast<QMainWindow*>(tb->parentWidget());-
350 if (!mainWindow || !mainWindow->isWindow() || !mainWindow->unifiedTitleAndToolBarOnMac())-
351 return;-
352-
353 QPlatformNativeInterface *nativeInterface = QApplication::platformNativeInterface();-
354 QPlatformNativeInterface::NativeResourceForIntegrationFunction function =-
355 nativeInterface->nativeResourceFunctionForIntegration("registerContentBorderArea");-
356 if (!function)-
357 return; // Not Cocoa platform plugin.-
358-
359 QPoint upper = tb->mapToParent(rect.topLeft());-
360 QPoint lower = tb->mapToParent(rect.bottomLeft() + QPoint(0, 1));-
361-
362 typedef void (*RegisterContentBorderAreaFunction)(QWindow *window, void *identifier, int upper, int lower);-
363 if (mainWindow->toolBarArea(tb) == Qt::TopToolBarArea) {-
364 (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(tb->window()->windowHandle(), tb, upper.y(), lower.y());-
365 } else {-
366 (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(tb->window()->windowHandle(), tb, 0, 0);-
367 }-
368#endif-
369}-
370-
371void QToolBarLayout::setGeometry(const QRect &rect)-
372{-
373 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
374 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
375 return;
never executed: return;
0
376 QStyle *style = tb->style();-
377 QStyleOptionToolBar opt;-
378 tb->initStyleOption(&opt);-
379 const int margin = this->margin();-
380 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);-
381 Qt::Orientation o = tb->orientation();-
382-
383 QLayout::setGeometry(rect);-
384-
385 updateMacBorderMetrics();-
386-
387 bool ranOutOfSpace = false;-
388 if (!animating)
!animatingDescription
TRUEnever evaluated
FALSEnever evaluated
0
389 ranOutOfSpace = layoutActions(rect.size());
never executed: ranOutOfSpace = layoutActions(rect.size());
0
390-
391 if (expanded || animating || ranOutOfSpace) {
expandedDescription
TRUEnever evaluated
FALSEnever evaluated
animatingDescription
TRUEnever evaluated
FALSEnever evaluated
ranOutOfSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
392 Qt::ToolBarArea area = Qt::TopToolBarArea;-
393 if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget()))
QMainWindow *w...arentWidget())Description
TRUEnever evaluated
FALSEnever evaluated
0
394 area = win->toolBarArea(tb);
never executed: area = win->toolBarArea(tb);
0
395 QSize hint = sizeHint();-
396-
397 QPoint pos;-
398 rpick(o, pos) = pick(o, rect.bottomRight()) - margin - extensionExtent + 2;-
399 if (area == Qt::LeftToolBarArea || area == Qt::TopToolBarArea)
area == Qt::LeftToolBarAreaDescription
TRUEnever evaluated
FALSEnever evaluated
area == Qt::TopToolBarAreaDescription
TRUEnever evaluated
FALSEnever evaluated
0
400 rperp(o, pos) = perp(o, rect.topLeft()) + margin;
never executed: rperp(o, pos) = perp(o, rect.topLeft()) + margin;
0
401 else-
402 rperp(o, pos) = perp(o, rect.bottomRight()) - margin - (perp(o, hint) - 2*margin) + 1;
never executed: rperp(o, pos) = perp(o, rect.bottomRight()) - margin - (perp(o, hint) - 2*margin) + 1;
0
403 QSize size;-
404 rpick(o, size) = extensionExtent;-
405 rperp(o, size) = perp(o, hint) - 2*margin;-
406 QRect r(pos, size);-
407-
408 if (o == Qt::Horizontal)
o == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
409 r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
never executed: r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
0
410-
411 extension->setGeometry(r);-
412-
413 if (extension->isHidden())
extension->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
414 extension->show();
never executed: extension->show();
0
415 } else {
never executed: end of block
0
416 if (!extension->isHidden())
!extension->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
417 extension->hide();
never executed: extension->hide();
0
418 }
never executed: end of block
0
419}-
420-
421bool QToolBarLayout::layoutActions(const QSize &size)-
422{-
423 if (dirty)
dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
424 updateGeomArray();
never executed: updateGeomArray();
0
425-
426 QRect rect(0, 0, size.width(), size.height());-
427-
428 QList<QWidget*> showWidgets, hideWidgets;-
429-
430 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
431 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
432 return false;
never executed: return false;
0
433 QStyle *style = tb->style();-
434 QStyleOptionToolBar opt;-
435 tb->initStyleOption(&opt);-
436 const int handleExtent = movable()
movable()Description
TRUEnever evaluated
FALSEnever evaluated
0
437 ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;-
438 const int margin = this->margin();-
439 const int spacing = this->spacing();-
440 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);-
441 Qt::Orientation o = tb->orientation();-
442 bool extensionMenuContainsOnlyWidgetActions = true;-
443-
444 int space = pick(o, rect.size()) - 2*margin - handleExtent;-
445 if (space <= 0)
space <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
446 return false; // nothing to do.
never executed: return false;
0
447-
448 if(popupMenu)
popupMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
449 popupMenu->clear();
never executed: popupMenu->clear();
0
450-
451 bool ranOutOfSpace = false;-
452 int rows = 0;-
453 int rowPos = perp(o, rect.topLeft()) + margin;-
454 int i = 0;-
455 while (i < items.count()) {
i < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
456 QVector<QLayoutStruct> a = geomArray;-
457-
458 int start = i;-
459 int size = 0;-
460 int prev = -1;-
461 int rowHeight = 0;-
462 int count = 0;-
463 int maximumSize = 0;-
464 bool expansiveRow = false;-
465 for (; i < items.count(); ++i) {
i < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
466 if (a[i].empty)
a[i].emptyDescription
TRUEnever evaluated
FALSEnever evaluated
0
467 continue;
never executed: continue;
0
468-
469 int newSize = size + (count == 0 ? 0 : spacing) + a[i].minimumSize;
count == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
470 if (prev != -1 && newSize > space) {
prev != -1Description
TRUEnever evaluated
FALSEnever evaluated
newSize > spaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
471 if (rows == 0)
rows == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
472 ranOutOfSpace = true;
never executed: ranOutOfSpace = true;
0
473 // do we have to move the previous item to the next line to make space for-
474 // the extension button?-
475 if (count > 1 && size + spacing + extensionExtent > space)
count > 1Description
TRUEnever evaluated
FALSEnever evaluated
size + spacing...Extent > spaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
476 i = prev;
never executed: i = prev;
0
477 break;
never executed: break;
0
478 }-
479-
480 if (expanded)
expandedDescription
TRUEnever evaluated
FALSEnever evaluated
0
481 rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint()));
never executed: rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint()));
0
482 expansiveRow = expansiveRow || a[i].expansive;
expansiveRowDescription
TRUEnever evaluated
FALSEnever evaluated
a[i].expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
483 size = newSize;-
484 maximumSize += spacing + (a[i].expansive ? a[i].maximumSize : a[i].smartSizeHint());
a[i].expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
485 prev = i;-
486 ++count;-
487 }
never executed: end of block
0
488-
489 // stretch at the end-
490 a[i].sizeHint = 0;-
491 a[i].maximumSize = QWIDGETSIZE_MAX;-
492 a[i].minimumSize = 0;-
493 a[i].expansive = true;-
494 a[i].stretch = 0;-
495 a[i].empty = true;-
496-
497 if (expansiveRow && maximumSize < space) {
expansiveRowDescription
TRUEnever evaluated
FALSEnever evaluated
maximumSize < spaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
498 expansiveRow = false;-
499 a[i].maximumSize = space - maximumSize;-
500 }
never executed: end of block
0
501-
502 qGeomCalc(a, start, i - start + (expansiveRow ? 0 : 1), 0,-
503 space - (ranOutOfSpace ? (extensionExtent + spacing) : 0),-
504 spacing);-
505-
506 for (int j = start; j < i; ++j) {
j < iDescription
TRUEnever evaluated
FALSEnever evaluated
0
507 QToolBarItem *item = items.at(j);-
508-
509 if (a[j].empty) {
a[j].emptyDescription
TRUEnever evaluated
FALSEnever evaluated
0
510 if (!item->widget()->isHidden())
!item->widget()->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
511 hideWidgets << item->widget();
never executed: hideWidgets << item->widget();
0
512 continue;
never executed: continue;
0
513 }-
514-
515 QPoint pos;-
516 rpick(o, pos) = margin + handleExtent + a[j].pos;-
517 rperp(o, pos) = rowPos;-
518 QSize size;-
519 rpick(o, size) = a[j].size;-
520 if (expanded)
expandedDescription
TRUEnever evaluated
FALSEnever evaluated
0
521 rperp(o, size) = rowHeight;
never executed: rperp(o, size) = rowHeight;
0
522 else-
523 rperp(o, size) = perp(o, rect.size()) - 2*margin;
never executed: rperp(o, size) = perp(o, rect.size()) - 2*margin;
0
524 QRect r(pos, size);-
525-
526 if (o == Qt::Horizontal)
o == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
527 r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
never executed: r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
0
528-
529 item->setGeometry(r);-
530-
531 if (item->widget()->isHidden())
item->widget()->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
532 showWidgets << item->widget();
never executed: showWidgets << item->widget();
0
533 }
never executed: end of block
0
534-
535 if (!expanded) {
!expandedDescription
TRUEnever evaluated
FALSEnever evaluated
0
536 for (int j = i; j < items.count(); ++j) {
j < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
537 QToolBarItem *item = items.at(j);-
538 if (!item->widget()->isHidden())
!item->widget()->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
539 hideWidgets << item->widget();
never executed: hideWidgets << item->widget();
0
540 if (popupMenu) {
popupMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
541 if (!defaultWidgetAction(item)) {
!defaultWidgetAction(item)Description
TRUEnever evaluated
FALSEnever evaluated
0
542 popupMenu->addAction(item->action);-
543 extensionMenuContainsOnlyWidgetActions = false;-
544 }
never executed: end of block
0
545 }
never executed: end of block
0
546 }
never executed: end of block
0
547 break;
never executed: break;
0
548 }-
549-
550 rowPos += rowHeight + spacing;-
551 ++rows;-
552 }
never executed: end of block
0
553-
554 // if we are using a popup menu, not the expadning toolbar effect, we cannot move custom-
555 // widgets into the menu. If only custom widget actions are chopped off, the popup menu-
556 // is empty. So we show the little extension button to show something is chopped off,-
557 // but we make it disabled.-
558 extension->setEnabled(popupMenu == 0 || !extensionMenuContainsOnlyWidgetActions);-
559-
560 // we have to do the show/hide here, because it triggers more calls to setGeometry :(-
561 for (int i = 0; i < showWidgets.count(); ++i)
i < showWidgets.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
562 showWidgets.at(i)->show();
never executed: showWidgets.at(i)->show();
0
563 for (int i = 0; i < hideWidgets.count(); ++i)
i < hideWidgets.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
564 hideWidgets.at(i)->hide();
never executed: hideWidgets.at(i)->hide();
0
565-
566 return ranOutOfSpace;
never executed: return ranOutOfSpace;
0
567}-
568-
569QSize QToolBarLayout::expandedSize(const QSize &size) const-
570{-
571 if (dirty)
dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
572 updateGeomArray();
never executed: updateGeomArray();
0
573-
574 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
575 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
576 return QSize(0, 0);
never executed: return QSize(0, 0);
0
577 QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget());-
578 Qt::Orientation o = tb->orientation();-
579 QStyle *style = tb->style();-
580 QStyleOptionToolBar opt;-
581 tb->initStyleOption(&opt);-
582 const int handleExtent = movable()
movable()Description
TRUEnever evaluated
FALSEnever evaluated
0
583 ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;-
584 const int margin = this->margin();-
585 const int spacing = this->spacing();-
586 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);-
587-
588 int total_w = 0;-
589 int count = 0;-
590 for (int x = 0; x < items.count(); ++x) {
x < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
591 if (!geomArray[x].empty) {
!geomArray[x].emptyDescription
TRUEnever evaluated
FALSEnever evaluated
0
592 total_w += (count == 0 ? 0 : spacing) + geomArray[x].minimumSize;
count == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
593 ++count;-
594 }
never executed: end of block
0
595 }
never executed: end of block
0
596 if (count == 0)
count == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
597 return QSize(0, 0);
never executed: return QSize(0, 0);
0
598-
599 int min_w = pick(o, size);-
600 int rows = (int)qSqrt(qreal(count));-
601 if (rows == 1)
rows == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
602 ++rows; // we want to expand to at least two rows
never executed: ++rows;
0
603 int space = total_w/rows + spacing + extensionExtent;-
604 space = qMax(space, min_w - 2*margin - handleExtent);-
605 if (win != 0)
win != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
606 space = qMin(space, pick(o, win->size()) - 2*margin - handleExtent);
never executed: space = qMin(space, pick(o, win->size()) - 2*margin - handleExtent);
0
607-
608 int w = 0;-
609 int h = 0;-
610 int i = 0;-
611 while (i < items.count()) {
i < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
612 int count = 0;-
613 int size = 0;-
614 int prev = -1;-
615 int rowHeight = 0;-
616 for (; i < items.count(); ++i) {
i < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
617 if (geomArray[i].empty)
geomArray[i].emptyDescription
TRUEnever evaluated
FALSEnever evaluated
0
618 continue;
never executed: continue;
0
619-
620 int newSize = size + (count == 0 ? 0 : spacing) + geomArray[i].minimumSize;
count == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
621 rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint()));-
622 if (prev != -1 && newSize > space) {
prev != -1Description
TRUEnever evaluated
FALSEnever evaluated
newSize > spaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
623 if (count > 1 && size + spacing + extensionExtent > space) {
count > 1Description
TRUEnever evaluated
FALSEnever evaluated
size + spacing...Extent > spaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
624 size -= spacing + geomArray[prev].minimumSize;-
625 i = prev;-
626 }
never executed: end of block
0
627 break;
never executed: break;
0
628 }-
629-
630 size = newSize;-
631 prev = i;-
632 ++count;-
633 }
never executed: end of block
0
634-
635 w = qMax(size, w);-
636 h += rowHeight + spacing;-
637 }
never executed: end of block
0
638-
639 w += 2*margin + handleExtent + spacing + extensionExtent;-
640 w = qMax(w, min_w);-
641 if (win != 0)
win != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
642 w = qMin(w, pick(o, win->size()));
never executed: w = qMin(w, pick(o, win->size()));
0
643 h += 2*margin - spacing; //there is no spacing before the first row-
644-
645 QSize result;-
646 rpick(o, result) = w;-
647 rperp(o, result) = h;-
648 return result;
never executed: return result;
0
649}-
650-
651void QToolBarLayout::setExpanded(bool exp)-
652{-
653 QWidget *tb = qobject_cast<QToolBar*>(parentWidget());-
654 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
655 return;
never executed: return;
0
656 if (exp == expanded && !tb->isWindow())
exp == expandedDescription
TRUEnever evaluated
FALSEnever evaluated
!tb->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
657 return;
never executed: return;
0
658-
659 expanded = exp;-
660 extension->setChecked(expanded);-
661-
662 if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) {
QMainWindow *w...arentWidget())Description
TRUEnever evaluated
FALSEnever evaluated
0
663#ifdef QT_NO_DOCKWIDGET-
664 animating = false;-
665#else-
666 animating = !tb->isWindow() && win->isAnimated();
!tb->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
win->isAnimated()Description
TRUEnever evaluated
FALSEnever evaluated
0
667#endif-
668 QMainWindowLayout *layout = qt_mainwindow_layout(win);-
669 if (expanded) {
expandedDescription
TRUEnever evaluated
FALSEnever evaluated
0
670 tb->raise();-
671 } else {
never executed: end of block
0
672 QList<int> path = layout->layoutState.indexOf(tb);-
673 if (!path.isEmpty()) {
!path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
674 QRect rect = layout->layoutState.itemRect(path);-
675 layoutActions(rect.size());-
676 }
never executed: end of block
0
677 }
never executed: end of block
0
678 layout->layoutState.toolBarAreaLayout.apply(animating);-
679 }
never executed: end of block
0
680}
never executed: end of block
0
681-
682QSize QToolBarLayout::minimumSize() const-
683{-
684 if (dirty)
dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
685 updateGeomArray();
never executed: updateGeomArray();
0
686 return minSize;
never executed: return minSize;
0
687}-
688-
689QSize QToolBarLayout::sizeHint() const-
690{-
691 if (dirty)
dirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
692 updateGeomArray();
never executed: updateGeomArray();
0
693 return hint;
never executed: return hint;
0
694}-
695-
696QToolBarItem *QToolBarLayout::createItem(QAction *action)-
697{-
698 bool customWidget = false;-
699 bool standardButtonWidget = false;-
700 QWidget *widget = 0;-
701 QToolBar *tb = qobject_cast<QToolBar*>(parentWidget());-
702 if (!tb)
!tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
703 return (QToolBarItem *)0;
never executed: return (QToolBarItem *)0;
0
704-
705 if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action)) {
QWidgetAction ...ion *>(action)Description
TRUEnever evaluated
FALSEnever evaluated
0
706 widget = widgetAction->requestWidget(tb);-
707 if (widget != 0) {
widget != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
708 widget->setAttribute(Qt::WA_LayoutUsesWidgetRect);-
709 customWidget = true;-
710 }
never executed: end of block
0
711 } else if (action->isSeparator()) {
never executed: end of block
action->isSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
0
712 QToolBarSeparator *sep = new QToolBarSeparator(tb);-
713 connect(tb, SIGNAL(orientationChanged(Qt::Orientation)),-
714 sep, SLOT(setOrientation(Qt::Orientation)));-
715 widget = sep;-
716 }
never executed: end of block
0
717-
718 if (!widget) {
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
719 QToolButton *button = new QToolButton(tb);-
720 button->setAutoRaise(true);-
721 button->setFocusPolicy(Qt::NoFocus);-
722 button->setIconSize(tb->iconSize());-
723 button->setToolButtonStyle(tb->toolButtonStyle());-
724 QObject::connect(tb, SIGNAL(iconSizeChanged(QSize)),-
725 button, SLOT(setIconSize(QSize)));-
726 QObject::connect(tb, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),-
727 button, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));-
728 button->setDefaultAction(action);-
729 QObject::connect(button, SIGNAL(triggered(QAction*)), tb, SIGNAL(actionTriggered(QAction*)));-
730 widget = button;-
731 standardButtonWidget = true;-
732 }
never executed: end of block
0
733-
734 widget->hide();-
735 QToolBarItem *result = new QToolBarItem(widget);-
736 if (standardButtonWidget)
standardButtonWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
737 result->setAlignment(Qt::AlignJustify);
never executed: result->setAlignment(Qt::AlignJustify);
0
738 result->customWidget = customWidget;-
739 result->action = action;-
740 return result;
never executed: return result;
0
741}-
742-
743QT_END_NAMESPACE-
744-
745#include "moc_qtoolbarlayout_p.cpp"-
746-
747#endif // QT_NO_TOOLBAR-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9