⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qevent.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.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 GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qevent.h"#include "qcursor.h"#include "qapplication.h"#include "private/qapplication_p.h"#include "private/qkeysequence_p.h"#include "qwidget.h"#include "qdebug.h"#include "qmime.h"#include "qdnd_p.h"#include "qevent_p.h"/*!    \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()*//*!    \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.    The state of the keyboard modifier keys can be found by calling the    \l{QInputEvent::modifiers()}{modifiers()} function, inhertied 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){}/*!    \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.*//*!    \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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -