src/gui/kernel/qevent.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   397     Mouse events occur when a mouse cursor is moved into, out of, or within a
   397     Mouse events occur when a mouse cursor is moved into, out of, or within a
   398     widget, and if the widget has the Qt::WA_Hover attribute.
   398     widget, and if the widget has the Qt::WA_Hover attribute.
   399 
   399 
   400     The function pos() gives the current cursor position, while oldPos() gives
   400     The function pos() gives the current cursor position, while oldPos() gives
   401     the old mouse position.
   401     the old mouse position.
       
   402 
       
   403     There are a few similarities between the events QEvent::HoverEnter
       
   404     and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
       
   405     However, they are slightly different because we do an update() in the event
       
   406     handler of HoverEnter and HoverLeave.
       
   407 
       
   408     QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
       
   409     consider a top-level window A containing a child B which in turn contains a
       
   410     child C (all with mouse tracking enabled):
       
   411 
       
   412     \image hoverevents.png
       
   413 
       
   414     Now, if you move the cursor from the top to the bottom in the middle of A,
       
   415     you will get the following QEvent::MouseMove events:
       
   416 
       
   417     \list 1
       
   418         \o A::MouseMove
       
   419         \o B::MouseMove
       
   420         \o C::MouseMove
       
   421     \endlist
       
   422 
       
   423     You will get the same events for QEvent::HoverMove, except that the event
       
   424     always propagates to the top-level regardless whether the event is accepted
       
   425     or not. It will only stop propagating with the Qt::WA_NoMousePropagation
       
   426     attribute.
       
   427 
       
   428     In this case the events will occur in the following way:
       
   429 
       
   430     \list 1
       
   431         \o A::HoverMove
       
   432         \o A::HoverMove, B::HoverMove
       
   433         \o A::HoverMove, B::HoverMove, C::HoverMove
       
   434     \endlist
       
   435 
   402 */
   436 */
   403 
   437 
   404 /*!
   438 /*!
   405     \fn const QPoint &QHoverEvent::pos() const
   439     \fn const QPoint &QHoverEvent::pos() const
   406 
   440 
  2974 */
  3008 */
  2975 
  3009 
  2976 /*!
  3010 /*!
  2977     \class QFileOpenEvent
  3011     \class QFileOpenEvent
  2978     \brief The QFileOpenEvent class provides an event that will be
  3012     \brief The QFileOpenEvent class provides an event that will be
  2979     sent when there is a request to open a file.
  3013     sent when there is a request to open a file or a URL.
  2980 
  3014 
  2981     \ingroup events
  3015     \ingroup events
  2982 
  3016 
  2983     File open events will be sent to the QApplication::instance()
  3017     File open events will be sent to the QApplication::instance()
  2984     when the operating system requests that a file be opened. This is
  3018     when the operating system requests that a file or URL should be opened.
  2985     a high-level event that can be caused by different user actions
  3019     This is a high-level event that can be caused by different user actions
  2986     depending on the user's desktop environment; for example, double
  3020     depending on the user's desktop environment; for example, double
  2987     clicking on an file icon in the Finder on Mac OS X.
  3021     clicking on an file icon in the Finder on Mac OS X.
  2988 
  3022 
  2989     This event is only used to notify the application of a request.
  3023     This event is only used to notify the application of a request.
  2990     It may be safely ignored.
  3024     It may be safely ignored.
  2991 
  3025 
  2992     \note This class is currently supported for Mac Os X only.
  3026     \note This class is currently supported for Mac OS X only.
  2993 */
  3027 */
  2994 
  3028 
  2995 /*!
  3029 /*!
  2996     \internal
  3030     \internal
  2997 
  3031 
  2998     Constructs a file open event for the given \a file.
  3032     Constructs a file open event for the given \a file.
  2999 */
  3033 */
  3000 QFileOpenEvent::QFileOpenEvent(const QString &file)
  3034 QFileOpenEvent::QFileOpenEvent(const QString &file)
  3001     : QEvent(FileOpen), f(file)
  3035     : QEvent(FileOpen), f(file)
  3002 {}
  3036 {
       
  3037     d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(QUrl::fromLocalFile(file)));
       
  3038 }
       
  3039 
       
  3040 /*!
       
  3041     \internal
       
  3042 
       
  3043     Constructs a file open event for the given \a url.
       
  3044 */
       
  3045 QFileOpenEvent::QFileOpenEvent(const QUrl &url)
       
  3046     : QEvent(FileOpen)
       
  3047 {
       
  3048     d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(url));
       
  3049     f = url.toLocalFile();
       
  3050 }
  3003 
  3051 
  3004 /*! \internal
  3052 /*! \internal
  3005 */
  3053 */
  3006 QFileOpenEvent::~QFileOpenEvent()
  3054 QFileOpenEvent::~QFileOpenEvent()
  3007 {
  3055 {
       
  3056     delete reinterpret_cast<QFileOpenEventPrivate *>(d);
  3008 }
  3057 }
  3009 
  3058 
  3010 /*!
  3059 /*!
  3011     \fn QString QFileOpenEvent::file() const
  3060     \fn QString QFileOpenEvent::file() const
  3012 
  3061 
  3013     Returns the file that is being opened.
  3062     Returns the file that is being opened.
  3014 */
  3063 */
       
  3064 
       
  3065 /*!
       
  3066     \fn QUrl QFileOpenEvent::url() const
       
  3067 
       
  3068     Returns the url that is being opened.
       
  3069 
       
  3070     \since 4.6
       
  3071 */
       
  3072 QUrl QFileOpenEvent::url() const
       
  3073 {
       
  3074     return reinterpret_cast<const QFileOpenEventPrivate *>(d)->url;
       
  3075 }
  3015 
  3076 
  3016 #ifndef QT_NO_TOOLBAR
  3077 #ifndef QT_NO_TOOLBAR
  3017 /*!
  3078 /*!
  3018     \internal
  3079     \internal
  3019     \class QToolBarChangeEvent
  3080     \class QToolBarChangeEvent
  4200     \ingroup gestures
  4261     \ingroup gestures
  4201 
  4262 
  4202     \brief The QGestureEvent class provides the description of triggered gestures.
  4263     \brief The QGestureEvent class provides the description of triggered gestures.
  4203 
  4264 
  4204     The QGestureEvent class contains a list of gestures, which can be obtained using the
  4265     The QGestureEvent class contains a list of gestures, which can be obtained using the
  4205     allGestures() function.
  4266     gestures() function.
  4206 
  4267 
  4207     The gestures are either active or canceled. A list of those that are currently being
  4268     The gestures are either active or canceled. A list of those that are currently being
  4208     executed can be obtained using the activeGestures() function. A list of those which
  4269     executed can be obtained using the activeGestures() function. A list of those which
  4209     were previously active and have been canceled can be accessed using the
  4270     were previously active and have been canceled can be accessed using the
  4210     canceledGestures() function. A gesture might be canceled if the current window loses
  4271     canceledGestures() function. A gesture might be canceled if the current window loses
  4211     focus, for example, or because of a timeout, or for other reasons.
  4272     focus, for example, or because of a timeout, or for other reasons.
  4212 
  4273 
  4213     If the event handler does not accept the event by calling the generic
  4274     If the event handler does not accept the event by calling the generic
  4214     QEvent::accept() function, all individual QGesture object that were not accepted
  4275     QEvent::accept() function, all individual QGesture object that were not
  4215     will be propagated up the parent widget chain until a widget accepts them
  4276     accepted and in the Qt::GestureStarted state will be propagated up the
  4216     individually, by calling QGestureEvent::accept() for each of them, or an event
  4277     parent widget chain until a widget accepts them individually, by calling
  4217     filter consumes the event.
  4278     QGestureEvent::accept() for each of them, or an event filter consumes the
       
  4279     event.
  4218 
  4280 
  4219     \sa QGesture, QGestureRecognizer,
  4281     \sa QGesture, QGestureRecognizer,
  4220         QWidget::grabGesture(), QGraphicsObject::grabGesture()
  4282         QWidget::grabGesture(), QGraphicsObject::grabGesture()
  4221 */
  4283 */
  4222 
  4284 
  4238 }
  4300 }
  4239 
  4301 
  4240 /*!
  4302 /*!
  4241     Returns all gestures that are delivered in the event.
  4303     Returns all gestures that are delivered in the event.
  4242 */
  4304 */
  4243 QList<QGesture *> QGestureEvent::allGestures() const
  4305 QList<QGesture *> QGestureEvent::gestures() const
  4244 {
  4306 {
  4245     return d_func()->gestures;
  4307     return d_func()->gestures;
  4246 }
  4308 }
  4247 
  4309 
  4248 /*!
  4310 /*!
  4260 /*!
  4322 /*!
  4261     Returns a list of active (not canceled) gestures.
  4323     Returns a list of active (not canceled) gestures.
  4262 */
  4324 */
  4263 QList<QGesture *> QGestureEvent::activeGestures() const
  4325 QList<QGesture *> QGestureEvent::activeGestures() const
  4264 {
  4326 {
  4265     return d_func()->gestures;
  4327     QList<QGesture *> gestures;
       
  4328     foreach (QGesture *gesture, d_func()->gestures) {
       
  4329         if (gesture->state() != Qt::GestureCanceled)
       
  4330             gestures.append(gesture);
       
  4331     }
       
  4332     return gestures;
  4266 }
  4333 }
  4267 
  4334 
  4268 /*!
  4335 /*!
  4269     Returns a list of canceled gestures.
  4336     Returns a list of canceled gestures.
  4270 */
  4337 */
  4271 QList<QGesture *> QGestureEvent::canceledGestures() const
  4338 QList<QGesture *> QGestureEvent::canceledGestures() const
  4272 {
  4339 {
  4273     return d_func()->gestures;
  4340     QList<QGesture *> gestures;
       
  4341     foreach (QGesture *gesture, d_func()->gestures) {
       
  4342         if (gesture->state() == Qt::GestureCanceled)
       
  4343             gestures.append(gesture);
       
  4344     }
       
  4345     return gestures;
  4274 }
  4346 }
  4275 
  4347 
  4276 /*!
  4348 /*!
  4277     Sets the accept flag of the given \a gesture object to the specified \a value.
  4349     Sets the accept flag of the given \a gesture object to the specified \a value.
  4278 
  4350 
  4286     \l{QGestureEvent::accept()}{accept(gesture)}, and cleared with
  4358     \l{QGestureEvent::accept()}{accept(gesture)}, and cleared with
  4287     \l{QGestureEvent::ignore()}{ignore(gesture)}.
  4359     \l{QGestureEvent::ignore()}{ignore(gesture)}.
  4288 */
  4360 */
  4289 void QGestureEvent::setAccepted(QGesture *gesture, bool value)
  4361 void QGestureEvent::setAccepted(QGesture *gesture, bool value)
  4290 {
  4362 {
  4291     setAccepted(false);
       
  4292     if (gesture)
  4363     if (gesture)
  4293         d_func()->accepted[gesture->gestureType()] = value;
  4364         setAccepted(gesture->gestureType(), value);
  4294 }
  4365 }
  4295 
  4366 
  4296 /*!
  4367 /*!
  4297     Sets the accept flag of the given \a gesture object, the equivalent of calling
  4368     Sets the accept flag of the given \a gesture object, the equivalent of calling
  4298     \l{QGestureEvent::setAccepted()}{setAccepted(gesture, true)}.
  4369     \l{QGestureEvent::setAccepted()}{setAccepted(gesture, true)}.
  4302 
  4373 
  4303     \sa QGestureEvent::ignore()
  4374     \sa QGestureEvent::ignore()
  4304 */
  4375 */
  4305 void QGestureEvent::accept(QGesture *gesture)
  4376 void QGestureEvent::accept(QGesture *gesture)
  4306 {
  4377 {
  4307     setAccepted(gesture, true);
  4378     if (gesture)
       
  4379         setAccepted(gesture->gestureType(), true);
  4308 }
  4380 }
  4309 
  4381 
  4310 /*!
  4382 /*!
  4311     Clears the accept flag parameter of the given \a gesture object, the equivalent
  4383     Clears the accept flag parameter of the given \a gesture object, the equivalent
  4312     of calling \l{QGestureEvent::setAccepted()}{setAccepted(gesture, false)}.
  4384     of calling \l{QGestureEvent::setAccepted()}{setAccepted(gesture, false)}.
  4316 
  4388 
  4317     \sa QGestureEvent::accept()
  4389     \sa QGestureEvent::accept()
  4318 */
  4390 */
  4319 void QGestureEvent::ignore(QGesture *gesture)
  4391 void QGestureEvent::ignore(QGesture *gesture)
  4320 {
  4392 {
  4321     setAccepted(gesture, false);
  4393     if (gesture)
       
  4394         setAccepted(gesture->gestureType(), false);
  4322 }
  4395 }
  4323 
  4396 
  4324 /*!
  4397 /*!
  4325     Returns true if the \a gesture is accepted; otherwise returns false.
  4398     Returns true if the \a gesture is accepted; otherwise returns false.
  4326 */
  4399 */
  4327 bool QGestureEvent::isAccepted(QGesture *gesture) const
  4400 bool QGestureEvent::isAccepted(QGesture *gesture) const
  4328 {
  4401 {
  4329     return gesture ? d_func()->accepted.value(gesture->gestureType(), true) : false;
  4402     return gesture ? isAccepted(gesture->gestureType()) : false;
  4330 }
  4403 }
  4331 
  4404 
  4332 /*!
  4405 /*!
  4333     Sets the widget for this event.
  4406     Sets the accept flag of the given \a gestureType object to the specified
       
  4407     \a value.
       
  4408 
       
  4409     Setting the accept flag indicates that the event receiver wants to receive
       
  4410     gestures of the specified type, \a gestureType. Unwanted gestures may be
       
  4411     propagated to the parent widget.
       
  4412 
       
  4413     By default, gestures in events of type QEvent::Gesture are accepted, and
       
  4414     gestures in QEvent::GestureOverride events are ignored.
       
  4415 
       
  4416     For convenience, the accept flag can also be set with
       
  4417     \l{QGestureEvent::accept()}{accept(gestureType)}, and cleared with
       
  4418     \l{QGestureEvent::ignore()}{ignore(gestureType)}.
       
  4419 */
       
  4420 void QGestureEvent::setAccepted(Qt::GestureType gestureType, bool value)
       
  4421 {
       
  4422     setAccepted(false);
       
  4423     d_func()->accepted[gestureType] = value;
       
  4424 }
       
  4425 
       
  4426 /*!
       
  4427     Sets the accept flag of the given \a gestureType, the equivalent of calling
       
  4428     \l{QGestureEvent::setAccepted()}{setAccepted(gestureType, true)}.
       
  4429 
       
  4430     Setting the accept flag indicates that the event receiver wants the
       
  4431     gesture. Unwanted gestures may be propagated to the parent widget.
       
  4432 
       
  4433     \sa QGestureEvent::ignore()
       
  4434 */
       
  4435 void QGestureEvent::accept(Qt::GestureType gestureType)
       
  4436 {
       
  4437     setAccepted(gestureType, true);
       
  4438 }
       
  4439 
       
  4440 /*!
       
  4441     Clears the accept flag parameter of the given \a gestureType, the equivalent
       
  4442     of calling \l{QGestureEvent::setAccepted()}{setAccepted(gesture, false)}.
       
  4443 
       
  4444     Clearing the accept flag indicates that the event receiver does not
       
  4445     want the gesture. Unwanted gestures may be propgated to the parent widget.
       
  4446 
       
  4447     \sa QGestureEvent::accept()
       
  4448 */
       
  4449 void QGestureEvent::ignore(Qt::GestureType gestureType)
       
  4450 {
       
  4451     setAccepted(gestureType, false);
       
  4452 }
       
  4453 
       
  4454 /*!
       
  4455     Returns true if the gesture of type \a gestureType is accepted; otherwise
       
  4456     returns false.
       
  4457 */
       
  4458 bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const
       
  4459 {
       
  4460     return d_func()->accepted.value(gestureType, true);
       
  4461 }
       
  4462 
       
  4463 /*!
       
  4464     \internal
       
  4465 
       
  4466     Sets the widget for this event to the \a widget specified.
  4334 */
  4467 */
  4335 void QGestureEvent::setWidget(QWidget *widget)
  4468 void QGestureEvent::setWidget(QWidget *widget)
  4336 {
  4469 {
  4337     d_func()->widget = widget;
  4470     d_func()->widget = widget;
  4338 }
  4471 }
  4343 QWidget *QGestureEvent::widget() const
  4476 QWidget *QGestureEvent::widget() const
  4344 {
  4477 {
  4345     return d_func()->widget;
  4478     return d_func()->widget;
  4346 }
  4479 }
  4347 
  4480 
  4348 /*!
  4481 #ifndef QT_NO_GRAPHICSVIEW
  4349     Returns the scene-local coordinates if the \a gesturePoint is inside a graphics view.
  4482 /*!
       
  4483     Returns the scene-local coordinates if the \a gesturePoint is inside a
       
  4484     graphics view.
       
  4485 
       
  4486     This functional might be useful when the gesture event is delivered to a
       
  4487     QGraphicsObject to translate a point in screen coordinates to scene-local
       
  4488     coordinates.
  4350 
  4489 
  4351     \sa QPointF::isNull().
  4490     \sa QPointF::isNull().
  4352 */
  4491 */
  4353 QPointF QGestureEvent::mapToScene(const QPointF &gesturePoint) const
  4492 QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
  4354 {
  4493 {
  4355     QWidget *w = widget();
  4494     QWidget *w = widget();
  4356     if (w) // we get the viewport as widget, not the graphics view
  4495     if (w) // we get the viewport as widget, not the graphics view
  4357         w = w->parentWidget();
  4496         w = w->parentWidget();
  4358     QGraphicsView *view = qobject_cast<QGraphicsView*>(w);
  4497     QGraphicsView *view = qobject_cast<QGraphicsView*>(w);
  4359     if (view) {
  4498     if (view) {
  4360         return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint()));
  4499         return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint()));
  4361     }
  4500     }
  4362     return QPointF();
  4501     return QPointF();
  4363 }
  4502 }
       
  4503 #endif //QT_NO_GRAPHICSVIEW
  4364 
  4504 
  4365 /*!
  4505 /*!
  4366     \internal
  4506     \internal
  4367 */
  4507 */
  4368 QGestureEventPrivate *QGestureEvent::d_func()
  4508 QGestureEventPrivate *QGestureEvent::d_func()