summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp39
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h6
-rw-r--r--src/gui/graphicsview/qgraphicslayoutitem.cpp4
-rw-r--r--src/gui/graphicsview/qgraphicsproxywidget.cpp6
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp14
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicssceneevent.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp10
-rw-r--r--src/gui/graphicsview/qgraphicsview_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicswidget.cpp18
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp317
-rw-r--r--src/gui/graphicsview/qgridlayoutengine_p.h13
12 files changed, 198 insertions, 235 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 83aafe9..e9a2f9f 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -2365,7 +2365,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
while (fsi->d_ptr->focusScopeItem && fsi->d_ptr->focusScopeItem->isVisible())
fsi = fsi->d_ptr->focusScopeItem;
fsi->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ true,
- /* focusFromShow = */ true);
+ /* focusFromHide = */ false);
}
break;
}
@@ -2375,6 +2375,10 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
QGraphicsItem *fi = subFocusItem;
if (fi && fi != scene->focusItem()) {
scene->setFocusItem(fi);
+ } else if (flags & QGraphicsItem::ItemIsFocusScope &&
+ !scene->focusItem() &&
+ q->isAncestorOf(scene->d_func()->lastFocusItem)) {
+ q_ptr->setFocus();
}
}
} else {
@@ -2385,7 +2389,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
if (p->d_ptr->visible) {
p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ true,
- /* focusFromShow = */ true);
+ /* focusFromHide = */ true);
}
break;
}
@@ -3245,13 +3249,13 @@ bool QGraphicsItem::hasFocus() const
*/
void QGraphicsItem::setFocus(Qt::FocusReason focusReason)
{
- d_ptr->setFocusHelper(focusReason, /* climb = */ true, /* focusFromShow = */ false);
+ d_ptr->setFocusHelper(focusReason, /* climb = */ true, /* focusFromHide = */ false);
}
/*!
\internal
*/
-void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromShow)
+void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromHide)
{
// Disabled / unfocusable items cannot accept focus.
if (!q_ptr->isEnabled() || !(flags & QGraphicsItem::ItemIsFocusable))
@@ -3272,7 +3276,7 @@ void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool clim
if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
QGraphicsItem *oldFocusScopeItem = p->d_ptr->focusScopeItem;
p->d_ptr->focusScopeItem = q_ptr;
- if (!p->focusItem() && !focusFromShow) {
+ if (!p->focusItem() && !focusFromHide) {
if (oldFocusScopeItem)
oldFocusScopeItem->d_ptr->focusScopeItemChange(false);
focusScopeItemChange(true);
@@ -3318,8 +3322,7 @@ void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool clim
*/
void QGraphicsItem::clearFocus()
{
- if (hasFocus())
- d_ptr->clearFocusHelper(/* giveFocusToParent = */ true);
+ d_ptr->clearFocusHelper(/* giveFocusToParent = */ true);
}
/*!
@@ -3333,8 +3336,14 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent)
QGraphicsItem *p = parent;
while (p) {
if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
- p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false,
- /* focusFromShow = */ false);
+ if (p->d_ptr->focusScopeItem == q_ptr) {
+ p->d_ptr->focusScopeItem = 0;
+ if (!q_ptr->hasFocus()) //if it has focus, focusScopeItemChange is called elsewhere
+ focusScopeItemChange(false);
+ }
+ if (q_ptr->hasFocus())
+ p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false,
+ /* focusFromHide = */ false);
return;
}
p = p->d_ptr->parent;
@@ -3342,10 +3351,10 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent)
}
}
- // Invisible items with focus must explicitly clear subfocus.
- clearSubFocus(q_ptr);
-
if (q_ptr->hasFocus()) {
+ // Invisible items with focus must explicitly clear subfocus.
+ clearSubFocus(q_ptr);
+
// If this item has the scene's input focus, clear it.
scene->setFocusItem(0);
}
@@ -3702,6 +3711,8 @@ void QGraphicsItem::setPos(const QPointF &pos)
d_ptr->setPosHelper(pos);
if (d_ptr->isWidget)
static_cast<QGraphicsWidget *>(this)->d_func()->setGeometryFromSetPos();
+ if (d_ptr->scenePosDescendants)
+ d_ptr->sendScenePosChange();
return;
}
@@ -4384,8 +4395,10 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)
return;
// Update and set the new transformation.
- if (!(d_ptr->flags & ItemSendsGeometryChanges)) {
+ if (!(d_ptr->flags & (ItemSendsGeometryChanges | ItemSendsScenePositionChanges))) {
d_ptr->setTransformHelper(newTransform);
+ if (d_ptr->scenePosDescendants)
+ d_ptr->sendScenePosChange();
return;
}
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index c8a7699..1b7aa97 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -477,7 +477,7 @@ public:
inline void markParentDirty(bool updateBoundingRect = false);
- void setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromShow);
+ void setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromHide);
void clearFocusHelper(bool giveFocusToParent);
void setSubFocus(QGraphicsItem *rootItem = 0);
void clearSubFocus(QGraphicsItem *rootItem = 0);
@@ -722,7 +722,7 @@ public:
/*!
Returns true if \a item1 is on top of \a item2.
- The items dont need to be siblings.
+ The items don't need to be siblings.
\internal
*/
@@ -776,7 +776,7 @@ inline bool qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem
/*!
Returns true if \a item2 is on top of \a item1.
- The items dont need to be siblings.
+ The items don't need to be siblings.
\internal
*/
diff --git a/src/gui/graphicsview/qgraphicslayoutitem.cpp b/src/gui/graphicsview/qgraphicslayoutitem.cpp
index 34ec4e0..fab1bbb 100644
--- a/src/gui/graphicsview/qgraphicslayoutitem.cpp
+++ b/src/gui/graphicsview/qgraphicslayoutitem.cpp
@@ -140,11 +140,9 @@ QSizeF *QGraphicsLayoutItemPrivate::effectiveSizeHints(const QSizeF &constraint)
if (!sizeHintCacheDirty && cachedConstraint == constraint)
return cachedSizeHints;
- const bool hasConstraint = constraint.width() >= 0 || constraint.height() >= 0;
-
for (int i = 0; i < Qt::NSizeHints; ++i) {
cachedSizeHints[i] = constraint;
- if (userSizeHints && !hasConstraint)
+ if (userSizeHints)
combineSize(cachedSizeHints[i], userSizeHints[i]);
}
diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp
index 320395e..bf61150 100644
--- a/src/gui/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp
@@ -266,8 +266,8 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
}
if (!lastWidgetUnderMouse) {
- QApplicationPrivate::dispatchEnterLeave(embeddedMouseGrabber ? embeddedMouseGrabber : widget, 0);
- lastWidgetUnderMouse = widget;
+ QApplicationPrivate::dispatchEnterLeave(embeddedMouseGrabber ? embeddedMouseGrabber : receiver, 0);
+ lastWidgetUnderMouse = receiver;
}
// Map event position from us to the receiver
@@ -1508,7 +1508,7 @@ int QGraphicsProxyWidget::type() const
Creates a proxy widget for the given \a child of the widget
contained in this proxy.
- This function makes it possible to aquire proxies for
+ This function makes it possible to acquire proxies for
non top-level widgets. For instance, you can embed a dialog,
and then transform only one of its widgets.
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 5b1da9e..981fbbc 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -3461,7 +3461,8 @@ bool QGraphicsScene::event(QEvent *event)
break;
}
case QEvent::Leave:
- d->leaveScene();
+ // hackieshly unpacking the viewport pointer from the leave event.
+ d->leaveScene(reinterpret_cast<QWidget *>(event->d));
break;
case QEvent::GraphicsSceneHelp:
helpEvent(static_cast<QGraphicsSceneHelpEvent *>(event));
@@ -3933,20 +3934,19 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv
Handles all actions necessary to clean up the scene when the mouse leaves
the view.
*/
-void QGraphicsScenePrivate::leaveScene()
+void QGraphicsScenePrivate::leaveScene(QWidget *viewport)
{
- Q_Q(QGraphicsScene);
#ifndef QT_NO_TOOLTIP
QToolTip::hideText();
#endif
+ QGraphicsView *view = qobject_cast<QGraphicsView *>(viewport->parent());
// Send HoverLeave events to all existing hover items, topmost first.
- QGraphicsView *senderWidget = qobject_cast<QGraphicsView *>(q->sender());
QGraphicsSceneHoverEvent hoverEvent;
- hoverEvent.setWidget(senderWidget);
+ hoverEvent.setWidget(viewport);
- if (senderWidget) {
+ if (view) {
QPoint cursorPos = QCursor::pos();
- hoverEvent.setScenePos(senderWidget->mapToScene(senderWidget->mapFromGlobal(cursorPos)));
+ hoverEvent.setScenePos(view->mapToScene(viewport->mapFromGlobal(cursorPos)));
hoverEvent.setLastScenePos(hoverEvent.scenePos());
hoverEvent.setScreenPos(cursorPos);
hoverEvent.setLastScreenPos(hoverEvent.screenPos());
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index f28dfe9..2818fb2 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -201,7 +201,7 @@ public:
bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent);
bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const;
- void leaveScene();
+ void leaveScene(QWidget *viewport);
void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
QGraphicsSceneDragDropEvent *source);
diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp
index a0ecd4c..d9ff655 100644
--- a/src/gui/graphicsview/qgraphicssceneevent.cpp
+++ b/src/gui/graphicsview/qgraphicssceneevent.cpp
@@ -1629,7 +1629,7 @@ QGraphicsSceneMoveEvent::~QGraphicsSceneMoveEvent()
}
/*!
- Returns the old position (i.e., the position immediatly before the widget
+ Returns the old position (i.e., the position immediately before the widget
was moved).
\sa newPos(), QGraphicsItem::setPos()
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index 2db29b9..73f1493 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -80,9 +80,7 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
yourself, you can call setSceneRect(). This will adjust the scroll bars'
ranges appropriately. Note that although the scene supports a virtually
unlimited size, the range of the scroll bars will never exceed the range of
- an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll
- bars' values, you can choose to use translate() to navigate the scene
- instead.
+ an integer (INT_MIN, INT_MAX).
QGraphicsView visualizes the scene by calling render(). By default, the
items are drawn onto the viewport by using a regular QPainter, and using
@@ -101,7 +99,8 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
convenience functions rotate(), scale(), translate() or shear(). The most
two common transformations are scaling, which is used to implement
zooming, and rotation. QGraphicsView keeps the center of the view fixed
- during a transformation.
+ during a transformation. Because of the scene alignment (setAligment()),
+ translating the view will have no visual impact.
You can interact with the items on the scene by using the mouse and
keyboard. QGraphicsView translates the mouse and key events into \e scene
@@ -2790,6 +2789,9 @@ bool QGraphicsView::viewportEvent(QEvent *event)
d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.first());
}
d->useLastMouseEvent = false;
+ // a hack to pass a viewport pointer to the scene inside the leave event
+ Q_ASSERT(event->d == 0);
+ event->d = reinterpret_cast<QEventPrivate *>(viewport());
QApplication::sendEvent(d->scene, event);
break;
#ifndef QT_NO_TOOLTIP
diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h
index 62be800..38c3bca 100644
--- a/src/gui/graphicsview/qgraphicsview_p.h
+++ b/src/gui/graphicsview/qgraphicsview_p.h
@@ -184,7 +184,7 @@ public:
#ifdef Q_WS_MAC
// QWidget::update() works slightly different on the Mac without the raster engine;
// it's not part of our backing store so it needs special threatment.
- if (QApplicationPrivate::graphics_system_name != "raster") {
+ if (QApplicationPrivate::graphics_system_name != QLatin1String("raster")) {
// At this point either HIViewSetNeedsDisplay (Carbon) or setNeedsDisplay: YES (Cocoa)
// is called, which means there's a pending update request. We want to dispatch it
// now because otherwise graphics view updates would require two
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp
index 1bfe266..e48f9a7 100644
--- a/src/gui/graphicsview/qgraphicswidget.cpp
+++ b/src/gui/graphicsview/qgraphicswidget.cpp
@@ -450,7 +450,7 @@ void QGraphicsWidget::setGeometry(const QRectF &rect)
bottom.
Contents margins are used by the assigned layout to define the placement
- of subwidgets and layouts. Margins are particularily useful for widgets
+ of subwidgets and layouts. Margins are particularly useful for widgets
that constrain subwidgets to only a section of its own geometry. For
example, a group box with a layout will place subwidgets inside its frame,
but below the title.
@@ -750,6 +750,22 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
/*!
\property QGraphicsWidget::layout
\brief The layout of the widget
+
+ Any existing layout manager is deleted before the new layout is assigned. If
+ \a layout is 0, the widget is left without a layout. Existing subwidgets'
+ geometries will remain unaffected.
+
+ QGraphicsWidget takes ownership of \a layout.
+
+ All widgets that are currently managed by \a layout or all of its
+ sublayouts, are automatically reparented to this item. The layout is then
+ invalidated, and the child widget geometries are adjusted according to
+ this item's geometry() and contentsMargins(). Children who are not
+ explicitly managed by \a layout remain unaffected by the layout after
+ it has been assigned to this widget.
+
+ If no layout is currently managing this widget, layout() will return 0.
+
*/
/*!
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index f8cd593..7f8d574 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -631,14 +631,17 @@ QRectF QGridLayoutItem::geometryWithin(qreal x, qreal y, qreal width, qreal heig
qreal cellWidth = width;
qreal cellHeight = height;
- QSize constraint;
+
+ QSizeF size = effectiveMaxSize(QSizeF(-1,-1));
if (hasDynamicConstraint()) {
- if (dynamicConstraintOrientation() == Qt::Vertical)
- constraint.setWidth(cellWidth);
- else
- constraint.setHeight(cellHeight);
+ if (dynamicConstraintOrientation() == Qt::Vertical) {
+ if (size.width() > cellWidth)
+ size = effectiveMaxSize(QSizeF(cellWidth, -1));
+ } else if(size.height() > cellHeight) {
+ size = effectiveMaxSize(QSizeF(-1, cellHeight));
+ }
}
- QSizeF size = effectiveMaxSize(constraint).boundedTo(QSizeF(cellWidth, cellHeight));
+ size = size.boundedTo(QSizeF(cellWidth, cellHeight));
width = size.width();
height = size.height();
@@ -714,7 +717,7 @@ QSizeF QGridLayoutItem::effectiveMaxSize(const QSizeF &constraint) const
}
if (!size.isValid()) {
- QSizeF maxSize = layoutItem()->effectiveSizeHint(Qt::MaximumSize, constraint);
+ QSizeF maxSize = layoutItem()->effectiveSizeHint(Qt::MaximumSize, size);
if (size.width() == -1)
size.setWidth(maxSize.width());
if (size.height() == -1)
@@ -1111,20 +1114,76 @@ QRectF QGridLayoutEngine::cellRect(const QLayoutStyleInfo &styleInfo,
QSizeF QGridLayoutEngine::sizeHint(const QLayoutStyleInfo &styleInfo, Qt::SizeHint which,
const QSizeF &constraint) const
{
- ensureColumnAndRowData(styleInfo);
+ QGridLayoutBox sizehint_totalBoxes[NOrientations];
- if (hasDynamicConstraint())
- return dynamicallyConstrainedSizeHint(which, constraint);
+ if(rowCount() < 1 || columnCount() < 1 || !hasDynamicConstraint()) {
+ //No items with height for width, so it doesn't matter which order we do these in
+ if(q_cachedDataForStyleInfo != styleInfo) {
+ ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, NULL, NULL, Qt::Horizontal);
+ ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, NULL, NULL, Qt::Vertical);
+ } else {
+ sizehint_totalBoxes[Hor] = q_totalBoxes[Hor];
+ sizehint_totalBoxes[Ver] = q_totalBoxes[Ver];
+ }
+ } else if(constraintOrientation() == Qt::Vertical) {
+ //We have items whose width depends on their height
+ if(q_cachedDataForStyleInfo != styleInfo)
+ ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, NULL, NULL, Qt::Horizontal);
+ else
+ sizehint_totalBoxes[Hor] = q_totalBoxes[Hor];
+ QVector<qreal> sizehint_xx;
+ QVector<qreal> sizehint_widths;
+
+ sizehint_xx.resize(columnCount());
+ sizehint_widths.resize(columnCount());
+ qreal width = constraint.width();
+ if(width < 0) {
+ /* It's not obvious what the behaviour should be. */
+/* if(which == Qt::MaximumSize)
+ width = sizehint_totalBoxes[Hor].q_maximumSize;
+ else if(which == Qt::MinimumSize)
+ width = sizehint_totalBoxes[Hor].q_minimumSize;
+ else*/
+ width = sizehint_totalBoxes[Hor].q_preferredSize;
+ }
+ //Calculate column widths and positions, and put results in q_xx.data() and q_widths.data() so that we can use this information as
+ //constraints to find the row heights
+ q_columnData.calculateGeometries(0, columnCount(), width, sizehint_xx.data(), sizehint_widths.data(),
+ 0, sizehint_totalBoxes[Hor]);
+ ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, sizehint_xx.data(), sizehint_widths.data(), Qt::Vertical);
+ } else {
+ //We have items whose height depends on their width
+ ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, NULL, NULL, Qt::Vertical);
+ QVector<qreal> sizehint_yy;
+ QVector<qreal> sizehint_heights;
+
+ sizehint_yy.resize(rowCount());
+ sizehint_heights.resize(rowCount());
+ qreal height = constraint.height();
+ if(height < 0) {
+/* if(which == Qt::MaximumSize)
+ height = sizehint_totalBoxes[Ver].q_maximumSize;
+ else if(which == Qt::MinimumSize)
+ height = sizehint_totalBoxes[Ver].q_minimumSize;
+ else*/
+ height = sizehint_totalBoxes[Ver].q_preferredSize;
+ }
+ //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() so that we can use this information as
+ //constraints to find the column widths
+ q_rowData.calculateGeometries(0, rowCount(), height, sizehint_yy.data(), sizehint_heights.data(),
+ 0, sizehint_totalBoxes[Ver]);
+ ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, sizehint_yy.data(), sizehint_heights.data(), Qt::Vertical);
+ }
switch (which) {
case Qt::MinimumSize:
- return QSizeF(q_totalBoxes[Hor].q_minimumSize, q_totalBoxes[Ver].q_minimumSize);
+ return QSizeF(sizehint_totalBoxes[Hor].q_minimumSize, sizehint_totalBoxes[Ver].q_minimumSize);
case Qt::PreferredSize:
- return QSizeF(q_totalBoxes[Hor].q_preferredSize, q_totalBoxes[Ver].q_preferredSize);
+ return QSizeF(sizehint_totalBoxes[Hor].q_preferredSize, sizehint_totalBoxes[Ver].q_preferredSize);
case Qt::MaximumSize:
- return QSizeF(q_totalBoxes[Hor].q_maximumSize, q_totalBoxes[Ver].q_maximumSize);
+ return QSizeF(sizehint_totalBoxes[Hor].q_maximumSize, sizehint_totalBoxes[Ver].q_maximumSize);
case Qt::MinimumDescent:
- return QSizeF(-1.0, q_totalBoxes[Hor].q_minimumDescent); // ### doesn't work
+ return QSizeF(-1.0, sizehint_totalBoxes[Hor].q_minimumDescent); // ### doesn't work
default:
break;
}
@@ -1300,6 +1359,7 @@ void QGridLayoutEngine::insertOrRemoveRows(int row, int delta, Qt::Orientation o
}
void QGridLayoutEngine::fillRowData(QGridLayoutRowData *rowData, const QLayoutStyleInfo &styleInfo,
+ qreal *colPositions, qreal *colSizes,
Qt::Orientation orientation) const
{
const int ButtonMask = QSizePolicy::ButtonBox | QSizePolicy::PushButton;
@@ -1413,11 +1473,21 @@ void QGridLayoutEngine::fillRowData(QGridLayoutRowData *rowData, const QLayoutSt
box = &multiCell.q_box;
multiCell.q_stretch = itemStretch;
}
- // Items with constraints are not included in the orientation that
- // they are constrained (since it depends on the hfw/constraint function).
- // They must be combined at a later stage.
- if (!item->hasDynamicConstraint() || orientation != item->dynamicConstraintOrientation())
+ // Items with constraints need to be passed the constraint
+ if (colSizes && colPositions && item->hasDynamicConstraint() && orientation == item->dynamicConstraintOrientation()) {
+ /* Get the width of the item by summing up the widths of the columns that it spans.
+ * We need to have already calculated the widths of the columns by calling
+ * q_columns->calculateGeometries() before hand and passing the value in the colSizes
+ * and colPositions parameters.
+ * The variable name is still colSizes even when it actually has the row sizes
+ */
+ qreal length = colSizes[item->lastColumn(orientation)];
+ if (item->columnSpan(orientation) != 1)
+ length += colPositions[item->lastColumn(orientation)] - colPositions[item->firstColumn(orientation)];
+ box->combine(item->box(orientation, length));
+ } else {
box->combine(item->box(orientation));
+ }
if (effectiveRowSpan == 1) {
QSizePolicy::ControlTypes controls = item->controlTypes(top);
@@ -1554,115 +1624,18 @@ void QGridLayoutEngine::ensureEffectiveFirstAndLastRows() const
}
}
-void QGridLayoutEngine::ensureColumnAndRowData(const QLayoutStyleInfo &styleInfo) const
+void QGridLayoutEngine::ensureColumnAndRowData(QGridLayoutRowData *rowData, QGridLayoutBox *totalBox,
+ const QLayoutStyleInfo &styleInfo,
+ qreal *colPositions, qreal *colSizes,
+ Qt::Orientation orientation) const
{
- if (q_cachedDataForStyleInfo == styleInfo)
- return;
-
- q_columnData.reset(columnCount());
- q_rowData.reset(rowCount());
-
- fillRowData(&q_columnData, styleInfo, Qt::Horizontal);
- fillRowData(&q_rowData, styleInfo, Qt::Vertical);
-
- q_columnData.distributeMultiCells();
- q_rowData.distributeMultiCells();
-
- q_totalBoxes[Hor] = q_columnData.totalBox(0, columnCount());
- q_totalBoxes[Ver] = q_rowData.totalBox(0, rowCount());
-
- q_cachedDataForStyleInfo = styleInfo;
+ rowData->reset(rowCount(orientation));
+ fillRowData(rowData, styleInfo, colPositions, colSizes, orientation);
+ rowData->distributeMultiCells();
+ *totalBox = rowData->totalBox(0, rowCount(orientation));
+ //We have items whose width depends on their height
}
-QSizeF QGridLayoutEngine::dynamicallyConstrainedSizeHint(Qt::SizeHint which,
- const QSizeF &constraint) const
-{
- Q_ASSERT(hasDynamicConstraint());
- if (constraint.width() < 0 && constraint.height() < 0) {
- // Process the hfw / wfh items that we did not process in fillRowData()
- const Qt::Orientation constraintOrient = constraintOrientation();
-
- QGridLayoutRowData rowData = constraintOrient == Qt::Vertical ? q_rowData : q_columnData;
- for (int i = q_items.count() - 1; i >= 0; --i) {
- QGridLayoutItem *item = q_items.at(i);
- if (item->hasDynamicConstraint()) {
- QGridLayoutBox box = item->box(constraintOrient);
- QGridLayoutBox &rowBox = rowData.boxes[item->firstRow(constraintOrient)];
- rowBox.combine(box);
- }
- }
-
- QGridLayoutBox totalBoxes[2];
- if (constraintOrient == Qt::Vertical) {
- totalBoxes[Hor] = q_columnData.totalBox(0, columnCount());
- totalBoxes[Ver] = rowData.totalBox(0, rowCount());
- } else {
- totalBoxes[Hor] = rowData.totalBox(0, columnCount());
- totalBoxes[Ver] = q_rowData.totalBox(0, rowCount());
- }
- return QSizeF(totalBoxes[Hor].q_sizes(which), totalBoxes[Ver].q_sizes(which));
- }
-
-
- Q_ASSERT(constraint.width() >= 0 || constraint.height() >= 0);
- q_xx.resize(columnCount());
- q_yy.resize(rowCount());
- q_widths.resize(columnCount());
- q_heights.resize(rowCount());
- q_descents.resize(rowCount());
-
-
- const Qt::Orientation orientation = constraintOrientation();
- QGridLayoutRowData *colData;
- QGridLayoutRowData constrainedRowData;
- QGridLayoutBox *totalBox;
- qreal *sizes;
- qreal *pos;
- qreal *descents;
- qreal targetSize;
- qreal cCount;
- qreal rCount;
-
- if (orientation == Qt::Vertical) {
- // height for width
- colData = &q_columnData;
- totalBox = &q_totalBoxes[Hor];
- sizes = q_widths.data();
- pos = q_xx.data();
- descents = 0;
- targetSize = constraint.width();
- cCount = columnCount();
- rCount = rowCount();
- constrainedRowData = q_rowData;
- } else {
- // width for height
- colData = &q_rowData;
- totalBox = &q_totalBoxes[Ver];
- sizes = q_heights.data();
- pos = q_yy.data();
- descents = q_descents.data();
- targetSize = constraint.height();
- cCount = rowCount();
- rCount = columnCount();
- constrainedRowData = q_columnData;
- }
- colData->calculateGeometries(0, cCount, targetSize, pos, sizes, descents, *totalBox);
- for (int i = q_items.count() - 1; i >= 0; --i) {
- QGridLayoutItem *item = q_items.at(i);
-
- if (item->hasDynamicConstraint()) {
- const qreal size = sizes[item->firstColumn(orientation)];
- QGridLayoutBox box = item->box(orientation, size);
- QGridLayoutBox &rowBox = constrainedRowData.boxes[item->firstRow(orientation)];
- rowBox.combine(box);
- }
- }
- const qreal newSize = constrainedRowData.totalBox(0, rCount).q_sizes(which);
-
- return (orientation == Qt::Vertical) ? QSizeF(targetSize, newSize) : QSizeF(newSize, targetSize);
-}
-
-
/**
returns false if the layout has contradicting constraints (i.e. some items with a horizontal
constraint and other items with a vertical constraint)
@@ -1709,85 +1682,41 @@ Qt::Orientation QGridLayoutEngine::constraintOrientation() const
void QGridLayoutEngine::ensureGeometries(const QLayoutStyleInfo &styleInfo,
const QSizeF &size) const
{
- ensureColumnAndRowData(styleInfo);
- if (q_cachedSize == size)
+ if (q_cachedDataForStyleInfo == styleInfo && q_cachedSize == size)
return;
+ q_cachedDataForStyleInfo = styleInfo;
+ q_cachedSize = size;
+
q_xx.resize(columnCount());
- q_yy.resize(rowCount());
q_widths.resize(columnCount());
+ q_yy.resize(rowCount());
q_heights.resize(rowCount());
q_descents.resize(rowCount());
-
- Qt::Orientation orientation = Qt::Vertical;
- if (hasDynamicConstraint())
- orientation = constraintOrientation();
-
- /*
- In order to do hfw we need to first distribute the columns, then the rows.
- In order to do wfh we need to first distribute the rows, then the columns.
-
- If there is no constraint, the order of distributing the rows or columns first is irrelevant.
- We choose horizontal just to keep the same behaviour as before (however, there shouldn't
- be any behaviour difference).
- */
-
- QGridLayoutRowData *colData;
- QGridLayoutRowData rowData;
- qreal *widths;
- qreal *heights;
- qreal *xx;
- qreal *yy;
- qreal *xdescents = 0;
- qreal *ydescents = 0;
- qreal cCount;
- qreal rCount;
- QSizeF oSize = size;
- if (orientation == Qt::Vertical) {
- // height for width
- colData = &q_columnData;
- rowData = q_rowData;
- widths = q_widths.data();
- heights = q_heights.data();
- xx = q_xx.data();
- yy = q_yy.data();
- cCount = columnCount();
- rCount = rowCount();
- ydescents = q_descents.data();
+ if(constraintOrientation() != Qt::Horizontal) {
+ //We might have items whose width depends on their height
+ ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], styleInfo, NULL, NULL, Qt::Horizontal);
+ //Calculate column widths and positions, and put results in q_xx.data() and q_widths.data() so that we can use this information as
+ //constraints to find the row heights
+ q_columnData.calculateGeometries(0, columnCount(), size.width(), q_xx.data(), q_widths.data(),
+ 0, q_totalBoxes[Hor]);
+ ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], styleInfo, q_xx.data(), q_widths.data(), Qt::Vertical);
+ //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data()
+ q_rowData.calculateGeometries(0, rowCount(), size.height(), q_yy.data(), q_heights.data(),
+ q_descents.data(), q_totalBoxes[Ver]);
} else {
- // width for height
- colData = &q_rowData;
- rowData = q_columnData;
- widths = q_heights.data();
- heights = q_widths.data();
- xx = q_yy.data();
- yy = q_xx.data();
- cCount = rowCount();
- rCount = columnCount();
- xdescents = q_descents.data();
- oSize.transpose();
+ //We have items whose height depends on their width
+ ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], styleInfo, NULL, NULL, Qt::Vertical);
+ //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() so that we can use this information as
+ //constraints to find the column widths
+ q_rowData.calculateGeometries(0, rowCount(), size.height(), q_yy.data(), q_heights.data(),
+ q_descents.data(), q_totalBoxes[Ver]);
+ ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], styleInfo, q_yy.data(), q_heights.data(), Qt::Horizontal);
+ //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data()
+ q_columnData.calculateGeometries(0, columnCount(), size.width(), q_xx.data(), q_widths.data(),
+ 0, q_totalBoxes[Hor]);
}
-
- colData->calculateGeometries(0, cCount, oSize.width(), xx, widths,
- xdescents, q_totalBoxes[orientation == Qt::Horizontal]);
- for (int i = q_items.count() - 1; i >= 0; --i) {
- QGridLayoutItem *item = q_items.at(i);
- const int col = item->firstColumn(orientation);
- const int row = item->firstRow(orientation);
- if (item->hasDynamicConstraint()) {
- const qreal sz = widths[col];
- QGridLayoutBox box = item->box(orientation, sz);
- rowData.boxes[row].combine(box);
- }
- }
-
- QGridLayoutBox &totalBox = q_totalBoxes[orientation == Qt::Vertical];
- totalBox = rowData.totalBox(0, rCount);
- rowData.calculateGeometries(0, rCount, oSize.height(), yy, heights,
- ydescents, totalBox);
-
- q_cachedSize = size;
}
QT_END_NAMESPACE
diff --git a/src/gui/graphicsview/qgridlayoutengine_p.h b/src/gui/graphicsview/qgridlayoutengine_p.h
index 55451d7..7c77b2a 100644
--- a/src/gui/graphicsview/qgridlayoutengine_p.h
+++ b/src/gui/graphicsview/qgridlayoutengine_p.h
@@ -93,8 +93,8 @@ enum LayoutSide {
enum {
NoConstraint,
- HorizontalConstraint,
- VerticalConstraint,
+ HorizontalConstraint, // Width depends on the height
+ VerticalConstraint, // Height depends on the width
UnknownConstraint, // need to update cache
UnfeasibleConstraint // not feasible, it be has some items with Vertical and others with Horizontal constraints
};
@@ -411,9 +411,14 @@ private:
void setItemAt(int row, int column, QGridLayoutItem *item);
void insertOrRemoveRows(int row, int delta, Qt::Orientation orientation = Qt::Vertical);
void fillRowData(QGridLayoutRowData *rowData, const QLayoutStyleInfo &styleInfo,
- Qt::Orientation orientation = Qt::Vertical) const;
+ qreal *colPositions, qreal *colSizes,
+ Qt::Orientation orientation = Qt::Vertical) const;
void ensureEffectiveFirstAndLastRows() const;
- void ensureColumnAndRowData(const QLayoutStyleInfo &styleInfo) const;
+ void ensureColumnAndRowData(QGridLayoutRowData *rowData, QGridLayoutBox *totalBox,
+ const QLayoutStyleInfo &styleInfo,
+ qreal *colPositions, qreal *colSizes,
+ Qt::Orientation orientation) const;
+
void ensureGeometries(const QLayoutStyleInfo &styleInfo, const QSizeF &size) const;
// User input