summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicswidget.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-05-16 10:19:02 +0200
committerLars Knoll <lars.knoll@nokia.com>2011-05-16 10:19:02 +0200
commit276d60a4d6c9d1b72c4aa7df1f86e7ce9097beeb (patch)
tree73130ce8a80181fb9d234028c5057d7eb86f02ab /src/widgets/graphicsview/qgraphicswidget.cpp
parent850b602c7a72635eb37a998089ee085d5d505c34 (diff)
parent173099696f44073441975febfa35ddfb3585e8c5 (diff)
Merge remote branch 'origin/master' into refactor
Conflicts: src/modules/qt_openvg.pri src/widgets/to_be_moved/qlinecontrol_p.h
Diffstat (limited to 'src/widgets/graphicsview/qgraphicswidget.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.cpp105
1 files changed, 71 insertions, 34 deletions
diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp
index 60a80fc8b8..06f7013c46 100644
--- a/src/widgets/graphicsview/qgraphicswidget.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget.cpp
@@ -354,8 +354,10 @@ void QGraphicsWidget::setGeometry(const QRectF &rect)
newGeom = rect;
newGeom.setSize(rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize))
.boundedTo(effectiveSizeHint(Qt::MaximumSize)));
- if (newGeom == d->geom)
- return;
+
+ if (newGeom == d->geom) {
+ goto relayoutChildrenAndReturn;
+ }
// setPos triggers ItemPositionChange, which can adjust position
wd->inSetGeometry = 1;
@@ -363,8 +365,9 @@ void QGraphicsWidget::setGeometry(const QRectF &rect)
wd->inSetGeometry = 0;
newGeom.moveTopLeft(pos());
- if (newGeom == d->geom)
- return;
+ if (newGeom == d->geom) {
+ goto relayoutChildrenAndReturn;
+ }
// Update and prepare to change the geometry (remove from index) if the size has changed.
if (wd->scene) {
@@ -375,35 +378,54 @@ void QGraphicsWidget::setGeometry(const QRectF &rect)
}
// Update the layout item geometry
- bool moved = oldPos != pos();
- if (moved) {
- // Send move event.
- QGraphicsSceneMoveEvent event;
- event.setOldPos(oldPos);
- event.setNewPos(pos());
- QApplication::sendEvent(this, &event);
- if (wd->inSetPos) {
- //set the new pos
- d->geom.moveTopLeft(pos());
- emit geometryChanged();
- return;
+ {
+ bool moved = oldPos != pos();
+ if (moved) {
+ // Send move event.
+ QGraphicsSceneMoveEvent event;
+ event.setOldPos(oldPos);
+ event.setNewPos(pos());
+ QApplication::sendEvent(this, &event);
+ if (wd->inSetPos) {
+ //set the new pos
+ d->geom.moveTopLeft(pos());
+ emit geometryChanged();
+ goto relayoutChildrenAndReturn;
+ }
+ }
+ QSizeF oldSize = size();
+ QGraphicsLayoutItem::setGeometry(newGeom);
+ // Send resize event
+ bool resized = newGeom.size() != oldSize;
+ if (resized) {
+ QGraphicsSceneResizeEvent re;
+ re.setOldSize(oldSize);
+ re.setNewSize(newGeom.size());
+ if (oldSize.width() != newGeom.size().width())
+ emit widthChanged();
+ if (oldSize.height() != newGeom.size().height())
+ emit heightChanged();
+ QGraphicsLayout *lay = wd->layout;
+ if (QGraphicsLayout::instantInvalidatePropagation()) {
+ if (!lay || lay->isActivated()) {
+ QApplication::sendEvent(this, &re);
+ }
+ } else {
+ QApplication::sendEvent(this, &re);
+ }
}
}
- QSizeF oldSize = size();
- QGraphicsLayoutItem::setGeometry(newGeom);
- // Send resize event
- bool resized = newGeom.size() != oldSize;
- if (resized) {
- QGraphicsSceneResizeEvent re;
- re.setOldSize(oldSize);
- re.setNewSize(newGeom.size());
- if (oldSize.width() != newGeom.size().width())
- emit widthChanged();
- if (oldSize.height() != newGeom.size().height())
- emit heightChanged();
- QApplication::sendEvent(this, &re);
- }
+
emit geometryChanged();
+relayoutChildrenAndReturn:
+ if (QGraphicsLayout::instantInvalidatePropagation()) {
+ if (QGraphicsLayout *lay = wd->layout) {
+ if (!lay->isActivated()) {
+ QEvent layoutRequest(QEvent::LayoutRequest);
+ QApplication::sendEvent(this, &layoutRequest);
+ }
+ }
+ }
}
/*!
@@ -1052,16 +1074,31 @@ void QGraphicsWidget::updateGeometry()
QGraphicsLayoutItem *parentItem = parentLayoutItem();
if (parentItem && parentItem->isLayout()) {
- parentItem->updateGeometry();
+ if (QGraphicsLayout::instantInvalidatePropagation()) {
+ static_cast<QGraphicsLayout *>(parentItem)->invalidate();
+ } else {
+ parentItem->updateGeometry();
+ }
} else {
if (parentItem) {
+ // This is for custom layouting
QGraphicsWidget *parentWid = parentWidget(); //###
if (parentWid->isVisible())
QApplication::postEvent(parentWid, new QEvent(QEvent::LayoutRequest));
+ } else {
+ /**
+ * If this is the topmost widget, post a LayoutRequest event to the widget.
+ * When the event is received, it will start flowing all the way down to the leaf
+ * widgets in one go. This will make a relayout flicker-free.
+ */
+ if (QGraphicsLayout::instantInvalidatePropagation())
+ QApplication::postEvent(static_cast<QGraphicsWidget *>(this), new QEvent(QEvent::LayoutRequest));
+ }
+ if (!QGraphicsLayout::instantInvalidatePropagation()) {
+ bool wasResized = testAttribute(Qt::WA_Resized);
+ resize(size()); // this will restrict the size
+ setAttribute(Qt::WA_Resized, wasResized);
}
- bool wasResized = testAttribute(Qt::WA_Resized);
- resize(size()); // this will restrict the size
- setAttribute(Qt::WA_Resized, wasResized);
}
}