aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-07-09 15:35:47 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-07-11 07:17:34 +0000
commit538f47cb77f2dcc34383859bd64de3667987f17b (patch)
tree4e419daa811dfdcf874b929a440cc092316ceffa
parent09706e8f9fc481d848a3616cace58baf5bc8b67c (diff)
QQuickAbstractButton: make the press point available via private API
The Material style ripple effect needs it to be able to anchor waves at the press point. Export QQuickAbstractButtonPrivate to make it accessible, and update the press point before emitting pressedChanged() since that's what the ripple effect reacts to. Press point dependent ripple effects follow in separate commits. Change-Id: I63eb51eeabcbeb307dea9d0b1731bdb51b518ec7 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/controls/material/qquickmaterialripple.cpp37
-rw-r--r--src/imports/controls/material/qquickmaterialripple_p.h11
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp4
-rw-r--r--src/quicktemplates2/qquickabstractbutton_p_p.h2
4 files changed, 36 insertions, 18 deletions
diff --git a/src/imports/controls/material/qquickmaterialripple.cpp b/src/imports/controls/material/qquickmaterialripple.cpp
index 1923d554..b3afe1eb 100644
--- a/src/imports/controls/material/qquickmaterialripple.cpp
+++ b/src/imports/controls/material/qquickmaterialripple.cpp
@@ -42,6 +42,8 @@
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanimatorjob_p.h>
#include <QtQuick/private/qsgadaptationlayer_p.h>
+#include <QtQuickTemplates2/private/qquickabstractbutton_p.h>
+#include <QtQuickTemplates2/private/qquickabstractbutton_p_p.h>
QT_BEGIN_NAMESPACE
@@ -200,7 +202,7 @@ QQuickAnimatorJob *QQuickMaterialRippleAnimator::createJob() const
}
QQuickMaterialRipple::QQuickMaterialRipple(QQuickItem *parent)
- : QQuickItem(parent), m_active(false), m_pressed(false), m_anchored(false), m_clipRadius(0.0), m_opacityAnimator(nullptr)
+ : QQuickItem(parent), m_active(false), m_pressed(false), m_clipRadius(0.0), m_anchor(nullptr), m_opacityAnimator(nullptr)
{
setOpacity(0.0);
setFlag(ItemHasContents);
@@ -279,30 +281,45 @@ void QQuickMaterialRipple::setPressed(bool pressed)
exitWave();
}
-QPointF QQuickMaterialRipple::anchor() const
+QPointF QQuickMaterialRipple::anchorPoint() const
{
const QRectF bounds = boundingRect();
const QPointF center = bounds.center();
- if (!m_anchored)
+ if (!m_anchor)
return center;
+ QPointF anchorPoint = bounds.center();
+ if (QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(m_anchor)) {
+ if (QQuickWindow *window = button->window()) {
+ if (button == window->mouseGrabberItem()) {
+ QQuickAbstractButtonPrivate *p = QQuickAbstractButtonPrivate::get(button);
+ anchorPoint = p->pressPoint;
+ }
+ }
+ }
+ anchorPoint = mapFromItem(m_anchor, anchorPoint);
+
// calculate whether the anchor point is within the ripple circle bounds,
// that is, whether waves should start expanding from the anchor point
const qreal r = qSqrt(bounds.width() * bounds.width() + bounds.height() * bounds.height()) / 2;
- if (QLineF(center, m_anchor).length() < r)
- return m_anchor;
+ if (QLineF(center, anchorPoint).length() < r)
+ return anchorPoint;
// if the anchor point is outside the ripple circle bounds, start expanding
// from the intersection point of the ripple circle and a line from its center
// to the the anchor point
- const qreal p = qAtan2(m_anchor.y() - center.y(), m_anchor.x() - center.x());
+ const qreal p = qAtan2(anchorPoint.y() - center.y(), anchorPoint.x() - center.x());
return QPointF(center.x() + r * qCos(p), center.y() + r * qSin(p));
}
-void QQuickMaterialRipple::setAnchor(const QPointF &anchor)
+QQuickItem *QQuickMaterialRipple::anchor() const
+{
+ return m_anchor;
+}
+
+void QQuickMaterialRipple::setAnchor(QQuickItem *item)
{
- m_anchor = anchor;
- m_anchored = true;
+ m_anchor = item;
}
void QQuickMaterialRipple::itemChange(ItemChange change, const ItemChangeData &data)
@@ -371,7 +388,7 @@ void QQuickMaterialRipple::enterWave()
wave->setColor(color());
wave->setOpacity(0.0);
- QQuickMaterialRippleAnimator *animator = new QQuickMaterialRippleAnimator(anchor(), boundingRect(), wave);
+ QQuickMaterialRippleAnimator *animator = new QQuickMaterialRippleAnimator(anchorPoint(), boundingRect(), wave);
animator->setDuration(qRound(RIPPLE_ENTER_DELAY + 1000.0 * qSqrt(sz / 2.0 / WAVE_TOUCH_DOWN_ACCELERATION)));
animator->setTargetItem(wave);
animator->setTo(sz);
diff --git a/src/imports/controls/material/qquickmaterialripple_p.h b/src/imports/controls/material/qquickmaterialripple_p.h
index bff714ea..14e31aa6 100644
--- a/src/imports/controls/material/qquickmaterialripple_p.h
+++ b/src/imports/controls/material/qquickmaterialripple_p.h
@@ -62,7 +62,7 @@ class QQuickMaterialRipple : public QQuickItem
Q_PROPERTY(qreal clipRadius READ clipRadius WRITE setClipRadius FINAL)
Q_PROPERTY(bool pressed READ isPressed WRITE setPressed FINAL)
Q_PROPERTY(bool active READ isActive WRITE setActive FINAL)
- Q_PROPERTY(QPointF anchor READ anchor WRITE setAnchor FINAL)
+ Q_PROPERTY(QQuickItem *anchor READ anchor WRITE setAnchor FINAL)
public:
QQuickMaterialRipple(QQuickItem *parent = nullptr);
@@ -79,8 +79,10 @@ public:
bool isPressed() const;
void setPressed(bool pressed);
- QPointF anchor() const;
- void setAnchor(const QPointF &anchor);
+ QPointF anchorPoint() const;
+
+ QQuickItem *anchor() const;
+ void setAnchor(QQuickItem *anchor);
protected:
void itemChange(ItemChange change, const ItemChangeData &data) override;
@@ -92,10 +94,9 @@ protected:
private:
bool m_active;
bool m_pressed;
- bool m_anchored;
qreal m_clipRadius;
- QPointF m_anchor;
QColor m_color;
+ QQuickItem *m_anchor;
QQuickOpacityAnimator *m_opacityAnimator;
QVector<QQuickMaterialRippleAnimator *> m_rippleAnimators;
};
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp
index c4b2b6f0..ac5fbf55 100644
--- a/src/quicktemplates2/qquickabstractbutton.cpp
+++ b/src/quicktemplates2/qquickabstractbutton.cpp
@@ -474,8 +474,8 @@ void QQuickAbstractButton::keyPressEvent(QKeyEvent *event)
Q_D(QQuickAbstractButton);
QQuickControl::keyPressEvent(event);
if (event->key() == Qt::Key_Space) {
- setPressed(true);
d->pressPoint = QPoint(qRound(width() / 2), qRound(height() / 2));
+ setPressed(true);
if (d->autoRepeat) {
d->startRepeatDelay();
@@ -506,8 +506,8 @@ void QQuickAbstractButton::mousePressEvent(QMouseEvent *event)
{
Q_D(QQuickAbstractButton);
QQuickControl::mousePressEvent(event);
- setPressed(true);
d->pressPoint = event->pos();
+ setPressed(true);
emit pressed();
diff --git a/src/quicktemplates2/qquickabstractbutton_p_p.h b/src/quicktemplates2/qquickabstractbutton_p_p.h
index e690bbd0..a7d4d6c2 100644
--- a/src/quicktemplates2/qquickabstractbutton_p_p.h
+++ b/src/quicktemplates2/qquickabstractbutton_p_p.h
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
class QQuickButtonGroup;
-class QQuickAbstractButtonPrivate : public QQuickControlPrivate
+class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButtonPrivate : public QQuickControlPrivate
{
Q_DECLARE_PUBLIC(QQuickAbstractButton)