aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-18 20:34:17 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-25 21:30:18 +0000
commitb0fd258cbb2a17610a185f76076cf6cda0bdfc09 (patch)
tree7a4f711ca7bb07ab54a505936cbe547552598e22 /src/quicktemplates2
parente33443d9b8de1917d8d3b85f185bbb75b78dc448 (diff)
Add Drawer::interactive
[ChangeLog][Controls][Drawer] Added interactive property that specifies whether the drawer reacts to swipes. This can be used to make drawer a non-closable persistent side-bar. Task-number: QTBUG-53169 Change-Id: I00a794b5ce47b86fcb28e0db784ca0488cd13a7d Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickdrawer.cpp34
-rw-r--r--src/quicktemplates2/qquickdrawer_p.h5
-rw-r--r--src/quicktemplates2/qquickpopup.cpp4
-rw-r--r--src/quicktemplates2/qquickpopup_p_p.h1
-rw-r--r--src/quicktemplates2/qquickpopupitem.cpp7
5 files changed, 47 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp
index 59caa230..a465a13e 100644
--- a/src/quicktemplates2/qquickdrawer.cpp
+++ b/src/quicktemplates2/qquickdrawer.cpp
@@ -239,7 +239,7 @@ static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event, int th
bool QQuickDrawerPrivate::startDrag(QQuickWindow *window, QMouseEvent *event)
{
- if (!window || dragMargin < 0.0 || qFuzzyIsNull(dragMargin))
+ if (!window || !interactive || dragMargin < 0.0 || qFuzzyIsNull(dragMargin))
return false;
bool drag = false;
@@ -272,7 +272,7 @@ bool QQuickDrawerPrivate::startDrag(QQuickWindow *window, QMouseEvent *event)
bool QQuickDrawerPrivate::grabMouse(QMouseEvent *event)
{
Q_Q(QQuickDrawer);
- if (!window || popupItem->keepMouseGrab())
+ if (!window || !interactive || popupItem->keepMouseGrab())
return false;
const QPointF movePoint = event->windowPos();
@@ -542,6 +542,8 @@ void QQuickDrawer::setPosition(qreal position)
prevents opening the drawer by dragging.
The default value is \c Qt.styleHints.startDragDistance.
+
+ \sa interactive
*/
qreal QQuickDrawer::dragMargin() const
{
@@ -564,6 +566,34 @@ void QQuickDrawer::resetDragMargin()
setDragMargin(QGuiApplication::styleHints()->startDragDistance());
}
+/*!
+ \since QtQuick.Controls 2.2
+ \qmlproperty bool QtQuick.Controls::Drawer::interactive
+
+ This property holds whether the drawer is interactive. A non-interactive
+ drawer does not react to swipes.
+
+ The default value is \c true.
+
+ \sa dragMargin
+*/
+bool QQuickDrawer::isInteractive() const
+{
+ Q_D(const QQuickDrawer);
+ return d->interactive;
+}
+
+void QQuickDrawer::setInteractive(bool interactive)
+{
+ Q_D(QQuickDrawer);
+ if (d->interactive == interactive)
+ return;
+
+ setFiltersChildMouseEvents(interactive);
+ d->interactive = interactive;
+ emit interactiveChanged();
+}
+
bool QQuickDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event)
{
Q_D(QQuickDrawer);
diff --git a/src/quicktemplates2/qquickdrawer_p.h b/src/quicktemplates2/qquickdrawer_p.h
index bada1344..6a7d8b6d 100644
--- a/src/quicktemplates2/qquickdrawer_p.h
+++ b/src/quicktemplates2/qquickdrawer_p.h
@@ -60,6 +60,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDrawer : public QQuickPopup
Q_PROPERTY(Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged FINAL)
Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL)
Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin RESET resetDragMargin NOTIFY dragMarginChanged FINAL)
+ Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION 2)
public:
explicit QQuickDrawer(QObject *parent = nullptr);
@@ -74,10 +75,14 @@ public:
void setDragMargin(qreal margin);
void resetDragMargin();
+ bool isInteractive() const;
+ void setInteractive(bool interactive);
+
Q_SIGNALS:
void edgeChanged();
void positionChanged();
void dragMarginChanged();
+ Q_REVISION(2) void interactiveChanged();
protected:
bool childMouseEventFilter(QQuickItem *child, QEvent *event) override;
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index 7ff99c49..95d1a7e2 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -209,6 +209,7 @@ QQuickPopupPrivate::QQuickPopupPrivate()
, allowVerticalResize(true)
, allowHorizontalResize(true)
, hadActiveFocusBeforeExitTransition(false)
+ , interactive(true)
, x(0)
, y(0)
, effectiveX(0)
@@ -257,6 +258,9 @@ void QQuickPopupPrivate::closeOrReject()
bool QQuickPopupPrivate::tryClose(QQuickItem *item, QMouseEvent *event)
{
+ if (!interactive)
+ return false;
+
const bool isPress = event->type() == QEvent::MouseButtonPress;
const bool onOutside = closePolicy.testFlag(isPress ? QQuickPopup::CloseOnPressOutside : QQuickPopup::CloseOnReleaseOutside);
const bool onOutsideParent = closePolicy.testFlag(isPress ? QQuickPopup::CloseOnPressOutsideParent : QQuickPopup::CloseOnReleaseOutsideParent);
diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h
index 2cf92864..4aa62d23 100644
--- a/src/quicktemplates2/qquickpopup_p_p.h
+++ b/src/quicktemplates2/qquickpopup_p_p.h
@@ -138,6 +138,7 @@ public:
bool allowVerticalResize;
bool allowHorizontalResize;
bool hadActiveFocusBeforeExitTransition;
+ bool interactive;
qreal x;
qreal y;
qreal effectiveX;
diff --git a/src/quicktemplates2/qquickpopupitem.cpp b/src/quicktemplates2/qquickpopupitem.cpp
index de8a9de2..8a84cc20 100644
--- a/src/quicktemplates2/qquickpopupitem.cpp
+++ b/src/quicktemplates2/qquickpopupitem.cpp
@@ -152,8 +152,11 @@ bool QQuickPopupItem::event(QEvent *event)
if (event->type() == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(event);
if (se->shortcutId() == d->escapeId || se->shortcutId() == d->backId) {
- QQuickPopupPrivate::get(d->popup)->closeOrReject();
- return true;
+ QQuickPopupPrivate *p = QQuickPopupPrivate::get(d->popup);
+ if (p->interactive) {
+ p->closeOrReject();
+ return true;
+ }
}
}
return QQuickItem::event(event);