aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickoverlay.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-02-26 13:52:56 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-23 12:46:11 +0000
commit0dd8a34f3b454d516f75e9b4be7691f934d2e849 (patch)
tree1b176eb891ce675e653093da645acd25253ff776 /src/templates/qquickoverlay.cpp
parente346ed6f6db3fc0751c02b4b289f344d415cfdc9 (diff)
Inherit QQuickDrawer from QQuickPopup
Change-Id: Icf71270e63aedd93ba975ab9743de68c3a54e849 Task-number: QTBUG-51007 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickoverlay.cpp')
-rw-r--r--src/templates/qquickoverlay.cpp79
1 files changed, 53 insertions, 26 deletions
diff --git a/src/templates/qquickoverlay.cpp b/src/templates/qquickoverlay.cpp
index 8af5cb88..4977d08d 100644
--- a/src/templates/qquickoverlay.cpp
+++ b/src/templates/qquickoverlay.cpp
@@ -58,6 +58,7 @@ public:
QQuickItem *background;
QVector<QQuickDrawer *> drawers;
QVector<QQuickPopup *> popups;
+ QPointer<QQuickPopup> mouseGrabberPopup;
int modalPopups;
};
@@ -93,7 +94,7 @@ void QQuickOverlayPrivate::drawerPositionChange()
{
Q_Q(QQuickOverlay);
QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(q->sender());
- if (!background || !drawer || modalPopups > 0)
+ if (!background || !drawer || !drawer->isModal())
return;
// call QQuickItem::setOpacity() directly to avoid triggering QML Behaviors
@@ -155,18 +156,7 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data)
QQuickPopup *popup = nullptr;
if (change == ItemChildAddedChange || change == ItemChildRemovedChange) {
- QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(data.item);
- if (drawer) {
- if (change == ItemChildAddedChange) {
- QObjectPrivate::connect(drawer, &QQuickDrawer::positionChanged, d, &QQuickOverlayPrivate::drawerPositionChange);
- d->drawers.append(drawer);
- } else {
- QObjectPrivate::disconnect(drawer, &QQuickDrawer::positionChanged, d, &QQuickOverlayPrivate::drawerPositionChange);
- d->drawers.removeOne(drawer);
- }
- } else {
- popup = qobject_cast<QQuickPopup *>(data.item->parent());
- }
+ popup = qobject_cast<QQuickPopup *>(data.item->parent());
setVisible(!childItems().isEmpty());
}
if (!popup)
@@ -174,18 +164,32 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data)
if (change == ItemChildAddedChange) {
d->popups.append(popup);
- if (popup->isModal())
- ++d->modalPopups;
- QObjectPrivate::connect(popup, &QQuickPopup::aboutToShow, d, &QQuickOverlayPrivate::popupAboutToShow);
- QObjectPrivate::connect(popup, &QQuickPopup::aboutToHide, d, &QQuickOverlayPrivate::popupAboutToHide);
+ QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(popup);
+ if (drawer) {
+ QObjectPrivate::connect(drawer, &QQuickDrawer::positionChanged, d, &QQuickOverlayPrivate::drawerPositionChange);
+ d->drawers.append(drawer);
+ } else {
+ if (popup->isModal())
+ ++d->modalPopups;
+
+ QObjectPrivate::connect(popup, &QQuickPopup::aboutToShow, d, &QQuickOverlayPrivate::popupAboutToShow);
+ QObjectPrivate::connect(popup, &QQuickPopup::aboutToHide, d, &QQuickOverlayPrivate::popupAboutToHide);
+ }
} else if (change == ItemChildRemovedChange) {
d->popups.removeOne(popup);
- if (popup->isModal())
- --d->modalPopups;
- QObjectPrivate::disconnect(popup, &QQuickPopup::aboutToShow, d, &QQuickOverlayPrivate::popupAboutToShow);
- QObjectPrivate::disconnect(popup, &QQuickPopup::aboutToHide, d, &QQuickOverlayPrivate::popupAboutToHide);
+ QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(popup);
+ if (drawer) {
+ QObjectPrivate::disconnect(drawer, &QQuickDrawer::positionChanged, d, &QQuickOverlayPrivate::drawerPositionChange);
+ d->drawers.removeOne(drawer);
+ } else {
+ if (popup->isModal())
+ --d->modalPopups;
+
+ QObjectPrivate::disconnect(popup, &QQuickPopup::aboutToShow, d, &QQuickOverlayPrivate::popupAboutToShow);
+ QObjectPrivate::disconnect(popup, &QQuickPopup::aboutToHide, d, &QQuickOverlayPrivate::popupAboutToHide);
+ }
}
}
@@ -203,19 +207,42 @@ bool QQuickOverlay::event(QEvent *event)
switch (event->type()) {
case QEvent::MouseButtonPress:
emit pressed();
+ for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) {
+ if ((*it)->overlayEvent(this, event)) {
+ d->mouseGrabberPopup = *it;
+ return true;
+ }
+ }
+ break;
+ case QEvent::MouseMove:
+ if (d->mouseGrabberPopup) {
+ if (d->mouseGrabberPopup->overlayEvent(this, event))
+ return true;
+ } else {
+ for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) {
+ if ((*it)->overlayEvent(this, event))
+ return true;
+ }
+ }
break;
case QEvent::MouseButtonRelease:
emit released();
+ if (d->mouseGrabberPopup) {
+ QQuickPopup *grabber = d->mouseGrabberPopup;
+ d->mouseGrabberPopup = nullptr;
+ if (grabber->overlayEvent(this, event))
+ return true;
+ } else {
+ for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) {
+ if ((*it)->overlayEvent(this, event))
+ return true;
+ }
+ }
break;
default:
break;
}
- for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) {
- if ((*it)->overlayEvent(this, event))
- return true;
- }
-
return QQuickItem::event(event);
}