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

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