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