source: trunk/src/gui/kernel/qevent.cpp@ 748

Last change on this file since 748 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 130.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
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**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qevent.h"
43#include "qcursor.h"
44#include "qapplication.h"
45#include "private/qapplication_p.h"
46#include "private/qkeysequence_p.h"
47#include "qwidget.h"
48#include "qgraphicsview.h"
49#include "qdebug.h"
50#include "qmime.h"
51#include "qdnd_p.h"
52#include "qevent_p.h"
53#include "qgesture.h"
54#include "qgesture_p.h"
55
56QT_BEGIN_NAMESPACE
57
58/*!
59 \class QInputEvent
60 \ingroup events
61
62 \brief The QInputEvent class is the base class for events that
63 describe user input.
64*/
65
66/*!
67 \internal
68*/
69QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
70 : QEvent(type), modState(modifiers)
71{}
72
73/*!
74 \internal
75*/
76QInputEvent::~QInputEvent()
77{
78}
79
80/*!
81 \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
82
83 Returns the keyboard modifier flags that existed immediately
84 before the event occurred.
85
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.
94*/
95
96/*!
97 \class QMouseEvent
98 \ingroup events
99
100 \brief The QMouseEvent class contains parameters that describe a mouse event.
101
102 Mouse events occur when a mouse button is pressed or released
103 inside a widget, or when the mouse cursor is moved.
104
105 Mouse move events will occur only when a mouse button is pressed
106 down, unless mouse tracking has been enabled with
107 QWidget::setMouseTracking().
108
109 Qt automatically grabs the mouse when a mouse button is pressed
110 inside a widget; the widget will continue to receive mouse events
111 until the last mouse button is released.
112
113 A mouse event contains a special accept flag that indicates
114 whether the receiver wants the event. You should call ignore() if
115 the mouse event is not handled by your widget. A mouse event is
116 propagated up the parent widget chain until a widget accepts it
117 with accept(), or an event filter consumes it.
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
123 The state of the keyboard modifier keys can be found by calling the
124 \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
125 QInputEvent.
126
127 The functions pos(), x(), and y() give the cursor position
128 relative to the widget that receives the mouse event. If you
129 move the widget as a result of the mouse event, use the global
130 position returned by globalPos() to avoid a shaking motion.
131
132 The QWidget::setEnabled() function can be used to enable or
133 disable mouse and keyboard events for a widget.
134
135 Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
136 QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
137 and QWidget::mouseMoveEvent() to receive mouse events in your own
138 widgets.
139
140 \sa QWidget::setMouseTracking() QWidget::grabMouse()
141 QCursor::pos()
142*/
143
144/*!
145 Constructs a mouse event object.
146
147 The \a type parameter must be one of QEvent::MouseButtonPress,
148 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
149 or QEvent::MouseMove.
150
151 The \a position is the mouse cursor's position relative to the
152 receiving widget.
153 The \a button that caused the event is given as a value from
154 the Qt::MouseButton enum. If the event \a type is
155 \l MouseMove, the appropriate button for this event is Qt::NoButton.
156 The mouse and keyboard states at the time of the event are specified by
157 \a buttons and \a modifiers.
158
159 The globalPos() is initialized to QCursor::pos(), which may not
160 be appropriate. Use the other constructor to specify the global
161 position explicitly.
162*/
163
164QMouseEvent::QMouseEvent(Type type, const QPoint &position, Qt::MouseButton button,
165 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
166 : QInputEvent(type, modifiers), p(position), b(button), mouseState(buttons)
167{
168 g = QCursor::pos();
169}
170
171/*!
172 \internal
173*/
174QMouseEvent::~QMouseEvent()
175{
176}
177
178#ifdef QT3_SUPPORT
179/*!
180 Use QMouseEvent(\a type, \a pos, \a button, \c buttons, \c
181 modifiers) instead, where \c buttons is \a state &
182 Qt::MouseButtonMask and \c modifiers is \a state &
183 Qt::KeyButtonMask.
184*/
185QMouseEvent::QMouseEvent(Type type, const QPoint &pos, Qt::ButtonState button, int state)
186 : QInputEvent(type), p(pos), b((Qt::MouseButton)button)
187{
188 g = QCursor::pos();
189 mouseState = Qt::MouseButtons((state ^ b) & Qt::MouseButtonMask);
190 modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
191}
192
193/*!
194 Use QMouseEvent(\a type, \a pos, \a globalPos, \a button,
195 \c buttons, \c modifiers) instead, where
196 \c buttons is \a state & Qt::MouseButtonMask and
197 \c modifiers is \a state & Qt::KeyButtonMask.
198*/
199QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
200 Qt::ButtonState button, int state)
201 : QInputEvent(type), p(pos), g(globalPos), b((Qt::MouseButton)button)
202{
203 mouseState = Qt::MouseButtons((state ^ b) & Qt::MouseButtonMask);
204 modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
205}
206#endif
207
208
209/*!
210 Constructs a mouse event object.
211
212 The \a type parameter must be QEvent::MouseButtonPress,
213 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
214 or QEvent::MouseMove.
215
216 The \a pos is the mouse cursor's position relative to the
217 receiving widget. The cursor's position in global coordinates is
218 specified by \a globalPos. The \a button that caused the event is
219 given as a value from the \l Qt::MouseButton enum. If the event \a
220 type is \l MouseMove, the appropriate button for this event is
221 Qt::NoButton. \a buttons is the state of all buttons at the
222 time of the event, \a modifiers the state of all keyboard
223 modifiers.
224
225*/
226QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
227 Qt::MouseButton button, Qt::MouseButtons buttons,
228 Qt::KeyboardModifiers modifiers)
229 : QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons)
230{}
231
232/*!
233 \internal
234*/
235QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos,
236 const QPoint &globalPos, Qt::MouseButton button,
237 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
238{
239 return new QMouseEventEx(type, pos, globalPos, button, buttons, modifiers);
240}
241
242/*!
243 \fn bool QMouseEvent::hasExtendedInfo() const
244 \internal
245*/
246
247/*!
248 \since 4.4
249
250 Returns the position of the mouse cursor as a QPointF, relative to the
251 widget that received the event.
252
253 If you move the widget as a result of the mouse event, use the
254 global position returned by globalPos() to avoid a shaking
255 motion.
256
257 \sa x() y() pos() globalPos()
258*/
259QPointF QMouseEvent::posF() const
260{
261 return hasExtendedInfo() ? reinterpret_cast<const QMouseEventEx *>(this)->posF : QPointF(pos());
262}
263
264/*!
265 \internal
266*/
267QMouseEventEx::QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos,
268 Qt::MouseButton button, Qt::MouseButtons buttons,
269 Qt::KeyboardModifiers modifiers)
270 : QMouseEvent(type, pos.toPoint(), globalPos, button, buttons, modifiers), posF(pos)
271{
272 d = reinterpret_cast<QEventPrivate *>(this);
273}
274
275/*!
276 \internal
277*/
278QMouseEventEx::~QMouseEventEx()
279{
280}
281
282/*!
283 \fn const QPoint &QMouseEvent::pos() const
284
285 Returns the position of the mouse cursor, relative to the widget
286 that received the event.
287
288 If you move the widget as a result of the mouse event, use the
289 global position returned by globalPos() to avoid a shaking
290 motion.
291
292 \sa x() y() globalPos()
293*/
294
295/*!
296 \fn const QPoint &QMouseEvent::globalPos() const
297
298 Returns the global position of the mouse cursor \e{at the time
299 of the event}. This is important on asynchronous window systems
300 like X11. Whenever you move your widgets around in response to
301 mouse events, globalPos() may differ a lot from the current
302 pointer position QCursor::pos(), and from
303 QWidget::mapToGlobal(pos()).
304
305 \sa globalX() globalY()
306*/
307
308/*!
309 \fn int QMouseEvent::x() const
310
311 Returns the x position of the mouse cursor, relative to the
312 widget that received the event.
313
314 \sa y() pos()
315*/
316
317/*!
318 \fn int QMouseEvent::y() const
319
320 Returns the y position of the mouse cursor, relative to the
321 widget that received the event.
322
323 \sa x() pos()
324*/
325
326/*!
327 \fn int QMouseEvent::globalX() const
328
329 Returns the global x position of the mouse cursor at the time of
330 the event.
331
332 \sa globalY() globalPos()
333*/
334
335/*!
336 \fn int QMouseEvent::globalY() const
337
338 Returns the global y position of the mouse cursor at the time of
339 the event.
340
341 \sa globalX() globalPos()
342*/
343
344/*!
345 \fn Qt::MouseButton QMouseEvent::button() const
346
347 Returns the button that caused the event.
348
349 Note that the returned value is always Qt::NoButton for mouse
350 move events.
351
352 \sa buttons() Qt::MouseButton
353*/
354
355/*!
356 \fn Qt::MouseButton QMouseEvent::buttons() const
357
358 Returns the button state when the event was generated. The button
359 state is a combination of Qt::LeftButton, Qt::RightButton,
360 Qt::MidButton using the OR operator. For mouse move events,
361 this is all buttons that are pressed down. For mouse press and
362 double click events this includes the button that caused the
363 event. For mouse release events this excludes the button that
364 caused the event.
365
366 \sa button() Qt::MouseButton
367*/
368
369
370/*!
371 \fn Qt::ButtonState QMouseEvent::state() const
372
373 Returns the button state immediately before the event was
374 generated. The button state is a combination of mouse buttons
375 (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
376
377 Use buttons() and/or modifiers() instead. Be aware that buttons()
378 return the state immediately \e after the event was generated.
379*/
380
381/*!
382 \fn Qt::ButtonState QMouseEvent::stateAfter() const
383
384 Returns the button state immediately after the event was
385 generated. The button state is a combination of mouse buttons
386 (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
387
388 Use buttons() and/or modifiers() instead.
389*/
390
391/*!
392 \class QHoverEvent
393 \ingroup events
394
395 \brief The QHoverEvent class contains parameters that describe a mouse event.
396
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.
399
400 The function pos() gives the current cursor position, while oldPos() gives
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
436*/
437
438/*!
439 \fn const QPoint &QHoverEvent::pos() const
440
441 Returns the position of the mouse cursor, relative to the widget
442 that received the event.
443
444 On QEvent::HoverLeave events, this position will always be
445 QPoint(-1, -1).
446
447 \sa oldPos()
448*/
449
450/*!
451 \fn const QPoint &QHoverEvent::oldPos() const
452
453 Returns the previous position of the mouse cursor, relative to the widget
454 that received the event. If there is no previous position, oldPos() will
455 return the same position as pos().
456
457 On QEvent::HoverEnter events, this position will always be
458 QPoint(-1, -1).
459
460 \sa pos()
461*/
462
463/*!
464 Constructs a hover event object.
465
466 The \a type parameter must be QEvent::HoverEnter,
467 QEvent::HoverLeave, or QEvent::HoverMove.
468
469 The \a pos is the current mouse cursor's position relative to the
470 receiving widget, while \a oldPos is the previous mouse cursor's
471 position relative to the receiving widget.
472*/
473QHoverEvent::QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos)
474 : QEvent(type), p(pos), op(oldPos)
475{
476}
477
478/*!
479 \internal
480*/
481QHoverEvent::~QHoverEvent()
482{
483}
484
485
486/*!
487 \class QWheelEvent
488 \brief The QWheelEvent class contains parameters that describe a wheel event.
489
490 \ingroup events
491
492 Wheel events are sent to the widget under the mouse cursor, but
493 if that widget does not handle the event they are sent to the
494 focus widget. The rotation distance is provided by delta().
495 The functions pos() and globalPos() return the mouse cursor's
496 location at the time of the event.
497
498 A wheel event contains a special accept flag that indicates
499 whether the receiver wants the event. You should call ignore() if
500 you do not handle the wheel event; this ensures that it will be
501 sent to the parent widget.
502
503 The QWidget::setEnabled() function can be used to enable or
504 disable mouse and keyboard events for a widget.
505
506 The event handler QWidget::wheelEvent() receives wheel events.
507
508 \sa QMouseEvent QWidget::grabMouse()
509*/
510
511/*!
512 \fn Qt::MouseButtons QWheelEvent::buttons() const
513
514 Returns the mouse state when the event occurred.
515*/
516
517/*!
518 \fn Qt::Orientation QWheelEvent::orientation() const
519
520 Returns the wheel's orientation.
521*/
522
523/*!
524 Constructs a wheel event object.
525
526 The position, \a pos, is the location of the mouse cursor within
527 the widget. The globalPos() is initialized to QCursor::pos()
528 which is usually, but not always, correct.
529 Use the other constructor if you need to specify the global
530 position explicitly.
531
532 The \a buttons describe the state of the mouse buttons at the time
533 of the event, \a delta contains the rotation distance,
534 \a modifiers holds the keyboard modifier flags at the time of the
535 event, and \a orient holds the wheel's orientation.
536
537 \sa pos() delta() state()
538*/
539#ifndef QT_NO_WHEELEVENT
540QWheelEvent::QWheelEvent(const QPoint &pos, int delta,
541 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
542 Qt::Orientation orient)
543 : QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient)
544{
545 g = QCursor::pos();
546}
547
548/*!
549 \internal
550*/
551QWheelEvent::~QWheelEvent()
552{
553}
554
555#ifdef QT3_SUPPORT
556/*!
557 Use one of the other constructors instead.
558*/
559QWheelEvent::QWheelEvent(const QPoint &pos, int delta, int state, Qt::Orientation orient)
560 : QInputEvent(Wheel), p(pos), d(delta), o(orient)
561{
562 g = QCursor::pos();
563 mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
564 modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
565}
566#endif
567
568/*!
569 Constructs a wheel event object.
570
571 The \a pos provides the location of the mouse cursor
572 within the widget. The position in global coordinates is specified
573 by \a globalPos. \a delta contains the rotation distance, \a modifiers
574 holds the keyboard modifier flags at the time of the event, and
575 \a orient holds the wheel's orientation.
576
577 \sa pos() globalPos() delta() state()
578*/
579QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta,
580 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
581 Qt::Orientation orient)
582 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient)
583{}
584
585#ifdef QT3_SUPPORT
586/*!
587 Use one of the other constructors instead.
588*/
589QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, int state,
590 Qt::Orientation orient)
591 : QInputEvent(Wheel), p(pos), g(globalPos), d(delta), o(orient)
592{
593 mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
594 modState = Qt::KeyboardModifiers(state & (int) Qt::KeyButtonMask);
595}
596#endif
597#endif // QT_NO_WHEELEVENT
598
599/*!
600 \fn int QWheelEvent::delta() const
601
602 Returns the distance that the wheel is rotated, in eighths of a
603 degree. A positive value indicates that the wheel was rotated
604 forwards away from the user; a negative value indicates that the
605 wheel was rotated backwards toward the user.
606
607 Most mouse types work in steps of 15 degrees, in which case the
608 delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
609
610 However, some mice have finer-resolution wheels and send delta values
611 that are less than 120 units (less than 15 degrees). To support this
612 possibility, you can either cumulatively add the delta values from events
613 until the value of 120 is reached, then scroll the widget, or you can
614 partially scroll the widget in response to each wheel event.
615
616 Example:
617
618 \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
619*/
620
621/*!
622 \fn const QPoint &QWheelEvent::pos() const
623
624 Returns the position of the mouse cursor relative to the widget
625 that received the event.
626
627 If you move your widgets around in response to mouse events,
628 use globalPos() instead of this function.
629
630 \sa x() y() globalPos()
631*/
632
633/*!
634 \fn int QWheelEvent::x() const
635
636 Returns the x position of the mouse cursor, relative to the
637 widget that received the event.
638
639 \sa y() pos()
640*/
641
642/*!
643 \fn int QWheelEvent::y() const
644
645 Returns the y position of the mouse cursor, relative to the
646 widget that received the event.
647
648 \sa x() pos()
649*/
650
651
652/*!
653 \fn const QPoint &QWheelEvent::globalPos() const
654
655 Returns the global position of the mouse pointer \e{at the time
656 of the event}. This is important on asynchronous window systems
657 such as X11; whenever you move your widgets around in response to
658 mouse events, globalPos() can differ a lot from the current
659 cursor position returned by QCursor::pos().
660
661 \sa globalX() globalY()
662*/
663
664/*!
665 \fn int QWheelEvent::globalX() const
666
667 Returns the global x position of the mouse cursor at the time of
668 the event.
669
670 \sa globalY() globalPos()
671*/
672
673/*!
674 \fn int QWheelEvent::globalY() const
675
676 Returns the global y position of the mouse cursor at the time of
677 the event.
678
679 \sa globalX() globalPos()
680*/
681
682
683/*! \obsolete
684 \fn Qt::ButtonState QWheelEvent::state() const
685
686 Returns the keyboard modifier flags at the time of the event.
687
688 The returned value is a selection of the following values,
689 combined using the OR operator: Qt::ShiftButton,
690 Qt::ControlButton, and Qt::AltButton.
691*/
692
693
694/*!
695 \class QKeyEvent
696 \brief The QKeyEvent class describes a key event.
697
698 \ingroup events
699
700 Key events are sent to the widget with keyboard input focus
701 when keys are pressed or released.
702
703 A key event contains a special accept flag that indicates whether
704 the receiver will handle the key event. You should call ignore()
705 if the key press or release event is not handled by your widget.
706 A key event is propagated up the parent widget chain until a
707 widget accepts it with accept() or an event filter consumes it.
708 Key events for multimedia keys are ignored by default. You should
709 call accept() if your widget handles those events.
710
711 The QWidget::setEnable() function can be used to enable or disable
712 mouse and keyboard events for a widget.
713
714 The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
715 QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
716 receive key events.
717
718 \sa QFocusEvent, QWidget::grabKeyboard()
719*/
720
721/*!
722 Constructs a key event object.
723
724 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
725 or QEvent::ShortcutOverride.
726
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.
734*/
735QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
736 bool autorep, ushort count)
737 : QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep)
738{
739}
740
741/*!
742 \internal
743*/
744QKeyEvent::~QKeyEvent()
745{
746}
747
748/*!
749 \internal
750*/
751QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
752 quint32 nativeScanCode, quint32 nativeVirtualKey,
753 quint32 nativeModifiers,
754 const QString& text, bool autorep, ushort count)
755{
756 return new QKeyEventEx(type, key, modifiers, text, autorep, count,
757 nativeScanCode, nativeVirtualKey, nativeModifiers);
758}
759
760/*!
761 \fn bool QKeyEvent::hasExtendedInfo() const
762 \internal
763*/
764
765/*!
766 \since 4.2
767
768 Returns the native scan code of the key event. If the key event
769 does not contain this data 0 is returned.
770
771 Note: The native scan code may be 0, even if the key event contains
772 extended information.
773
774 Note: On Mac OS/X, this function is not useful, because there is no
775 way to get the scan code from Carbon or Cocoa. The function always
776 returns 1 (or 0 in the case explained above).
777*/
778quint32 QKeyEvent::nativeScanCode() const
779{
780 return (reinterpret_cast<const QKeyEvent*>(d) != this
781 ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nScanCode);
782}
783
784/*!
785 \since 4.2
786
787 Returns the native virtual key, or key sym of the key event.
788 If the key event does not contain this data 0 is returned.
789
790 Note: The native virtual key may be 0, even if the key event contains extended information.
791*/
792quint32 QKeyEvent::nativeVirtualKey() const
793{
794 return (reinterpret_cast<const QKeyEvent*>(d) != this
795 ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nVirtualKey);
796}
797
798/*!
799 \since 4.2
800
801 Returns the native modifiers of a key event.
802 If the key event does not contain this data 0 is returned.
803
804 Note: The native modifiers may be 0, even if the key event contains extended information.
805*/
806quint32 QKeyEvent::nativeModifiers() const
807{
808 return (reinterpret_cast<const QKeyEvent*>(d) != this
809 ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nModifiers);
810}
811
812/*!
813 \internal
814 Creates an extended key event object, which in addition to the normal key event data, also
815 contains the native scan code, virtual key and modifiers. This extra data is used by the
816 shortcut system, to determine which shortcuts to trigger.
817*/
818QKeyEventEx::QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
819 const QString &text, bool autorep, ushort count,
820 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers)
821 : QKeyEvent(type, key, modifiers, text, autorep, count),
822 nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers)
823{
824 d = reinterpret_cast<QEventPrivate*>(this);
825}
826
827/*!
828 \internal
829 Creates a copy of an other extended key event.
830*/
831QKeyEventEx::QKeyEventEx(const QKeyEventEx &other)
832 : QKeyEvent(QEvent::Type(other.t), other.k, other.modState, other.txt, other.autor, other.c),
833 nScanCode(other.nScanCode), nVirtualKey(other.nVirtualKey), nModifiers(other.nModifiers)
834{
835 d = reinterpret_cast<QEventPrivate*>(this);
836}
837
838/*!
839 \internal
840*/
841QKeyEventEx::~QKeyEventEx()
842{
843}
844
845/*!
846 \fn int QKeyEvent::key() const
847
848 Returns the code of the key that was pressed or released.
849
850 See \l Qt::Key for the list of keyboard codes. These codes are
851 independent of the underlying window system. Note that this
852 function does not distinguish between capital and non-capital
853 letters, use the text() function (returning the Unicode text the
854 key generated) for this purpose.
855
856 A value of either 0 or Qt::Key_unknown means that the event is not
857 the result of a known key; for example, it may be the result of
858 a compose sequence, a keyboard macro, or due to key event
859 compression.
860
861 \sa Qt::WA_KeyCompression
862*/
863
864/*!
865 \fn QString QKeyEvent::text() const
866
867 Returns the Unicode text that this key generated. The text
868 returned can be an empty string in cases
869 where modifier keys, such as Shift, Control, Alt, and Meta,
870 are being pressed or released. In such cases key() will contain
871 a valid value.
872
873 \sa Qt::WA_KeyCompression
874*/
875
876/*!
877 Returns the keyboard modifier flags that existed immediately
878 after the event occurred.
879
880 \warning This function cannot always be trusted. The user can
881 confuse it by pressing both \key{Shift} keys simultaneously and
882 releasing one of them, for example.
883
884 \sa QApplication::keyboardModifiers()
885*/
886//###### We must check with XGetModifierMapping
887Qt::KeyboardModifiers QKeyEvent::modifiers() const
888{
889 if (key() == Qt::Key_Shift)
890 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
891 if (key() == Qt::Key_Control)
892 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
893 if (key() == Qt::Key_Alt)
894 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
895 if (key() == Qt::Key_Meta)
896 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
897 return QInputEvent::modifiers();
898}
899
900#ifndef QT_NO_SHORTCUT
901/*!
902 \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
903 \since 4.2
904
905 Returns true if the key event matches the given standard \a key;
906 otherwise returns false.
907*/
908bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
909{
910 uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference
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
923
924 uint N = QKeySequencePrivate::numberOfKeyBindings;
925 int first = 0;
926 int last = N - 1;
927
928 while (first <= last) {
929 int mid = (first + last) / 2;
930 QKeyBinding midVal = QKeySequencePrivate::keyBindings[mid];
931
932 if (searchkey > midVal.shortcut){
933 first = mid + 1; // Search in top half
934 }
935 else if (searchkey < midVal.shortcut){
936 last = mid - 1; // Search in bottom half
937 }
938 else {
939 //found correct shortcut value, now we must check for platform match
940 if ((midVal.platform & platform) && (midVal.standardKey == matchKey)) {
941 return true;
942 } else { //We may have several equal values for different platforms, so we must search in both directions
943
944 //search forward
945 for ( unsigned int i = mid + 1 ; i < N - 1 ; ++i) {
946 QKeyBinding current = QKeySequencePrivate::keyBindings[i];
947 if (current.shortcut != searchkey)
948 break;
949 else if (current.platform & platform && current.standardKey == matchKey)
950 return true;
951 }
952
953 //search back
954 for ( int i = mid - 1 ; i >= 0 ; --i) {
955 QKeyBinding current = QKeySequencePrivate::keyBindings[i];
956 if (current.shortcut != searchkey)
957 break;
958 else if (current.platform & platform && current.standardKey == matchKey)
959 return true;
960 }
961 return false; //we could not find it among the matching keySequences
962 }
963 }
964 }
965 return false; //we could not find matching keySequences at all
966}
967#endif // QT_NO_SHORTCUT
968
969
970/*!
971 \fn bool QKeyEvent::isAutoRepeat() const
972
973 Returns true if this event comes from an auto-repeating key;
974 returns false if it comes from an initial key press.
975
976 Note that if the event is a multiple-key compressed event that is
977 partly due to auto-repeat, this function could return either true
978 or false indeterminately.
979*/
980
981/*!
982 \fn int QKeyEvent::count() const
983
984 Returns the number of keys involved in this event. If text()
985 is not empty, this is simply the length of the string.
986
987 \sa Qt::WA_KeyCompression
988*/
989
990#ifdef QT3_SUPPORT
991/*!
992 \fn QKeyEvent::QKeyEvent(Type type, int key, int ascii,
993 int modifiers, const QString &text,
994 bool autorep, ushort count)
995
996 Use one of the other constructors instead.
997*/
998
999/*!
1000 \fn int QKeyEvent::ascii() const
1001
1002 Use text() instead.
1003*/
1004
1005/*!
1006 \fn Qt::ButtonState QKeyEvent::state() const
1007
1008 Use QInputEvent::modifiers() instead.
1009*/
1010
1011/*!
1012 \fn Qt::ButtonState QKeyEvent::stateAfter() const
1013
1014 Use modifiers() instead.
1015*/
1016#endif
1017
1018/*!
1019 \class QFocusEvent
1020 \brief The QFocusEvent class contains event parameters for widget focus
1021 events.
1022
1023 \ingroup events
1024
1025 Focus events are sent to widgets when the keyboard input focus
1026 changes. Focus events occur due to mouse actions, key presses
1027 (such as \gui{Tab} or \gui{Backtab}), the window system, popup
1028 menus, keyboard shortcuts, or other application-specific reasons.
1029 The reason for a particular focus event is returned by reason()
1030 in the appropriate event handler.
1031
1032 The event handlers QWidget::focusInEvent(),
1033 QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
1034 QGraphicsItem::focusOutEvent() receive focus events.
1035
1036 \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}
1037*/
1038
1039/*!
1040 Constructs a focus event object.
1041
1042 The \a type parameter must be either QEvent::FocusIn or
1043 QEvent::FocusOut. The \a reason describes the cause of the change
1044 in focus.
1045*/
1046QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
1047 : QEvent(type), m_reason(reason)
1048{}
1049
1050/*!
1051 \internal
1052*/
1053QFocusEvent::~QFocusEvent()
1054{
1055}
1056
1057// ### Qt 5: remove
1058/*!
1059 \internal
1060 */
1061Qt::FocusReason QFocusEvent::reason()
1062{
1063 return m_reason;
1064}
1065
1066/*!
1067 Returns the reason for this focus event.
1068 */
1069Qt::FocusReason QFocusEvent::reason() const
1070{
1071 return m_reason;
1072}
1073
1074/*!
1075 \fn bool QFocusEvent::gotFocus() const
1076
1077 Returns true if type() is QEvent::FocusIn; otherwise returns
1078 false.
1079*/
1080
1081/*!
1082 \fn bool QFocusEvent::lostFocus() const
1083
1084 Returns true if type() is QEvent::FocusOut; otherwise returns
1085 false.
1086*/
1087
1088#ifdef QT3_SUPPORT
1089/*!
1090 \enum QFocusEvent::Reason
1091 \compat
1092
1093 Use Qt::FocusReason instead.
1094
1095 \value Mouse Same as Qt::MouseFocusReason.
1096 \value Tab Same as Qt::TabFocusReason.
1097 \value Backtab Same as Qt::BacktabFocusReason.
1098 \value MenuBar Same as Qt::MenuBarFocusReason.
1099 \value ActiveWindow Same as Qt::ActiveWindowFocusReason
1100 \value Other Same as Qt::OtherFocusReason
1101 \value Popup Same as Qt::PopupFocusReason
1102 \value Shortcut Same as Qt::ShortcutFocusReason
1103*/
1104#endif
1105
1106/*!
1107 \class QPaintEvent
1108 \brief The QPaintEvent class contains event parameters for paint events.
1109
1110 \ingroup events
1111
1112 Paint events are sent to widgets that need to update themselves,
1113 for instance when part of a widget is exposed because a covering
1114 widget was moved.
1115
1116 The event contains a region() that needs to be updated, and a
1117 rect() that is the bounding rectangle of that region. Both are
1118 provided because many widgets can't make much use of region(),
1119 and rect() can be much faster than region().boundingRect().
1120
1121 \section1 Automatic Clipping
1122
1123 Painting is clipped to region() during the processing of a paint
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.
1131
1132 \sa QPainter, QWidget::update(), QWidget::repaint(),
1133 QWidget::paintEvent()
1134*/
1135
1136/*!
1137 \fn bool QPaintEvent::erased() const
1138 \compat
1139
1140 Returns true if the paint event region (or rectangle) has been
1141 erased with the widget's background; otherwise returns false.
1142
1143 Qt 4 \e always erases regions that require painting. The exception
1144 to this rule is if the widget sets the Qt::WA_OpaquePaintEvent or
1145 Qt::WA_NoSystemBackground attributes. If either one of those
1146 attributes is set \e and the window system does not make use of
1147 subwidget alpha composition (currently X11 and Windows, but this
1148 may change), then the region is not erased.
1149*/
1150
1151/*!
1152 \fn void QPaintEvent::setErased(bool b) { m_erased = b; }
1153 \internal
1154*/
1155
1156/*!
1157 Constructs a paint event object with the region that needs to
1158 be updated. The region is specified by \a paintRegion.
1159*/
1160QPaintEvent::QPaintEvent(const QRegion& paintRegion)
1161 : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
1162{}
1163
1164/*!
1165 Constructs a paint event object with the rectangle that needs
1166 to be updated. The region is specified by \a paintRect.
1167*/
1168QPaintEvent::QPaintEvent(const QRect &paintRect)
1169 : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
1170{}
1171
1172
1173#ifdef QT3_SUPPORT
1174 /*!
1175 Constructs a paint event object with both a \a paintRegion and a
1176 \a paintRect, both of which represent the area of the widget that
1177 needs to be updated.
1178
1179*/
1180QPaintEvent::QPaintEvent(const QRegion &paintRegion, const QRect &paintRect)
1181 : QEvent(Paint), m_rect(paintRect), m_region(paintRegion), m_erased(false)
1182{}
1183#endif
1184
1185/*!
1186 \internal
1187*/
1188QPaintEvent::~QPaintEvent()
1189{
1190}
1191
1192/*!
1193 \fn const QRect &QPaintEvent::rect() const
1194
1195 Returns the rectangle that needs to be updated.
1196
1197 \sa region() QPainter::setClipRect()
1198*/
1199
1200/*!
1201 \fn const QRegion &QPaintEvent::region() const
1202
1203 Returns the region that needs to be updated.
1204
1205 \sa rect() QPainter::setClipRegion()
1206*/
1207
1208
1209QUpdateLaterEvent::QUpdateLaterEvent(const QRegion& paintRegion)
1210 : QEvent(UpdateLater), m_region(paintRegion)
1211{
1212}
1213
1214QUpdateLaterEvent::~QUpdateLaterEvent()
1215{
1216}
1217
1218/*!
1219 \class QMoveEvent
1220 \brief The QMoveEvent class contains event parameters for move events.
1221
1222 \ingroup events
1223
1224 Move events are sent to widgets that have been moved to a new
1225 position relative to their parent.
1226
1227 The event handler QWidget::moveEvent() receives move events.
1228
1229 \sa QWidget::move(), QWidget::setGeometry()
1230*/
1231
1232/*!
1233 Constructs a move event with the new and old widget positions,
1234 \a pos and \a oldPos respectively.
1235*/
1236QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
1237 : QEvent(Move), p(pos), oldp(oldPos)
1238{}
1239
1240/*!
1241 \internal
1242*/
1243QMoveEvent::~QMoveEvent()
1244{
1245}
1246
1247/*!
1248 \fn const QPoint &QMoveEvent::pos() const
1249
1250 Returns the new position of the widget. This excludes the window
1251 frame for top level widgets.
1252*/
1253
1254/*!
1255 \fn const QPoint &QMoveEvent::oldPos() const
1256
1257 Returns the old position of the widget.
1258*/
1259
1260
1261/*!
1262 \class QResizeEvent
1263 \brief The QResizeEvent class contains event parameters for resize events.
1264
1265 \ingroup events
1266
1267 Resize events are sent to widgets that have been resized.
1268
1269 The event handler QWidget::resizeEvent() receives resize events.
1270
1271 \sa QWidget::resize() QWidget::setGeometry()
1272*/
1273
1274/*!
1275 Constructs a resize event with the new and old widget sizes, \a
1276 size and \a oldSize respectively.
1277*/
1278QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
1279 : QEvent(Resize), s(size), olds(oldSize)
1280{}
1281
1282/*!
1283 \internal
1284*/
1285QResizeEvent::~QResizeEvent()
1286{
1287}
1288
1289/*!
1290 \fn const QSize &QResizeEvent::size() const
1291
1292 Returns the new size of the widget. This is the same as
1293 QWidget::size().
1294*/
1295
1296/*!
1297 \fn const QSize &QResizeEvent::oldSize() const
1298
1299 Returns the old size of the widget.
1300*/
1301
1302
1303/*!
1304 \class QCloseEvent
1305 \brief The QCloseEvent class contains parameters that describe a close event.
1306
1307 \ingroup events
1308
1309 Close events are sent to widgets that the user wants to close,
1310 usually by choosing "Close" from the window menu, or by clicking
1311 the \gui{X} title bar button. They are also sent when you call
1312 QWidget::close() to close a widget programmatically.
1313
1314 Close events contain a flag that indicates whether the receiver
1315 wants the widget to be closed or not. When a widget accepts the
1316 close event, it is hidden (and destroyed if it was created with
1317 the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
1318 event nothing happens. (Under X11 it is possible that the window
1319 manager will forcibly close the window; but at the time of writing
1320 we are not aware of any window manager that does this.)
1321
1322 The event handler QWidget::closeEvent() receives close events. The
1323 default implementation of this event handler accepts the close
1324 event. If you do not want your widget to be hidden, or want some
1325 special handing, you should reimplement the event handler and
1326 ignore() the event.
1327
1328 The \l{mainwindows/application#close event handler}{closeEvent() in the
1329 Application example} shows a close event handler that
1330 asks whether to save a document before closing.
1331
1332 If you want the widget to be deleted when it is closed, create it
1333 with the Qt::WA_DeleteOnClose flag. This is very useful for
1334 independent top-level windows in a multi-window application.
1335
1336 \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
1337 signal when they are deleted.
1338
1339 If the last top-level window is closed, the
1340 QApplication::lastWindowClosed() signal is emitted.
1341
1342 The isAccepted() function returns true if the event's receiver has
1343 agreed to close the widget; call accept() to agree to close the
1344 widget and call ignore() if the receiver of this event does not
1345 want the widget to be closed.
1346
1347 \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
1348 QCoreApplication::exec(), QCoreApplication::quit(),
1349 QApplication::lastWindowClosed()
1350*/
1351
1352/*!
1353 Constructs a close event object.
1354
1355 \sa accept()
1356*/
1357QCloseEvent::QCloseEvent()
1358 : QEvent(Close)
1359{}
1360
1361/*! \internal
1362*/
1363QCloseEvent::~QCloseEvent()
1364{
1365}
1366
1367/*!
1368 \class QIconDragEvent
1369 \brief The QIconDragEvent class indicates that a main icon drag has begun.
1370
1371 \ingroup events
1372
1373 Icon drag events are sent to widgets when the main icon of a window
1374 has been dragged away. On Mac OS X, this happens when the proxy
1375 icon of a window is dragged off the title bar.
1376
1377 It is normal to begin using drag and drop in response to this
1378 event.
1379
1380 \sa {Drag and Drop}, QMimeData, QDrag
1381*/
1382
1383/*!
1384 Constructs an icon drag event object with the accept flag set to
1385 false.
1386
1387 \sa accept()
1388*/
1389QIconDragEvent::QIconDragEvent()
1390 : QEvent(IconDrag)
1391{ ignore(); }
1392
1393/*! \internal */
1394QIconDragEvent::~QIconDragEvent()
1395{
1396}
1397
1398/*!
1399 \class QContextMenuEvent
1400 \brief The QContextMenuEvent class contains parameters that describe a context menu event.
1401
1402 \ingroup events
1403
1404 Context menu events are sent to widgets when a user performs
1405 an action associated with opening a context menu.
1406 The actions required to open context menus vary between platforms;
1407 for example, on Windows, pressing the menu button or clicking the
1408 right mouse button will cause this event to be sent.
1409
1410 When this event occurs it is customary to show a QMenu with a
1411 context menu, if this is relevant to the context.
1412
1413 Context menu events contain a special accept flag that indicates
1414 whether the receiver accepted the event. If the event handler does
1415 not accept the event then, if possible, whatever triggered the event will be
1416 handled as a regular input event.
1417*/
1418
1419#ifndef QT_NO_CONTEXTMENU
1420/*!
1421 Constructs a context menu event object with the accept parameter
1422 flag set to false.
1423
1424 The \a reason parameter must be QContextMenuEvent::Mouse or
1425 QContextMenuEvent::Keyboard.
1426
1427 The \a pos parameter specifies the mouse position relative to the
1428 receiving widget. \a globalPos is the mouse position in absolute
1429 coordinates.
1430*/
1431QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
1432 : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
1433{}
1434
1435/*!
1436 Constructs a context menu event object with the accept parameter
1437 flag set to false.
1438
1439 The \a reason parameter must be QContextMenuEvent::Mouse or
1440 QContextMenuEvent::Keyboard.
1441
1442 The \a pos parameter specifies the mouse position relative to the
1443 receiving widget. \a globalPos is the mouse position in absolute
1444 coordinates. The \a modifiers holds the keyboard modifiers.
1445*/
1446QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
1447 Qt::KeyboardModifiers modifiers)
1448 : QInputEvent(ContextMenu, modifiers), p(pos), gp(globalPos), reas(reason)
1449{}
1450
1451#ifdef QT3_SUPPORT
1452/*!
1453 Constructs a context menu event with the given \a reason for the
1454 position specified by \a pos in widget coordinates and \a globalPos
1455 in global screen coordinates. \a dummy is ignored.
1456*/
1457QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
1458 int /* dummy */)
1459 : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
1460{}
1461#endif
1462
1463/*! \internal */
1464QContextMenuEvent::~QContextMenuEvent()
1465{
1466}
1467/*!
1468 Constructs a context menu event object with the accept parameter
1469 flag set to false.
1470
1471 The \a reason parameter must be QContextMenuEvent::Mouse or
1472 QContextMenuEvent::Keyboard.
1473
1474 The \a pos parameter specifies the mouse position relative to the
1475 receiving widget.
1476
1477 The globalPos() is initialized to QCursor::pos(), which may not be
1478 appropriate. Use the other constructor to specify the global
1479 position explicitly.
1480*/
1481QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
1482 : QInputEvent(ContextMenu), p(pos), reas(reason)
1483{
1484 gp = QCursor::pos();
1485}
1486
1487#ifdef QT3_SUPPORT
1488/*!
1489 Constructs a context menu event with the given \a reason for the
1490 position specified by \a pos in widget coordinates. \a dummy is
1491 ignored.
1492*/
1493QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, int /* dummy */)
1494 : QInputEvent(ContextMenu), p(pos), reas(reason)
1495{
1496 gp = QCursor::pos();
1497}
1498
1499Qt::ButtonState QContextMenuEvent::state() const
1500{
1501 return Qt::ButtonState(int(QApplication::keyboardModifiers())|QApplication::mouseButtons());
1502}
1503#endif
1504
1505/*!
1506 \fn const QPoint &QContextMenuEvent::pos() const
1507
1508 Returns the position of the mouse pointer relative to the widget
1509 that received the event.
1510
1511 \sa x(), y(), globalPos()
1512*/
1513
1514/*!
1515 \fn int QContextMenuEvent::x() const
1516
1517 Returns the x position of the mouse pointer, relative to the
1518 widget that received the event.
1519
1520 \sa y(), pos()
1521*/
1522
1523/*!
1524 \fn int QContextMenuEvent::y() const
1525
1526 Returns the y position of the mouse pointer, relative to the
1527 widget that received the event.
1528
1529 \sa x(), pos()
1530*/
1531
1532/*!
1533 \fn const QPoint &QContextMenuEvent::globalPos() const
1534
1535 Returns the global position of the mouse pointer at the time of
1536 the event.
1537
1538 \sa x(), y(), pos()
1539*/
1540
1541/*!
1542 \fn int QContextMenuEvent::globalX() const
1543
1544 Returns the global x position of the mouse pointer at the time of
1545 the event.
1546
1547 \sa globalY(), globalPos()
1548*/
1549
1550/*!
1551 \fn int QContextMenuEvent::globalY() const
1552
1553 Returns the global y position of the mouse pointer at the time of
1554 the event.
1555
1556 \sa globalX(), globalPos()
1557*/
1558#endif // QT_NO_CONTEXTMENU
1559
1560/*!
1561 \fn Qt::ButtonState QContextMenuEvent::state() const
1562
1563 Returns the button state (a combination of mouse buttons
1564 and keyboard modifiers) immediately before the event was
1565 generated.
1566
1567 The returned value is a selection of the following values,
1568 combined with the OR operator:
1569 Qt::LeftButton, Qt::RightButton, Qt::MidButton,
1570 Qt::ShiftButton, Qt::ControlButton, and Qt::AltButton.
1571*/
1572
1573/*!
1574 \enum QContextMenuEvent::Reason
1575
1576 This enum describes the reason why the event was sent.
1577
1578 \value Mouse The mouse caused the event to be sent. Normally this
1579 means the right mouse button was clicked, but this is platform
1580 dependent.
1581
1582 \value Keyboard The keyboard caused this event to be sent. On
1583 Windows, this means the menu button was pressed.
1584
1585 \value Other The event was sent by some other means (i.e. not by
1586 the mouse or keyboard).
1587*/
1588
1589
1590/*!
1591 \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
1592
1593 Returns the reason for this context event.
1594*/
1595
1596
1597/*!
1598 \class QInputMethodEvent
1599 \brief The QInputMethodEvent class provides parameters for input method events.
1600
1601 \ingroup events
1602
1603 Input method events are sent to widgets when an input method is
1604 used to enter text into a widget. Input methods are widely used
1605 to enter text for languages with non-Latin alphabets.
1606
1607 Note that when creating custom text editing widgets, the
1608 Qt::WA_InputMethodEnabled window attribute must be set explicitly
1609 (using the QWidget::setAttribute() function) in order to receive
1610 input method events.
1611
1612 The events are of interest to authors of keyboard entry widgets
1613 who want to be able to correctly handle languages with complex
1614 character input. Text input in such languages is usually a three
1615 step process:
1616
1617 \list 1
1618 \o \bold{Starting to Compose}
1619
1620 When the user presses the first key on a keyboard, an input
1621 context is created. This input context will contain a string
1622 of the typed characters.
1623
1624 \o \bold{Composing}
1625
1626 With every new key pressed, the input method will try to create a
1627 matching string for the text typed so far called preedit
1628 string. While the input context is active, the user can only move
1629 the cursor inside the string belonging to this input context.
1630
1631 \o \bold{Completing}
1632
1633 At some point, the user will activate a user interface component
1634 (perhaps using a particular key) where they can choose from a
1635 number of strings matching the text they have typed so far. The
1636 user can either confirm their choice cancel the input; in either
1637 case the input context will be closed.
1638 \endlist
1639
1640 QInputMethodEvent models these three stages, and transfers the
1641 information needed to correctly render the intermediate result. A
1642 QInputMethodEvent has two main parameters: preeditString() and
1643 commitString(). The preeditString() parameter gives the currently
1644 active preedit string. The commitString() parameter gives a text
1645 that should get added to (or replace parts of) the text of the
1646 editor widget. It usually is a result of the input operations and
1647 has to be inserted to the widgets text directly before the preedit
1648 string.
1649
1650 If the commitString() should replace parts of the of the text in
1651 the editor, replacementLength() will contain the number of
1652 characters to be replaced. replacementStart() contains the position
1653 at which characters are to be replaced relative from the start of
1654 the preedit string.
1655
1656 A number of attributes control the visual appearance of the
1657 preedit string (the visual appearance of text outside the preedit
1658 string is controlled by the widget only). The AttributeType enum
1659 describes the different attributes that can be set.
1660
1661 A class implementing QWidget::inputMethodEvent() or
1662 QGraphicsItem::inputMethodEvent() should at least understand and
1663 honor the \l TextFormat and \l Cursor attributes.
1664
1665 Since input methods need to be able to query certain properties
1666 from the widget or graphics item, subclasses must also implement
1667 QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
1668 respectively.
1669
1670 When receiving an input method event, the text widget has to performs the
1671 following steps:
1672
1673 \list 1
1674 \o If the widget has selected text, the selected text should get
1675 removed.
1676
1677 \o Remove the text starting at replacementStart() with length
1678 replacementLength() and replace it by the commitString(). If
1679 replacementLength() is 0, replacementStart() gives the insertion
1680 position for the commitString().
1681