| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 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 | | - |
| 54 | QT_BEGIN_NAMESPACE | - |
| 55 | | - |
| 56 | | - |
| 57 | extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window); | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | | - |
| 62 | | - |
| 63 | QToolBarItem::QToolBarItem(QWidget *widget) | - |
| 64 | : QWidgetItem(widget), action(0), customWidget(false) | - |
| 65 | { | - |
| 66 | } never executed: end of block | 0 |
| 67 | | - |
| 68 | bool QToolBarItem::isEmpty() const | - |
| 69 | { | - |
| 70 | return action == 0 || !action->isVisible(); never executed: return action == 0 || !action->isVisible(); | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 71 | } | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | QToolBarLayout::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)| TRUE | never evaluated | | FALSE | never 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 | | - |
| 94 | QToolBarLayout::~QToolBarLayout() | - |
| 95 | { | - |
| 96 | while (!items.isEmpty()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 97 | QToolBarItem *item = items.takeFirst(); | - |
| 98 | if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction*>(item->action)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 99 | if (item->customWidget)| TRUE | never evaluated | | FALSE | never 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 | | - |
| 106 | void QToolBarLayout::updateMarginAndSpacing() | - |
| 107 | { | - |
| 108 | QToolBar *tb = qobject_cast<QToolBar*>(parentWidget()); | - |
| 109 | if (!tb)| TRUE | never evaluated | | FALSE | never 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 | | - |
| 119 | bool QToolBarLayout::hasExpandFlag() const | - |
| 120 | { | - |
| 121 | return expandFlag; never executed: return expandFlag; | 0 |
| 122 | } | - |
| 123 | | - |
| 124 | void QToolBarLayout::setUsePopupMenu(bool set) | - |
| 125 | { | - |
| 126 | if (!dirty && ((popupMenu == 0) == set))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 127 | invalidate(); never executed: invalidate(); | 0 |
| 128 | if (!set) {| TRUE | never evaluated | | FALSE | never 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) {| TRUE | never evaluated | | FALSE | never 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 | | - |
| 146 | void 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 | | - |
| 154 | void QToolBarLayout::addItem(QLayoutItem*) | - |
| 155 | { | - |
| 156 | qWarning("QToolBarLayout::addItem(): please use addAction() instead"); | - |
| 157 | return; never executed: return; | 0 |
| 158 | } | - |
| 159 | | - |
| 160 | QLayoutItem *QToolBarLayout::itemAt(int index) const | - |
| 161 | { | - |
| 162 | if (index < 0 || index >= items.count())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 163 | return 0; never executed: return 0; | 0 |
| 164 | return items.at(index); never executed: return items.at(index); | 0 |
| 165 | } | - |
| 166 | | - |
| 167 | QLayoutItem *QToolBarLayout::takeAt(int index) | - |
| 168 | { | - |
| 169 | if (index < 0 || index >= items.count())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 170 | return 0; never executed: return 0; | 0 |
| 171 | QToolBarItem *item = items.takeAt(index); | - |
| 172 | | - |
| 173 | if (popupMenu)| TRUE | never evaluated | | FALSE | never 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) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 178 | widgetAction->releaseWidget(item->widget()); | - |
| 179 | } else { never executed: end of block | 0 |
| 180 | | - |
| 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 | | - |
| 189 | void 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) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 196 | items.insert(index, item); | - |
| 197 | invalidate(); | - |
| 198 | } never executed: end of block | 0 |
| 199 | } never executed: end of block | 0 |
| 200 | | - |
| 201 | int QToolBarLayout::indexOf(QAction *action) const | - |
| 202 | { | - |
| 203 | for (int i = 0; i < items.count(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 204 | if (items.at(i)->action == action)| TRUE | never evaluated | | FALSE | never 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 | | - |
| 210 | int QToolBarLayout::count() const | - |
| 211 | { | - |
| 212 | return items.count(); never executed: return items.count(); | 0 |
| 213 | } | - |
| 214 | | - |
| 215 | bool QToolBarLayout::isEmpty() const | - |
| 216 | { | - |
| 217 | if (dirty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 218 | updateGeomArray(); never executed: updateGeomArray(); | 0 |
| 219 | return empty; never executed: return empty; | 0 |
| 220 | } | - |
| 221 | | - |
| 222 | void QToolBarLayout::invalidate() | - |
| 223 | { | - |
| 224 | dirty = true; | - |
| 225 | QLayout::invalidate(); | - |
| 226 | } never executed: end of block | 0 |
| 227 | | - |
| 228 | Qt::Orientations QToolBarLayout::expandingDirections() const | - |
| 229 | { | - |
| 230 | if (dirty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 231 | updateGeomArray(); never executed: updateGeomArray(); | 0 |
| 232 | QToolBar *tb = qobject_cast<QToolBar*>(parentWidget()); | - |
| 233 | if (!tb)| TRUE | never evaluated | | FALSE | never 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); | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 237 | } | - |
| 238 | | - |
| 239 | bool QToolBarLayout::movable() const | - |
| 240 | { | - |
| 241 | QToolBar *tb = qobject_cast<QToolBar*>(parentWidget()); | - |
| 242 | if (!tb)| TRUE | never evaluated | | FALSE | never 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; | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 246 | } | - |
| 247 | | - |
| 248 | void QToolBarLayout::updateGeomArray() const | - |
| 249 | { | - |
| 250 | if (!dirty)| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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()| TRUE | never evaluated | | FALSE | never 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); | - |
| 277 | | - |
| 278 | int count = 0; | - |
| 279 | for (int i = 0; i < items.count(); ++i) {| TRUE | never evaluated | | FALSE | never 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;| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 289 | | - |
| 290 | | - |
| 291 | if (item->widget()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 292 | if ((item->widget()->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 293 | that->expandFlag = true; | - |
| 294 | } never executed: end of block | 0 |
| 295 | } never executed: end of block | 0 |
| 296 | | - |
| 297 | if (!empty) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 298 | if (count == 0) | TRUE | never evaluated | | FALSE | never 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 | | - |
| 304 | rpick(o, that->hint) += (count == 0 ? 0 : spacing) + pick(o, hint);| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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 | | - |
| 334 | static 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(); | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 338 | } | - |
| 339 | | - |
| 340 | void 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; | - |
| 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 | | - |
| 371 | void QToolBarLayout::setGeometry(const QRect &rect) | - |
| 372 | { | - |
| 373 | QToolBar *tb = qobject_cast<QToolBar*>(parentWidget()); | - |
| 374 | if (!tb)| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 389 | ranOutOfSpace = layoutActions(rect.size()); never executed: ranOutOfSpace = layoutActions(rect.size()); | 0 |
| 390 | | - |
| 391 | if (expanded || animating || ranOutOfSpace) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 392 | Qt::ToolBarArea area = Qt::TopToolBarArea; | - |
| 393 | if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget()))| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 414 | extension->show(); never executed: extension->show(); | 0 |
| 415 | } else { never executed: end of block | 0 |
| 416 | if (!extension->isHidden())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 417 | extension->hide(); never executed: extension->hide(); | 0 |
| 418 | } never executed: end of block | 0 |
| 419 | } | - |
| 420 | | - |
| 421 | bool QToolBarLayout::layoutActions(const QSize &size) | - |
| 422 | { | - |
| 423 | if (dirty)| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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()| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 446 | return false; never executed: return false; | 0 |
| 447 | | - |
| 448 | if(popupMenu)| TRUE | never evaluated | | FALSE | never 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()) {| TRUE | never evaluated | | FALSE | never 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) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 466 | if (a[i].empty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 467 | continue; never executed: continue; | 0 |
| 468 | | - |
| 469 | int newSize = size + (count == 0 ? 0 : spacing) + a[i].minimumSize;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 470 | if (prev != -1 && newSize > space) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 471 | if (rows == 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 472 | ranOutOfSpace = true; never executed: ranOutOfSpace = true; | 0 |
| 473 | | - |
| 474 | | - |
| 475 | if (count > 1 && size + spacing + extensionExtent > space)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 476 | i = prev; never executed: i = prev; | 0 |
| 477 | break; never executed: break; | 0 |
| 478 | } | - |
| 479 | | - |
| 480 | if (expanded)| TRUE | never evaluated | | FALSE | never 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;| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 483 | size = newSize; | - |
| 484 | maximumSize += spacing + (a[i].expansive ? a[i].maximumSize : a[i].smartSizeHint());| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 485 | prev = i; | - |
| 486 | ++count; | - |
| 487 | } never executed: end of block | 0 |
| 488 | | - |
| 489 | | - |
| 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) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never 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) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 507 | QToolBarItem *item = items.at(j); | - |
| 508 | | - |
| 509 | if (a[j].empty) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 510 | if (!item->widget()->isHidden())| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 532 | showWidgets << item->widget(); never executed: showWidgets << item->widget(); | 0 |
| 533 | } never executed: end of block | 0 |
| 534 | | - |
| 535 | if (!expanded) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 536 | for (int j = i; j < items.count(); ++j) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 537 | QToolBarItem *item = items.at(j); | - |
| 538 | if (!item->widget()->isHidden())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 539 | hideWidgets << item->widget(); never executed: hideWidgets << item->widget(); | 0 |
| 540 | if (popupMenu) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 541 | if (!defaultWidgetAction(item)) {| TRUE | never evaluated | | FALSE | never 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 | | - |
| 555 | | - |
| 556 | | - |
| 557 | | - |
| 558 | extension->setEnabled(popupMenu == 0 || !extensionMenuContainsOnlyWidgetActions); | - |
| 559 | | - |
| 560 | | - |
| 561 | for (int i = 0; i < showWidgets.count(); ++i)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 562 | showWidgets.at(i)->show(); never executed: showWidgets.at(i)->show(); | 0 |
| 563 | for (int i = 0; i < hideWidgets.count(); ++i)| TRUE | never evaluated | | FALSE | never 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 | | - |
| 569 | QSize QToolBarLayout::expandedSize(const QSize &size) const | - |
| 570 | { | - |
| 571 | if (dirty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 572 | updateGeomArray(); never executed: updateGeomArray(); | 0 |
| 573 | | - |
| 574 | QToolBar *tb = qobject_cast<QToolBar*>(parentWidget()); | - |
| 575 | if (!tb)| TRUE | never evaluated | | FALSE | never 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()| TRUE | never evaluated | | FALSE | never 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) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 591 | if (!geomArray[x].empty) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 592 | total_w += (count == 0 ? 0 : spacing) + geomArray[x].minimumSize;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 593 | ++count; | - |
| 594 | } never executed: end of block | 0 |
| 595 | } never executed: end of block | 0 |
| 596 | if (count == 0)| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 602 | ++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)| TRUE | never evaluated | | FALSE | never 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()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 612 | int count = 0; | - |
| 613 | int size = 0; | - |
| 614 | int prev = -1; | - |
| 615 | int rowHeight = 0; | - |
| 616 | for (; i < items.count(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 617 | if (geomArray[i].empty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 618 | continue; never executed: continue; | 0 |
| 619 | | - |
| 620 | int newSize = size + (count == 0 ? 0 : spacing) + geomArray[i].minimumSize;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 621 | rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint())); | - |
| 622 | if (prev != -1 && newSize > space) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 623 | if (count > 1 && size + spacing + extensionExtent > space) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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; | - |
| 644 | | - |
| 645 | QSize result; | - |
| 646 | rpick(o, result) = w; | - |
| 647 | rperp(o, result) = h; | - |
| 648 | return result; never executed: return result; | 0 |
| 649 | } | - |
| 650 | | - |
| 651 | void QToolBarLayout::setExpanded(bool exp) | - |
| 652 | { | - |
| 653 | QWidget *tb = qobject_cast<QToolBar*>(parentWidget()); | - |
| 654 | if (!tb)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 655 | return; never executed: return; | 0 |
| 656 | if (exp == expanded && !tb->isWindow())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never 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())) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 663 | #ifdef QT_NO_DOCKWIDGET | - |
| 664 | animating = false; | - |
| 665 | #else | - |
| 666 | animating = !tb->isWindow() && win->isAnimated();| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 667 | #endif | - |
| 668 | QMainWindowLayout *layout = qt_mainwindow_layout(win); | - |
| 669 | if (expanded) {| TRUE | never evaluated | | FALSE | never 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()) {| TRUE | never evaluated | | FALSE | never 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 | | - |
| 682 | QSize QToolBarLayout::minimumSize() const | - |
| 683 | { | - |
| 684 | if (dirty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 685 | updateGeomArray(); never executed: updateGeomArray(); | 0 |
| 686 | return minSize; never executed: return minSize; | 0 |
| 687 | } | - |
| 688 | | - |
| 689 | QSize QToolBarLayout::sizeHint() const | - |
| 690 | { | - |
| 691 | if (dirty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 692 | updateGeomArray(); never executed: updateGeomArray(); | 0 |
| 693 | return hint; never executed: return hint; | 0 |
| 694 | } | - |
| 695 | | - |
| 696 | QToolBarItem *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)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 703 | return (QToolBarItem *)0; never executed: return (QToolBarItem *)0; | 0 |
| 704 | | - |
| 705 | if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 706 | widget = widgetAction->requestWidget(tb); | - |
| 707 | if (widget != 0) {| TRUE | never evaluated | | FALSE | never 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 | TRUE | never evaluated | | FALSE | never 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) {| TRUE | never evaluated | | FALSE | never 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)| TRUE | never evaluated | | FALSE | never 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 | | - |
| 743 | QT_END_NAMESPACE | - |
| 744 | | - |
| 745 | #include "moc_qtoolbarlayout_p.cpp" | - |
| 746 | | - |
| 747 | #endif // QT_NO_TOOLBAR | - |
| | |