summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2009-08-31 00:29:56 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2009-08-31 00:29:56 (GMT)
commitf5c0745622a914003aa75aaaa1e828854c1c85ba (patch)
tree6f9c27a22d5987a8bddd512222ab29dfeda5caf3 /src/gui/graphicsview
parent9cc59a858d116f75c19a782602ab8679405d9764 (diff)
parent9dade8d2e57655019ed4dc2fcdc4e226401138a2 (diff)
downloadQt-f5c0745622a914003aa75aaaa1e828854c1c85ba.zip
Qt-f5c0745622a914003aa75aaaa1e828854c1c85ba.tar.gz
Qt-f5c0745622a914003aa75aaaa1e828854c1c85ba.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.cpp45
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp124
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h6
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h10
-rw-r--r--src/gui/graphicsview/qgraphicslayout.cpp4
-rw-r--r--src/gui/graphicsview/qgraphicslayout_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicslayoutitem_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicslinearlayout.cpp3
-rw-r--r--src/gui/graphicsview/qgraphicsproxywidget_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp250
-rw-r--r--src/gui/graphicsview/qgraphicsscene.h3
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h7
-rw-r--r--src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicssceneevent.cpp8
-rw-r--r--src/gui/graphicsview/qgraphicssceneindex_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicstransform_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicsview_p.h4
-rw-r--r--src/gui/graphicsview/qgraphicswidget.cpp19
-rw-r--r--src/gui/graphicsview/qgraphicswidget_p.h4
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp22
-rw-r--r--src/gui/graphicsview/qgridlayoutengine_p.h4
-rw-r--r--src/gui/graphicsview/qsimplex_p.cpp2
23 files changed, 368 insertions, 173 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
index 2894c59..95561b7 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
@@ -65,8 +65,9 @@
automatically added to the layout, and if items are removed, all their anchors will be
automatically removed
- \section1 Size Hints and Size Policies in QGraphicsLinearLayout
- QGraphicsLinearLayout respects each item's size hints and size policies. However it does
+ \section1 Size Hints and Size Policies in QGraphicsAnchorLayout
+
+ QGraphicsAnchorLayout respects each item's size hints and size policies. However it does
not respect stretch factors currently. This might change in the future, so please refrain
from using stretch factors in anchor layout to avoid any future regressions.
@@ -83,6 +84,10 @@
QT_BEGIN_NAMESPACE
+/*!
+ Constructs a QGraphicsAnchorLayout instance. \a parent is passed to
+ QGraphicsLayout's constructor.
+ */
QGraphicsAnchorLayout::QGraphicsAnchorLayout(QGraphicsLayoutItem *parent)
: QGraphicsLayout(*new QGraphicsAnchorLayoutPrivate(), parent)
{
@@ -90,6 +95,9 @@ QGraphicsAnchorLayout::QGraphicsAnchorLayout(QGraphicsLayoutItem *parent)
d->createLayoutEdges();
}
+/*!
+ Destroys the QGraphicsAnchorLayout object.
+*/
QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
{
Q_D(QGraphicsAnchorLayout);
@@ -187,32 +195,41 @@ void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem,
}
/*!
- \fn QGraphicsAnchorLayout::addLeftAndRightAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge)
+ \fn QGraphicsAnchorLayout::addLeftAndRightAnchors(QGraphicsLayoutItem *firstItem, QGraphicsLayoutItem *secondItem)
+
+ Anchors the left and right edges of \a firstItem to the same edges of
+ \a secondItem.
This convenience function is equivalent to calling
\code
- l->addAnchor(firstEdge, Qt::AnchorLeft, secondEdge, Qt::AnchorLeft);
- l->addAnchor(firstEdge, Qt::AnchorRight, secondEdge, Qt::AnchorRight);
+ l->addAnchor(firstItem, Qt::AnchorLeft, secondItem, Qt::AnchorLeft);
+ l->addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
\endcode
*/
/*!
- \fn QGraphicsAnchorLayout::addTopAndBottomAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge)
+ \fn QGraphicsAnchorLayout::addTopAndBottomAnchors(QGraphicsLayoutItem *firstItem, QGraphicsLayoutItem *secondItem)
+
+ Anchors the top and bottom edges of \a firstItem to the same edges of
+ \a secondItem.
This convenience function is equivalent to calling
\code
- l->addAnchor(firstEdge, Qt::AnchorTop, secondEdge, Qt::AnchorTop);
- l->addAnchor(firstEdge, Qt::AnchorBottom, secondEdge, Qt::AnchorBottom);
+ l->addAnchor(firstItem, Qt::AnchorTop, secondItem, Qt::AnchorTop);
+ l->addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom);
\endcode
*/
/*!
- \fn QGraphicsAnchorLayout::addAllAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge)
+ \fn QGraphicsAnchorLayout::addAllAnchors(QGraphicsLayoutItem *firstItem, QGraphicsLayoutItem *secondItem)
+
+ Anchors all edges (left, right, top and bottom) of \a firstItem to the same edges of
+ \a secondItem.
This convenience function is equivalent to calling
\code
- l->addLeftAndRightAnchors(firstEdge, secondEdge);
- l->addTopAndBottomAnchors(firstEdge, secondEdge);
+ l->addLeftAndRightAnchors(firstItem, secondItem);
+ l->addTopAndBottomAnchors(firstItem, secondItem);
\endcode
*/
@@ -228,6 +245,7 @@ void QGraphicsAnchorLayout::setAnchorSpacing(const QGraphicsLayoutItem *firstIte
if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, &spacing)) {
qWarning("setAnchorSpacing: The anchor does not exist.");
+ return;
}
invalidate();
}
@@ -369,7 +387,12 @@ void QGraphicsAnchorLayout::setGeometry(const QRectF &geom)
}
/*!
+ Removes the layout item at \a index without destroying it. Ownership of
+ the item is transferred to the caller.
+
Removing an item will also remove any of the anchors associated with it.
+
+ \sa itemAt(), count()
*/
void QGraphicsAnchorLayout::removeAt(int index)
{
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index c965712..d4afa5b 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -554,7 +554,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
qDebug("candidate list for sequential simplification:\n[%s]", qPrintable(strPath));
#endif
- bool forward;
+ bool forward = true;
AnchorVertex *prev = beforeSequence;
int intervalFrom = 0;
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index ead5aee..e1e95b1 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -331,6 +331,13 @@
\value ItemNegativeZStacksBehindParent The item automatically stacks behind
it's parent if it's z-value is negative. This flag enables setZValue() to
toggle ItemStacksBehindParent.
+
+ \value ItemIsPanel. The item is a panel. A panel provides activation and
+ contained focus handling. Only one panel can be active at a time (see
+ QGraphicsItem::isActive()). When no panel is active, QGraphicsScene
+ activates all non-panel items. Window items (i.e.,
+ QGraphicsItem::isWindow() returns true) are panels. This flag was
+ introduced in Qt 4.6.
*/
/*!
@@ -1341,14 +1348,29 @@ QGraphicsWidget *QGraphicsItem::topLevelWidget() const
*/
QGraphicsWidget *QGraphicsItem::window() const
{
- if (isWidget() && static_cast<const QGraphicsWidget *>(this)->isWindow())
- return static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this));
- if (QGraphicsWidget *parent = parentWidget())
- return parent->window();
+ QGraphicsItem *p = panel();
+ if (p && p->isWindow())
+ return static_cast<QGraphicsWidget *>(p);
return 0;
}
/*!
+ \since 4.6
+
+ Returns the item's panel, or 0 if this item does not have a panel. If the
+ item is a panel, it will return itself. Otherwise it will return the
+ closest ancestor that is a panel.
+
+ \sa isPanel(), ItemIsPanel
+*/
+QGraphicsItem *QGraphicsItem::panel() const
+{
+ if (d_ptr->flags & ItemIsPanel)
+ return const_cast<QGraphicsItem *>(this);
+ return d_ptr->parent ? d_ptr->parent->panel() : 0;
+}
+
+/*!
\since 4.6
Return the graphics item cast to a QGraphicsObject, if the class is actually a
@@ -1434,6 +1456,17 @@ bool QGraphicsItem::isWindow() const
}
/*!
+ \since 4.6
+ Returns true if the item is a panel; otherwise returns false.
+
+ \sa QGraphicsItem::panel(), ItemIsPanel
+*/
+bool QGraphicsItem::isPanel() const
+{
+ return d_ptr->flags & ItemIsPanel;
+}
+
+/*!
Returns this item's flags. The flags describe what configurable features
of the item are enabled and not. For example, if the flags include
ItemIsFocusable, the item can accept input focus.
@@ -1496,6 +1529,9 @@ static void _q_qgraphicsItemSetFlag(QGraphicsItem *item, QGraphicsItem::Graphics
*/
void QGraphicsItem::setFlags(GraphicsItemFlags flags)
{
+ if (isWindow())
+ flags |= ItemIsPanel;
+
// Notify change and check for adjustment.
if (quint32(d_ptr->flags) == quint32(flags))
return;
@@ -1850,16 +1886,16 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
q->ungrabKeyboard();
}
if (q_ptr->hasFocus() && scene) {
- // Hiding the closest non-window ancestor of the focus item
+ // Hiding the closest non-panel ancestor of the focus item
QGraphicsItem *focusItem = scene->focusItem();
bool clear = true;
- if (isWidget && !focusItem->isWindow()) {
+ if (isWidget && !focusItem->isPanel()) {
do {
if (focusItem == q_ptr) {
clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
break;
}
- } while ((focusItem = focusItem->parentWidget()) && !focusItem->isWindow());
+ } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
}
if (clear)
q_ptr->clearFocus();
@@ -1981,17 +2017,17 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo
if (scene && scene->mouseGrabberItem() == q_ptr)
q_ptr->ungrabMouse();
if (q_ptr->hasFocus()) {
- // Disabling the closest non-window ancestor of the focus item
+ // Disabling the closest non-panel ancestor of the focus item
// causes focus to pop to the next item, otherwise it's cleared.
QGraphicsItem *focusItem = scene->focusItem();
bool clear = true;
- if (isWidget && !focusItem->isWindow() && q_ptr->isAncestorOf(focusItem)) {
+ if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) {
do {
if (focusItem == q_ptr) {
clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
break;
}
- } while ((focusItem = focusItem->parentWidget()) && !focusItem->isWindow());
+ } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
}
if (clear)
q_ptr->clearFocus();
@@ -2588,12 +2624,33 @@ void QGraphicsItem::setHandlesChildEvents(bool enabled)
d_ptr->handlesChildEvents = enabled;
d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
}
+/*!
+ \since 4.6
+ Returns true if this item is active; otherwise returns false.
+
+ An item can only be active if the scene is active. An item is active
+ if it is, or is a descendent of, an active panel. Items in non-active
+ panels are not active.
+
+ Items that are not part of a panel follow scene activation when the
+ scene has no active panel.
+
+ Only active items can gain input focus.
+
+ \sa QGraphicsScene::isActive(), QGraphicsScene::activePanel(), panel(), isPanel()
+*/
+bool QGraphicsItem::isActive() const
+{
+ if (!d_ptr->scene || !d_ptr->scene->isActive())
+ return false;
+ return panel() == d_ptr->scene->activePanel();
+}
/*!
- Returns true if this item or its \l{focusProxy()}{focus proxy} has keyboard
- input focus; otherwise, returns false.
+ Returns true if this item is active, and it or its \l{focusProxy()}{focus
+ proxy} has keyboard input focus; otherwise, returns false.
- \sa focusItem(), setFocus(), QGraphicsScene::setFocusItem()
+ \sa focusItem(), setFocus(), QGraphicsScene::setFocusItem(), isActive()
*/
bool QGraphicsItem::hasFocus() const
{
@@ -2610,9 +2667,10 @@ bool QGraphicsItem::hasFocus() const
Only enabled items that set the ItemIsFocusable flag can accept keyboard
focus.
- If this item is not visible, or not associated with a scene, it will not
- gain immediate input focus. However, it will be registered as the preferred
- focus item for its subtree of items, should it later become visible.
+ If this item is not visible, not active, or not associated with a scene,
+ it will not gain immediate input focus. However, it will be registered as
+ the preferred focus item for its subtree of items, should it later become
+ visible.
As a result of calling this function, this item will receive a
\l{focusInEvent()}{focus in event} with \a focusReason. If another item
@@ -2655,8 +2713,8 @@ void QGraphicsItem::setFocus(Qt::FocusReason focusReason)
}
d_ptr->setItemFocusedInScope(false);
- QGraphicsWidget *w = window();
- if (!w || w->isActiveWindow()) {
+ QGraphicsItem *p = panel();
+ if (!p || p->isActive()) {
// Visible items immediately gain focus from scene.
d_ptr->scene->d_func()->setFocusItemHelper(f, focusReason);
}
@@ -2668,8 +2726,8 @@ void QGraphicsItem::setFocus(Qt::FocusReason focusReason)
/*!
Takes keyboard input focus from the item.
- If it has focus, a \l{focusOutEvent()}{focus out event} is sent to this item
- to tell it that it is about to lose the focus.
+ If it has focus, a \l{focusOutEvent()}{focus out event} is sent to this
+ item to tell it that it is about to lose the focus.
Only items that set the ItemIsFocusable flag, or widgets that set an
appropriate focus policy, can accept keyboard focus.
@@ -4783,7 +4841,7 @@ void QGraphicsItemPrivate::setSubFocus()
bool hidden = !visible;
do {
parent->d_func()->subFocusItem = item;
- } while (!parent->isWindow() && (parent = parent->d_ptr->parent) && (!hidden || !parent->d_func()->visible) && !(parent->d_ptr->flags & QGraphicsItem::ItemIsFocusScope));
+ } while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (!hidden || !parent->d_func()->visible) && !(parent->d_ptr->flags & QGraphicsItem::ItemIsFocusScope));
}
/*!
@@ -4797,7 +4855,7 @@ void QGraphicsItemPrivate::clearSubFocus()
if (parent->d_ptr->subFocusItem != q_ptr)
break;
parent->d_ptr->subFocusItem = 0;
- } while (!parent->isWindow() && (parent = parent->d_ptr->parent));
+ } while (!parent->isPanel() && (parent = parent->d_ptr->parent));
}
/*!
@@ -6048,6 +6106,17 @@ bool QGraphicsItem::sceneEvent(QEvent *event)
case QEvent::InputMethod:
inputMethodEvent(static_cast<QInputMethodEvent *>(event));
break;
+ case QEvent::WindowActivate:
+ case QEvent::WindowDeactivate:
+ // Propagate panel activation.
+ if (d_ptr->scene) {
+ for (int i = 0; i < d_ptr->children.size(); ++i) {
+ QGraphicsItem *child = d_ptr->children.at(i);
+ if (!(child->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents))
+ d_ptr->scene->sendEvent(child, event);
+ }
+ }
+ break;
default:
return false;
}
@@ -10214,10 +10283,8 @@ void QGraphicsItemEffectSourcePrivate::draw(QPainter *painter)
info->widget, info->opacity, info->effectTransform, info->wasDirtySceneTransform,
info->drawItem);
} else {
- QTransform effectTransform = painter->worldTransform();
- effectTransform *= info->painter->worldTransform().inverted();
- if (info->effectTransform)
- effectTransform *= *info->effectTransform;
+ QTransform effectTransform = info->painter->worldTransform().inverted();
+ effectTransform *= painter->worldTransform();
scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,
info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
info->drawItem);
@@ -10453,6 +10520,9 @@ QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag)
case QGraphicsItem::ItemIsFocusScope:
str = "ItemIsFocusScope";
break;
+ case QGraphicsItem::ItemIsPanel:
+ str = "ItemIsPanel";
+ break;
}
debug << str;
return debug;
@@ -10462,7 +10532,7 @@ QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags)
{
debug << '(';
bool f = false;
- for (int i = 0; i < 9; ++i) {
+ for (int i = 0; i < 16; ++i) {
if (flags & (1 << i)) {
if (f)
debug << '|';
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index b76f5ac..59659c9 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -103,8 +103,9 @@ public:
ItemHasNoContents = 0x400,
ItemSendsGeometryChanges = 0x800,
ItemAcceptsInputMethod = 0x1000,
+ ItemIsFocusScope = 0x2000,
ItemNegativeZStacksBehindParent = 0x4000,
- ItemIsFocusScope = 0x8000
+ ItemIsPanel = 0x8000
// NB! Don't forget to increase the d_ptr->flags bit field by 1 when adding a new flag.
};
Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
@@ -161,11 +162,13 @@ public:
QGraphicsWidget *parentWidget() const;
QGraphicsWidget *topLevelWidget() const;
QGraphicsWidget *window() const;
+ QGraphicsItem *panel() const;
void setParentItem(QGraphicsItem *parent);
QList<QGraphicsItem *> children() const; // ### obsolete
QList<QGraphicsItem *> childItems() const;
bool isWidget() const;
bool isWindow() const;
+ bool isPanel() const;
QGraphicsObject *toGraphicsObject();
const QGraphicsObject *toGraphicsObject() const;
@@ -231,6 +234,7 @@ public:
bool handlesChildEvents() const;
void setHandlesChildEvents(bool enabled);
+ bool isActive() const;
bool hasFocus() const;
void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
void clearFocus();
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index 7abd7f5..60db4a7 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
@@ -498,7 +498,7 @@ public:
quint32 needSortChildren : 1;
quint32 allChildrenDirty : 1;
- // New 32 bits
+ // Packed 32 bits
quint32 fullUpdatePending : 1;
quint32 flags : 16;
quint32 dirtyChildrenBoundingRect : 1;
@@ -516,8 +516,10 @@ public:
quint32 notifyBoundingRectChanged : 1;
quint32 notifyInvalidated : 1;
quint32 mouseSetsFocus : 1;
+
+ // New 32 bits
quint32 itemIsFocusedInScope : 1;
- quint32 unused : 1; // feel free to use
+ quint32 unused : 31; // feel free to use
// Optional stacking order
int globalStackingOrder;
diff --git a/src/gui/graphicsview/qgraphicslayout.cpp b/src/gui/graphicsview/qgraphicslayout.cpp
index 58c174c..df6be90 100644
--- a/src/gui/graphicsview/qgraphicslayout.cpp
+++ b/src/gui/graphicsview/qgraphicslayout.cpp
@@ -390,8 +390,10 @@ void QGraphicsLayout::widgetEvent(QEvent *e)
QGraphicsLayout to return a pointer to the item at index \a i. The
reimplementation can assume that \a i is valid (i.e., it respects the
value of count()).
+ Together with count(), it is provided as a means of iterating over all items in a layout.
- The subclass is free to decide how to store the items.
+ The subclass is free to decide how to store the items, and the visual arrangement
+ does not have to be reflected through this function.
\sa count(), removeAt()
*/
diff --git a/src/gui/graphicsview/qgraphicslayout_p.h b/src/gui/graphicsview/qgraphicslayout_p.h
index 2ad853b..0e43b55 100644
--- a/src/gui/graphicsview/qgraphicslayout_p.h
+++ b/src/gui/graphicsview/qgraphicslayout_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgraphicslayoutitem_p.h b/src/gui/graphicsview/qgraphicslayoutitem_p.h
index 5bda3ca..4d9a8c9 100644
--- a/src/gui/graphicsview/qgraphicslayoutitem_p.h
+++ b/src/gui/graphicsview/qgraphicslayoutitem_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgraphicslinearlayout.cpp b/src/gui/graphicsview/qgraphicslinearlayout.cpp
index 185780a..1b271e5 100644
--- a/src/gui/graphicsview/qgraphicslinearlayout.cpp
+++ b/src/gui/graphicsview/qgraphicslinearlayout.cpp
@@ -277,7 +277,7 @@ void QGraphicsLinearLayout::insertItem(int index, QGraphicsLayoutItem *item)
Q_ASSERT(item);
d->fixIndex(&index);
d->engine.insertRow(index, d->orientation);
- new QGridLayoutItem(&d->engine, item, d->gridRow(index), d->gridColumn(index));
+ new QGridLayoutItem(&d->engine, item, d->gridRow(index), d->gridColumn(index), 1, 1, 0, index);
invalidate();
}
@@ -471,6 +471,7 @@ int QGraphicsLinearLayout::count() const
/*!
\reimp
+ When iterating from 0 and up, it will return the items in the visual arranged order.
*/
QGraphicsLayoutItem *QGraphicsLinearLayout::itemAt(int index) const
{
diff --git a/src/gui/graphicsview/qgraphicsproxywidget_p.h b/src/gui/graphicsview/qgraphicsproxywidget_p.h
index e2be89c..04fe40a 100644
--- a/src/gui/graphicsview/qgraphicsproxywidget_p.h
+++ b/src/gui/graphicsview/qgraphicsproxywidget_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index af137e7..3efb511 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -288,7 +288,8 @@ QGraphicsScenePrivate::QGraphicsScenePrivate()
focusItem(0),
lastFocusItem(0),
tabFocusFirst(0),
- activeWindow(0),
+ activePanel(0),
+ lastActivePanel(0),
activationRefCount(0),
lastMouseGrabberItem(0),
lastMouseGrabberItemHasImplicitMouseGrab(false),
@@ -516,10 +517,12 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
focusItem = 0;
if (item == lastFocusItem)
lastFocusItem = 0;
- if (item == activeWindow) {
+ if (item == activePanel) {
// ### deactivate...
- activeWindow = 0;
+ activePanel = 0;
}
+ if (item == lastActivePanel)
+ lastActivePanel = 0;
// Disable selectionChanged() for individual items
++selectionChanging;
@@ -672,8 +675,8 @@ void QGraphicsScenePrivate::removePopup(QGraphicsWidget *widget, bool itemIsDyin
if (focusItem && popupWidgets.isEmpty()) {
QFocusEvent event(QEvent::FocusIn, Qt::PopupFocusReason);
sendEvent(focusItem, &event);
- } else {
- ungrabKeyboard((QGraphicsItem *)widget, itemIsDying);
+ } else if (keyboardGrabberItems.contains(static_cast<QGraphicsItem *>(widget))) {
+ ungrabKeyboard(static_cast<QGraphicsItem *>(widget), itemIsDying);
}
if (!itemIsDying && widget->isVisible()) {
widget->hide();
@@ -1078,8 +1081,9 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
}
// Update window activation.
- QGraphicsWidget *newActiveWindow = windowForItem(cachedItemsUnderMouse.value(0));
- if (newActiveWindow != activeWindow)
+ QGraphicsItem *topItem = cachedItemsUnderMouse.value(0);
+ QGraphicsWidget *newActiveWindow = topItem ? topItem->window() : 0;
+ if (newActiveWindow != q->activeWindow())
q->setActiveWindow(newActiveWindow);
// Set focus on the topmost enabled item that can take focus.
@@ -1114,7 +1118,7 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
// check if the item we are sending to are disabled (before we send the event)
bool disabled = !item->isEnabled();
- bool isWindow = item->isWindow();
+ bool isPanel = item->isPanel();
if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick
&& item != lastMouseGrabberItem && lastMouseGrabberItem) {
// If this item is different from the item that received the last
@@ -1155,8 +1159,8 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
}
ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents);
- // Don't propagate through windows.
- if (isWindow)
+ // Don't propagate through panels.
+ if (isPanel)
break;
}
@@ -1178,18 +1182,6 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
}
}
-QGraphicsWidget *QGraphicsScenePrivate::windowForItem(const QGraphicsItem *item) const
-{
- if (!item)
- return 0;
- do {
- if (item->isWidget())
- return static_cast<const QGraphicsWidget *>(item)->window();
- item = item->parentItem();
- } while (item);
- return 0;
-}
-
/*!
\internal
@@ -2236,6 +2228,9 @@ void QGraphicsScene::destroyItemGroup(QGraphicsItemGroup *group)
moved to this scene), QGraphicsScene will send an addition notification as
the item is removed from its previous scene.
+ If the item is a panel, the scene is active, and there is no active panel
+ in the scene, then the item will be activated.
+
\sa removeItem(), addEllipse(), addLine(), addPath(), addPixmap(),
addRect(), addText(), addWidget()
*/
@@ -2368,9 +2363,9 @@ void QGraphicsScenePrivate::addItem(QGraphicsItem *item,
// Deliver post-change notification
item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant);
- // Auto-activate the first inactive window if the scene is active.
- if (activationRefCount > 0 && !activeWindow && item->isWindow())
- q->setActiveWindow(static_cast<QGraphicsWidget *>(item));
+ // Auto-activate the first inactive panel if the scene is active.
+ if (q->isActive() && !activePanel && item->isPanel())
+ q->setActivePanel(item);
// Ensure that newly added items that have subfocus set, gain
// focus automatically if there isn't a focus item already.
@@ -3143,40 +3138,43 @@ bool QGraphicsScene::event(QEvent *event)
case QEvent::InputMethod:
inputMethodEvent(static_cast<QInputMethodEvent *>(event));
break;
- case QEvent::WindowActivate: {
+ case QEvent::WindowActivate:
if (!d->activationRefCount++) {
- // Notify all non-window widgets.
- foreach (QGraphicsItem *item, items()) {
- if (item->isWidget() && item->isVisible() && !item->isWindow() && !item->parentWidget()) {
- QEvent event(QEvent::WindowActivate);
- QApplication::sendEvent(static_cast<QGraphicsWidget *>(item), &event);
+ if (d->lastActivePanel) {
+ // Activate the last panel.
+ setActivePanel(d->lastActivePanel);
+ } else if (d->tabFocusFirst && d->tabFocusFirst->isPanel()) {
+ // Activate the panel of the first item in the tab focus
+ // chain.
+ setActivePanel(d->tabFocusFirst);
+ } else {
+ // Activate all toplevel items.
+ QEvent event(QEvent::WindowActivate);
+ foreach (QGraphicsItem *item, items()) {
+ if (item->isVisible() && !item->isPanel() && !item->parentItem())
+ sendEvent(item, &event);
}
}
-
- // Restore window activation.
- QGraphicsItem *nextFocusItem = d->focusItem ? d->focusItem : d->lastFocusItem;
- if (nextFocusItem && nextFocusItem->window())
- setActiveWindow(static_cast<QGraphicsWidget *>(nextFocusItem));
- else if (d->tabFocusFirst && d->tabFocusFirst->isWindow())
- setActiveWindow(d->tabFocusFirst);
}
break;
- }
- case QEvent::WindowDeactivate: {
+ case QEvent::WindowDeactivate:
if (!--d->activationRefCount) {
- // Remove window activation.
- setActiveWindow(0);
-
- // Notify all non-window widgets.
- foreach (QGraphicsItem *item, items()) {
- if (item->isWidget() && item->isVisible() && !item->isWindow() && !item->parentWidget()) {
- QEvent event(QEvent::WindowDeactivate);
- QApplication::sendEvent(static_cast<QGraphicsWidget *>(item), &event);
+ if (d->activePanel) {
+ // Deactivate the active panel (but keep it so we can
+ // reactivate it later).
+ QGraphicsItem *lastActivePanel = d->activePanel;
+ setActivePanel(0);
+ d->lastActivePanel = lastActivePanel;
+ } else {
+ // Activate all toplevel items.
+ QEvent event(QEvent::WindowDeactivate);
+ foreach (QGraphicsItem *item, items()) {
+ if (item->isVisible() && !item->isPanel() && !item->parentItem())
+ sendEvent(item, &event);
}
}
}
break;
- }
case QEvent::ApplicationFontChange: {
// Resolve the existing scene font.
d->resolveFont();
@@ -3539,8 +3537,8 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv
QGraphicsItem *commonAncestorItem = (item && !hoverItems.isEmpty()) ? item->commonAncestorItem(hoverItems.last()) : 0;
while (commonAncestorItem && !itemAcceptsHoverEvents_helper(commonAncestorItem))
commonAncestorItem = commonAncestorItem->parentItem();
- if (commonAncestorItem && commonAncestorItem->window() != item->window()) {
- // The common ancestor isn't in the same window as the two hovered
+ if (commonAncestorItem && commonAncestorItem->panel() != item->panel()) {
+ // The common ancestor isn't in the same panel as the two hovered
// items.
commonAncestorItem = 0;
}
@@ -3561,8 +3559,8 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv
QGraphicsItem *parent = item;
while (parent && parent != commonAncestorItem) {
parents.prepend(parent);
- if (parent->isWindow()) {
- // Stop at the window - we don't deliver beyond this point.
+ if (parent->isPanel()) {
+ // Stop at the panel - we don't deliver beyond this point.
break;
}
parent = parent->parentItem();
@@ -3639,7 +3637,7 @@ void QGraphicsScene::keyPressEvent(QKeyEvent *keyEvent)
// is filtered out, stop propagating it.
if (!d->sendEvent(p, keyEvent))
break;
- } while (!keyEvent->isAccepted() && !p->isWindow() && (p = p->parentItem()));
+ } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem()));
} else {
keyEvent->ignore();
}
@@ -3669,7 +3667,7 @@ void QGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent)
// is filtered out, stop propagating it.
if (!d->sendEvent(p, keyEvent))
break;
- } while (!keyEvent->isAccepted() && !p->isWindow() && (p = p->parentItem()));
+ } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem()));
} else {
keyEvent->ignore();
}
@@ -3831,9 +3829,9 @@ void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
wheelEvent->setPos(item->d_ptr->genericMapFromScene(wheelEvent->scenePos(),
wheelEvent->widget()));
wheelEvent->accept();
- bool isWindow = item->isWindow();
+ bool isPanel = item->isPanel();
d->sendEvent(item, wheelEvent);
- if (isWindow || wheelEvent->isAccepted())
+ if (isPanel || wheelEvent->isAccepted())
break;
}
}
@@ -4892,7 +4890,7 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
if (widget->flags() & QGraphicsItem::ItemIsFocusable
&& widget->isEnabled() && widget->isVisibleTo(0)
&& (widget->focusPolicy() & Qt::TabFocus)
- && (!item || !item->isWindow() || item->isAncestorOf(widget))
+ && (!item || !item->isPanel() || item->isAncestorOf(widget))
) {
setFocusItem(widget, next ? Qt::TabFocusReason : Qt::BacktabFocusReason);
return true;
@@ -5079,84 +5077,150 @@ void QGraphicsScene::setPalette(const QPalette &palette)
}
/*!
- \since 4.4
+ \since 4.6
- Returns the current active window, or 0 if there is no window is currently
- active.
+ Returns true if the scene is active (e.g., it's viewed by
+ at least one QGraphicsView that is active); otherwise returns false.
- \sa QGraphicsScene::setActiveWindow()
+ \sa QGraphicsItem::isActive(), QWidget::isActiveWindow()
*/
-QGraphicsWidget *QGraphicsScene::activeWindow() const
+bool QGraphicsScene::isActive() const
{
Q_D(const QGraphicsScene);
- return d->activeWindow;
+ return d->activationRefCount > 0;
}
/*!
- \since 4.4
- Activates \a widget, which must be a widget in this scene. You can also
- pass 0 for \a widget, in which case QGraphicsScene will deactivate any
- currently active window.
+ \since 4.6
+ Returns the current active panel, or 0 if no panel is currently active.
- \sa activeWindow(), QGraphicsWidget::isActiveWindow()
+ \sa QGraphicsScene::setActivePanel()
*/
-void QGraphicsScene::setActiveWindow(QGraphicsWidget *widget)
+QGraphicsItem *QGraphicsScene::activePanel() const
+{
+ Q_D(const QGraphicsScene);
+ return d->activePanel;
+}
+
+/*!
+ \since 4.6
+ Activates \a item, which must be an item in this scene. You
+ can also pass 0 for \a item, in which case QGraphicsScene will
+ deactivate any currently active panel.
+
+ \sa activePanel(), isActive(), QGraphicsItem::isActive()
+*/
+void QGraphicsScene::setActivePanel(QGraphicsItem *item)
{
Q_D(QGraphicsScene);
- if (widget && widget->scene() != this) {
- qWarning("QGraphicsScene::setActiveWindow: widget %p must be part of this scene",
- widget);
+ if (item && item->scene() != this) {
+ qWarning("QGraphicsScene::setActivePanel: item %p must be part of this scene",
+ item);
return;
}
- // Activate the widget's window.
- QGraphicsWidget *window = widget ? widget->window() : 0;
- if (window == d->activeWindow)
+ // Find the item's panel.
+ QGraphicsItem *panel = item ? item->panel() : 0;
+ d->lastActivePanel = panel ? d->activePanel : 0;
+ if (panel == d->activePanel)
return;
- // Deactivate the last active window.
- if (d->activeWindow) {
- if (QGraphicsWidget *fw = d->activeWindow->focusWidget()) {
+ // Deactivate the last active panel.
+ if (d->activePanel) {
+ if (QGraphicsItem *fi = d->activePanel->focusItem()) {
// Remove focus from the current focus item.
- if (fw == focusItem())
+ if (fi == focusItem())
setFocusItem(0, Qt::ActiveWindowFocusReason);
}
QEvent event(QEvent::WindowDeactivate);
- QApplication::sendEvent(d->activeWindow, &event);
+ sendEvent(d->activePanel, &event);
+ } else if (panel) {
+ // Deactivate the scene if changing activation to a panel.
+ QEvent event(QEvent::WindowDeactivate);
+ foreach (QGraphicsItem *item, items()) {
+ if (item->isVisible() && !item->isPanel() && !item->parentItem())
+ sendEvent(item, &event);
+ }
}
// Update activate state.
- d->activeWindow = window;
+ d->activePanel = panel;
QEvent event(QEvent::ActivationChange);
QApplication::sendEvent(this, &event);
// Activate
- if (window) {
+ if (panel) {
QEvent event(QEvent::WindowActivate);
- QApplication::sendEvent(window, &event);
+ sendEvent(panel, &event);
+ // Set focus on the panel's focus item.
+ if (QGraphicsItem *focusItem = panel->focusItem())
+ focusItem->setFocus(Qt::ActiveWindowFocusReason);
+ } else if (isActive()) {
+ // Activate the scene
+ QEvent event(QEvent::WindowActivate);
+ foreach (QGraphicsItem *item, items()) {
+ if (item->isVisible() && !item->isPanel() && !item->parentItem())
+ sendEvent(item, &event);
+ }
+ }
+}
+
+/*!
+ \since 4.4
+
+ Returns the current active window, or 0 if there is no window is currently
+ active.
+
+ \sa QGraphicsScene::setActiveWindow()
+*/
+QGraphicsWidget *QGraphicsScene::activeWindow() const
+{
+ Q_D(const QGraphicsScene);
+ if (d->activePanel && d->activePanel->isWindow())
+ return static_cast<QGraphicsWidget *>(d->activePanel);
+ return 0;
+}
+
+/*!
+ \since 4.4
+ Activates \a widget, which must be a widget in this scene. You can also
+ pass 0 for \a widget, in which case QGraphicsScene will deactivate any
+ currently active window.
+
+ \sa activeWindow(), QGraphicsWidget::isActiveWindow()
+*/
+void QGraphicsScene::setActiveWindow(QGraphicsWidget *widget)
+{
+ if (widget && widget->scene() != this) {
+ qWarning("QGraphicsScene::setActiveWindow: widget %p must be part of this scene",
+ widget);
+ return;
+ }
+
+ // Activate the widget's panel (all windows are panels).
+ QGraphicsItem *panel = widget ? widget->panel() : 0;
+ setActivePanel(panel);
+
+ // Raise
+ if (panel) {
QList<QGraphicsItem *> siblingWindows;
- QGraphicsItem *parent = window->parentItem();
+ QGraphicsItem *parent = panel->parentItem();
// Raise ### inefficient for toplevels
foreach (QGraphicsItem *sibling, parent ? parent->children() : items()) {
- if (sibling != window && sibling->isWidget()
- && static_cast<QGraphicsWidget *>(sibling)->isWindow()) {
+ if (sibling != panel && sibling->isWindow())
siblingWindows << sibling;
- }
}
// Find the highest z value.
- qreal z = window->zValue();
+ qreal z = panel->zValue();
for (int i = 0; i < siblingWindows.size(); ++i)
z = qMax(z, siblingWindows.at(i)->zValue());
// This will probably never overflow.
const qreal litt = qreal(0.001);
- window->setZValue(z + litt);
-
- if (QGraphicsWidget *focusChild = window->focusWidget())
- focusChild->setFocus(Qt::ActiveWindowFocusReason);
+ panel->setZValue(z + litt);
}
}
diff --git a/src/gui/graphicsview/qgraphicsscene.h b/src/gui/graphicsview/qgraphicsscene.h
index 26cb1c2..9478879 100644
--- a/src/gui/graphicsview/qgraphicsscene.h
+++ b/src/gui/graphicsview/qgraphicsscene.h
@@ -243,6 +243,9 @@ public:
QPalette palette() const;
void setPalette(const QPalette &palette);
+ bool isActive() const;
+ QGraphicsItem *activePanel() const;
+ void setActivePanel(QGraphicsItem *item);
QGraphicsWidget *activeWindow() const;
void setActiveWindow(QGraphicsWidget *widget);
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index 9e62901..def6f46 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
@@ -131,7 +131,8 @@ public:
QGraphicsItem *focusItem;
QGraphicsItem *lastFocusItem;
QGraphicsWidget *tabFocusFirst;
- QGraphicsWidget *activeWindow;
+ QGraphicsItem *activePanel;
+ QGraphicsItem *lastActivePanel;
int activationRefCount;
void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason);
diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
index 27c499d..5cc8449 100644
--- a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
+++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
@@ -44,8 +44,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp
index 3ec14c3..afcc4e1 100644
--- a/src/gui/graphicsview/qgraphicssceneevent.cpp
+++ b/src/gui/graphicsview/qgraphicssceneevent.cpp
@@ -87,9 +87,11 @@
\since 4.2
\ingroup graphicsview-api
- When a QGraphicsView receives a QMouseEvent, it translates it to
- a QGraphicsSceneMouseEvent. The event is then forwarded to the
- QGraphicsScene associated with the view.
+ When a QGraphicsView receives a QMouseEvent, it translates it to a
+ QGraphicsSceneMouseEvent. The event is then forwarded to the
+ QGraphicsScene associated with the view. If the event is not
+ handled by the scene, the view may use it, e.g., for the
+ \l{QGraphicsView::}{DragMode}.
In addition to containing the item, scene, and screen coordinates
of the event (as pos(), scenePos(), and screenPos()), mouse
diff --git a/src/gui/graphicsview/qgraphicssceneindex_p.h b/src/gui/graphicsview/qgraphicssceneindex_p.h
index d922036..00e5f89 100644
--- a/src/gui/graphicsview/qgraphicssceneindex_p.h
+++ b/src/gui/graphicsview/qgraphicssceneindex_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgraphicstransform_p.h b/src/gui/graphicsview/qgraphicstransform_p.h
index 2c563e4..c9b95fd 100644
--- a/src/gui/graphicsview/qgraphicstransform_p.h
+++ b/src/gui/graphicsview/qgraphicstransform_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h
index bdf5ddd..a40dfdc 100644
--- a/src/gui/graphicsview/qgraphicsview_p.h
+++ b/src/gui/graphicsview/qgraphicsview_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp
index 7f9fe65..40addf6 100644
--- a/src/gui/graphicsview/qgraphicswidget.cpp
+++ b/src/gui/graphicsview/qgraphicswidget.cpp
@@ -1285,10 +1285,6 @@ bool QGraphicsWidget::event(QEvent *event)
case QEvent::WindowActivate:
case QEvent::WindowDeactivate:
update();
- foreach (QGraphicsItem *child, childItems()) {
- if (child->isWidget())
- QApplication::sendEvent(static_cast<QGraphicsWidget *>(child), event);
- }
break;
// Taken from QWidget::event
case QEvent::ActivationChange:
@@ -1598,6 +1594,8 @@ void QGraphicsWidget::ungrabKeyboardEvent(QEvent *event)
/*!
Returns the widgets window type.
+
+ \sa windowFlags(), isWindow(), isPanel()
*/
Qt::WindowType QGraphicsWidget::windowType() const
{
@@ -1613,6 +1611,13 @@ Qt::WindowType QGraphicsWidget::windowType() const
is platform-dependent.
By default, this property contains no window flags.
+
+ Windows are panels. If you set the Qt::Window flag, the ItemIsPanel flag
+ will be set automatically. If you clear the Qt::Window flag, the
+ ItemIsPanel flag is also cleared. Note that the ItemIsPanel flag can be
+ set independently of Qt::Window.
+
+ \sa isWindow(), isPanel()
*/
Qt::WindowFlags QGraphicsWidget::windowFlags() const
{
@@ -1631,6 +1636,8 @@ void QGraphicsWidget::setWindowFlags(Qt::WindowFlags wFlags)
if (!d->setWindowFrameMargins)
unsetWindowFrameMargins();
+ setFlag(ItemIsPanel, d->windowFlags & Qt::Window);
+
bool isPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
if (d->scene && isVisible() && wasPopup != isPopup) {
// Popup state changed; update implicit mouse grab.
@@ -1654,7 +1661,7 @@ void QGraphicsWidget::setWindowFlags(Qt::WindowFlags wFlags)
The active window is the window that either contains a child widget that
currently has input focus, or that itself has input focus.
- \sa QGraphicsScene::activeWindow(), QGraphicsScene::setActiveWindow()
+ \sa QGraphicsScene::activeWindow(), QGraphicsScene::setActiveWindow(), isActive()
*/
bool QGraphicsWidget::isActiveWindow() const
{
@@ -1662,7 +1669,7 @@ bool QGraphicsWidget::isActiveWindow() const
if (!d->scene)
return false;
const QGraphicsWidget *w = window();
- return (!w && d->scene->d_func()->activationRefCount) || (w && d->scene->activeWindow() == w);
+ return (!w && d->scene->isActive()) || (w && d->scene->activeWindow() == w);
}
/*!
diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h
index 0e1fe46..1ee79e1 100644
--- a/src/gui/graphicsview/qgraphicswidget_p.h
+++ b/src/gui/graphicsview/qgraphicswidget_p.h
@@ -47,8 +47,8 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index 5ad6ac9..beb9cb0 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -461,7 +461,7 @@ void QGridLayoutRowData::dump(int indent) const
QGridLayoutItem::QGridLayoutItem(QGridLayoutEngine *engine, QGraphicsLayoutItem *layoutItem,
int row, int column, int rowSpan, int columnSpan,
- Qt::Alignment alignment)
+ Qt::Alignment alignment, int itemAtIndex)
: q_engine(engine), q_layoutItem(layoutItem), q_alignment(alignment)
{
q_firstRows[Hor] = column;
@@ -471,7 +471,7 @@ QGridLayoutItem::QGridLayoutItem(QGridLayoutEngine *engine, QGraphicsLayoutItem
q_stretches[Hor] = -1;
q_stretches[Ver] = -1;
- q_engine->addItem(this);
+ q_engine->insertItem(this, itemAtIndex);
}
int QGridLayoutItem::firstRow(Qt::Orientation orientation) const
@@ -937,11 +937,20 @@ Qt::Alignment QGridLayoutEngine::effectiveAlignment(const QGridLayoutItem *layou
return align;
}
-void QGridLayoutEngine::addItem(QGridLayoutItem *item)
+/*!
+ \internal
+ The \a index is only used by QGraphicsLinearLayout to ensure that itemAt() reflects the order
+ of visual arrangement. Strictly speaking it does not have to, but most people expect it to.
+ (And if it didn't we would have to add itemArrangedAt(int index) or something..)
+ */
+void QGridLayoutEngine::insertItem(QGridLayoutItem *item, int index)
{
maybeExpandGrid(item->lastRow(), item->lastColumn());
- q_items.append(item);
+ if (index == -1)
+ q_items.append(item);
+ else
+ q_items.insert(index, item);
for (int i = item->firstRow(); i <= item->lastRow(); ++i) {
for (int j = item->firstColumn(); j <= item->lastColumn(); ++j) {
@@ -952,6 +961,11 @@ void QGridLayoutEngine::addItem(QGridLayoutItem *item)
}
}
+void QGridLayoutEngine::addItem(QGridLayoutItem *item)
+{
+ insertItem(item, -1);
+}
+
void QGridLayoutEngine::removeItem(QGridLayoutItem *item)
{
Q_ASSERT(q_items.contains(item));
diff --git a/src/gui/graphicsview/qgridlayoutengine_p.h b/src/gui/graphicsview/qgridlayoutengine_p.h
index 8f3eb13..aab695a 100644
--- a/src/gui/graphicsview/qgridlayoutengine_p.h
+++ b/src/gui/graphicsview/qgridlayoutengine_p.h
@@ -267,7 +267,8 @@ class QGridLayoutItem
{
public:
QGridLayoutItem(QGridLayoutEngine *engine, QGraphicsLayoutItem *layoutItem, int row, int column,
- int rowSpan = 1, int columnSpan = 1, Qt::Alignment alignment = 0);
+ int rowSpan = 1, int columnSpan = 1, Qt::Alignment alignment = 0,
+ int itemAtIndex = -1);
inline int firstRow() const { return q_firstRows[Ver]; }
inline int firstColumn() const { return q_firstRows[Hor]; }
@@ -378,6 +379,7 @@ public:
Qt::Alignment effectiveAlignment(const QGridLayoutItem *layoutItem) const;
+ void insertItem(QGridLayoutItem *item, int index);
void addItem(QGridLayoutItem *item);
void removeItem(QGridLayoutItem *item);
QGridLayoutItem *findLayoutItem(QGraphicsLayoutItem *layoutItem) const;
diff --git a/src/gui/graphicsview/qsimplex_p.cpp b/src/gui/graphicsview/qsimplex_p.cpp
index dbd8d4f..30a7d5d 100644
--- a/src/gui/graphicsview/qsimplex_p.cpp
+++ b/src/gui/graphicsview/qsimplex_p.cpp
@@ -293,7 +293,7 @@ int QSimplex::findPivotColumn()
int QSimplex::pivotRowForColumn(int column)
{
- qreal min = 999999999999.0; // ###
+ qreal min = qreal(999999999999.0); // ###
int minIndex = -1;
for (int i = 1; i < rows; ++i) {