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