summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-17 09:11:07 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-17 09:18:17 (GMT)
commitfd73185195633fd97228a0c832c247b761967598 (patch)
treed072553d85b24424371cbd9d0c2deb6ddc891935 /src/gui/graphicsview
parent18ec250e0bdc5ca901744b926d9a062e6920ebbc (diff)
downloadQt-fd73185195633fd97228a0c832c247b761967598.zip
Qt-fd73185195633fd97228a0c832c247b761967598.tar.gz
Qt-fd73185195633fd97228a0c832c247b761967598.tar.bz2
Fix two bugs in Graphics View's mouse grab logics + add autotests.
Change fd4d94df4eb16e9e54f61dd8ee45914e24832ae9 introduced mouse grab and keyboard grab support to Graphics View (this was as part of 4.4). The change was missing a large set of autotests that I wrote to test the behavior of these features. As part of task 245317, which involves investigating modality in Graphics View, I figured it would be a good idea to start off but reconstructing these autotests. So this change is mainly about adding autotests for mouse grabbing. And of course, as it always is, I found two bugs while writing these tests. 1) Calling QGraphicsItem::grabMouse() while the item is holding the implicit mouse grab will now upgrade the implicit grab to an explicit grab. 2) Adding a popup to the scene will automatically grab the mouse. Before, the popup would get the grab on show(), but if it was already visible when added to the scene it would not gain the grab. Task-number: 245317 Reviewed-by: jasplin
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp13
-rw-r--r--src/gui/graphicsview/qgraphicswidget_p.cpp9
2 files changed, 15 insertions, 7 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index c616e91..d9e0eec 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -902,11 +902,18 @@ void QGraphicsScenePrivate::grabMouse(QGraphicsItem *item, bool implicit)
{
// Append to list of mouse grabber items, and send a mouse grab event.
if (mouseGrabberItems.contains(item)) {
- if (mouseGrabberItems.last() == item)
- qWarning("QGraphicsItem::grabMouse: already a mouse grabber");
- else
+ if (mouseGrabberItems.last() == item) {
+ Q_ASSERT(!implicit);
+ if (!lastMouseGrabberItemHasImplicitMouseGrab) {
+ qWarning("QGraphicsItem::grabMouse: already a mouse grabber");
+ } else {
+ // Upgrade to an explicit mouse grab
+ lastMouseGrabberItemHasImplicitMouseGrab = false;
+ }
+ } else {
qWarning("QGraphicsItem::grabMouse: already blocked by mouse grabber: %p",
mouseGrabberItems.last());
+ }
return;
}
diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp
index 789f8da..06ffe73 100644
--- a/src/gui/graphicsview/qgraphicswidget_p.cpp
+++ b/src/gui/graphicsview/qgraphicswidget_p.cpp
@@ -66,15 +66,16 @@ void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFl
isWidget = 1; // QGraphicsItem::isWidget() returns true.
focusNext = focusPrev = q;
focusPolicy = Qt::NoFocus;
+
+ if (!parentItem)
+ adjustWindowFlags(&wFlags);
+ windowFlags = wFlags;
+
q->setParentItem(parentItem);
q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType));
q->setGraphicsItem(q);
resolveLayoutDirection();
-
- if (!parentItem)
- adjustWindowFlags(&wFlags);
- windowFlags = wFlags;
q->unsetWindowFrameMargins();
}
qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const