/src/gui/kernel/qevent.cpp
https://bitbucket.org/ultra_iter/qt-vtl · C++ · 4631 lines · 1221 code · 388 blank · 3022 comment · 105 complexity · 0e9cb96fb1d3a36014d010545af4fe49 MD5 · raw file
Large files are truncated click here to view the full file
- /****************************************************************************
- **
- ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
- ** All rights reserved.
- ** Contact: Nokia Corporation (qt-info@nokia.com)
- **
- ** This file is part of the QtGui module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** GNU Lesser General Public License Usage
- ** This file may be used under the terms of the GNU Lesser General Public
- ** License version 2.1 as published by the Free Software Foundation and
- ** appearing in the file LICENSE.LGPL included in the packaging of this
- ** file. Please review the following information to ensure the GNU Lesser
- ** General Public License version 2.1 requirements will be met:
- ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
- **
- ** In addition, as a special exception, Nokia gives you certain additional
- ** rights. These rights are described in the Nokia Qt LGPL Exception
- ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU General
- ** Public License version 3.0 as published by the Free Software Foundation
- ** and appearing in the file LICENSE.GPL included in the packaging of this
- ** file. Please review the following information to ensure the GNU General
- ** Public License version 3.0 requirements will be met:
- ** http://www.gnu.org/copyleft/gpl.html.
- **
- ** Other Usage
- ** Alternatively, this file may be used in accordance with the terms and
- ** conditions contained in a signed written agreement between you and Nokia.
- **
- **
- **
- **
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
- #include "qevent.h"
- #include "qcursor.h"
- #include "qapplication.h"
- #include "private/qapplication_p.h"
- #include "private/qevent_p.h"
- #include "private/qkeysequence_p.h"
- #include "qwidget.h"
- #include "qgraphicsview.h"
- #include "qdebug.h"
- #include "qmime.h"
- #include "qdnd_p.h"
- #include "qevent_p.h"
- #include "qgesture.h"
- #include "qgesture_p.h"
- #ifdef Q_OS_SYMBIAN
- #include "private/qcore_symbian_p.h"
- #endif
- QT_BEGIN_NAMESPACE
- /*!
- \class QInputEvent
- \ingroup events
- \brief The QInputEvent class is the base class for events that
- describe user input.
- */
- /*!
- \internal
- */
- QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
- : QEvent(type), modState(modifiers)
- {}
- /*!
- \internal
- */
- QInputEvent::~QInputEvent()
- {
- }
- /*!
- \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
- Returns the keyboard modifier flags that existed immediately
- before the event occurred.
- \sa QApplication::keyboardModifiers()
- */
- /*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers)
- \internal
- Sets the keyboard modifiers flags for this event.
- */
- /*!
- \class QMouseEvent
- \ingroup events
- \brief The QMouseEvent class contains parameters that describe a mouse event.
- Mouse events occur when a mouse button is pressed or released
- inside a widget, or when the mouse cursor is moved.
- Mouse move events will occur only when a mouse button is pressed
- down, unless mouse tracking has been enabled with
- QWidget::setMouseTracking().
- Qt automatically grabs the mouse when a mouse button is pressed
- inside a widget; the widget will continue to receive mouse events
- until the last mouse button is released.
- A mouse event contains a special accept flag that indicates
- whether the receiver wants the event. You should call ignore() if
- the mouse event is not handled by your widget. A mouse event is
- propagated up the parent widget chain until a widget accepts it
- with accept(), or an event filter consumes it.
- \note If a mouse event is propagated to a \l{QWidget}{widget} for
- which Qt::WA_NoMousePropagation has been set, that mouse event
- will not be propagated further up the parent widget chain.
- The state of the keyboard modifier keys can be found by calling the
- \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
- QInputEvent.
- The functions pos(), x(), and y() give the cursor position
- relative to the widget that receives the mouse event. If you
- move the widget as a result of the mouse event, use the global
- position returned by globalPos() to avoid a shaking motion.
- The QWidget::setEnabled() function can be used to enable or
- disable mouse and keyboard events for a widget.
- Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
- QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
- and QWidget::mouseMoveEvent() to receive mouse events in your own
- widgets.
- \sa QWidget::setMouseTracking() QWidget::grabMouse() QCursor::pos()
- */
- /*!
- Constructs a mouse event object.
- The \a type parameter must be one of QEvent::MouseButtonPress,
- QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
- or QEvent::MouseMove.
- The \a position is the mouse cursor's position relative to the
- receiving widget.
- The \a button that caused the event is given as a value from
- the Qt::MouseButton enum. If the event \a type is
- \l MouseMove, the appropriate button for this event is Qt::NoButton.
- The mouse and keyboard states at the time of the event are specified by
- \a buttons and \a modifiers.
- The globalPos() is initialized to QCursor::pos(), which may not
- be appropriate. Use the other constructor to specify the global
- position explicitly.
- */
- QMouseEvent::QMouseEvent(Type type, const QPoint &position, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, modifiers), p(position), b(button), mouseState(buttons)
- {
- g = QCursor::pos();
- }
- /*!
- \internal
- */
- QMouseEvent::~QMouseEvent()
- {
- }
- #ifdef QT3_SUPPORT
- /*!
- Use QMouseEvent(\a type, \a pos, \a button, \c buttons, \c
- modifiers) instead, where \c buttons is \a state &
- Qt::MouseButtonMask and \c modifiers is \a state &
- Qt::KeyButtonMask.
- */
- QMouseEvent::QMouseEvent(Type type, const QPoint &pos, Qt::ButtonState button, int state)
- : QInputEvent(type), p(pos), b((Qt::MouseButton)button)
- {
- g = QCursor::pos();
- mouseState = Qt::MouseButtons((state ^ b) & Qt::MouseButtonMask);
- modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
- }
- /*!
- Use QMouseEvent(\a type, \a pos, \a globalPos, \a button,
- \c buttons, \c modifiers) instead, where
- \c buttons is \a state & Qt::MouseButtonMask and
- \c modifiers is \a state & Qt::KeyButtonMask.
- */
- QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
- Qt::ButtonState button, int state)
- : QInputEvent(type), p(pos), g(globalPos), b((Qt::MouseButton)button)
- {
- mouseState = Qt::MouseButtons((state ^ b) & Qt::MouseButtonMask);
- modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
- }
- #endif
- /*!
- Constructs a mouse event object.
- The \a type parameter must be QEvent::MouseButtonPress,
- QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
- or QEvent::MouseMove.
- The \a pos is the mouse cursor's position relative to the
- receiving widget. The cursor's position in global coordinates is
- specified by \a globalPos. The \a button that caused the event is
- given as a value from the \l Qt::MouseButton enum. If the event \a
- type is \l MouseMove, the appropriate button for this event is
- Qt::NoButton. \a buttons is the state of all buttons at the
- time of the event, \a modifiers the state of all keyboard
- modifiers.
- */
- QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
- Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons)
- {}
- /*!
- \internal
- */
- QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos,
- const QPoint &globalPos, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
- {
- return new QMouseEventEx(type, pos, globalPos, button, buttons, modifiers);
- }
- /*!
- \fn bool QMouseEvent::hasExtendedInfo() const
- \internal
- */
- /*!
- \since 4.4
- Returns the position of the mouse cursor as a QPointF, relative to the
- widget that received the event.
- If you move the widget as a result of the mouse event, use the
- global position returned by globalPos() to avoid a shaking
- motion.
- \sa x() y() pos() globalPos()
- */
- QPointF QMouseEvent::posF() const
- {
- return hasExtendedInfo() ? reinterpret_cast<const QMouseEventEx *>(this)->posF : QPointF(pos());
- }
- /*!
- \internal
- */
- QMouseEventEx::QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos,
- Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QMouseEvent(type, pos.toPoint(), globalPos, button, buttons, modifiers), posF(pos)
- {
- d = reinterpret_cast<QEventPrivate *>(this);
- }
- /*!
- \internal
- */
- QMouseEventEx::~QMouseEventEx()
- {
- }
- /*!
- \fn const QPoint &QMouseEvent::pos() const
- Returns the position of the mouse cursor, relative to the widget
- that received the event.
- If you move the widget as a result of the mouse event, use the
- global position returned by globalPos() to avoid a shaking
- motion.
- \sa x() y() globalPos()
- */
- /*!
- \fn const QPoint &QMouseEvent::globalPos() const
- Returns the global position of the mouse cursor \e{at the time
- of the event}. This is important on asynchronous window systems
- like X11. Whenever you move your widgets around in response to
- mouse events, globalPos() may differ a lot from the current
- pointer position QCursor::pos(), and from
- QWidget::mapToGlobal(pos()).
- \sa globalX() globalY()
- */
- /*!
- \fn int QMouseEvent::x() const
- Returns the x position of the mouse cursor, relative to the
- widget that received the event.
- \sa y() pos()
- */
- /*!
- \fn int QMouseEvent::y() const
- Returns the y position of the mouse cursor, relative to the
- widget that received the event.
- \sa x() pos()
- */
- /*!
- \fn int QMouseEvent::globalX() const
- Returns the global x position of the mouse cursor at the time of
- the event.
- \sa globalY() globalPos()
- */
- /*!
- \fn int QMouseEvent::globalY() const
- Returns the global y position of the mouse cursor at the time of
- the event.
- \sa globalX() globalPos()
- */
- /*!
- \fn Qt::MouseButton QMouseEvent::button() const
- Returns the button that caused the event.
- Note that the returned value is always Qt::NoButton for mouse
- move events.
- \sa buttons() Qt::MouseButton
- */
- /*!
- \fn Qt::MouseButton QMouseEvent::buttons() const
- Returns the button state when the event was generated. The button
- state is a combination of Qt::LeftButton, Qt::RightButton,
- Qt::MidButton using the OR operator. For mouse move events,
- this is all buttons that are pressed down. For mouse press and
- double click events this includes the button that caused the
- event. For mouse release events this excludes the button that
- caused the event.
- \sa button() Qt::MouseButton
- */
- /*!
- \fn Qt::ButtonState QMouseEvent::state() const
- Returns the button state immediately before the event was
- generated. The button state is a combination of mouse buttons
- (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
- Use buttons() and/or modifiers() instead. Be aware that buttons()
- return the state immediately \e after the event was generated.
- */
- /*!
- \fn Qt::ButtonState QMouseEvent::stateAfter() const
- Returns the button state immediately after the event was
- generated. The button state is a combination of mouse buttons
- (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
- Use buttons() and/or modifiers() instead.
- */
- /*!
- \class QHoverEvent
- \ingroup events
- \brief The QHoverEvent class contains parameters that describe a mouse event.
- Mouse events occur when a mouse cursor is moved into, out of, or within a
- widget, and if the widget has the Qt::WA_Hover attribute.
- The function pos() gives the current cursor position, while oldPos() gives
- the old mouse position.
- There are a few similarities between the events QEvent::HoverEnter
- and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
- However, they are slightly different because we do an update() in the event
- handler of HoverEnter and HoverLeave.
- QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
- consider a top-level window A containing a child B which in turn contains a
- child C (all with mouse tracking enabled):
- \image hoverevents.png
- Now, if you move the cursor from the top to the bottom in the middle of A,
- you will get the following QEvent::MouseMove events:
- \list 1
- \o A::MouseMove
- \o B::MouseMove
- \o C::MouseMove
- \endlist
- You will get the same events for QEvent::HoverMove, except that the event
- always propagates to the top-level regardless whether the event is accepted
- or not. It will only stop propagating with the Qt::WA_NoMousePropagation
- attribute.
- In this case the events will occur in the following way:
- \list 1
- \o A::HoverMove
- \o A::HoverMove, B::HoverMove
- \o A::HoverMove, B::HoverMove, C::HoverMove
- \endlist
- */
- /*!
- \fn const QPoint &QHoverEvent::pos() const
- Returns the position of the mouse cursor, relative to the widget
- that received the event.
- On QEvent::HoverLeave events, this position will always be
- QPoint(-1, -1).
- \sa oldPos()
- */
- /*!
- \fn const QPoint &QHoverEvent::oldPos() const
- Returns the previous position of the mouse cursor, relative to the widget
- that received the event. If there is no previous position, oldPos() will
- return the same position as pos().
- On QEvent::HoverEnter events, this position will always be
- QPoint(-1, -1).
- \sa pos()
- */
- /*!
- Constructs a hover event object.
- The \a type parameter must be QEvent::HoverEnter,
- QEvent::HoverLeave, or QEvent::HoverMove.
- The \a pos is the current mouse cursor's position relative to the
- receiving widget, while \a oldPos is the previous mouse cursor's
- position relative to the receiving widget.
- */
- QHoverEvent::QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos)
- : QEvent(type), p(pos), op(oldPos)
- {
- }
- /*!
- \internal
- */
- QHoverEvent::~QHoverEvent()
- {
- }
- /*!
- \class QWheelEvent
- \brief The QWheelEvent class contains parameters that describe a wheel event.
- \ingroup events
- Wheel events are sent to the widget under the mouse cursor, but
- if that widget does not handle the event they are sent to the
- focus widget. The rotation distance is provided by delta().
- The functions pos() and globalPos() return the mouse cursor's
- location at the time of the event.
- A wheel event contains a special accept flag that indicates
- whether the receiver wants the event. You should call ignore() if
- you do not handle the wheel event; this ensures that it will be
- sent to the parent widget.
- The QWidget::setEnabled() function can be used to enable or
- disable mouse and keyboard events for a widget.
- The event handler QWidget::wheelEvent() receives wheel events.
- \sa QMouseEvent QWidget::grabMouse()
- */
- /*!
- \fn Qt::MouseButtons QWheelEvent::buttons() const
- Returns the mouse state when the event occurred.
- */
- /*!
- \fn Qt::Orientation QWheelEvent::orientation() const
- Returns the wheel's orientation.
- */
- /*!
- Constructs a wheel event object.
- The position, \a pos, is the location of the mouse cursor within
- the widget. The globalPos() is initialized to QCursor::pos()
- which is usually, but not always, correct.
- Use the other constructor if you need to specify the global
- position explicitly.
- The \a buttons describe the state of the mouse buttons at the time
- of the event, \a delta contains the rotation distance,
- \a modifiers holds the keyboard modifier flags at the time of the
- event, and \a orient holds the wheel's orientation.
- \sa pos() delta() state()
- */
- #ifndef QT_NO_WHEELEVENT
- QWheelEvent::QWheelEvent(const QPoint &pos, int delta,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
- Qt::Orientation orient)
- : QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient)
- {
- g = QCursor::pos();
- }
- /*!
- \internal
- */
- QWheelEvent::~QWheelEvent()
- {
- }
- #ifdef QT3_SUPPORT
- /*!
- Use one of the other constructors instead.
- */
- QWheelEvent::QWheelEvent(const QPoint &pos, int delta, int state, Qt::Orientation orient)
- : QInputEvent(Wheel), p(pos), d(delta), o(orient)
- {
- g = QCursor::pos();
- mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
- modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
- }
- #endif
- /*!
- Constructs a wheel event object.
- The \a pos provides the location of the mouse cursor
- within the widget. The position in global coordinates is specified
- by \a globalPos. \a delta contains the rotation distance, \a modifiers
- holds the keyboard modifier flags at the time of the event, and
- \a orient holds the wheel's orientation.
- \sa pos() globalPos() delta() state()
- */
- QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
- Qt::Orientation orient)
- : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient)
- {}
- #ifdef QT3_SUPPORT
- /*!
- Use one of the other constructors instead.
- */
- QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, int state,
- Qt::Orientation orient)
- : QInputEvent(Wheel), p(pos), g(globalPos), d(delta), o(orient)
- {
- mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
- modState = Qt::KeyboardModifiers(state & (int) Qt::KeyButtonMask);
- }
- #endif
- #endif // QT_NO_WHEELEVENT
- /*!
- \fn int QWheelEvent::delta() const
- Returns the distance that the wheel is rotated, in eighths of a
- degree. A positive value indicates that the wheel was rotated
- forwards away from the user; a negative value indicates that the
- wheel was rotated backwards toward the user.
- Most mouse types work in steps of 15 degrees, in which case the
- delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
- However, some mice have finer-resolution wheels and send delta values
- that are less than 120 units (less than 15 degrees). To support this
- possibility, you can either cumulatively add the delta values from events
- until the value of 120 is reached, then scroll the widget, or you can
- partially scroll the widget in response to each wheel event.
- Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
- */
- /*!
- \fn const QPoint &QWheelEvent::pos() const
- Returns the position of the mouse cursor relative to the widget
- that received the event.
- If you move your widgets around in response to mouse events,
- use globalPos() instead of this function.
- \sa x() y() globalPos()
- */
- /*!
- \fn int QWheelEvent::x() const
- Returns the x position of the mouse cursor, relative to the
- widget that received the event.
- \sa y() pos()
- */
- /*!
- \fn int QWheelEvent::y() const
- Returns the y position of the mouse cursor, relative to the
- widget that received the event.
- \sa x() pos()
- */
- /*!
- \fn const QPoint &QWheelEvent::globalPos() const
- Returns the global position of the mouse pointer \e{at the time
- of the event}. This is important on asynchronous window systems
- such as X11; whenever you move your widgets around in response to
- mouse events, globalPos() can differ a lot from the current
- cursor position returned by QCursor::pos().
- \sa globalX() globalY()
- */
- /*!
- \fn int QWheelEvent::globalX() const
- Returns the global x position of the mouse cursor at the time of
- the event.
- \sa globalY() globalPos()
- */
- /*!
- \fn int QWheelEvent::globalY() const
- Returns the global y position of the mouse cursor at the time of
- the event.
- \sa globalX() globalPos()
- */
- /*! \obsolete
- \fn Qt::ButtonState QWheelEvent::state() const
- Returns the keyboard modifier flags at the time of the event.
- The returned value is a selection of the following values,
- combined using the OR operator: Qt::ShiftButton,
- Qt::ControlButton, and Qt::AltButton.
- */
- /*!
- \class QKeyEvent
- \brief The QKeyEvent class describes a key event.
- \ingroup events
- Key events are sent to the widget with keyboard input focus
- when keys are pressed or released.
- A key event contains a special accept flag that indicates whether
- the receiver will handle the key event. You should call ignore()
- if the key press or release event is not handled by your widget.
- A key event is propagated up the parent widget chain until a
- widget accepts it with accept() or an event filter consumes it.
- Key events for multimedia keys are ignored by default. You should
- call accept() if your widget handles those events.
- The QWidget::setEnable() function can be used to enable or disable
- mouse and keyboard events for a widget.
- The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
- QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
- receive key events.
- \sa QFocusEvent, QWidget::grabKeyboard()
- */
- /*!
- Constructs a key event object.
- The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
- or QEvent::ShortcutOverride.
- Int \a key is the code for the Qt::Key that the event loop should listen
- for. If \a key is 0, the event is not a result of a known key; for
- example, it may be the result of a compose sequence or keyboard macro.
- The \a modifiers holds the keyboard modifiers, and the given \a text
- is the Unicode text that the key generated. If \a autorep is true,
- isAutoRepeat() will be true. \a count is the number of keys involved
- in the event.
- */
- QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
- bool autorep, ushort count)
- : QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep)
- {
- }
- /*!
- \internal
- */
- QKeyEvent::~QKeyEvent()
- {
- }
- /*!
- \internal
- */
- QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
- quint32 nativeScanCode, quint32 nativeVirtualKey,
- quint32 nativeModifiers,
- const QString& text, bool autorep, ushort count)
- {
- return new QKeyEventEx(type, key, modifiers, text, autorep, count,
- nativeScanCode, nativeVirtualKey, nativeModifiers);
- }
- /*!
- \fn bool QKeyEvent::hasExtendedInfo() const
- \internal
- */
- /*!
- \since 4.2
- Returns the native scan code of the key event. If the key event
- does not contain this data 0 is returned.
- Note: The native scan code may be 0, even if the key event contains
- extended information.
- Note: On Mac OS/X, this function is not useful, because there is no
- way to get the scan code from Carbon or Cocoa. The function always
- returns 1 (or 0 in the case explained above).
- */
- quint32 QKeyEvent::nativeScanCode() const
- {
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nScanCode);
- }
- /*!
- \since 4.2
- Returns the native virtual key, or key sym of the key event.
- If the key event does not contain this data 0 is returned.
- Note: The native virtual key may be 0, even if the key event contains extended information.
- */
- quint32 QKeyEvent::nativeVirtualKey() const
- {
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nVirtualKey);
- }
- /*!
- \since 4.2
- Returns the native modifiers of a key event.
- If the key event does not contain this data 0 is returned.
- Note: The native modifiers may be 0, even if the key event contains extended information.
- */
- quint32 QKeyEvent::nativeModifiers() const
- {
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nModifiers);
- }
- /*!
- \internal
- Creates an extended key event object, which in addition to the normal key event data, also
- contains the native scan code, virtual key and modifiers. This extra data is used by the
- shortcut system, to determine which shortcuts to trigger.
- */
- QKeyEventEx::QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
- const QString &text, bool autorep, ushort count,
- quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers)
- : QKeyEvent(type, key, modifiers, text, autorep, count),
- nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers)
- {
- d = reinterpret_cast<QEventPrivate*>(this);
- }
- /*!
- \internal
- Creates a copy of an other extended key event.
- */
- QKeyEventEx::QKeyEventEx(const QKeyEventEx &other)
- : QKeyEvent(QEvent::Type(other.t), other.k, other.modState, other.txt, other.autor, other.c),
- nScanCode(other.nScanCode), nVirtualKey(other.nVirtualKey), nModifiers(other.nModifiers)
- {
- d = reinterpret_cast<QEventPrivate*>(this);
- }
- /*!
- \internal
- */
- QKeyEventEx::~QKeyEventEx()
- {
- }
- /*!
- \fn int QKeyEvent::key() const
- Returns the code of the key that was pressed or released.
- See \l Qt::Key for the list of keyboard codes. These codes are
- independent of the underlying window system. Note that this
- function does not distinguish between capital and non-capital
- letters, use the text() function (returning the Unicode text the
- key generated) for this purpose.
- A value of either 0 or Qt::Key_unknown means that the event is not
- the result of a known key; for example, it may be the result of
- a compose sequence, a keyboard macro, or due to key event
- compression.
- \sa Qt::WA_KeyCompression
- */
- /*!
- \fn QString QKeyEvent::text() const
- Returns the Unicode text that this key generated. The text
- returned can be an empty string in cases
- where modifier keys, such as Shift, Control, Alt, and Meta,
- are being pressed or released. In such cases key() will contain
- a valid value.
- \sa Qt::WA_KeyCompression
- */
- /*!
- Returns the keyboard modifier flags that existed immediately
- after the event occurred.
- \warning This function cannot always be trusted. The user can
- confuse it by pressing both \key{Shift} keys simultaneously and
- releasing one of them, for example.
- \sa QApplication::keyboardModifiers()
- */
- //###### We must check with XGetModifierMapping
- Qt::KeyboardModifiers QKeyEvent::modifiers() const
- {
- if (key() == Qt::Key_Shift)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
- if (key() == Qt::Key_Control)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
- if (key() == Qt::Key_Alt)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
- if (key() == Qt::Key_Meta)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
- return QInputEvent::modifiers();
- }
- #ifndef QT_NO_SHORTCUT
- /*!
- \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
- \since 4.2
- Returns true if the key event matches the given standard \a key;
- otherwise returns false.
- */
- bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
- {
- uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference
- uint platform = QApplicationPrivate::currentPlatform();
- #ifdef Q_WS_MAC
- if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
- uint oldSearchKey = searchkey;
- searchkey &= ~(Qt::ControlModifier | Qt::MetaModifier);
- if (oldSearchKey & Qt::ControlModifier)
- searchkey |= Qt::MetaModifier;
- if (oldSearchKey & Qt::MetaModifier)
- searchkey |= Qt::ControlModifier;
- }
- #endif
- uint N = QKeySequencePrivate::numberOfKeyBindings;
- int first = 0;
- int last = N - 1;
- while (first <= last) {
- int mid = (first + last) / 2;
- QKeyBinding midVal = QKeySequencePrivate::keyBindings[mid];
- if (searchkey > midVal.shortcut){
- first = mid + 1; // Search in top half
- }
- else if (searchkey < midVal.shortcut){
- last = mid - 1; // Search in bottom half
- }
- else {
- //found correct shortcut value, now we must check for platform match
- if ((midVal.platform & platform) && (midVal.standardKey == matchKey)) {
- return true;
- } else { //We may have several equal values for different platforms, so we must search in both directions
- //search forward
- for ( unsigned int i = mid + 1 ; i < N - 1 ; ++i) {
- QKeyBinding current = QKeySequencePrivate::keyBindings[i];
- if (current.shortcut != searchkey)
- break;
- else if (current.platform & platform && current.standardKey == matchKey)
- return true;
- }
- //search back
- for ( int i = mid - 1 ; i >= 0 ; --i) {
- QKeyBinding current = QKeySequencePrivate::keyBindings[i];
- if (current.shortcut != searchkey)
- break;
- else if (current.platform & platform && current.standardKey == matchKey)
- return true;
- }
- return false; //we could not find it among the matching keySequences
- }
- }
- }
- return false; //we could not find matching keySequences at all
- }
- #endif // QT_NO_SHORTCUT
- /*!
- \fn bool QKeyEvent::isAutoRepeat() const
- Returns true if this event comes from an auto-repeating key;
- returns false if it comes from an initial key press.
- Note that if the event is a multiple-key compressed event that is
- partly due to auto-repeat, this function could return either true
- or false indeterminately.
- */
- /*!
- \fn int QKeyEvent::count() const
- Returns the number of keys involved in this event. If text()
- is not empty, this is simply the length of the string.
- \sa Qt::WA_KeyCompression
- */
- #ifdef QT3_SUPPORT
- /*!
- \fn QKeyEvent::QKeyEvent(Type type, int key, int ascii,
- int modifiers, const QString &text,
- bool autorep, ushort count)
- Use one of the other constructors instead.
- */
- /*!
- \fn int QKeyEvent::ascii() const
- Use text() instead.
- */
- /*!
- \fn Qt::ButtonState QKeyEvent::state() const
- Use QInputEvent::modifiers() instead.
- */
- /*!
- \fn Qt::ButtonState QKeyEvent::stateAfter() const
- Use modifiers() instead.
- */
- #endif
- /*!
- \class QFocusEvent
- \brief The QFocusEvent class contains event parameters for widget focus
- events.
- \ingroup events
- Focus events are sent to widgets when the keyboard input focus
- changes. Focus events occur due to mouse actions, key presses
- (such as \gui{Tab} or \gui{Backtab}), the window system, popup
- menus, keyboard shortcuts, or other application-specific reasons.
- The reason for a particular focus event is returned by reason()
- in the appropriate event handler.
- The event handlers QWidget::focusInEvent(),
- QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
- QGraphicsItem::focusOutEvent() receive focus events.
- \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}
- */
- /*!
- Constructs a focus event object.
- The \a type parameter must be either QEvent::FocusIn or
- QEvent::FocusOut. The \a reason describes the cause of the change
- in focus.
- */
- QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
- : QEvent(type), m_reason(reason)
- {}
- /*!
- \internal
- */
- QFocusEvent::~QFocusEvent()
- {
- }
- // ### Qt 5: remove
- /*!
- \internal
- */
- Qt::FocusReason QFocusEvent::reason()
- {
- return m_reason;
- }
- /*!
- Returns the reason for this focus event.
- */
- Qt::FocusReason QFocusEvent::reason() const
- {
- return m_reason;
- }
- /*!
- \fn bool QFocusEvent::gotFocus() const
- Returns true if type() is QEvent::FocusIn; otherwise returns
- false.
- */
- /*!
- \fn bool QFocusEvent::lostFocus() const
- Returns true if type() is QEvent::FocusOut; otherwise returns
- false.
- */
- #ifdef QT3_SUPPORT
- /*!
- \enum QFocusEvent::Reason
- \compat
- Use Qt::FocusReason instead.
- \value Mouse Same as Qt::MouseFocusReason.
- \value Tab Same as Qt::TabFocusReason.
- \value Backtab Same as Qt::BacktabFocusReason.
- \value MenuBar Same as Qt::MenuBarFocusReason.
- \value ActiveWindow Same as Qt::ActiveWindowFocusReason
- \value Other Same as Qt::OtherFocusReason
- \value Popup Same as Qt::PopupFocusReason
- \value Shortcut Same as Qt::ShortcutFocusReason
- */
- #endif
- /*!
- \class QPaintEvent
- \brief The QPaintEvent class contains event parameters for paint events.
- \ingroup events
- Paint events are sent to widgets that need to update themselves,
- for instance when part of a widget is exposed because a covering
- widget was moved.
- The event contains a region() that needs to be updated, and a
- rect() that is the bounding rectangle of that region. Both are
- provided because many widgets can't make much use of region(),
- and rect() can be much faster than region().boundingRect().
- \section1 Automatic Clipping
- Painting is clipped to region() during the processing of a paint
- event. This clipping is performed by Qt's paint system and is
- independent of any clipping that may be applied to a QPainter used to
- draw on the paint device.
- As a result, the value returned by QPainter::clipRegion() on
- a newly-constructed QPainter will not reflect the clip region that is
- used by the paint system.
- \sa QPainter, QWidget::update(), QWidget::repaint(),
- QWidget::paintEvent()
- */
- /*!
- \fn bool QPaintEvent::erased() const
- \compat
- Returns true if the paint event region (or rectangle) has been
- erased with the widget's background; otherwise returns false.
- Qt 4 \e always erases regions that require painting. The exception
- to this rule is if the widget sets the Qt::WA_OpaquePaintEvent or
- Qt::WA_NoSystemBackground attributes. If either one of those
- attributes is set \e and the window system does not make use of
- subwidget alpha composition (currently X11 and Windows, but this
- may change), then the region is not erased.
- */
- /*!
- \fn void QPaintEvent::setErased(bool b) { m_erased = b; }
- \internal
- */
- /*!
- Constructs a paint event object with the region that needs to
- be updated. The region is specified by \a paintRegion.
- */
- QPaintEvent::QPaintEvent(const QRegion& paintRegion)
- : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
- {}
- /*!
- Constructs a paint event object with the rectangle that needs
- to be updated. The region is specified by \a paintRect.
- */
- QPaintEvent::QPaintEvent(const QRect &paintRect)
- : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
- {}
- #ifdef QT3_SUPPORT
- /*!
- Constructs a paint event object with both a \a paintRegion and a
- \a paintRect, both of which represent the area of the widget that
- needs to be updated.
- */
- QPaintEvent::QPaintEvent(const QRegion &paintRegion, const QRect &paintRect)
- : QEvent(Paint), m_rect(paintRect), m_region(paintRegion), m_erased(false)
- {}
- #endif
- /*!
- \internal
- */
- QPaintEvent::~QPaintEvent()
- {
- }
- /*!
- \fn const QRect &QPaintEvent::rect() const
- Returns the rectangle that needs to be updated.
- \sa region() QPainter::setClipRect()
- */
- /*!
- \fn const QRegion &QPaintEvent::region() const
- Returns the region that needs to be updated.
- \sa rect() QPainter::setClipRegion()
- */
- QUpdateLaterEvent::QUpdateLaterEvent(const QRegion& paintRegion)
- : QEvent(UpdateLater), m_region(paintRegion)
- {
- }
- QUpdateLaterEvent::~QUpdateLaterEvent()
- {
- }
- /*!
- \class QMoveEvent
- \brief The QMoveEvent class contains event parameters for move events.
- \ingroup events
- Move events are sent to widgets that have been moved to a new
- position relative to their parent.
- The event handler QWidget::moveEvent() receives move events.
- \sa QWidget::move(), QWidget::setGeometry()
- */
- /*!
- Constructs a move event with the new and old widget positions,
- \a pos and \a oldPos respectively.
- */
- QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
- : QEvent(Move), p(pos), oldp(oldPos)
- {}
- /*!
- \internal
- */
- QMoveEvent::~QMoveEvent()
- {
- }
- /*!
- \fn const QPoint &QMoveEvent::pos() const
- Returns the new position of the widget. This excludes the window
- frame for top level widgets.
- */
- /*!
- \fn const QPoint &QMoveEvent::oldPos() const
- Returns the old position of the widget.
- */
- /*!
- \class QResizeEvent
- \brief The QResizeEvent class contains event parameters for resize events.
- \ingroup events
- Resize events are sent to widgets that have been resized.
- The event handler QWidget::resizeEvent() receives resize events.
- \sa QWidget::resize() QWidget::setGeometry()
- */
- /*!
- Constructs a resize event with the new and old widget sizes, \a
- size and \a oldSize respectively.
- */
- QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
- : QEvent(Resize), s(size), olds(oldSize)
- {}
- /*!
- \internal
- */
- QResizeEvent::~QResizeEvent()
- {
- }
- /*!
- \fn const QSize &QResizeEvent::size() const
- Returns the new size of the widget. This is the same as
- QWidget::size().
- */
- /*!
- \fn const QSize &QResizeEvent::oldSize() const
- Returns the old size of the widget.
- */
- /*!
- \class QCloseEvent
- \brief The QCloseEvent class contains parameters that describe a close event.
- \ingroup events
- Close events are sent to widgets that the user wants to close,
- usually by choosing "Close" from the window menu, or by clicking
- the \gui{X} title bar button. They are also sent when you call
- QWidget::close() to close a widget programmatically.
- Close events contain a flag that indicates whether the receiver
- wants the widget to be closed or not. When a widget accepts the
- close event, it is hidden (and destroyed if it was created with
- the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
- event nothing happens. (Under X11 it is possible that the window
- manager will forcibly close the window; but at the time of writing
- we are not aware of any window manager that does this.)
- The event handler QWidget::closeEvent() receives close events. The
- default implementation of this event handler accepts the close
- event. If you do not want your widget to be hidden, or want some
- special handing, you should reimplement the event handler and
- ignore() the event.
- The \l{mainwindows/application#close event handler}{closeEvent() in the
- Application example} shows a close event handler that
- asks whether to save a document before closing.
- If you want the widget to be deleted when it is closed, create it
- with the Qt::WA_DeleteOnClose flag. This is very useful for
- independent top-level windows in a multi-window application.
- \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
- signal when they are deleted.
- If the last top-level window is closed, the
- QApplication::lastWindowClosed() signal is emitted.
- The isAccepted() function returns true if the event's receiver has
- agreed to close the widget; call accept() to agree to close the
- widget and call ignore() if the receiver of this event does not
- want the widget to be closed.
- \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
- QCoreApplication::exec(), QCoreApplication::quit(),
- QApplication::lastWindowClosed()
- */
- /*!
- Constructs a close event object.
- \sa accept()
- */
- QCloseEvent::QCloseEvent()
- : QEvent(Close)
- {}
- /*! \internal
- */
- QCloseEvent::~QCloseEvent()
- {
- }
- /*!
- \class QIconDragEvent
- \brief The QIconDragEvent class indicates that a main icon drag has begun.
- \ingroup events
- Icon drag events are sent to widgets when the main icon of a window
- has been dragged away. On Mac OS X, this happens when the proxy
- icon of a window is dragged off the title bar.
- It is normal to begin using drag and drop in response to this
- event.
- \sa {Drag and Drop}, QMimeData, QDrag
- */
- /*!
- Constructs an icon drag event object with the accept flag set to
- false.
- \sa accept()
- */
- QIconDragEvent::QIconDragEvent()
- : QEvent(IconDrag)
- { ignore(); }
- /*! \internal */
- QIconDragEvent::~QIconDragEvent()
- {
- }
- /*!
- \class QContextMenuEvent
- \brief The QContextMenuEvent class contains parameters that describe a context menu event.
- \ingroup events
- Context menu events are sent to widgets when a user performs
- an action associated with opening a context menu.
- The actions required to open context menus vary between platforms;
- for example, on Windows, pressing the menu button or clicking the
- right mouse button will cause this event to be sent.
- When this event occurs it is customary to show a QMenu with a
- context menu, if this is relevant to the context.
- Context menu events contain a special accept flag that indicates
- whether the receiver accepted the event. If the event handler does
- not accept the event then, if possible, whatever triggered the event will be
- handled as a regular input event.
- */
- #ifndef QT_NO_CONTEXTMENU
- /*!
- Constructs a context menu event object with the accept parameter
- flag set to false.
- The \a reason parameter must be QContextMenuEvent::Mouse or
- QContextMenuEvent::Keyboard.
- The \a pos parameter specifies the mouse position relative to the
- receiving widget. \a globalPos is the mouse position in absolute
- coordinates.
- */
- QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
- : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
- {}
- /*!
- Constructs a context menu event object with the accept parameter
- flag set to false.
- The \a reason parameter must be QContextMenuEvent::Mouse or
- QContextMenuEvent::Keyboard.
- The \a pos parameter specifies the mouse position relative to the
- receiving widget. \a globalPos is the mouse position in absolute
- coordinates. The \a modifiers holds the keyboard modifiers.
- */
- QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
- Qt::KeyboardModifiers modifiers)
- : QInputEvent(ContextMenu, modifiers), p(pos), gp(globalPos), reas(reason)
- {}
- #ifdef QT3_SUPPORT
- /*!
- Constructs a context menu event with the given \a reason for the
- position specified by \a pos in widget coordinates and \a globalPos
- in global screen coordinates. \a dummy is ignored.
- */
- QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
- int /* dummy */)
- : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
- {}
- #endif
- /*! \internal */
- QContextMenuEvent::~QContextMenuEvent()
- {
- }
- /*!
- Constructs a context menu event object with the accept parameter
- flag set to false.
- The \a reason parameter must be QContextMenuEvent::Mouse or
- QContextMenuEvent::Keyboard.
- The \a pos parameter specifies the mouse position relative to the
- receiving widget.
- The globalPos() is initialized to QCursor::pos(), which may not be
- appropriate. Use the other constructor to specify the global
- position explicitly.
- */
- QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
- : QInputEvent(ContextMenu), p(pos), reas(reason)
- {
- gp = QCursor::pos();
- }
- #ifdef QT3_SUPPORT
- /*!
- Constructs a context menu event with the given \a reason for the
- position specified by \a pos in widget coordinates. \a dummy is
- ignored.
- */
- QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, int /* dummy */)
- : QInputEvent(ContextMenu), p(pos), reas(reason)
- {
- gp = QCursor::pos();
- }
- Qt::ButtonState QContextMenuEvent::state() const
- {
- return Qt::ButtonState(int(QApplication::keyboardModifiers())|QApplication::mouseButtons());
- }
- #endif
- /*!
- \fn const QPoint &QContextMenuEvent::pos() const
- Returns the position of the mouse pointer relative to the widget
- that received the event.
- \sa x(), y(), globalPos()
- */
- /*!
- \fn int QContextMenuEvent::x() const
- Returns the x position of the mouse pointer, relative to the
- widget that received the event.
- \sa y(), pos()
- */
- /*!
- \fn int QContextMenuEvent::y() const
- Returns the y position of the mouse pointer, relative to the
- widget that received the event.
- \sa x(), pos()
- */
- /*!
- \fn const QPoint &QContextMenuEvent::globalPos() const
- Returns the global position of the mouse pointer at the time of
- the event.
- \sa x(), y(), pos()
- */
- /*!
- \fn int QContextMenuEvent::globalX() const
- Returns the global x position of the mouse pointer at the time of
- the event.
- \sa globalY(), globalPos()
- */
- /*!
- \fn int QContextMenuEvent::globalY() const
- Returns the global y position of the mouse pointer at the time of
- the event.
- \sa globalX(), globalPos()
- */
- #endif // QT_NO_CONTEXTMENU
- /*!
- \fn Qt::ButtonState QContextMenuEvent::state() const
- Returns the button state (a combination of mouse buttons
- and keyboard modifiers) immediately before the event was
- generated.
- The returned value is a selection of the following values,
- combined with the OR operator:
- Qt::LeftButton, Qt::RightButton, Qt::MidButton,
- Qt::ShiftButton, Qt::ControlButton, and Qt::AltButton.
- */
- /*!
- \enum QContextMenuEvent::Reason
- This enum describes the reason why the event was sent.
- \value Mouse The mouse caused the event to be sent. Normally this
- means the right mouse button was clicked, but this is platform
- dependent.
- \value Keyboard The keyboard caused this event to be sent. On
- Windows, this means the menu button was pressed.
- \value Other The event was sent by some other means (i.e. not by
- the mouse or keyboard).
- */
- /*!
- \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
- Returns the reason for this context event.
- */
- /*!
- \class QInputMethodEvent
- \brief The QInputMethodEvent class provides parameters for input method events.
- \ingroup events
- Input method events are sent to widgets when an input method is
- used to enter text into a widget. Input methods are widely used
- to enter text for languages with non-Latin alphabets.
- Note that when creating custom text editing widgets, the
- Qt::WA_InputMethodEnabled window attribute must be set explicitly
- (using the QWidget::setAttribute() function) in order to receive
- input method events.
- The events are of interest to authors of keyboard entry widgets
- who want to be able to correctly handle languages with complex
- character input. Text input in such languages is usually a three
- step process:
- \list 1
- \o \bold{Starting to Compose}
- When the user presses the first key on a keyboard, an input
- context is created. This input context will contain a string
- of the typed characters.
- \o \bold{Composing}
- With every new key pressed, the input method will try to create a
- matching string for the text typed so far called preedit
- string. While the input context is active, the user can only move
- the cursor inside the string belonging to this input context.
- \o \bold{Completing}
- At some point, the user will activate a user interface component
- (perhaps using a particular key) where they can choose from a
- number of strings matching the text they have typed so far. The
- user can either confirm their choice cancel the input; in either
- case the input context will be closed.
- \endlist
- QInputMethodEvent models these three stages, and transfers the
- information needed to correctly render the intermediate result. A
- QInputMethodEvent has two main parameters: preeditString() and
- commitString(). The preeditString() parameter gives the currently
- active preedit string. The commitString() parameter gives a text
- that should get added to (or replace parts of) the text of the
- editor widget. It usually is a result of the input operations and
- has to be inserted to the widgets text directly before the preedit
- string.
- If the commitString() should replace parts of the of the text in
- the editor, replacementLength() will contain the number of
- characters to be replaced. repla…