Changeset 561 for trunk/src/gui/kernel/qevent.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/kernel/qevent.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 46 46 #include "private/qkeysequence_p.h" 47 47 #include "qwidget.h" 48 #include "qgraphicsview.h" 48 49 #include "qdebug.h" 49 50 #include "qmime.h" 50 51 #include "qdnd_p.h" 51 52 #include "qevent_p.h" 53 #include "qgesture.h" 54 #include "qgesture_p.h" 52 55 53 56 QT_BEGIN_NAMESPACE … … 82 85 83 86 \sa QApplication::keyboardModifiers() 87 */ 88 89 /*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers) 90 91 \internal 92 93 Sets the keyboard modifiers flags for this event. 84 94 */ 85 95 … … 107 117 with accept(), or an event filter consumes it. 108 118 119 \note If a mouse event is propagated to a \l{QWidget}{widget} for 120 which Qt::WA_NoMousePropagation has been set, that mouse event 121 will not be propagated further up the parent widget chain. 122 109 123 The state of the keyboard modifier keys can be found by calling the 110 \l{QInputEvent::modifiers()}{modifiers()} function, inher tied from124 \l{QInputEvent::modifiers()}{modifiers()} function, inherited from 111 125 QInputEvent. 112 126 … … 386 400 The function pos() gives the current cursor position, while oldPos() gives 387 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 388 436 */ 389 437 … … 664 712 mouse and keyboard events for a widget. 665 713 666 The event handlers QWidget::keyPressEvent() and 667 QWidget::keyReleaseEvent() receive key events. 714 The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(), 715 QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent() 716 receive key events. 668 717 669 718 \sa QFocusEvent, QWidget::grabKeyboard() … … 676 725 or QEvent::ShortcutOverride. 677 726 678 If \a key is 0, the event is not a result of 679 a known key; for example, it may be the result of a compose 680 sequence or keyboard macro. The \a modifiers holds the keyboard 681 modifiers, and the given \a text is the Unicode text that the 682 key generated. If \a autorep is true, isAutoRepeat() will be 683 true. \a count is the number of keys involved in the event. 727 Int \a key is the code for the Qt::Key that the event loop should listen 728 for. If \a key is 0, the event is not a result of a known key; for 729 example, it may be the result of a compose sequence or keyboard macro. 730 The \a modifiers holds the keyboard modifiers, and the given \a text 731 is the Unicode text that the key generated. If \a autorep is true, 732 isAutoRepeat() will be true. \a count is the number of keys involved 733 in the event. 684 734 */ 685 735 QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text, … … 860 910 uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference 861 911 uint platform = QApplicationPrivate::currentPlatform(); 912 913 #ifdef Q_WS_MAC 914 if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) { 915 uint oldSearchKey = searchkey; 916 searchkey &= ~(Qt::ControlModifier | Qt::MetaModifier); 917 if (oldSearchKey & Qt::ControlModifier) 918 searchkey |= Qt::MetaModifier; 919 if (oldSearchKey & Qt::MetaModifier) 920 searchkey |= Qt::ControlModifier; 921 } 922 #endif 862 923 863 924 uint N = QKeySequencePrivate::numberOfKeyBindings; … … 969 1030 in the appropriate event handler. 970 1031 971 The event handlers QWidget::focusInEvent() and 972 QWidget::focusOutEvent() receive focus events. 1032 The event handlers QWidget::focusInEvent(), 1033 QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and 1034 QGraphicsItem::focusOutEvent() receive focus events. 973 1035 974 1036 \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus} … … 1056 1118 provided because many widgets can't make much use of region(), 1057 1119 and rect() can be much faster than region().boundingRect(). 1120 1121 \section1 Automatic Clipping 1122 1058 1123 Painting is clipped to region() during the processing of a paint 1059 event. 1124 event. This clipping is performed by Qt's paint system and is 1125 independent of any clipping that may be applied to a QPainter used to 1126 draw on the paint device. 1127 1128 As a result, the value returned by QPainter::clipRegion() on 1129 a newly-constructed QPainter will not reflect the clip region that is 1130 used by the paint system. 1060 1131 1061 1132 \sa QPainter, QWidget::update(), QWidget::repaint(), … … 1588 1659 describes the different attributes that can be set. 1589 1660 1590 A class implementing QWidget::inputMethodEvent() should at least 1591 understand and honor the \l TextFormat and \l Cursor attributes. 1661 A class implementing QWidget::inputMethodEvent() or 1662 QGraphicsItem::inputMethodEvent() should at least understand and 1663 honor the \l TextFormat and \l Cursor attributes. 1592 1664 1593 1665 Since input methods need to be able to query certain properties 1594 from the widget, the widget must also implement 1595 QWidget::inputMethodQuery(). 1666 from the widget or graphics item, subclasses must also implement 1667 QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(), 1668 respectively. 1596 1669 1597 1670 When receiving an input method event, the text widget has to performs the … … 1664 1737 several are specified for any character in the string the behaviour 1665 1738 is undefined. 1739 1740 \value Selection 1741 If set, the edit cursor should be moved to the specified position 1742 in the editor text contents. In contrast with \c Cursor, this 1743 attribute does not work on the preedit text, but on the surrounding 1744 text. The cursor will be moved after the commit string has been 1745 committed, and the preedit string will be located at the new edit 1746 position. 1747 The start position specifies the new position and the length 1748 variable can be used to set a selection starting from that point. 1749 The value is unused. 1666 1750 1667 1751 \sa Attribute … … 2927 3011 \class QFileOpenEvent 2928 3012 \brief The QFileOpenEvent class provides an event that will be 2929 sent when there is a request to open a file .3013 sent when there is a request to open a file or a URL. 2930 3014 2931 3015 \ingroup events 2932 3016 2933 3017 File open events will be sent to the QApplication::instance() 2934 when the operating system requests that a file be opened. This is2935 a high-level event that can be caused by different user actions3018 when the operating system requests that a file or URL should be opened. 3019 This is a high-level event that can be caused by different user actions 2936 3020 depending on the user's desktop environment; for example, double 2937 3021 clicking on an file icon in the Finder on Mac OS X. … … 2940 3024 It may be safely ignored. 2941 3025 2942 \note This class is currently supported for Mac O sX only.3026 \note This class is currently supported for Mac OS X only. 2943 3027 */ 2944 3028 … … 2950 3034 QFileOpenEvent::QFileOpenEvent(const QString &file) 2951 3035 : QEvent(FileOpen), f(file) 2952 {} 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 } 2953 3051 2954 3052 /*! \internal … … 2956 3054 QFileOpenEvent::~QFileOpenEvent() 2957 3055 { 3056 delete reinterpret_cast<QFileOpenEventPrivate *>(d); 2958 3057 } 2959 3058 … … 2963 3062 Returns the file that is being opened. 2964 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 } 2965 3076 2966 3077 #ifndef QT_NO_TOOLBAR … … 3070 3181 << ", " << hex << (int)me->buttons() 3071 3182 << ", " << hex << (int)me->modifiers() 3072 << ")";3183 << ')'; 3073 3184 } 3074 3185 return dbg.space(); … … 3091 3202 case QEvent::Wheel: 3092 3203 dbg.nospace() << "QWheelEvent(" << static_cast<const QWheelEvent *>(e)->delta() 3093 << ")";3204 << ')'; 3094 3205 return dbg.space(); 3095 3206 #endif … … 3117 3228 << "\", " << ke->isAutoRepeat() 3118 3229 << ", " << ke->count() 3119 << ")";3230 << ')'; 3120 3231 } 3121 3232 return dbg.space(); … … 3311 3422 dbg.nospace() << "QChildEvent(" << n << ", " << (static_cast<const QChildEvent*>(e))->child(); 3312 3423 return dbg.space(); 3424 case QEvent::Gesture: 3425 n = "Gesture"; 3426 break; 3313 3427 default: 3314 3428 dbg.nospace() << "QEvent(" << (const void *)e << ", type = " << e->type() << ')'; … … 3507 3621 #endif 3508 3622 3623 /*! 3624 \class QTouchEvent 3625 \brief The QTouchEvent class contains parameters that describe a touch event. 3626 \since 4.6 3627 \ingroup events 3628 \ingroup multitouch 3629 3630 \section1 Enabling Touch Events 3631 3632 Touch events occur when pressing, releasing, or moving one or more touch points on a touch 3633 device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the 3634 Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the 3635 \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true. 3636 3637 When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents 3638 attribute on the scroll area's \l{QAbstractScrollArea::viewport()}{viewport}. 3639 3640 Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a 3641 widget, and the widget will receive all updates for the touch point until it is released. 3642 Note that it is possible for a widget to receive events for multiple touch points, and that 3643 multiple widgets may be receiving touch events at the same time. 3644 3645 \section1 Event Handling 3646 3647 All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, or QEvent::TouchEnd. 3648 Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for widgets and 3649 QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events. 3650 3651 The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that 3652 accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not 3653 filtered by an event filter, then no further touch events are sent until the next 3654 QEvent::TouchBegin. 3655 3656 The touchPoints() function returns a list of all touch points contained in the event. 3657 Information about each touch point can be retrieved using the QTouchEvent::TouchPoint class. 3658 The Qt::TouchPointState enum describes the different states that a touch point may have. 3659 3660 \section1 Event Delivery and Propagation 3661 3662 By default, QWidget::event() translates the first non-primary touch point in a QTouchEvent into 3663 a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not 3664 normally handle QTouchEvent. See below for information on some special considerations needed 3665 when doing this. 3666 3667 QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event 3668 contains a special accept flag that indicates whether the receiver wants the event. By default, 3669 the event is accepted. You should call ignore() if the touch event is not handled by your 3670 widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget 3671 accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the 3672 QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event 3673 propagation for QGraphicsItems). 3674 3675 \section1 Touch Point Grouping 3676 3677 As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the 3678 same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same 3679 widget, which could theoretically happen during propagation if, for example, the user touched 2 3680 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event. 3681 3682 To avoid this, Qt will group new touch points together using the following rules: 3683 3684 \list 3685 3686 \i When the first touch point is detected, the destination widget is determined firstly by the 3687 location on screen and secondly by the propagation rules. 3688 3689 \i When additional touch points are detected, Qt first looks to see if there are any active 3690 touch points on any ancestor or descendent of the widget under the new touch point. If there 3691 are, the new touch point is grouped with the first, and the new touch point will be sent in a 3692 single QTouchEvent to the widget that handled the first touch point. (The widget under the new 3693 touch point will not receive an event). 3694 3695 \endlist 3696 3697 This makes it possible for sibling widgets to handle touch events independently while making 3698 sure that the sequence of QTouchEvents is always correct. 3699 3700 \section1 Mouse Events and the Primary Touch Point 3701 3702 QTouchEvent delivery is independent from that of QMouseEvent. On some windowing systems, mouse 3703 events are also sent for the \l{QTouchEvent::TouchPoint::isPrimary()}{primary touch point}. 3704 This means it is possible for your widget to receive both QTouchEvent and QMouseEvent for the 3705 same user interaction point. You can use the QTouchEvent::TouchPoint::isPrimary() function to 3706 identify the primary touch point. 3707 3708 Note that on some systems, it is possible to receive touch events without a primary touch 3709 point. All this means is that there will be no mouse event generated for the touch points in 3710 the QTouchEvent. 3711 3712 \section1 Caveats 3713 3714 \list 3715 3716 \i As mentioned above, enabling touch events means multiple widgets can be receiving touch 3717 events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents, 3718 this gives you great flexibility in designing multi-touch user interfaces. Be aware of the 3719 implications. For example, it is possible that the user is moving a QSlider with one finger and 3720 pressing a QPushButton with another. The signals emitted by these widgets will be 3721 interleaved. 3722 3723 \i Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or 3724 QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event 3725 recipients, recursion may cause problems, including but not limited to lost events 3726 and unexpected infinite recursion. 3727 3728 \i QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an 3729 \l{QApplication::activePopupWidget()}{active pop-up widget}. The behavior of QTouchEvents is 3730 undefined when opening a pop-up or grabbing the mouse while there are multiple active touch 3731 points. 3732 3733 \endlist 3734 3735 \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents, 3736 QGraphicsItem::acceptTouchEvents() 3737 */ 3738 3739 /*! \enum Qt::TouchPointState 3740 \since 4.6 3741 3742 This enum represents the state of a touch point at the time the 3743 QTouchEvent occurred. 3744 3745 \value TouchPointPressed The touch point is now pressed. 3746 \value TouchPointMoved The touch point moved. 3747 \value TouchPointStationary The touch point did not move. 3748 \value TouchPointReleased The touch point was released. 3749 3750 \omitvalue TouchPointStateMask 3751 \omitvalue TouchPointPrimary 3752 */ 3753 3754 /*! \enum QTouchEvent::DeviceType 3755 3756 This enum represents the type of device that generated a QTouchEvent. 3757 3758 \value TouchScreen In this type of device, the touch surface and display are integrated. This 3759 means the surface and display typically have the same size, such that there 3760 is a direct relationship between the touch points' physical positions and the 3761 coordinate reported by QTouchEvent::TouchPoint. As a result, Qt allows the 3762 user to interact directly with multiple QWidgets and QGraphicsItems at the 3763 same time. 3764 3765 \value TouchPad In this type of device, the touch surface is separate from the display. There 3766 is not a direct relationship between the physical touch location and the 3767 on-screen coordinates. Instead, they are calculated relative to the current 3768 mouse position, and the user must use the touch-pad to move this reference 3769 point. Unlike touch-screens, Qt allows users to only interact with a single 3770 QWidget or QGraphicsItem at a time. 3771 */ 3772 3773 /*! 3774 Constructs a QTouchEvent with the given \a eventType, \a deviceType, and \a touchPoints. 3775 The \a touchPointStates and \a modifiers are the current touch point states and keyboard 3776 modifiers at the time of the event. 3777 */ 3778 QTouchEvent::QTouchEvent(QEvent::Type eventType, 3779 QTouchEvent::DeviceType deviceType, 3780 Qt::KeyboardModifiers modifiers, 3781 Qt::TouchPointStates touchPointStates, 3782 const QList<QTouchEvent::TouchPoint> &touchPoints) 3783 : QInputEvent(eventType, modifiers), 3784 _widget(0), 3785 _deviceType(deviceType), 3786 _touchPointStates(touchPointStates), 3787 _touchPoints(touchPoints) 3788 { } 3789 3790 /*! 3791 Destroys the QTouchEvent. 3792 */ 3793 QTouchEvent::~QTouchEvent() 3794 { } 3795 3796 /*! \fn QWidget *QTouchEvent::widget() const 3797 3798 Returns the widget on which the event occurred. 3799 */ 3800 3801 3802 /*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const 3803 3804 Returns a bitwise OR of all the touch point states for this event. 3805 */ 3806 3807 /*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::touchPoints() const 3808 3809 Returns the list of touch points contained in the touch event. 3810 */ 3811 3812 /*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const 3813 3814 Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}. 3815 */ 3816 3817 /*! \fn void QTouchEvent::setWidget(QWidget *widget) 3818 3819 \internal 3820 3821 Sets the widget for this event. 3822 */ 3823 3824 /*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates) 3825 3826 \internal 3827 3828 Sets a bitwise OR of all the touch point states for this event. 3829 */ 3830 3831 /*! \fn void QTouchEvent::setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints) 3832 3833 \internal 3834 3835 Sets the list of touch points for this event. 3836 */ 3837 3838 /*! \fn void QTouchEvent::setDeviceType(DeviceType deviceType) 3839 3840 \internal 3841 3842 Sets the device type to \a deviceType, which is of type \l {QTouchEvent::DeviceType} 3843 {DeviceType}. 3844 */ 3845 3846 /*! \class QTouchEvent::TouchPoint 3847 \brief The TouchPoint class provides information about a touch point in a QTouchEvent. 3848 \since 4.6 3849 */ 3850 3851 /*! \internal 3852 3853 Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent. 3854 */ 3855 QTouchEvent::TouchPoint::TouchPoint(int id) 3856 : d(new QTouchEventTouchPointPrivate(id)) 3857 { } 3858 3859 /*! \internal 3860 3861 Constructs a copy of \a other. 3862 */ 3863 QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other) 3864 : d(other.d) 3865 { 3866 d->ref.ref(); 3867 } 3868 3869 /*! \internal 3870 3871 Destroys the QTouchEvent::TouchPoint. 3872 */ 3873 QTouchEvent::TouchPoint::~TouchPoint() 3874 { 3875 if (!d->ref.deref()) 3876 delete d; 3877 } 3878 3879 /*! 3880 Returns the id number of this touch point. 3881 3882 Id numbers are globally sequential, starting at zero, meaning the 3883 first touch point in the application has id 0, the second has id 1, 3884 and so on. 3885 */ 3886 int QTouchEvent::TouchPoint::id() const 3887 { 3888 return d->id; 3889 } 3890 3891 /*! 3892 Returns the current state of this touch point. 3893 */ 3894 Qt::TouchPointState QTouchEvent::TouchPoint::state() const 3895 { 3896 return Qt::TouchPointState(int(d->state) & Qt::TouchPointStateMask); 3897 } 3898 3899 /*! 3900 Returns true if this touch point is the primary touch point. The primary touch point is the 3901 point for which the windowing system generates mouse events. 3902 */ 3903 bool QTouchEvent::TouchPoint::isPrimary() const 3904 { 3905 return (d->state & Qt::TouchPointPrimary) != 0; 3906 } 3907 3908 /*! 3909 Returns the position of this touch point, relative to the widget 3910 or QGraphicsItem that received the event. 3911 3912 \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos() 3913 */ 3914 QPointF QTouchEvent::TouchPoint::pos() const 3915 { 3916 return d->rect.center(); 3917 } 3918 3919 /*! 3920 Returns the scene position of this touch point. 3921 3922 The scene position is the position in QGraphicsScene coordinates 3923 if the QTouchEvent is handled by a QGraphicsItem::touchEvent() 3924 reimplementation, and identical to the screen position for 3925 widgets. 3926 3927 \sa startScenePos(), lastScenePos(), pos() 3928 */ 3929 QPointF QTouchEvent::TouchPoint::scenePos() const 3930 { 3931 return d->sceneRect.center(); 3932 } 3933 3934 /*! 3935 Returns the screen position of this touch point. 3936 3937 \sa startScreenPos(), lastScreenPos(), pos() 3938 */ 3939 QPointF QTouchEvent::TouchPoint::screenPos() const 3940 { 3941 return d->screenRect.center(); 3942 } 3943 3944 /*! 3945 Returns the normalized position of this touch point. 3946 3947 The coordinates are normalized to the size of the touch device, 3948 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner. 3949 3950 \sa startNormalizedPos(), lastNormalizedPos(), pos() 3951 */ 3952 QPointF QTouchEvent::TouchPoint::normalizedPos() const 3953 { 3954 return d->normalizedPos; 3955 } 3956 3957 /*! 3958 Returns the starting position of this touch point, relative to the 3959 widget or QGraphicsItem that received the event. 3960 3961 \sa pos(), lastPos() 3962 */ 3963 QPointF QTouchEvent::TouchPoint::startPos() const 3964 { 3965 return d->startPos; 3966 } 3967 3968 /*! 3969 Returns the starting scene position of this touch point. 3970 3971 The scene position is the position in QGraphicsScene coordinates 3972 if the QTouchEvent is handled by a QGraphicsItem::touchEvent() 3973 reimplementation, and identical to the screen position for 3974 widgets. 3975 3976 \sa scenePos(), lastScenePos() 3977 */ 3978 QPointF QTouchEvent::TouchPoint::startScenePos() const 3979 { 3980 return d->startScenePos; 3981 } 3982 3983 /*! 3984 Returns the starting screen position of this touch point. 3985 3986 \sa screenPos(), lastScreenPos() 3987 */ 3988 QPointF QTouchEvent::TouchPoint::startScreenPos() const 3989 { 3990 return d->startScreenPos; 3991 } 3992 3993 /*! 3994 Returns the normalized starting position of this touch point. 3995 3996 The coordinates are normalized to the size of the touch device, 3997 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner. 3998 3999 \sa normalizedPos(), lastNormalizedPos() 4000 */ 4001 QPointF QTouchEvent::TouchPoint::startNormalizedPos() const 4002 { 4003 return d->startNormalizedPos; 4004 } 4005 4006 /*! 4007 Returns the position of this touch point from the previous touch 4008 event, relative to the widget or QGraphicsItem that received the event. 4009 4010 \sa pos(), startPos() 4011 */ 4012 QPointF QTouchEvent::TouchPoint::lastPos() const 4013 { 4014 return d->lastPos; 4015 } 4016 4017 /*! 4018 Returns the scene position of this touch point from the previous 4019 touch event. 4020 4021 The scene position is the position in QGraphicsScene coordinates 4022 if the QTouchEvent is handled by a QGraphicsItem::touchEvent() 4023 reimplementation, and identical to the screen position for 4024 widgets. 4025 4026 \sa scenePos(), startScenePos() 4027 */ 4028 QPointF QTouchEvent::TouchPoint::lastScenePos() const 4029 { 4030 return d->lastScenePos; 4031 } 4032 4033 /*! 4034 Returns the screen position of this touch point from the previous 4035 touch event. 4036 4037 \sa screenPos(), startScreenPos() 4038 */ 4039 QPointF QTouchEvent::TouchPoint::lastScreenPos() const 4040 { 4041 return d->lastScreenPos; 4042 } 4043 4044 /*! 4045 Returns the normalized position of this touch point from the 4046 previous touch event. 4047 4048 The coordinates are normalized to the size of the touch device, 4049 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner. 4050 4051 \sa normalizedPos(), startNormalizedPos() 4052 */ 4053 QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const 4054 { 4055 return d->lastNormalizedPos; 4056 } 4057 4058 /*! 4059 Returns the rect for this touch point, relative to the widget 4060 or QGraphicsItem that received the event. The rect is centered 4061 around the point returned by pos(). 4062 4063 \note This function returns an empty rect if the device does not report touch point sizes. 4064 */ 4065 QRectF QTouchEvent::TouchPoint::rect() const 4066 { 4067 return d->rect; 4068 } 4069 4070 /*! 4071 Returns the rect for this touch point in scene coordinates. 4072 4073 \note This function returns an empty rect if the device does not report touch point sizes. 4074 4075 \sa scenePos(), rect() 4076 */ 4077 QRectF QTouchEvent::TouchPoint::sceneRect() const 4078 { 4079 return d->sceneRect; 4080 } 4081 4082 /*! 4083 Returns the rect for this touch point in screen coordinates. 4084 4085 \note This function returns an empty rect if the device does not report touch point sizes. 4086 4087 \sa screenPos(), rect() 4088 */ 4089 QRectF QTouchEvent::TouchPoint::screenRect() const 4090 { 4091 return d->screenRect; 4092 } 4093 4094 /*! 4095 Returns the pressure of this touch point. The return value is in 4096 the range 0.0 to 1.0. 4097 */ 4098 qreal QTouchEvent::TouchPoint::pressure() const 4099 { 4100 return d->pressure; 4101 } 4102 4103 /*! \internal */ 4104 void QTouchEvent::TouchPoint::setId(int id) 4105 { 4106 if (d->ref != 1) 4107 d = d->detach(); 4108 d->id = id; 4109 } 4110 4111 /*! \internal */ 4112 void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state) 4113 { 4114 if (d->ref != 1) 4115 d = d->detach(); 4116 d->state = state; 4117 } 4118 4119 /*! \internal */ 4120 void QTouchEvent::TouchPoint::setPos(const QPointF &pos) 4121 { 4122 if (d->ref != 1) 4123 d = d->detach(); 4124 d->rect.moveCenter(pos); 4125 } 4126 4127 /*! \internal */ 4128 void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos) 4129 { 4130 if (d->ref != 1) 4131 d = d->detach(); 4132 d->sceneRect.moveCenter(scenePos); 4133 } 4134 4135 /*! \internal */ 4136 void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos) 4137 { 4138 if (d->ref != 1) 4139 d = d->detach(); 4140 d->screenRect.moveCenter(screenPos); 4141 } 4142 4143 /*! \internal */ 4144 void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos) 4145 { 4146 if (d->ref != 1) 4147 d = d->detach(); 4148 d->normalizedPos = normalizedPos; 4149 } 4150 4151 /*! \internal */ 4152 void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos) 4153 { 4154 if (d->ref != 1) 4155 d = d->detach(); 4156 d->startPos = startPos; 4157 } 4158 4159 /*! \internal */ 4160 void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos) 4161 { 4162 if (d->ref != 1) 4163 d = d->detach(); 4164 d->startScenePos = startScenePos; 4165 } 4166 4167 /*! \internal */ 4168 void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos) 4169 { 4170 if (d->ref != 1) 4171 d = d->detach(); 4172 d->startScreenPos = startScreenPos; 4173 } 4174 4175 /*! \internal */ 4176 void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos) 4177 { 4178 if (d->ref != 1) 4179 d = d->detach(); 4180 d->startNormalizedPos = startNormalizedPos; 4181 } 4182 4183 /*! \internal */ 4184 void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos) 4185 { 4186 if (d->ref != 1) 4187 d = d->detach(); 4188 d->lastPos = lastPos; 4189 } 4190 4191 /*! \internal */ 4192 void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos) 4193 { 4194 if (d->ref != 1) 4195 d = d->detach(); 4196 d->lastScenePos = lastScenePos; 4197 } 4198 4199 /*! \internal */ 4200 void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos) 4201 { 4202 if (d->ref != 1) 4203 d = d->detach(); 4204 d->lastScreenPos = lastScreenPos; 4205 } 4206 4207 /*! \internal */ 4208 void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos) 4209 { 4210 if (d->ref != 1) 4211 d = d->detach(); 4212 d->lastNormalizedPos = lastNormalizedPos; 4213 } 4214 4215 /*! \internal */ 4216 void QTouchEvent::TouchPoint::setRect(const QRectF &rect) 4217 { 4218 if (d->ref != 1) 4219 d = d->detach(); 4220 d->rect = rect; 4221 } 4222 4223 /*! \internal */ 4224 void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect) 4225 { 4226 if (d->ref != 1) 4227 d = d->detach(); 4228 d->sceneRect = sceneRect; 4229 } 4230 4231 /*! \internal */ 4232 void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect) 4233 { 4234 if (d->ref != 1) 4235 d = d->detach(); 4236 d->screenRect = screenRect; 4237 } 4238 4239 /*! \internal */ 4240 void QTouchEvent::TouchPoint::setPressure(qreal pressure) 4241 { 4242 if (d->ref != 1) 4243 d = d->detach(); 4244 d->pressure = pressure; 4245 } 4246 4247 /*! \internal */ 4248 QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other) 4249 { 4250 other.d->ref.ref(); 4251 if (!d->ref.deref()) 4252 delete d; 4253 d = other.d; 4254 return *this; 4255 } 4256 4257 /*! 4258 \class QGestureEvent 4259 \since 4.6 4260 \ingroup events 4261 \ingroup gestures 4262 4263 \brief The QGestureEvent class provides the description of triggered gestures. 4264 4265 The QGestureEvent class contains a list of gestures, which can be obtained using the 4266 gestures() function. 4267 4268 The gestures are either active or canceled. A list of those that are currently being 4269 executed can be obtained using the activeGestures() function. A list of those which 4270 were previously active and have been canceled can be accessed using the 4271 canceledGestures() function. A gesture might be canceled if the current window loses 4272 focus, for example, or because of a timeout, or for other reasons. 4273 4274 If the event handler does not accept the event by calling the generic 4275 QEvent::accept() function, all individual QGesture object that were not 4276 accepted and in the Qt::GestureStarted state will be propagated up the 4277 parent widget chain until a widget accepts them individually, by calling 4278 QGestureEvent::accept() for each of them, or an event filter consumes the 4279 event. 4280 4281 \sa QGesture, QGestureRecognizer, 4282 QWidget::grabGesture(), QGraphicsObject::grabGesture() 4283 */ 4284 4285 /*! 4286 Creates new QGestureEvent containing a list of \a gestures. 4287 */ 4288 QGestureEvent::QGestureEvent(const QList<QGesture *> &gestures) 4289 : QEvent(QEvent::Gesture) 4290 { 4291 d = reinterpret_cast<QEventPrivate *>(new QGestureEventPrivate(gestures)); 4292 } 4293 4294 /*! 4295 Destroys QGestureEvent. 4296 */ 4297 QGestureEvent::~QGestureEvent() 4298 { 4299 delete reinterpret_cast<QGestureEventPrivate *>(d); 4300 } 4301 4302 /*! 4303 Returns all gestures that are delivered in the event. 4304 */ 4305 QList<QGesture *> QGestureEvent::gestures() const 4306 { 4307 return d_func()->gestures; 4308 } 4309 4310 /*! 4311 Returns a gesture object by \a type. 4312 */ 4313 QGesture *QGestureEvent::gesture(Qt::GestureType type) const 4314 { 4315 const QGestureEventPrivate *d = d_func(); 4316 for(int i = 0; i < d->gestures.size(); ++i) 4317 if (d->gestures.at(i)->gestureType() == type) 4318 return d->gestures.at(i); 4319 return 0; 4320 } 4321 4322 /*! 4323 Returns a list of active (not canceled) gestures. 4324 */ 4325 QList<QGesture *> QGestureEvent::activeGestures() const 4326 { 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; 4333 } 4334 4335 /*! 4336 Returns a list of canceled gestures. 4337 */ 4338 QList<QGesture *> QGestureEvent::canceledGestures() const 4339 { 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; 4346 } 4347 4348 /*! 4349 Sets the accept flag of the given \a gesture object to the specified \a value. 4350 4351 Setting the accept flag indicates that the event receiver wants the \a gesture. 4352 Unwanted gestures may be propagated to the parent widget. 4353 4354 By default, gestures in events of type QEvent::Gesture are accepted, and 4355 gestures in QEvent::GestureOverride events are ignored. 4356 4357 For convenience, the accept flag can also be set with 4358 \l{QGestureEvent::accept()}{accept(gesture)}, and cleared with 4359 \l{QGestureEvent::ignore()}{ignore(gesture)}. 4360 */ 4361 void QGestureEvent::setAccepted(QGesture *gesture, bool value) 4362 { 4363 if (gesture) 4364 setAccepted(gesture->gestureType(), value); 4365 } 4366 4367 /*! 4368 Sets the accept flag of the given \a gesture object, the equivalent of calling 4369 \l{QGestureEvent::setAccepted()}{setAccepted(gesture, true)}. 4370 4371 Setting the accept flag indicates that the event receiver wants the 4372 gesture. Unwanted gestures may be propagated to the parent widget. 4373 4374 \sa QGestureEvent::ignore() 4375 */ 4376 void QGestureEvent::accept(QGesture *gesture) 4377 { 4378 if (gesture) 4379 setAccepted(gesture->gestureType(), true); 4380 } 4381 4382 /*! 4383 Clears the accept flag parameter of the given \a gesture object, the equivalent 4384 of calling \l{QGestureEvent::setAccepted()}{setAccepted(gesture, false)}. 4385 4386 Clearing the accept flag indicates that the event receiver does not 4387 want the gesture. Unwanted gestures may be propgated to the parent widget. 4388 4389 \sa QGestureEvent::accept() 4390 */ 4391 void QGestureEvent::ignore(QGesture *gesture) 4392 { 4393 if (gesture) 4394 setAccepted(gesture->gestureType(), false); 4395 } 4396 4397 /*! 4398 Returns true if the \a gesture is accepted; otherwise returns false. 4399 */ 4400 bool QGestureEvent::isAccepted(QGesture *gesture) const 4401 { 4402 return gesture ? isAccepted(gesture->gestureType()) : false; 4403 } 4404 4405 /*! 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. 4467 */ 4468 void QGestureEvent::setWidget(QWidget *widget) 4469 { 4470 d_func()->widget = widget; 4471 } 4472 4473 /*! 4474 Returns the widget on which the event occurred. 4475 */ 4476 QWidget *QGestureEvent::widget() const 4477 { 4478 return d_func()->widget; 4479 } 4480 4481 #ifndef QT_NO_GRAPHICSVIEW 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. 4489 4490 \sa QPointF::isNull(). 4491 */ 4492 QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const 4493 { 4494 QWidget *w = widget(); 4495 if (w) // we get the viewport as widget, not the graphics view 4496 w = w->parentWidget(); 4497 QGraphicsView *view = qobject_cast<QGraphicsView*>(w); 4498 if (view) { 4499 return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint())); 4500 } 4501 return QPointF(); 4502 } 4503 #endif //QT_NO_GRAPHICSVIEW 4504 4505 /*! 4506 \internal 4507 */ 4508 QGestureEventPrivate *QGestureEvent::d_func() 4509 { 4510 return reinterpret_cast<QGestureEventPrivate *>(d); 4511 } 4512 4513 /*! 4514 \internal 4515 */ 4516 const QGestureEventPrivate *QGestureEvent::d_func() const 4517 { 4518 return reinterpret_cast<const QGestureEventPrivate *>(d); 4519 } 4520 4521 #ifdef Q_NO_USING_KEYWORD 4522 /*! 4523 \fn void QGestureEvent::setAccepted(bool accepted) 4524 4525 Sets or clears the event's internal flag that determines whether it should 4526 be delivered to other objects. 4527 4528 Calling this function with a value of true for \a accepted indicates that the 4529 caller has accepted the event and that it should not be propagated further. 4530 Calling this function with a value of false indicates that the caller has 4531 ignored the event and that it should be delivered to other objects. 4532 4533 For convenience, the accept flag can also be set with accept(), and cleared 4534 with ignore(). 4535 4536 \sa QEvent::accepted 4537 */ 4538 /*! 4539 \fn bool QGestureEvent::isAccepted() const 4540 4541 Returns true is the event has been accepted; otherwise returns false. 4542 4543 \sa QEvent::accepted 4544 */ 4545 /*! 4546 \fn void QGestureEvent::accept() 4547 4548 Accepts the event, the equivalent of calling setAccepted(true). 4549 4550 \sa QEvent::accept() 4551 */ 4552 /*! 4553 \fn void QGestureEvent::ignore() 4554 4555 Ignores the event, the equivalent of calling setAccepted(false). 4556 4557 \sa QEvent::ignore() 4558 */ 4559 #endif 4560 3509 4561 QT_END_NAMESPACE
Note:
See TracChangeset
for help on using the changeset viewer.