From 19e353ca6fd98a3e91cd292936f341f31856b6a1 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 15 Dec 2015 13:47:47 +0100 Subject: QQuickOverlay: use d-pointer Change-Id: Ic97452efa8a356d323e74a824a496b947c26187f Reviewed-by: Mitch Curtis Reviewed-by: J-P Nurmi --- src/templates/qquickoverlay.cpp | 51 ++++++++++++++++++++++++++++++----------- src/templates/qquickoverlay_p.h | 5 ++-- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/templates/qquickoverlay.cpp b/src/templates/qquickoverlay.cpp index 84495bf0..73e0a39d 100644 --- a/src/templates/qquickoverlay.cpp +++ b/src/templates/qquickoverlay.cpp @@ -41,8 +41,24 @@ QT_BEGIN_NAMESPACE +class QQuickOverlayPrivate : public QQuickItemPrivate +{ + Q_DECLARE_PUBLIC(QQuickOverlay) + +public: + QQuickOverlayPrivate(); + + QHash popups; + int modalPopups; +}; + +QQuickOverlayPrivate::QQuickOverlayPrivate() : + modalPopups(0) +{ +} + QQuickOverlay::QQuickOverlay(QQuickItem *parent) - : QQuickItem(parent), m_modalPopups(0) + : QQuickItem(*(new QQuickOverlayPrivate), parent) { setAcceptedMouseButtons(Qt::AllButtons); setFiltersChildMouseEvents(true); @@ -51,6 +67,7 @@ QQuickOverlay::QQuickOverlay(QQuickItem *parent) void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) { + Q_D(QQuickOverlay); QQuickItem::itemChange(change, data); QQuickItem *contentItem = const_cast(data.item); @@ -63,60 +80,66 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) return; if (change == ItemChildAddedChange) { - if (QQuickPopup *prevPopup = m_popups.value(contentItem)) { + if (QQuickPopup *prevPopup = d->popups.value(contentItem)) { qmlInfo(popup).nospace() << "Popup is sharing item " << contentItem << " with " << prevPopup << ". This is not supported and strange things are about to happen."; return; } - m_popups.insert(contentItem, popup); + d->popups.insert(contentItem, popup); if (popup->isModal()) - ++m_modalPopups; + ++d->modalPopups; connect(this, &QQuickOverlay::pressed, popup, &QQuickPopup::pressedOutside); connect(this, &QQuickOverlay::released, popup, &QQuickPopup::releasedOutside); } else if (change == ItemChildRemovedChange) { - Q_ASSERT(popup == m_popups.value(contentItem)); + Q_ASSERT(popup == d->popups.value(contentItem)); disconnect(this, &QQuickOverlay::pressed, popup, &QQuickPopup::pressedOutside); disconnect(this, &QQuickOverlay::released, popup, &QQuickPopup::releasedOutside); if (popup->isModal()) - --m_modalPopups; - m_popups.remove(contentItem); + --d->modalPopups; + d->popups.remove(contentItem); } } void QQuickOverlay::keyPressEvent(QKeyEvent *event) { - event->setAccepted(m_modalPopups > 0); + Q_D(QQuickOverlay); + event->setAccepted(d->modalPopups > 0); } void QQuickOverlay::keyReleaseEvent(QKeyEvent *event) { - event->setAccepted(m_modalPopups > 0); + Q_D(QQuickOverlay); + event->setAccepted(d->modalPopups > 0); } void QQuickOverlay::mousePressEvent(QMouseEvent *event) { - event->setAccepted(m_modalPopups > 0); + Q_D(QQuickOverlay); + event->setAccepted(d->modalPopups > 0); emit pressed(); } void QQuickOverlay::mouseMoveEvent(QMouseEvent *event) { - event->setAccepted(m_modalPopups > 0); + Q_D(QQuickOverlay); + event->setAccepted(d->modalPopups > 0); } void QQuickOverlay::mouseReleaseEvent(QMouseEvent *event) { - event->setAccepted(m_modalPopups > 0); + Q_D(QQuickOverlay); + event->setAccepted(d->modalPopups > 0); emit released(); } bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) { - if (m_modalPopups == 0) + Q_D(QQuickOverlay); + if (d->modalPopups == 0) return false; // TODO Filter touch events if (event->type() != QEvent::MouseButtonPress) @@ -132,7 +155,7 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) if (contentItem == item) break; - QQuickPopup *popup = m_popups.value(contentItem); + QQuickPopup *popup = d->popups.value(contentItem); if (popup) { emit popup->pressedOutside(); diff --git a/src/templates/qquickoverlay_p.h b/src/templates/qquickoverlay_p.h index cdba2532..d63d78e7 100644 --- a/src/templates/qquickoverlay_p.h +++ b/src/templates/qquickoverlay_p.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE -class QQuickPopup; +class QQuickOverlayPrivate; class QQuickOverlay : public QQuickItem { @@ -77,8 +77,7 @@ protected: private: Q_DISABLE_COPY(QQuickOverlay) - QHash m_popups; - int m_modalPopups; + Q_DECLARE_PRIVATE(QQuickOverlay) }; QT_END_NAMESPACE -- cgit v1.2.3