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

📄 qgraphicssceneevent.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** 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.******************************************************************************//*!    \class QGraphicsSceneEvent    \brief The QGraphicsSceneEvent class provides a base class for all    graphics view related events.    \since 4.2    \ingroup multimedia    When a QGraphicsView receives Qt mouse, keyboard, and drag and    drop events (QMouseEvent, QKeyEvent, QDragEvent, etc.), it    translates them into instances of QGraphicsSceneEvent subclasses    and forwards them to the QGraphicsScene it displays. The scene    then forwards the events to the relevant items.    For example, when a QGraphicsView receives a QMouseEvent of type    MousePress as a response to a user click, the view sends a    QGraphicsSceneMouseEvent of type GraphicsSceneMousePress to the    underlying QGraphicsScene through its    \l{QGraphicsScene::}{mousePressEvent()} function. The default    QGraphicsScene::mousePressEvent() implementation determines which    item was clicked and forwards the event to    QGraphicsItem::mousePressEvent().    \omit ### Beskrive widget() \endomit    Subclasses such as QGraphicsSceneMouseEvent and    QGraphicsSceneContextMenuEvent provide the coordinates from the    original QEvent in screen, scene, and item coordinates (see    \l{QGraphicsSceneMouseEvent::}{screenPos()},    \l{QGraphicsSceneMouseEvent::}{scenePos()}, and    \l{QGraphicsSceneMouseEvent::}{pos()}). The item coordinates are    set by the QGraphicsScene before it forwards the event to the    event to a QGraphicsItem. The mouse events also add the    possibility to retrieve the coordinates from the last event    received by the view (see    \l{QGraphicsSceneMouseEvent::}{lastScreenPos()},    \l{QGraphicsSceneMouseEvent::}{lastScenePos()}, and    \l{QGraphicsSceneMouseEvent::}{lastPos()}).     \sa QEvent*//*!    \class QGraphicsSceneMouseEvent    \brief The QGraphicsSceneMouseEvent class provides mouse events 	   in the graphics view framework.    \since 4.2    \ingroup multimedia    When a QGraphicsView receives a QMouseEvent, it translates it to    a QGraphicsSceneMouseEvent. The event is then forwarded to the    QGraphicsScene associated with the view.    In addition to containing the item, scene, and screen coordinates    of the event (as pos(), scenePos(), and screenPos()), mouse    events also contain the coordinates of the previous mouse    event received by the view. These can be retrieved with    lastPos(), lastScreenPos(), and lastScenePos().    \sa QGraphicsSceneContextMenuEvent,	QGraphicsSceneHoverEvent, QGraphicsSceneWheelEvent,	QMouseEvent*//*!    \class QGraphicsSceneWheelEvent    \brief The QGraphicsSceneWheelEvent class provides wheel events 	   in the graphics view framework.    \brief The QGraphicsSceneWheelEvent class provides wheel events in the    graphics view framework.    \since 4.2    \ingroup multimedia    \l{QWheelEvent}{QWheelEvent}s received by a QGraphicsView are translated    into QGraphicsSceneWheelEvents; it translates the QWheelEvent::globalPos()    into item, scene, and screen coordinates (pos(), scenePos(), and    screenPos()).    \sa QGraphicsSceneMouseEvent, QGraphicsSceneContextMenuEvent,    QGraphicsSceneHoverEvent, QWheelEvent*//*!    \class QGraphicsSceneContextMenuEvent    \brief The QGraphicsSceneContextMenuEvent class provides context	   menu events in the graphics view framework.    \since 4.2    \ingroup multimedia    A QContextMenuEvent received by a QGraphicsView is translated    into a QGraphicsSceneContextMenuEvent. The    QWheelEvent::globalPos() is translated into item, scene, and    screen coordinates (pos(), scenePos(), and screenPos()).    \sa QGraphicsSceneMouseEvent, QGraphicsSceneWheelEvent,    QContextMenuEvent*//*!    \enum QGraphicsSceneContextMenuEvent::Reason    This enum describes the reason why the context event was sent.    \value Mouse The mouse caused the event to be sent. On most    platforms, this means the right mouse button was clicked.    \value Keyboard The keyboard caused this event to be sent. On    Windows and Mac OS X, 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).*//*!    \class QGraphicsSceneHoverEvent    \brief The QGraphicsSceneHoverEvent class provides hover events 	   in the graphics view framework.    \since 4.2    \ingroup multimedia    When a QGraphicsView receives a QHoverEvent event, it translates    it into QGraphicsSceneHoverEvent. The event is then forwarded to    the QGraphicsScene associated with the view.    \sa QGraphicsSceneMouseEvent, QGraphicsSceneContextMenuEvent,        QGraphicsSceneWheelEvent, QHoverEvent*//*!    \class QGraphicsSceneHelpEvent    \brief The QGraphicsSceneHelpEvent class provides events when a 	   tooltip is requested.    \since 4.2    \ingroup multimedia    When a QGraphicsView receives a QEvent of type    QEvent::ToolTip, it creates a QGraphicsSceneHelpEvent, which is    forwarded to the scene. You can set a tooltip on a QGraphicsItem    with \l{QGraphicsItem::}{setToolTip()}; by default QGraphicsScene    displays the tooltip of the QGraphicsItem with the highest    z-value (i.e, the top-most item) under the mouse position.        QGraphicsView does not forward events when    \l{QWhatsThis}{"What's This"} and \l{QStatusTipEvent}{status tip}    help is requested. If you need this, you can reimplement    QGraphicsView::viewportEvent() and forward QStatusTipEvent    events and \l{QEvent}{QEvents} of type QEvent::WhatsThis to the    scene.    \sa QEvent*//*!    \class QGraphicsSceneDragDropEvent    \brief The QGraphicsSceneDragDropEvent class provides events for	   drag and drop in the graphics view framework.     \since 4.2    \ingroup multimedia    QGraphicsView inherits the drag and drop functionality provided    by QWidget. When it receives a drag and drop event, it translates    it to a QGraphicsSceneDragDropEvent.    QGraphicsSceneDragDropEvent stores events of type    GraphicsSceneDragEnter, GraphicsSceneDragLeave,    GraphicsSceneDragMove, or GraphicsSceneDrop.    QGraphicsSceneDragDropEvent contains the position of the mouse    cursor in both item, scene, and screen coordinates; this can be    retrieved with pos(), scenePos(), and screenPos().    The scene sends the event to the first QGraphicsItem under the    mouse cursor that accepts drops; a graphics item is set to accept    drops with \l{QGraphicsItem::}{setAcceptDrops()}.*/#include "qgraphicssceneevent.h"#ifndef QT_NO_GRAPHICSVIEW#ifndef QT_NO_DEBUG#include <QtCore/qdebug.h>#endif#include <QtCore/qmap.h>#include <QtCore/qstring.h>class QGraphicsSceneEventPrivate{public:    inline QGraphicsSceneEventPrivate()        : widget(0),          q_ptr(0)    { }    inline virtual ~QGraphicsSceneEventPrivate()    { }    QWidget *widget;    QGraphicsSceneEvent *q_ptr;};/*!    \internal    Constructs a generic graphics scene event of the specified \a type.*/QGraphicsSceneEvent::QGraphicsSceneEvent(Type type)    : QEvent(type), d_ptr(new QGraphicsSceneEventPrivate){    d_ptr->q_ptr = this;}/*!    \internal    Constructs a generic graphics scene event.*/QGraphicsSceneEvent::QGraphicsSceneEvent(QGraphicsSceneEventPrivate &dd, Type type)    : QEvent(type), d_ptr(&dd){    d_ptr->q_ptr = this;}/*!    Destroys the event.*/QGraphicsSceneEvent::~QGraphicsSceneEvent(){    delete d_ptr;}/*!    Returns the widget where the event originated, or 0 if the event    originates from another application.*/QWidget *QGraphicsSceneEvent::widget() const{    return d_ptr->widget;}/*!    \internal    Sets the \a widget related to this event.    \sa widget()*/void QGraphicsSceneEvent::setWidget(QWidget *widget){    d_ptr->widget = widget;}class QGraphicsSceneMouseEventPrivate : public QGraphicsSceneEventPrivate{    Q_DECLARE_PUBLIC(QGraphicsSceneMouseEvent)public:    inline QGraphicsSceneMouseEventPrivate()        : button(Qt::NoButton),          buttons(0), modifiers(0)    { }    QPointF pos;    QPointF scenePos;    QPoint screenPos;    QPointF lastPos;    QPointF lastScenePos;    QPoint lastScreenPos;    QMap<Qt::MouseButton, QPointF> buttonDownPos;    QMap<Qt::MouseButton, QPointF> buttonDownScenePos;    QMap<Qt::MouseButton, QPoint> buttonDownScreenPos;    Qt::MouseButton button;    Qt::MouseButtons buttons;    Qt::KeyboardModifiers modifiers;};/*!    \internal    Constructs a generic graphics scene mouse event of the specified \a type.*/QGraphicsSceneMouseEvent::QGraphicsSceneMouseEvent(Type type)    : QGraphicsSceneEvent(*new QGraphicsSceneMouseEventPrivate, type){}/*!    Destroys the event.*/QGraphicsSceneMouseEvent::~QGraphicsSceneMouseEvent(){}/*!    Returns the mouse cursor position in item coordinates.    \sa scenePos(), screenPos(), lastPos()*/QPointF QGraphicsSceneMouseEvent::pos() const{    Q_D(const QGraphicsSceneMouseEvent);    return d->pos;}/*!    \internal*/void QGraphicsSceneMouseEvent::setPos(const QPointF &pos){    Q_D(QGraphicsSceneMouseEvent);    d->pos = pos;}/*!    Returns the mouse cursor position in scene coordinates.    \sa pos(), screenPos(), lastScenePos()*/QPointF QGraphicsSceneMouseEvent::scenePos() const{    Q_D(const QGraphicsSceneMouseEvent);    return d->scenePos;}/*!    \internal*/void QGraphicsSceneMouseEvent::setScenePos(const QPointF &pos){    Q_D(QGraphicsSceneMouseEvent);    d->scenePos = pos;}/*!    Returns the mouse cursor position in screen coordinates.    \sa pos(), scenePos(), lastScreenPos()*/QPoint QGraphicsSceneMouseEvent::screenPos() const{    Q_D(const QGraphicsSceneMouseEvent);    return d->screenPos;}/*!    \internal*/void QGraphicsSceneMouseEvent::setScreenPos(const QPoint &pos){    Q_D(QGraphicsSceneMouseEvent);    d->screenPos = pos;}/*!    Returns the mouse cursor position in item coordinates where the specified    \a button was clicked.    \sa buttonDownScenePos(), buttonDownScreenPos(), pos()*/QPointF QGraphicsSceneMouseEvent::buttonDownPos(Qt::MouseButton button) const{    Q_D(const QGraphicsSceneMouseEvent);    return d->buttonDownPos.value(button);}/*!    \internal*/void QGraphicsSceneMouseEvent::setButtonDownPos(Qt::MouseButton button, const QPointF &pos){    Q_D(QGraphicsSceneMouseEvent);    d->buttonDownPos.insert(button, pos);}/*!    Returns the mouse cursor position in scene coordinates where the    specified \a button was clicked.    \sa buttonDownPos(), buttonDownScreenPos(), scenePos()*/QPointF QGraphicsSceneMouseEvent::buttonDownScenePos(Qt::MouseButton button) const{    Q_D(const QGraphicsSceneMouseEvent);    return d->buttonDownScenePos.value(button);}/*!    \internal*/void QGraphicsSceneMouseEvent::setButtonDownScenePos(Qt::MouseButton button, const QPointF &pos){    Q_D(QGraphicsSceneMouseEvent);    d->buttonDownScenePos.insert(button, pos);}/*!    Returns the mouse cursor position in screen coordinates where the    specified \a button was clicked.    \sa screenPos(), buttonDownPos(), buttonDownScenePos()*/QPoint QGraphicsSceneMouseEvent::buttonDownScreenPos(Qt::MouseButton button) const{    Q_D(const QGraphicsSceneMouseEvent);    return d->buttonDownScreenPos.value(button);}/*!    \internal*/void QGraphicsSceneMouseEvent::setButtonDownScreenPos(Qt::MouseButton button, const QPoint &pos){    Q_D(QGraphicsSceneMouseEvent);    d->buttonDownScreenPos.insert(button, pos);}/*!    Returns the last recorded mouse cursor position in item    coordinates.    \sa lastScenePos(), lastScreenPos(), pos()*/QPointF QGraphicsSceneMouseEvent::lastPos() const{    Q_D(const QGraphicsSceneMouseEvent);    return d->lastPos;}/*!    \internal*/void QGraphicsSceneMouseEvent::setLastPos(const QPointF &pos)

⌨️ 快捷键说明

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