src/gui/kernel/qevent.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/gui/kernel/qevent.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/kernel/qevent.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -399,6 +399,40 @@
 
     The function pos() gives the current cursor position, while oldPos() gives
     the old mouse position.
+
+    There are a few similarities between the events QEvent::HoverEnter
+    and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
+    However, they are slightly different because we do an update() in the event
+    handler of HoverEnter and HoverLeave.
+
+    QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
+    consider a top-level window A containing a child B which in turn contains a
+    child C (all with mouse tracking enabled):
+
+    \image hoverevents.png
+
+    Now, if you move the cursor from the top to the bottom in the middle of A,
+    you will get the following QEvent::MouseMove events:
+
+    \list 1
+        \o A::MouseMove
+        \o B::MouseMove
+        \o C::MouseMove
+    \endlist
+
+    You will get the same events for QEvent::HoverMove, except that the event
+    always propagates to the top-level regardless whether the event is accepted
+    or not. It will only stop propagating with the Qt::WA_NoMousePropagation
+    attribute.
+
+    In this case the events will occur in the following way:
+
+    \list 1
+        \o A::HoverMove
+        \o A::HoverMove, B::HoverMove
+        \o A::HoverMove, B::HoverMove, C::HoverMove
+    \endlist
+
 */
 
 /*!
@@ -2976,20 +3010,20 @@
 /*!
     \class QFileOpenEvent
     \brief The QFileOpenEvent class provides an event that will be
-    sent when there is a request to open a file.
+    sent when there is a request to open a file or a URL.
 
     \ingroup events
 
     File open events will be sent to the QApplication::instance()
-    when the operating system requests that a file be opened. This is
-    a high-level event that can be caused by different user actions
+    when the operating system requests that a file or URL should be opened.
+    This is a high-level event that can be caused by different user actions
     depending on the user's desktop environment; for example, double
     clicking on an file icon in the Finder on Mac OS X.
 
     This event is only used to notify the application of a request.
     It may be safely ignored.
 
-    \note This class is currently supported for Mac Os X only.
+    \note This class is currently supported for Mac OS X only.
 */
 
 /*!
@@ -2999,12 +3033,27 @@
 */
 QFileOpenEvent::QFileOpenEvent(const QString &file)
     : QEvent(FileOpen), f(file)
-{}
+{
+    d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(QUrl::fromLocalFile(file)));
+}
+
+/*!
+    \internal
+
+    Constructs a file open event for the given \a url.
+*/
+QFileOpenEvent::QFileOpenEvent(const QUrl &url)
+    : QEvent(FileOpen)
+{
+    d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(url));
+    f = url.toLocalFile();
+}
 
 /*! \internal
 */
 QFileOpenEvent::~QFileOpenEvent()
 {
+    delete reinterpret_cast<QFileOpenEventPrivate *>(d);
 }
 
 /*!
@@ -3013,6 +3062,18 @@
     Returns the file that is being opened.
 */
 
+/*!
+    \fn QUrl QFileOpenEvent::url() const
+
+    Returns the url that is being opened.
+
+    \since 4.6
+*/
+QUrl QFileOpenEvent::url() const
+{
+    return reinterpret_cast<const QFileOpenEventPrivate *>(d)->url;
+}
+
 #ifndef QT_NO_TOOLBAR
 /*!
     \internal
@@ -4202,7 +4263,7 @@
     \brief The QGestureEvent class provides the description of triggered gestures.
 
     The QGestureEvent class contains a list of gestures, which can be obtained using the
-    allGestures() function.
+    gestures() function.
 
     The gestures are either active or canceled. A list of those that are currently being
     executed can be obtained using the activeGestures() function. A list of those which
@@ -4211,10 +4272,11 @@
     focus, for example, or because of a timeout, or for other reasons.
 
     If the event handler does not accept the event by calling the generic
-    QEvent::accept() function, all individual QGesture object that were not accepted
-    will be propagated up the parent widget chain until a widget accepts them
-    individually, by calling QGestureEvent::accept() for each of them, or an event
-    filter consumes the event.
+    QEvent::accept() function, all individual QGesture object that were not
+    accepted and in the Qt::GestureStarted state will be propagated up the
+    parent widget chain until a widget accepts them individually, by calling
+    QGestureEvent::accept() for each of them, or an event filter consumes the
+    event.
 
     \sa QGesture, QGestureRecognizer,
         QWidget::grabGesture(), QGraphicsObject::grabGesture()
@@ -4240,7 +4302,7 @@
 /*!
     Returns all gestures that are delivered in the event.
 */
-QList<QGesture *> QGestureEvent::allGestures() const
+QList<QGesture *> QGestureEvent::gestures() const
 {
     return d_func()->gestures;
 }
@@ -4262,7 +4324,12 @@
 */
 QList<QGesture *> QGestureEvent::activeGestures() const
 {
-    return d_func()->gestures;
+    QList<QGesture *> gestures;
+    foreach (QGesture *gesture, d_func()->gestures) {
+        if (gesture->state() != Qt::GestureCanceled)
+            gestures.append(gesture);
+    }
+    return gestures;
 }
 
 /*!
@@ -4270,7 +4337,12 @@
 */
 QList<QGesture *> QGestureEvent::canceledGestures() const
 {
-    return d_func()->gestures;
+    QList<QGesture *> gestures;
+    foreach (QGesture *gesture, d_func()->gestures) {
+        if (gesture->state() == Qt::GestureCanceled)
+            gestures.append(gesture);
+    }
+    return gestures;
 }
 
 /*!
@@ -4288,9 +4360,8 @@
 */
 void QGestureEvent::setAccepted(QGesture *gesture, bool value)
 {
-    setAccepted(false);
     if (gesture)
-        d_func()->accepted[gesture->gestureType()] = value;
+        setAccepted(gesture->gestureType(), value);
 }
 
 /*!
@@ -4304,7 +4375,8 @@
 */
 void QGestureEvent::accept(QGesture *gesture)
 {
-    setAccepted(gesture, true);
+    if (gesture)
+        setAccepted(gesture->gestureType(), true);
 }
 
 /*!
@@ -4318,7 +4390,8 @@
 */
 void QGestureEvent::ignore(QGesture *gesture)
 {
-    setAccepted(gesture, false);
+    if (gesture)
+        setAccepted(gesture->gestureType(), false);
 }
 
 /*!
@@ -4326,11 +4399,71 @@
 */
 bool QGestureEvent::isAccepted(QGesture *gesture) const
 {
-    return gesture ? d_func()->accepted.value(gesture->gestureType(), true) : false;
+    return gesture ? isAccepted(gesture->gestureType()) : false;
+}
+
+/*!
+    Sets the accept flag of the given \a gestureType object to the specified
+    \a value.
+
+    Setting the accept flag indicates that the event receiver wants to receive
+    gestures of the specified type, \a gestureType. Unwanted gestures may be
+    propagated to the parent widget.
+
+    By default, gestures in events of type QEvent::Gesture are accepted, and
+    gestures in QEvent::GestureOverride events are ignored.
+
+    For convenience, the accept flag can also be set with
+    \l{QGestureEvent::accept()}{accept(gestureType)}, and cleared with
+    \l{QGestureEvent::ignore()}{ignore(gestureType)}.
+*/
+void QGestureEvent::setAccepted(Qt::GestureType gestureType, bool value)
+{
+    setAccepted(false);
+    d_func()->accepted[gestureType] = value;
 }
 
 /*!
-    Sets the widget for this event.
+    Sets the accept flag of the given \a gestureType, the equivalent of calling
+    \l{QGestureEvent::setAccepted()}{setAccepted(gestureType, true)}.
+
+    Setting the accept flag indicates that the event receiver wants the
+    gesture. Unwanted gestures may be propagated to the parent widget.
+
+    \sa QGestureEvent::ignore()
+*/
+void QGestureEvent::accept(Qt::GestureType gestureType)
+{
+    setAccepted(gestureType, true);
+}
+
+/*!
+    Clears the accept flag parameter of the given \a gestureType, the equivalent
+    of calling \l{QGestureEvent::setAccepted()}{setAccepted(gesture, false)}.
+
+    Clearing the accept flag indicates that the event receiver does not
+    want the gesture. Unwanted gestures may be propgated to the parent widget.
+
+    \sa QGestureEvent::accept()
+*/
+void QGestureEvent::ignore(Qt::GestureType gestureType)
+{
+    setAccepted(gestureType, false);
+}
+
+/*!
+    Returns true if the gesture of type \a gestureType is accepted; otherwise
+    returns false.
+*/
+bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const
+{
+    return d_func()->accepted.value(gestureType, true);
+}
+
+/*!
+    \internal
+
+    Sets the widget for this event to the \a widget specified.
 */
 void QGestureEvent::setWidget(QWidget *widget)
 {
@@ -4345,12 +4478,18 @@
     return d_func()->widget;
 }
 
-/*!
-    Returns the scene-local coordinates if the \a gesturePoint is inside a graphics view.
+#ifndef QT_NO_GRAPHICSVIEW
+/*!
+    Returns the scene-local coordinates if the \a gesturePoint is inside a
+    graphics view.
+
+    This functional might be useful when the gesture event is delivered to a
+    QGraphicsObject to translate a point in screen coordinates to scene-local
+    coordinates.
 
     \sa QPointF::isNull().
 */
-QPointF QGestureEvent::mapToScene(const QPointF &gesturePoint) const
+QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
 {
     QWidget *w = widget();
     if (w) // we get the viewport as widget, not the graphics view
@@ -4361,6 +4500,7 @@
     }
     return QPointF();
 }
+#endif //QT_NO_GRAPHICSVIEW
 
 /*!
     \internal