static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry, QRectF *rect, Qt::WindowFrameSection section, const QSizeF &min, const QSizeF &max, const QGraphicsWidget *widget) { const QRectF proposedRect = *rect; qreal width = qBound(min.width(), proposedRect.width(), max.width()); qreal height = qBound(min.height(), proposedRect.height(), max.height()); const bool hasHFW = QGraphicsLayoutItemPrivate::get(widget)->hasHeightForWidth(); const bool hasWFH = QGraphicsLayoutItemPrivate::get(widget)->hasWidthForHeight(); const bool widthChanged = proposedRect.width() != widget->size().width(); const bool heightChanged = proposedRect.height() != widget->size().height(); if (hasHFW || hasWFH) { if (widthChanged || heightChanged) { qreal minExtent; qreal maxExtent; qreal constraint; qreal proposed; if (hasHFW) { minExtent = min.height(); maxExtent = max.height(); constraint = width; proposed = proposedRect.height(); } else { // width for height minExtent = min.width(); maxExtent = max.width(); constraint = height; proposed = proposedRect.width(); } if (minimumHeightForWidth(constraint, minExtent, maxExtent, widget, hasHFW) > proposed) { QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget); width = effectiveSize.width(); height = effectiveSize.height(); } } } switch (section) { case Qt::LeftSection: rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), qRound(width), startGeometry.height()); break; case Qt::TopLeftSection: rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height), qRound(width), qRound(height)); break; case Qt::TopSection: rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height), startGeometry.width(), qRound(height)); break; case Qt::TopRightSection: rect->setTop(rect->bottom() - qRound(height)); rect->setWidth(qRound(width)); break; case Qt::RightSection: rect->setWidth(qRound(width)); break; case Qt::BottomRightSection: rect->setWidth(qRound(width)); rect->setHeight(qRound(height)); break; case Qt::BottomSection: rect->setHeight(qRound(height)); break; case Qt::BottomLeftSection: rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), qRound(width), qRound(height)); break; default: break; } }
static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry, QRectF *rect, Qt::WindowFrameSection section, const QSizeF &min, const QSizeF &max, const QGraphicsWidget *widget) { const QRectF proposedRect = *rect; qreal width = qBound(min.width(), proposedRect.width(), max.width()); qreal height = qBound(min.height(), proposedRect.height(), max.height()); QSizePolicy sp = widget->sizePolicy(); if (const QGraphicsLayout *l = widget->layout()) { sp = l->sizePolicy(); } const bool hasHFW = sp.hasHeightForWidth(); // || sp.hasWidthForHeight(); const bool widthChanged = proposedRect.width() < widget->size().width(); const bool heightChanged = proposedRect.height() < widget->size().height(); if (hasHFW) { if (widthChanged || heightChanged) { const qreal minh = min.height(); const qreal maxh = max.height(); const qreal proposedHFW = minimumHeightForWidth(width, minh, maxh, widget); if (proposedHFW > proposedRect.height()) { QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget); width = effectiveSize.width(); height = effectiveSize.height(); } } } switch (section) { case Qt::LeftSection: rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), qRound(width), startGeometry.height()); break; case Qt::TopLeftSection: rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height), qRound(width), qRound(height)); break; case Qt::TopSection: rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height), startGeometry.width(), qRound(height)); break; case Qt::TopRightSection: rect->setTop(rect->bottom() - qRound(height)); rect->setWidth(qRound(width)); break; case Qt::RightSection: rect->setWidth(qRound(width)); break; case Qt::BottomRightSection: rect->setWidth(qRound(width)); rect->setHeight(qRound(height)); break; case Qt::BottomSection: rect->setHeight(qRound(height)); break; case Qt::BottomLeftSection: rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), qRound(width), qRound(height)); break; default: break; } }