280void QQuickSplitViewPrivate::layoutResizeSplitItems(qreal &usedWidth, qreal &usedHeight,
int &indexBeingResizedDueToDrag)
282 const int count = contentModel->count();
283 const bool horizontal = isHorizontal();
284 for (
int index = 0; index < count; ++index) {
285 QQuickItem *item = qobject_cast<QQuickItem*>(contentModel->object(index));
286 if (!item || !item->isVisible()) {
288 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": split item " << item
289 <<
" at index " << index <<
" is not visible; skipping it and its handles (if any)";
293 const QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
294 QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
295 qmlAttachedPropertiesObject<QQuickSplitView>(item,
false));
296 const auto sizeData = effectiveSizeData(itemPrivate, attached);
298 const bool resizeLeftItem = m_fillIndex > m_pressedHandleIndex;
300 const bool isAHandlePressed = m_pressedHandleIndex != -1;
302 const bool isBeingResized = isAHandlePressed && ((resizeLeftItem && index == m_pressedHandleIndex)
303 || (!resizeLeftItem && index == m_nextVisibleIndexAfterPressedHandle));
304 if (isBeingResized) {
305 indexBeingResizedDueToDrag = index;
306 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": dragging handle for item";
309 const qreal size = horizontal ? width : height;
310 qreal requestedSize = 0;
311 if (isBeingResized) {
313 const qreal clampedMousePos = horizontal
314 ? qBound(qreal(0.0), m_mousePos.x(), qreal(width))
315 : qBound(qreal(0.0), m_mousePos.y(), qreal(height));
319 const int firstIndex = resizeLeftItem ? m_nextVisibleIndexAfterPressedHandle : 0;
320 const int lastIndex = resizeLeftItem ? contentModel->count() - 1 : m_pressedHandleIndex;
321 const qreal accumulated = accumulatedSize(firstIndex, lastIndex);
323 const qreal mousePosRelativeToLeftHandleEdge = horizontal
324 ? m_pressPos.x() - m_handlePosBeforePress.x()
325 : m_pressPos.y() - m_handlePosBeforePress.y();
327 const QQuickItem *pressedHandleItem = m_handleItems.at(m_pressedHandleIndex);
328 const qreal pressedHandleSize = horizontal ? pressedHandleItem->width() : pressedHandleItem->height();
330 if (resizeLeftItem) {
334 for (
int i = m_pressedHandleIndex - 1; i >= 0; --i) {
335 const QQuickItem *nextHandleToTheLeft = m_handleItems.at(i);
336 if (nextHandleToTheLeft->isVisible()) {
337 leftEdge = horizontal
338 ? nextHandleToTheLeft->x() + nextHandleToTheLeft->width()
339 : nextHandleToTheLeft->y() + nextHandleToTheLeft->height();
346 const qreal pressedHandlePos = clampedMousePos - mousePosRelativeToLeftHandleEdge;
348 const qreal rightStop = size - accumulated - pressedHandleSize;
349 qreal leftStop = qMax(leftEdge, pressedHandlePos);
351 if (leftStop > rightStop)
352 leftStop = rightStop;
353 const qreal newHandlePos = qBound(leftStop, pressedHandlePos, rightStop);
354 const qreal newItemSize = newHandlePos - leftEdge;
359 requestedSize = newItemSize;
361 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": resized (dragged) " << item
362 <<
" (clampedMousePos=" << clampedMousePos
363 <<
" pressedHandlePos=" << pressedHandlePos
364 <<
" accumulated=" << accumulated
365 <<
" leftEdge=" << leftEdge
366 <<
" leftStop=" << leftStop
367 <<
" rightStop=" << rightStop
368 <<
" newHandlePos=" << newHandlePos
369 <<
" newItemSize=" << newItemSize <<
")";
373 qreal rightEdge = size;
374 if (m_nextVisibleIndexAfterPressedHandle < m_handleItems.size()) {
375 const QQuickItem *rightHandle = m_handleItems.at(m_nextVisibleIndexAfterPressedHandle);
376 rightEdge = horizontal ? rightHandle->x() : rightHandle->y();
381 const qreal pressedHandlePos = clampedMousePos - mousePosRelativeToLeftHandleEdge;
383 const qreal leftStop = accumulated - pressedHandleSize;
384 qreal rightStop = qMin(rightEdge - pressedHandleSize, pressedHandlePos);
386 if (rightStop < leftStop)
387 rightStop = leftStop;
388 const qreal newHandlePos = qBound(leftStop, pressedHandlePos, rightStop);
389 const qreal newItemSize = rightEdge - (newHandlePos + pressedHandleSize);
394 requestedSize = newItemSize;
396 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": resized (dragged) " << item
397 <<
" (clampedMousePos=" << clampedMousePos
398 <<
" pressedHandlePos=" << pressedHandlePos
399 <<
" accumulated=" << accumulated
400 <<
" leftEdge=" << rightEdge
401 <<
" leftStop=" << leftStop
402 <<
" rightStop=" << rightStop
403 <<
" newHandlePos=" << newHandlePos
404 <<
" newItemSize=" << newItemSize <<
")";
406 }
else if (index != m_fillIndex) {
409 requestedSize = horizontal
410 ? sizeData.effectivePreferredWidth : sizeData.effectivePreferredHeight;
413 if (index != m_fillIndex) {
414 LayoutData layoutData;
416 layoutData.width = qBound(
417 sizeData.effectiveMinimumWidth,
419 sizeData.effectiveMaximumWidth);
420 layoutData.height = height;
422 layoutData.width = width;
423 layoutData.height = qBound(
424 sizeData.effectiveMinimumHeight,
426 sizeData.effectiveMaximumHeight);
432 layoutData.wasResizedByHandle =
true;
434 m_layoutData.insert(item, layoutData);
436 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": calculated the following size data for split item " << item
437 <<
": eminW=" << sizeData.effectiveMinimumWidth
438 <<
", eminH=" << sizeData.effectiveMinimumHeight
439 <<
", eprfW=" << sizeData.effectivePreferredWidth
440 <<
", eprfH=" << sizeData.effectivePreferredHeight
441 <<
", emaxW=" << sizeData.effectiveMaximumWidth
442 <<
", emaxH=" << sizeData.effectiveMaximumHeight
443 <<
", w=" << layoutData.width
444 <<
", h=" << layoutData.height <<
"";
448 usedWidth += layoutData.width;
450 usedHeight += layoutData.height;
451 }
else if (indexBeingResizedDueToDrag != m_fillIndex) {
453 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": skipping fill item as we resize it last";
458 if (index < count - 1 && m_handle) {
459 QQuickItem *handleItem = m_handleItems.at(index);
467 if (handleItem->isVisible()) {
469 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index
470 <<
": handle takes up " << handleItem->width() <<
" width";
471 usedWidth += handleItem->width();
473 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index
474 <<
": handle takes up " << handleItem->height() <<
" height";
475 usedHeight += handleItem->height();
478 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": handle is not visible; skipping it";
490void QQuickSplitViewPrivate::layoutResizeFillItem(QQuickItem *fillItem,
491 qreal &usedWidth, qreal &usedHeight,
int indexBeingResizedDueToDrag)
495 if (!fillItem || !fillItem->isVisible() || indexBeingResizedDueToDrag == m_fillIndex) {
496 qCDebug(qlcQQuickSplitView).nospace() << m_fillIndex <<
": - fill item " << fillItem
497 <<
" is not visible or was already resized due to a drag;"
498 <<
" skipping it and its handles (if any)";
502 const QQuickItemPrivate *fillItemPrivate = QQuickItemPrivate::get(fillItem);
503 const QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
504 qmlAttachedPropertiesObject<QQuickSplitView>(fillItem,
false));
505 const auto fillSizeData = effectiveSizeData(fillItemPrivate, attached);
507 LayoutData layoutData;
508 if (isHorizontal()) {
509 layoutData.width = qBound(
510 fillSizeData.effectiveMinimumWidth,
512 fillSizeData.effectiveMaximumWidth);
513 layoutData.height = height;
514 usedWidth += layoutData.width;
516 layoutData.width = width;
517 layoutData.height = qBound(
518 fillSizeData.effectiveMinimumHeight,
520 fillSizeData.effectiveMaximumHeight);
521 usedHeight += layoutData.height;
524 m_layoutData.insert(fillItem, layoutData);
526 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << m_fillIndex
527 <<
": resized split fill item " << fillItem <<
" (effective"
528 <<
" minW=" << fillSizeData.effectiveMinimumWidth
529 <<
", minH=" << fillSizeData.effectiveMinimumHeight
530 <<
", maxW=" << fillSizeData.effectiveMaximumWidth
531 <<
", maxH=" << fillSizeData.effectiveMaximumHeight <<
")";
537void QQuickSplitViewPrivate::limitAndApplySizes(qreal usedWidth, qreal usedHeight)
539 const int count = contentModel->count();
540 const bool horizontal = isHorizontal();
542 const qreal maxSize = horizontal ? width : height;
543 const qreal usedSize = horizontal ? usedWidth : usedHeight;
544 if (usedSize > maxSize) {
545 qCDebug(qlcQQuickSplitView).nospace() <<
"usedSize " << usedSize <<
" is greater than maxSize "
546 << maxSize <<
"; reducing size of non-filled items from right to left / bottom to top";
551 qreal delta = usedSize - maxSize;
552 for (
int index = count - 1; index >= 0; --index) {
553 if (index == m_fillIndex)
555 QQuickItem *item = qobject_cast<QQuickItem*>(contentModel->object(index));
556 if (!item || !item->isVisible())
559 const QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
560 QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
561 qmlAttachedPropertiesObject<QQuickSplitView>(item,
false));
562 const auto sizeData = effectiveSizeData(itemPrivate, attached);
563 const qreal maxReduce = horizontal ?
564 m_layoutData[item].width - sizeData.effectiveMinimumWidth :
565 m_layoutData[item].height - sizeData.effectiveMinimumHeight;
567 const qreal reduce = std::min(maxReduce, delta);
569 m_layoutData[item].width -= reduce;
571 m_layoutData[item].height -= reduce;
581 qCDebug(qlcQQuickSplitView).nospace() <<
" applying new sizes to " << count <<
" items (excluding hidden items)";
584 for (
int index = 0; index < count; ++index) {
585 QQuickItem *item = qobject_cast<QQuickItem*>(contentModel->object(index));
586 if (!item || !item->isVisible())
589 QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
590 qmlAttachedPropertiesObject<QQuickSplitView>(item,
false));
591 LayoutData layoutData = m_layoutData.value(item);
592 if (layoutData.wasResizedByHandle) {
597 attached = qobject_cast<QQuickSplitViewAttached*>(
598 qmlAttachedPropertiesObject<QQuickSplitView>(item,
true));
601
602
603
604
605
606
607
608
609
610
611
612 m_ignoreNextLayoutRequest =
true;
614 attached->setPreferredWidth(layoutData.width);
616 attached->setPreferredHeight(layoutData.height);
619 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << index <<
": resized item " << item <<
" from "
620 << item->width() <<
"x" << item->height() <<
" to "
621 << layoutData.width <<
"x" << layoutData.height;
623 item->setWidth(layoutData.width);
624 item->setHeight(layoutData.height);
633void QQuickSplitViewPrivate::layoutPositionItems(
const QQuickItem *fillItem)
635 const bool horizontal = isHorizontal();
636 const int count = contentModel->count();
638 qreal usedHeight = 0;
640 for (
int i = 0; i < count; ++i) {
641 QQuickItem *item = qobject_cast<QQuickItem*>(contentModel->object(i));
642 if (!item || !item->isVisible()) {
643 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << i <<
": split item " << item
644 <<
" is not visible; skipping it and its handles (if any)";
650 item->setX(usedWidth);
654 item->setY(usedHeight);
659 usedWidth += item->width();
661 usedHeight += item->height();
663 if (Q_UNLIKELY(qlcQQuickSplitView().isDebugEnabled() && fillItem)) {
664 const QQuickItemPrivate *fillItemPrivate = QQuickItemPrivate::get(fillItem);
665 const QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
666 qmlAttachedPropertiesObject<QQuickSplitView>(fillItem,
false));
667 const auto sizeData = effectiveSizeData(fillItemPrivate, attached);
668 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << i <<
": positioned "
669 << (i == m_fillIndex ?
"fill item " :
"item ") << item <<
" (effective"
670 <<
" minW=" << sizeData.effectiveMinimumWidth
671 <<
", minH=" << sizeData.effectiveMinimumHeight
672 <<
", prfW=" << sizeData.effectivePreferredWidth
673 <<
", prfH=" << sizeData.effectivePreferredHeight
674 <<
", maxW=" << sizeData.effectiveMaximumWidth
675 <<
", maxH=" << sizeData.effectiveMaximumHeight <<
")";
679 if (i < count - 1 && m_handle) {
681 QQuickItem *handleItem = m_handleItems.at(i);
682 handleItem->setX(horizontal ? usedWidth : 0);
683 handleItem->setY(horizontal ? 0 : usedHeight);
686 usedWidth += handleItem->width();
688 usedHeight += handleItem->height();
690 qCDebug(qlcQQuickSplitView).nospace() <<
" - " << i <<
": positioned handle " << handleItem;
714void QQuickSplitViewPrivate::layout()
716 if (!componentComplete)
722 const int count = contentModel->count();
726 Q_ASSERT_X(m_fillIndex < count, Q_FUNC_INFO, qPrintable(
727 QString::fromLatin1(
"m_fillIndex is %1 but our count is %2").arg(m_fillIndex).arg(count)));
729 Q_ASSERT_X(!m_handle || m_handleItems.size() == count - 1, Q_FUNC_INFO, qPrintable(QString::fromLatin1(
730 "Expected %1 handle items, but there are %2").arg(count - 1).arg(m_handleItems.size())));
735 QScopedValueRollback guard(m_layingOut,
true);
737 const bool horizontal = isHorizontal();
738 qCDebug(qlcQQuickSplitView) <<
"laying out" << count <<
"split items"
739 << (horizontal ?
"horizontally" :
"vertically") <<
"in SplitView" << q_func();
743 qreal usedHeight = 0;
744 int indexBeingResizedDueToDrag = -1;
745 m_layoutData.clear();
747 qCDebug(qlcQQuickSplitView) <<
" resizing:";
751 layoutResizeSplitItems(usedWidth, usedHeight, indexBeingResizedDueToDrag);
753 qCDebug(qlcQQuickSplitView).nospace()
754 <<
" - (remaining width=" << width - usedWidth
755 <<
" remaining height=" << height - usedHeight <<
")";
758 QQuickItem *fillItem = qobject_cast<QQuickItem*>(contentModel->object(m_fillIndex));
759 layoutResizeFillItem(fillItem, usedWidth, usedHeight, indexBeingResizedDueToDrag);
762 limitAndApplySizes(usedWidth, usedHeight);
764 qCDebug(qlcQQuickSplitView) <<
" positioning:";
767 layoutPositionItems(fillItem);
769 qCDebug(qlcQQuickSplitView).nospace() <<
"finished layouting";
835qreal QQuickSplitViewPrivate::accumulatedSize(
int firstIndex,
int lastIndex)
const
838 const bool horizontal = isHorizontal();
839 for (
int i = firstIndex; i <= lastIndex; ++i) {
840 QQuickItem *item = qobject_cast<QQuickItem*>(contentModel->object(i));
841 if (item && item->isVisible()) {
842 if (i != m_fillIndex) {
843 size += horizontal ? item->width() : item->height();
846 const QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
847 qmlAttachedPropertiesObject<QQuickSplitView>(item,
false));
849 const QQuickSplitViewAttachedPrivate *attachedPrivate
850 = QQuickSplitViewAttachedPrivate::get(attached);
851 if (horizontal && attachedPrivate->m_isMinimumWidthSet)
852 size += attachedPrivate->m_minimumWidth;
853 else if (!horizontal && attachedPrivate->m_isMinimumHeightSet)
854 size += attachedPrivate->m_minimumHeight;
860 if (i < lastIndex || lastIndex < contentModel->count() - 1) {
861 const QQuickItem *handleItem = m_handleItems.at(i);
862 if (handleItem->isVisible())
863 size += horizontal ? handleItem->width() : handleItem->height();
992void QQuickSplitViewPrivate::updateHoveredHandle(QQuickItem *hoveredItem)
994 qCDebug(qlcQQuickSplitViewPointer) <<
"updating hovered handle after" << hoveredItem <<
"was hovered";
996 const int oldHoveredHandleIndex = m_hoveredHandleIndex;
997 m_hoveredHandleIndex = m_handleItems.indexOf(hoveredItem);
998 if (m_hoveredHandleIndex == oldHoveredHandleIndex)
1002 if (oldHoveredHandleIndex != -1) {
1003 QQuickItem *oldHoveredHandle = m_handleItems.at(oldHoveredHandleIndex);
1004 QQuickSplitHandleAttached *oldHoveredHandleAttached = qobject_cast<QQuickSplitHandleAttached*>(
1005 qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(oldHoveredHandle,
true));
1006 QQuickSplitHandleAttachedPrivate::get(oldHoveredHandleAttached)->setHovered(
false);
1007 qCDebug(qlcQQuickSplitViewPointer) <<
"handle item at index" << oldHoveredHandleIndex <<
"is no longer hovered";
1010 if (m_hoveredHandleIndex != -1) {
1011 QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
1012 qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(hoveredItem,
true));
1013 QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(
true);
1014 qCDebug(qlcQQuickSplitViewPointer) <<
"handle item at index" << m_hoveredHandleIndex <<
"is now hovered";
1016 qCDebug(qlcQQuickSplitViewPointer) <<
"either there is no hovered item or" << hoveredItem <<
"is not a handle";
1044bool QQuickSplitViewPrivate::handlePress(
const QPointF &point, ulong timestamp)
1046 Q_Q(QQuickSplitView);
1047 QQuickContainerPrivate::handlePress(point, timestamp);
1049 QQuickItem *pressedItem = q->childAt(point.x(), point.y());
1050 const int pressedHandleIndex = m_handleItems.indexOf(pressedItem);
1051 if (pressedHandleIndex != -1) {
1052 m_pressedHandleIndex = pressedHandleIndex;
1056 const QQuickItem *leftOrTopItem = qobject_cast<QQuickItem*>(contentModel->object(m_pressedHandleIndex));
1058 QQuickItem *rightOrBottomItem =
nullptr;
1059 m_nextVisibleIndexAfterPressedHandle = -1;
1060 for (
int i = m_pressedHandleIndex + 1; i < contentModel->count(); ++i) {
1061 auto nextItem = qobject_cast<QQuickItem*>(contentModel->object(i));
1062 if (nextItem && nextItem->isVisible()) {
1063 rightOrBottomItem = nextItem;
1064 m_nextVisibleIndexAfterPressedHandle = i;
1068 Q_ASSERT_X(rightOrBottomItem, Q_FUNC_INFO, qPrintable(QString::fromLatin1(
1069 "Failed to find a visible item to the right/bottom of the one that was pressed at index %1; this shouldn't happen")
1070 .arg(m_pressedHandleIndex)));
1072 const bool isHorizontal = m_orientation == Qt::Horizontal;
1073 if (leftOrTopItem) {
1074 m_leftOrTopItemSizeBeforePress = isHorizontal
1075 ? leftOrTopItem->width()
1076 : leftOrTopItem->height();
1078 m_rightOrBottomItemSizeBeforePress = isHorizontal ? rightOrBottomItem->width() : rightOrBottomItem->height();
1079 m_handlePosBeforePress = pressedItem->position();
1083 QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
1084 qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(pressedItem,
true));
1085 QQuickSplitHandleAttachedPrivate::get(handleAttached)->setPressed(
true);
1089 qCDebug(qlcQQuickSplitViewPointer).nospace() <<
"handled press -"
1090 <<
" left/top index=" << m_pressedHandleIndex <<
","
1091 <<
" size before press=" << m_leftOrTopItemSizeBeforePress <<
","
1092 <<
" item=" << leftOrTopItem
1093 <<
" right/bottom index=" << m_nextVisibleIndexAfterPressedHandle <<
","
1094 <<
" size before press=" << m_rightOrBottomItemSizeBeforePress
1095 <<
" item=" << rightOrBottomItem;
1345QVariant QQuickSplitView::saveState()
1347#if QT_CONFIG(cborstreamwriter)
1348 Q_D(QQuickSplitView);
1349 qCDebug(qlcQQuickSplitViewState) <<
"saving state for split items in" <<
this;
1352 QCborArray cborArray;
1353 for (
int i = 0; i < d->contentModel->count(); ++i) {
1354 const QQuickItem *item = qobject_cast<QQuickItem*>(d->contentModel->object(i));
1355 const QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
1356 qmlAttachedPropertiesObject<QQuickSplitView>(item,
false));
1365 const QQuickSplitViewAttachedPrivate *attachedPrivate = QQuickSplitViewAttachedPrivate::get(attached);
1366 if (!attachedPrivate->m_isPreferredWidthSet && !attachedPrivate->m_isPreferredHeightSet)
1370 cborMap[QLatin1String(
"index")] = i;
1371 if (attachedPrivate->m_isPreferredWidthSet) {
1372 cborMap[QLatin1String(
"preferredWidth")] =
static_cast<
double>(attachedPrivate->m_preferredWidth);
1374 qCDebug(qlcQQuickSplitViewState).nospace() <<
"- wrote preferredWidth of "
1375 << attachedPrivate->m_preferredWidth <<
" for split item " << item <<
" at index " << i;
1377 if (attachedPrivate->m_isPreferredHeightSet) {
1378 cborMap[QLatin1String(
"preferredHeight")] =
static_cast<
double>(attachedPrivate->m_preferredHeight);
1380 qCDebug(qlcQQuickSplitViewState).nospace() <<
"- wrote preferredHeight of "
1381 << attachedPrivate->m_preferredHeight <<
" for split item " << item <<
" at index " << i;
1384 cborArray.append(cborMap);
1387 const QByteArray byteArray = cborArray.toCborValue().toCbor();
1388 qCDebug(qlcQQuickSplitViewState) <<
"the resulting byte array is:" << byteArray;
1389 return QVariant(byteArray);
1404bool QQuickSplitView::restoreState(
const QVariant &state)
1406 const QByteArray cborByteArray = state.toByteArray();
1407 Q_D(QQuickSplitView);
1408 if (cborByteArray.isEmpty())
1411 QCborParserError parserError;
1412 const QCborValue cborValue(QCborValue::fromCbor(cborByteArray, &parserError));
1413 if (parserError.error != QCborError::NoError) {
1414 qmlWarning(
this) <<
"Error reading SplitView state:" << parserError.errorString();
1418 qCDebug(qlcQQuickSplitViewState) <<
"restoring state for split items of" <<
this
1419 <<
"from the following string:" << state;
1421 const QCborArray cborArray(cborValue.toArray());
1422 const int ourCount = d->contentModel->count();
1424 if (cborArray.size() > ourCount) {
1425 qmlWarning(
this) <<
"Error reading SplitView state: expected "
1426 << ourCount <<
" or less split items but got " << cborArray.size();
1430 for (
auto it = cborArray.constBegin(); it != cborArray.constEnd(); ++it) {
1431 QCborMap cborMap(it->toMap());
1432 const int splitItemIndex = cborMap.value(QLatin1String(
"index")).toInteger();
1433 const bool isPreferredWidthSet = cborMap.contains(QLatin1String(
"preferredWidth"));
1434 const bool isPreferredHeightSet = cborMap.contains(QLatin1String(
"preferredHeight"));
1436 QQuickItem *item = qobject_cast<QQuickItem*>(d->contentModel->object(splitItemIndex));
1440 QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
1441 qmlAttachedPropertiesObject<QQuickSplitView>(item,
true));
1442 if (isPreferredWidthSet) {
1443 const qreal preferredWidth = cborMap.value(QLatin1String(
"preferredWidth")).toDouble();
1444 attached->setPreferredWidth(preferredWidth);
1446 if (isPreferredHeightSet) {
1447 const qreal preferredHeight = cborMap.value(QLatin1String(
"preferredHeight")).toDouble();
1448 attached->setPreferredHeight(preferredHeight);
1451 const QQuickSplitViewAttachedPrivate *attachedPrivate = QQuickSplitViewAttachedPrivate::get(attached);
1452 qCDebug(qlcQQuickSplitViewState).nospace()
1453 <<
"- restored the following state for split item " << item <<
" at index " << splitItemIndex
1454 <<
": preferredWidthSet=" << attachedPrivate->m_isPreferredWidthSet
1455 <<
" preferredWidth=" << attachedPrivate->m_preferredWidth
1456 <<
" preferredHeightSet=" << attachedPrivate->m_isPreferredHeightSet
1457 <<
" preferredHeight=" << attachedPrivate->m_preferredHeight;
1488bool QQuickSplitView::childMouseEventFilter(QQuickItem *item, QEvent *event)
1490 Q_D(QQuickSplitView);
1491 qCDebug(qlcQQuickSplitViewPointer) <<
"childMouseEventFilter called with" << item << event;
1493 if (Q_LIKELY(event->isPointerEvent())) {
1494 auto *pointerEvent =
static_cast<QPointerEvent *>(event);
1495 const auto &eventPoint = pointerEvent->points().first();
1496 const QPointF point = mapFromItem(item, eventPoint.position());
1497 const auto timestamp = pointerEvent->timestamp();
1499 switch (event->type()) {
1500 case QEvent::MouseButtonPress:
1501 d->handlePress(point, timestamp);
1504 if (d->m_pressedHandleIndex != -1)
1505 item->setKeepMouseGrab(
true);
1507 case QEvent::MouseButtonRelease:
1508 d->handleRelease(point, timestamp);
1510 case QEvent::MouseMove:
1511 d->handleMove(point, timestamp);
1513 case QEvent::TouchBegin:
1514 if (pointerEvent->pointCount() == 1) {
1515 d->handlePress(point, timestamp);
1519 if (d->m_pressedHandleIndex != -1) {
1520 item->setKeepTouchGrab(
true);
1521 pointerEvent->setExclusiveGrabber(eventPoint, item);
1525 case QEvent::TouchEnd:
1526 if (pointerEvent->pointCount() == 1)
1527 d->handleRelease(point, timestamp);
1529 case QEvent::TouchUpdate:
1530 if (pointerEvent->pointCount() == 1)
1531 d->handleMove(point, timestamp);
1540 if (d->m_pressedHandleIndex != -1)
1543 return QQuickContainer::childMouseEventFilter(item, event);
1596void QQuickSplitView::itemRemoved(
int index, QQuickItem *item)
1598 Q_D(QQuickSplitView);
1599 if (QQuickItemPrivate::get(item)->isTransparentForPositioner())
1602 qCDebug(qlcQQuickSplitView).nospace() <<
"split item " << item <<
" removed from index " << index
1603 <<
"; there are now " << d->contentModel->count() <<
" items";
1606 if (d->m_hoveredHandleIndex != -1 || d->m_pressedHandleIndex != -1) {
1607 const int handleIndex = d->m_hoveredHandleIndex != -1 ? d->m_hoveredHandleIndex : d->m_pressedHandleIndex;
1608 QQuickItem *itemHandle = d->m_handleItems.at(handleIndex);
1609 QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
1610 qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(itemHandle,
false));
1611 if (handleAttached) {
1612 auto handleAttachedPrivate = QQuickSplitHandleAttachedPrivate::get(handleAttached);
1613 handleAttachedPrivate->setHovered(
false);
1614 handleAttachedPrivate->setPressed(
false);
1617 d->m_hoveredHandleIndex = -1;
1618 d->m_pressedHandleIndex = -1;
1622 QQuickSplitViewAttached *attached = qobject_cast<QQuickSplitViewAttached*>(
1623 qmlAttachedPropertiesObject<QQuickSplitView>(item,
false));
1625 QQuickSplitViewAttachedPrivate::get(attached)->setView(
this);
1627 d->removeImplicitSizeListener(item);
1629 d->removeExcessHandles();
1630 d->updateHandleVisibilities();
1631 d->updateFillIndex();