diff options
author | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2012-06-23 11:29:59 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-25 15:50:33 +0200 |
commit | 3a345056c734f0d475b3ecd9959b9ae83ae70acc (patch) | |
tree | 6a1814e7e4816173d120454b680af9951270ae11 /src/quick/items/qquickmousearea.cpp | |
parent | e6fe0708006b5b1165bc4f93ce2c496bb92bbefc (diff) |
Add mouse cursor shapes to MouseArea
This adds a new property that uses the enum
from the Qt namespace to allow setting of
custom cursor shapes for mouse areas.
Change-Id: I4d1ac6339b69dc9ea7855a8b8b6aa9276c71a90d
Reviewed-by: Jeremy Katz <jeremy.katz@nokia.com>
Diffstat (limited to 'src/quick/items/qquickmousearea.cpp')
-rw-r--r-- | src/quick/items/qquickmousearea.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index bf949e8c4d..17458abee6 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -197,6 +197,9 @@ QQuickMouseAreaPrivate::QQuickMouseAreaPrivate() #ifndef QT_NO_DRAGANDDROP , drag(0) #endif +#ifndef QT_NO_CURSOR + , cursor(0) +#endif { } @@ -205,6 +208,9 @@ QQuickMouseAreaPrivate::~QQuickMouseAreaPrivate() #ifndef QT_NO_DRAGANDDROP delete drag; #endif +#ifndef QT_NO_CURSOR + delete cursor; +#endif } void QQuickMouseAreaPrivate::init() @@ -1119,8 +1125,18 @@ void QQuickMouseArea::setHovered(bool h) d->hovered = h; emit hoveredChanged(); d->hovered ? emit entered() : emit exited(); +#ifndef QT_NO_CURSOR + if (d->cursor) { + if (d->hovered) { + canvas()->setCursor(QCursor(*d->cursor)); + } else { + canvas()->unsetCursor(); + } + } +#endif } } + /*! \qmlproperty QtQuick2::Qt::MouseButtons MouseArea::acceptedButtons This property holds the mouse buttons that the mouse area reacts to. @@ -1192,6 +1208,68 @@ bool QQuickMouseArea::setPressed(bool p) return false; } + +/*! + \qmlproperty QtQuick2::Qt::CursorShape MouseArea::cursorShape + This property holds the cursor shape for this mouse area. + Note that on platforms that do not display a mouse cursor this may have + no effect. + + The available cursor shapes are: + \list + \li Qt.ArrowCursor + \li Qt.UpArrowCursor + \li Qt.CrossCursor + \li Qt.WaitCursor + \li Qt.IBeamCursor + \li Qt.SizeVerCursor + \li Qt.SizeHorCursor + \li Qt.SizeBDiagCursor + \li Qt.SizeFDiagCursor + \li Qt.SizeAllCursor + \li Qt.BlankCursor + \li Qt.SplitVCursor + \li Qt.SplitHCursor + \li Qt.PointingHandCursor + \li Qt.ForbiddenCursor + \li Qt.WhatsThisCursor + \li Qt.BusyCursor + \li Qt.OpenHandCursor + \li Qt.ClosedHandCursor + \li Qt.DragCopyCursor + \li Qt.DragMoveCursor + \li Qt.DragLinkCursor + \endlist + + In order to only set a mouse cursor shape for a region without reacting + to mouse events set the acceptedButtons to none: + + \code + MouseArea { cursorShape: Qt.IBeamCursor; acceptedButtons: Qt.NoButton } + \endcode + + The default value is \c Qt.ArrowCursor. + \sa Qt::CursorShape +*/ + +#ifndef QT_NO_CURSOR +Qt::CursorShape QQuickMouseArea::cursorShape() const +{ + Q_D(const QQuickMouseArea); + if (d->cursor) + return d->cursor->shape(); + return Qt::ArrowCursor; +} + +void QQuickMouseArea::setCursorShape(Qt::CursorShape shape) +{ + Q_D(QQuickMouseArea); + setHoverEnabled(true); + delete d->cursor; + d->cursor = new QCursor(shape); +} +#endif + /*! \qmlproperty Item QtQuick2::MouseArea::drag.target \qmlproperty bool QtQuick2::MouseArea::drag.active |