| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | /*! |
| 5 | \class QGraphicsSceneEvent |
| 6 | \brief The QGraphicsSceneEvent class provides a base class for all |
| 7 | graphics view related events. |
| 8 | \since 4.2 |
| 9 | \ingroup graphicsview-api |
| 10 | \inmodule QtWidgets |
| 11 | |
| 12 | When a QGraphicsView receives Qt mouse, keyboard, and drag and |
| 13 | drop events (QMouseEvent, QKeyEvent, QDragEvent, etc.), it |
| 14 | translates them into instances of QGraphicsSceneEvent subclasses |
| 15 | and forwards them to the QGraphicsScene it displays. The scene |
| 16 | then forwards the events to the relevant items. |
| 17 | |
| 18 | For example, when a QGraphicsView receives a QMouseEvent of type |
| 19 | MousePress as a response to a user click, the view sends a |
| 20 | QGraphicsSceneMouseEvent of type GraphicsSceneMousePress to the |
| 21 | underlying QGraphicsScene through its |
| 22 | \l{QGraphicsScene::}{mousePressEvent()} function. The default |
| 23 | QGraphicsScene::mousePressEvent() implementation determines which |
| 24 | item was clicked and forwards the event to |
| 25 | QGraphicsItem::mousePressEvent(). |
| 26 | |
| 27 | \omit ### Beskrive widget() \endomit |
| 28 | |
| 29 | Subclasses such as QGraphicsSceneMouseEvent and |
| 30 | QGraphicsSceneContextMenuEvent provide the coordinates from the |
| 31 | original QEvent in screen, scene, and item coordinates (see |
| 32 | \l{QGraphicsSceneMouseEvent::}{screenPos()}, |
| 33 | \l{QGraphicsSceneMouseEvent::}{scenePos()}, and |
| 34 | \l{QGraphicsSceneMouseEvent::}{pos()}). The item coordinates are |
| 35 | set by the QGraphicsScene before it forwards the event to the |
| 36 | event to a QGraphicsItem. The mouse events also add the |
| 37 | possibility to retrieve the coordinates from the last event |
| 38 | received by the view (see |
| 39 | \l{QGraphicsSceneMouseEvent::}{lastScreenPos()}, |
| 40 | \l{QGraphicsSceneMouseEvent::}{lastScenePos()}, and |
| 41 | \l{QGraphicsSceneMouseEvent::}{lastPos()}). |
| 42 | |
| 43 | \sa QEvent |
| 44 | */ |
| 45 | |
| 46 | /*! |
| 47 | \class QGraphicsSceneMouseEvent |
| 48 | \brief The QGraphicsSceneMouseEvent class provides mouse events |
| 49 | in the graphics view framework. |
| 50 | \since 4.2 |
| 51 | \ingroup graphicsview-api |
| 52 | \inmodule QtWidgets |
| 53 | |
| 54 | When a QGraphicsView receives a QMouseEvent, it translates it to a |
| 55 | QGraphicsSceneMouseEvent. The event is then forwarded to the |
| 56 | QGraphicsScene associated with the view. If the event is not |
| 57 | handled by the scene, the view may use it, e.g., for the |
| 58 | \l{QGraphicsView::}{DragMode}. |
| 59 | |
| 60 | In addition to containing the item, scene, and screen coordinates |
| 61 | of the event (as pos(), scenePos(), and screenPos()), mouse |
| 62 | events also contain the coordinates of the previous mouse |
| 63 | event received by the view. These can be retrieved with |
| 64 | lastPos(), lastScreenPos(), and lastScenePos(). |
| 65 | |
| 66 | \sa QGraphicsSceneContextMenuEvent, |
| 67 | QGraphicsSceneHoverEvent, QGraphicsSceneWheelEvent, |
| 68 | QMouseEvent |
| 69 | */ |
| 70 | |
| 71 | /*! |
| 72 | \class QGraphicsSceneWheelEvent |
| 73 | \brief The QGraphicsSceneWheelEvent class provides wheel events |
| 74 | in the graphics view framework. |
| 75 | \brief The QGraphicsSceneWheelEvent class provides wheel events in the |
| 76 | graphics view framework. |
| 77 | \since 4.2 |
| 78 | \ingroup graphicsview-api |
| 79 | \inmodule QtWidgets |
| 80 | |
| 81 | \l{QWheelEvent}{QWheelEvent}s received by a QGraphicsView are translated |
| 82 | into QGraphicsSceneWheelEvents; it translates the QWheelEvent::globalPos() |
| 83 | into item, scene, and screen coordinates (pos(), scenePos(), and |
| 84 | screenPos()). |
| 85 | |
| 86 | \sa QGraphicsSceneMouseEvent, QGraphicsSceneContextMenuEvent, |
| 87 | QGraphicsSceneHoverEvent, QWheelEvent |
| 88 | */ |
| 89 | |
| 90 | /*! |
| 91 | \class QGraphicsSceneContextMenuEvent |
| 92 | \brief The QGraphicsSceneContextMenuEvent class provides context |
| 93 | menu events in the graphics view framework. |
| 94 | \since 4.2 |
| 95 | \ingroup graphicsview-api |
| 96 | \inmodule QtWidgets |
| 97 | |
| 98 | A QContextMenuEvent received by a QGraphicsView is translated |
| 99 | into a QGraphicsSceneContextMenuEvent. The |
| 100 | QContextMenuEvent::globalPos() is translated into item, scene, and |
| 101 | screen coordinates (pos(), scenePos(), and screenPos()). |
| 102 | |
| 103 | \sa QGraphicsSceneMouseEvent, QGraphicsSceneWheelEvent, |
| 104 | QContextMenuEvent |
| 105 | */ |
| 106 | |
| 107 | /*! |
| 108 | \enum QGraphicsSceneContextMenuEvent::Reason |
| 109 | |
| 110 | This enum describes the reason why the context event was sent. |
| 111 | |
| 112 | \value Mouse The mouse caused the event to be sent. On most |
| 113 | platforms, this means the right mouse button was clicked. |
| 114 | |
| 115 | \value Keyboard The keyboard caused this event to be sent. On |
| 116 | Windows and \macos, this means the menu button was pressed. |
| 117 | |
| 118 | \value Other The event was sent by some other means (i.e. not |
| 119 | by the mouse or keyboard). |
| 120 | */ |
| 121 | |
| 122 | /*! |
| 123 | \class QGraphicsSceneHoverEvent |
| 124 | \brief The QGraphicsSceneHoverEvent class provides hover events |
| 125 | in the graphics view framework. |
| 126 | \since 4.2 |
| 127 | \ingroup graphicsview-api |
| 128 | \inmodule QtWidgets |
| 129 | |
| 130 | When a QGraphicsView receives a QHoverEvent event, it translates |
| 131 | it into QGraphicsSceneHoverEvent. The event is then forwarded to |
| 132 | the QGraphicsScene associated with the view. |
| 133 | |
| 134 | \sa QGraphicsSceneMouseEvent, QGraphicsSceneContextMenuEvent, |
| 135 | QGraphicsSceneWheelEvent, QHoverEvent |
| 136 | */ |
| 137 | |
| 138 | /*! |
| 139 | \class QGraphicsSceneHelpEvent |
| 140 | \brief The QGraphicsSceneHelpEvent class provides events when a |
| 141 | tooltip is requested. |
| 142 | \since 4.2 |
| 143 | \ingroup graphicsview-api |
| 144 | \inmodule QtWidgets |
| 145 | |
| 146 | When a QGraphicsView receives a QEvent of type |
| 147 | QEvent::ToolTip, it creates a QGraphicsSceneHelpEvent, which is |
| 148 | forwarded to the scene. You can set a tooltip on a QGraphicsItem |
| 149 | with \l{QGraphicsItem::}{setToolTip()}; by default QGraphicsScene |
| 150 | displays the tooltip of the QGraphicsItem with the highest |
| 151 | z-value (i.e, the top-most item) under the mouse position. |
| 152 | |
| 153 | QGraphicsView does not forward events when |
| 154 | \l{QWhatsThis}{"What's This"} and \l{QStatusTipEvent}{status tip} |
| 155 | help is requested. If you need this, you can reimplement |
| 156 | QGraphicsView::viewportEvent() and forward QStatusTipEvent |
| 157 | events and \l{QEvent}{QEvents} of type QEvent::WhatsThis to the |
| 158 | scene. |
| 159 | |
| 160 | \sa QEvent |
| 161 | */ |
| 162 | |
| 163 | /*! |
| 164 | \class QGraphicsSceneDragDropEvent |
| 165 | \brief The QGraphicsSceneDragDropEvent class provides events for |
| 166 | drag and drop in the graphics view framework. |
| 167 | \since 4.2 |
| 168 | \ingroup graphicsview-api |
| 169 | \inmodule QtWidgets |
| 170 | |
| 171 | QGraphicsView inherits the drag and drop functionality provided |
| 172 | by QWidget. When it receives a drag and drop event, it translates |
| 173 | it to a QGraphicsSceneDragDropEvent. |
| 174 | |
| 175 | QGraphicsSceneDragDropEvent stores events of type |
| 176 | GraphicsSceneDragEnter, GraphicsSceneDragLeave, |
| 177 | GraphicsSceneDragMove, or GraphicsSceneDrop. |
| 178 | |
| 179 | QGraphicsSceneDragDropEvent contains the position of the mouse |
| 180 | cursor in both item, scene, and screen coordinates; this can be |
| 181 | retrieved with pos(), scenePos(), and screenPos(). |
| 182 | |
| 183 | The scene sends the event to the first QGraphicsItem under the |
| 184 | mouse cursor that accepts drops; a graphics item is set to accept |
| 185 | drops with \l{QGraphicsItem::}{setAcceptDrops()}. |
| 186 | */ |
| 187 | |
| 188 | /*! |
| 189 | \class QGraphicsSceneResizeEvent |
| 190 | \brief The QGraphicsSceneResizeEvent class provides events for widget |
| 191 | resizing in the graphics view framework. |
| 192 | \since 4.4 |
| 193 | \ingroup graphicsview-api |
| 194 | \inmodule QtWidgets |
| 195 | |
| 196 | A QGraphicsWidget sends itself a QGraphicsSceneResizeEvent immediately |
| 197 | when its geometry changes. |
| 198 | |
| 199 | It's similar to QResizeEvent, but its sizes, oldSize() and newSize(), use |
| 200 | QSizeF instead of QSize. |
| 201 | |
| 202 | \sa QGraphicsWidget::setGeometry(), QGraphicsWidget::resize() |
| 203 | */ |
| 204 | |
| 205 | /*! |
| 206 | \class QGraphicsSceneMoveEvent |
| 207 | \brief The QGraphicsSceneMoveEvent class provides events for widget |
| 208 | moving in the graphics view framework. |
| 209 | \since 4.4 |
| 210 | \ingroup graphicsview-api |
| 211 | \inmodule QtWidgets |
| 212 | |
| 213 | A QGraphicsWidget sends itself a QGraphicsSceneMoveEvent immediately when |
| 214 | its local position changes. The delivery is implemented as part of |
| 215 | QGraphicsItem::itemChange(). |
| 216 | |
| 217 | It's similar to QMoveEvent, but its positions, oldPos() and newPos(), use |
| 218 | QPointF instead of QPoint. |
| 219 | |
| 220 | \sa QGraphicsItem::setPos(), QGraphicsItem::ItemPositionChange, |
| 221 | QGraphicsItem::ItemPositionHasChanged |
| 222 | */ |
| 223 | |
| 224 | #include "qgraphicssceneevent.h" |
| 225 | |
| 226 | #ifndef QT_NO_DEBUG_STREAM |
| 227 | #include <QtCore/qdebug.h> |
| 228 | #include <private/qdebug_p.h> |
| 229 | #endif |
| 230 | #include <QtCore/qmap.h> |
| 231 | #include <QtCore/qpoint.h> |
| 232 | #include <QtCore/qsize.h> |
| 233 | #include <QtCore/qstring.h> |
| 234 | #include "qgraphicsview.h" |
| 235 | #include "qgraphicsitem.h" |
| 236 | #include <QtWidgets/qgesture.h> |
| 237 | #include <private/qevent_p.h> |
| 238 | |
| 239 | QT_BEGIN_NAMESPACE |
| 240 | |
| 241 | class QGraphicsSceneEventPrivate |
| 242 | { |
| 243 | public: |
| 244 | inline QGraphicsSceneEventPrivate() |
| 245 | : widget(nullptr), |
| 246 | q_ptr(nullptr) |
| 247 | { } |
| 248 | |
| 249 | inline virtual ~QGraphicsSceneEventPrivate() |
| 250 | { } |
| 251 | |
| 252 | QWidget *widget; |
| 253 | QGraphicsSceneEvent *q_ptr; |
| 254 | quint64 timestamp = 0; |
| 255 | }; |
| 256 | |
| 257 | /*! |
| 258 | \internal |
| 259 | |
| 260 | Constructs a generic graphics scene event of the specified \a type. |
| 261 | */ |
| 262 | QGraphicsSceneEvent::QGraphicsSceneEvent(Type type) |
| 263 | : QEvent(type), d_ptr(new QGraphicsSceneEventPrivate) |
| 264 | { |
| 265 | d_ptr->q_ptr = this; |
| 266 | } |
| 267 | |
| 268 | /*! |
| 269 | \internal |
| 270 | |
| 271 | Constructs a generic graphics scene event. |
| 272 | */ |
| 273 | QGraphicsSceneEvent::QGraphicsSceneEvent(QGraphicsSceneEventPrivate &dd, Type type) |
| 274 | : QEvent(type), d_ptr(&dd) |
| 275 | { |
| 276 | d_ptr->q_ptr = this; |
| 277 | } |
| 278 | |
| 279 | /*! |
| 280 | Destroys the event. |
| 281 | */ |
| 282 | QGraphicsSceneEvent::~QGraphicsSceneEvent() |
| 283 | { |
| 284 | } |
| 285 | |
| 286 | /*! |
| 287 | Returns the widget where the event originated, or \nullptr if the |
| 288 | event originates from another application. |
| 289 | */ |
| 290 | QWidget *QGraphicsSceneEvent::widget() const |
| 291 | { |
| 292 | return d_ptr->widget; |
| 293 | } |
| 294 | |
| 295 | /*! |
| 296 | \internal |
| 297 | |
| 298 | Sets the \a widget related to this event. |
| 299 | |
| 300 | \sa widget() |
| 301 | */ |
| 302 | void QGraphicsSceneEvent::setWidget(QWidget *widget) |
| 303 | { |
| 304 | d_ptr->widget = widget; |
| 305 | } |
| 306 | |
| 307 | /*! |
| 308 | \since 6.2 |
| 309 | |
| 310 | Returns the timestamp of the original event, or 0 if the |
| 311 | original event does not report a time stamp. |
| 312 | */ |
| 313 | quint64 QGraphicsSceneEvent::timestamp() const |
| 314 | { |
| 315 | return d_ptr->timestamp; |
| 316 | } |
| 317 | /*! |
| 318 | \internal |
| 319 | |
| 320 | Sets the timestamp for the event to \a ts. |
| 321 | */ |
| 322 | void QGraphicsSceneEvent::setTimestamp(quint64 ts) |
| 323 | { |
| 324 | d_ptr->timestamp = ts; |
| 325 | } |
| 326 | |
| 327 | class QGraphicsSceneMouseEventPrivate : public QGraphicsSceneEventPrivate |
| 328 | { |
| 329 | Q_DECLARE_PUBLIC(QGraphicsSceneMouseEvent) |
| 330 | public: |
| 331 | inline QGraphicsSceneMouseEventPrivate() |
| 332 | : button(Qt::NoButton), source(Qt::MouseEventNotSynthesized) |
| 333 | { } |
| 334 | |
| 335 | QPointF pos; |
| 336 | QPointF scenePos; |
| 337 | QPoint screenPos; |
| 338 | QPointF lastPos; |
| 339 | QPointF lastScenePos; |
| 340 | QPoint lastScreenPos; |
| 341 | QMap<Qt::MouseButton, QPointF> buttonDownPos; |
| 342 | QMap<Qt::MouseButton, QPointF> buttonDownScenePos; |
| 343 | QMap<Qt::MouseButton, QPoint> buttonDownScreenPos; |
| 344 | Qt::MouseButton button; |
| 345 | Qt::MouseButtons buttons; |
| 346 | Qt::KeyboardModifiers modifiers; |
| 347 | Qt::MouseEventSource source; |
| 348 | Qt::MouseEventFlags flags; |
| 349 | }; |
| 350 | |
| 351 | /*! |
| 352 | \internal |
| 353 | |
| 354 | Constructs a generic graphics scene mouse event of the specified \a type. |
| 355 | */ |
| 356 | QGraphicsSceneMouseEvent::QGraphicsSceneMouseEvent(Type type) |
| 357 | : QGraphicsSceneEvent(*new QGraphicsSceneMouseEventPrivate, type) |
| 358 | { |
| 359 | } |
| 360 | |
| 361 | /*! |
| 362 | Destroys the event. |
| 363 | */ |
| 364 | QGraphicsSceneMouseEvent::~QGraphicsSceneMouseEvent() |
| 365 | { |
| 366 | } |
| 367 | |
| 368 | /*! |
| 369 | Returns the mouse cursor position in item coordinates. |
| 370 | |
| 371 | \sa scenePos(), screenPos(), lastPos() |
| 372 | */ |
| 373 | QPointF QGraphicsSceneMouseEvent::pos() const |
| 374 | { |
| 375 | Q_D(const QGraphicsSceneMouseEvent); |
| 376 | return d->pos; |
| 377 | } |
| 378 | |
| 379 | /*! |
| 380 | \internal |
| 381 | */ |
| 382 | void QGraphicsSceneMouseEvent::setPos(const QPointF &pos) |
| 383 | { |
| 384 | Q_D(QGraphicsSceneMouseEvent); |
| 385 | d->pos = pos; |
| 386 | } |
| 387 | |
| 388 | /*! |
| 389 | Returns the mouse cursor position in scene coordinates. |
| 390 | |
| 391 | \sa pos(), screenPos(), lastScenePos() |
| 392 | */ |
| 393 | QPointF QGraphicsSceneMouseEvent::scenePos() const |
| 394 | { |
| 395 | Q_D(const QGraphicsSceneMouseEvent); |
| 396 | return d->scenePos; |
| 397 | } |
| 398 | |
| 399 | /*! |
| 400 | \internal |
| 401 | */ |
| 402 | void QGraphicsSceneMouseEvent::setScenePos(const QPointF &pos) |
| 403 | { |
| 404 | Q_D(QGraphicsSceneMouseEvent); |
| 405 | d->scenePos = pos; |
| 406 | } |
| 407 | |
| 408 | /*! |
| 409 | Returns the mouse cursor position in screen coordinates. |
| 410 | |
| 411 | \sa pos(), scenePos(), lastScreenPos() |
| 412 | */ |
| 413 | QPoint QGraphicsSceneMouseEvent::screenPos() const |
| 414 | { |
| 415 | Q_D(const QGraphicsSceneMouseEvent); |
| 416 | return d->screenPos; |
| 417 | } |
| 418 | |
| 419 | /*! |
| 420 | \internal |
| 421 | */ |
| 422 | void QGraphicsSceneMouseEvent::setScreenPos(const QPoint &pos) |
| 423 | { |
| 424 | Q_D(QGraphicsSceneMouseEvent); |
| 425 | d->screenPos = pos; |
| 426 | } |
| 427 | |
| 428 | /*! |
| 429 | Returns the mouse cursor position in item coordinates where the specified |
| 430 | \a button was clicked. |
| 431 | |
| 432 | \sa buttonDownScenePos(), buttonDownScreenPos(), pos() |
| 433 | */ |
| 434 | QPointF QGraphicsSceneMouseEvent::buttonDownPos(Qt::MouseButton button) const |
| 435 | { |
| 436 | Q_D(const QGraphicsSceneMouseEvent); |
| 437 | return d->buttonDownPos.value(key: button); |
| 438 | } |
| 439 | |
| 440 | /*! |
| 441 | \internal |
| 442 | */ |
| 443 | void QGraphicsSceneMouseEvent::setButtonDownPos(Qt::MouseButton button, const QPointF &pos) |
| 444 | { |
| 445 | Q_D(QGraphicsSceneMouseEvent); |
| 446 | d->buttonDownPos.insert(key: button, value: pos); |
| 447 | } |
| 448 | |
| 449 | /*! |
| 450 | Returns the mouse cursor position in scene coordinates where the |
| 451 | specified \a button was clicked. |
| 452 | |
| 453 | \sa buttonDownPos(), buttonDownScreenPos(), scenePos() |
| 454 | */ |
| 455 | QPointF QGraphicsSceneMouseEvent::buttonDownScenePos(Qt::MouseButton button) const |
| 456 | { |
| 457 | Q_D(const QGraphicsSceneMouseEvent); |
| 458 | return d->buttonDownScenePos.value(key: button); |
| 459 | } |
| 460 | |
| 461 | /*! |
| 462 | \internal |
| 463 | */ |
| 464 | void QGraphicsSceneMouseEvent::setButtonDownScenePos(Qt::MouseButton button, const QPointF &pos) |
| 465 | { |
| 466 | Q_D(QGraphicsSceneMouseEvent); |
| 467 | d->buttonDownScenePos.insert(key: button, value: pos); |
| 468 | } |
| 469 | |
| 470 | /*! |
| 471 | Returns the mouse cursor position in screen coordinates where the |
| 472 | specified \a button was clicked. |
| 473 | |
| 474 | \sa screenPos(), buttonDownPos(), buttonDownScenePos() |
| 475 | */ |
| 476 | QPoint QGraphicsSceneMouseEvent::buttonDownScreenPos(Qt::MouseButton button) const |
| 477 | { |
| 478 | Q_D(const QGraphicsSceneMouseEvent); |
| 479 | return d->buttonDownScreenPos.value(key: button); |
| 480 | } |
| 481 | |
| 482 | /*! |
| 483 | \internal |
| 484 | */ |
| 485 | void QGraphicsSceneMouseEvent::setButtonDownScreenPos(Qt::MouseButton button, const QPoint &pos) |
| 486 | { |
| 487 | Q_D(QGraphicsSceneMouseEvent); |
| 488 | d->buttonDownScreenPos.insert(key: button, value: pos); |
| 489 | } |
| 490 | |
| 491 | /*! |
| 492 | Returns the last recorded mouse cursor position in item |
| 493 | coordinates. |
| 494 | |
| 495 | \sa lastScenePos(), lastScreenPos(), pos() |
| 496 | */ |
| 497 | QPointF QGraphicsSceneMouseEvent::lastPos() const |
| 498 | { |
| 499 | Q_D(const QGraphicsSceneMouseEvent); |
| 500 | return d->lastPos; |
| 501 | } |
| 502 | |
| 503 | /*! |
| 504 | \internal |
| 505 | */ |
| 506 | void QGraphicsSceneMouseEvent::setLastPos(const QPointF &pos) |
| 507 | { |
| 508 | Q_D(QGraphicsSceneMouseEvent); |
| 509 | d->lastPos = pos; |
| 510 | } |
| 511 | |
| 512 | /*! |
| 513 | Returns the last recorded mouse cursor position in scene |
| 514 | coordinates. The last recorded position is the position of |
| 515 | the previous mouse event received by the view that created |
| 516 | the event. |
| 517 | |
| 518 | \sa lastPos(), lastScreenPos(), scenePos() |
| 519 | */ |
| 520 | QPointF QGraphicsSceneMouseEvent::lastScenePos() const |
| 521 | { |
| 522 | Q_D(const QGraphicsSceneMouseEvent); |
| 523 | return d->lastScenePos; |
| 524 | } |
| 525 | |
| 526 | /*! |
| 527 | \internal |
| 528 | */ |
| 529 | void QGraphicsSceneMouseEvent::setLastScenePos(const QPointF &pos) |
| 530 | { |
| 531 | Q_D(QGraphicsSceneMouseEvent); |
| 532 | d->lastScenePos = pos; |
| 533 | } |
| 534 | |
| 535 | /*! |
| 536 | Returns the last recorded mouse cursor position in screen |
| 537 | coordinates. The last recorded position is the position of |
| 538 | the previous mouse event received by the view that created |
| 539 | the event. |
| 540 | |
| 541 | \sa lastPos(), lastScenePos(), screenPos() |
| 542 | */ |
| 543 | QPoint QGraphicsSceneMouseEvent::lastScreenPos() const |
| 544 | { |
| 545 | Q_D(const QGraphicsSceneMouseEvent); |
| 546 | return d->lastScreenPos; |
| 547 | } |
| 548 | |
| 549 | /*! |
| 550 | \internal |
| 551 | */ |
| 552 | void QGraphicsSceneMouseEvent::setLastScreenPos(const QPoint &pos) |
| 553 | { |
| 554 | Q_D(QGraphicsSceneMouseEvent); |
| 555 | d->lastScreenPos = pos; |
| 556 | } |
| 557 | |
| 558 | /*! |
| 559 | Returns the combination of mouse buttons that were pressed at the |
| 560 | time the event was sent. |
| 561 | |
| 562 | \sa button(), modifiers() |
| 563 | */ |
| 564 | Qt::MouseButtons QGraphicsSceneMouseEvent::buttons() const |
| 565 | { |
| 566 | Q_D(const QGraphicsSceneMouseEvent); |
| 567 | return d->buttons; |
| 568 | } |
| 569 | |
| 570 | /*! |
| 571 | \internal |
| 572 | */ |
| 573 | void QGraphicsSceneMouseEvent::setButtons(Qt::MouseButtons buttons) |
| 574 | { |
| 575 | Q_D(QGraphicsSceneMouseEvent); |
| 576 | d->buttons = buttons; |
| 577 | } |
| 578 | |
| 579 | /*! |
| 580 | Returns the mouse button (if any) that caused the event. |
| 581 | |
| 582 | \sa buttons(), modifiers() |
| 583 | */ |
| 584 | Qt::MouseButton QGraphicsSceneMouseEvent::button() const |
| 585 | { |
| 586 | Q_D(const QGraphicsSceneMouseEvent); |
| 587 | return d->button; |
| 588 | } |
| 589 | |
| 590 | /*! |
| 591 | \internal |
| 592 | */ |
| 593 | void QGraphicsSceneMouseEvent::setButton(Qt::MouseButton button) |
| 594 | { |
| 595 | Q_D(QGraphicsSceneMouseEvent); |
| 596 | d->button = button; |
| 597 | } |
| 598 | |
| 599 | /*! |
| 600 | Returns the keyboard modifiers in use at the time the event was |
| 601 | sent. |
| 602 | |
| 603 | \sa buttons(), button() |
| 604 | */ |
| 605 | Qt::KeyboardModifiers QGraphicsSceneMouseEvent::modifiers() const |
| 606 | { |
| 607 | Q_D(const QGraphicsSceneMouseEvent); |
| 608 | return d->modifiers; |
| 609 | } |
| 610 | |
| 611 | /*! |
| 612 | \since 5.4 |
| 613 | |
| 614 | Returns information about the mouse event source. |
| 615 | |
| 616 | The mouse event source can be used to distinguish between genuine |
| 617 | and artificial mouse events. The latter are events that are |
| 618 | synthesized from touch events by the operating system or Qt itself. |
| 619 | |
| 620 | \sa Qt::MouseEventSource |
| 621 | \sa QMouseEvent::source() |
| 622 | */ |
| 623 | Qt::MouseEventSource QGraphicsSceneMouseEvent::source() const |
| 624 | { |
| 625 | Q_D(const QGraphicsSceneMouseEvent); |
| 626 | return d->source; |
| 627 | } |
| 628 | |
| 629 | /*! |
| 630 | \since 5.4 |
| 631 | \internal |
| 632 | */ |
| 633 | void QGraphicsSceneMouseEvent::setSource(Qt::MouseEventSource source) |
| 634 | { |
| 635 | Q_D(QGraphicsSceneMouseEvent); |
| 636 | d->source = source; |
| 637 | } |
| 638 | |
| 639 | /*! |
| 640 | \since 5.4 |
| 641 | |
| 642 | Returns the mouse event flags. |
| 643 | |
| 644 | The mouse event flags provide additional information about a mouse event. |
| 645 | |
| 646 | \sa Qt::MouseEventFlag |
| 647 | \sa QMouseEvent::flags() |
| 648 | */ |
| 649 | Qt::MouseEventFlags QGraphicsSceneMouseEvent::flags() const |
| 650 | { |
| 651 | Q_D(const QGraphicsSceneMouseEvent); |
| 652 | return d->flags; |
| 653 | } |
| 654 | |
| 655 | /*! |
| 656 | \since 5.4 |
| 657 | \internal |
| 658 | */ |
| 659 | void QGraphicsSceneMouseEvent::setFlags(Qt::MouseEventFlags flags) |
| 660 | { |
| 661 | Q_D(QGraphicsSceneMouseEvent); |
| 662 | d->flags = flags; |
| 663 | } |
| 664 | |
| 665 | /*! |
| 666 | \internal |
| 667 | */ |
| 668 | void QGraphicsSceneMouseEvent::setModifiers(Qt::KeyboardModifiers modifiers) |
| 669 | { |
| 670 | Q_D(QGraphicsSceneMouseEvent); |
| 671 | d->modifiers = modifiers; |
| 672 | } |
| 673 | |
| 674 | class QGraphicsSceneWheelEventPrivate : public QGraphicsSceneEventPrivate |
| 675 | { |
| 676 | Q_DECLARE_PUBLIC(QGraphicsSceneWheelEvent) |
| 677 | public: |
| 678 | inline QGraphicsSceneWheelEventPrivate() = default; |
| 679 | |
| 680 | QPointF pos; |
| 681 | QPointF scenePos; |
| 682 | QPoint screenPos; |
| 683 | QPoint pixelDelta; |
| 684 | Qt::MouseButtons buttons; |
| 685 | Qt::KeyboardModifiers modifiers; |
| 686 | int delta = 0; |
| 687 | Qt::Orientation orientation = Qt::Horizontal; |
| 688 | Qt::ScrollPhase scrollPhase = Qt::NoScrollPhase; |
| 689 | bool inverted = false; |
| 690 | }; |
| 691 | |
| 692 | /*! |
| 693 | \internal |
| 694 | |
| 695 | Constructs a QGraphicsSceneWheelEvent of type \a type, which |
| 696 | is always QEvent::GraphicsSceneWheel. |
| 697 | */ |
| 698 | QGraphicsSceneWheelEvent::QGraphicsSceneWheelEvent(Type type) |
| 699 | : QGraphicsSceneEvent(*new QGraphicsSceneWheelEventPrivate, type) |
| 700 | { |
| 701 | } |
| 702 | |
| 703 | /*! |
| 704 | Destroys the QGraphicsSceneWheelEvent. |
| 705 | */ |
| 706 | QGraphicsSceneWheelEvent::~QGraphicsSceneWheelEvent() |
| 707 | { |
| 708 | } |
| 709 | |
| 710 | /*! |
| 711 | Returns the position of the cursor in item coordinates when the |
| 712 | wheel event occurred. |
| 713 | |
| 714 | \sa scenePos(), screenPos() |
| 715 | */ |
| 716 | QPointF QGraphicsSceneWheelEvent::pos() const |
| 717 | { |
| 718 | Q_D(const QGraphicsSceneWheelEvent); |
| 719 | return d->pos; |
| 720 | } |
| 721 | |
| 722 | /*! |
| 723 | \internal |
| 724 | */ |
| 725 | void QGraphicsSceneWheelEvent::setPos(const QPointF &pos) |
| 726 | { |
| 727 | Q_D(QGraphicsSceneWheelEvent); |
| 728 | d->pos = pos; |
| 729 | } |
| 730 | |
| 731 | /*! |
| 732 | Returns the position of the cursor in scene coordinates when the wheel |
| 733 | event occurred. |
| 734 | |
| 735 | \sa pos(), screenPos() |
| 736 | */ |
| 737 | QPointF QGraphicsSceneWheelEvent::scenePos() const |
| 738 | { |
| 739 | Q_D(const QGraphicsSceneWheelEvent); |
| 740 | return d->scenePos; |
| 741 | } |
| 742 | |
| 743 | /*! |
| 744 | \internal |
| 745 | */ |
| 746 | void QGraphicsSceneWheelEvent::setScenePos(const QPointF &pos) |
| 747 | { |
| 748 | Q_D(QGraphicsSceneWheelEvent); |
| 749 | d->scenePos = pos; |
| 750 | } |
| 751 | |
| 752 | /*! |
| 753 | Returns the position of the cursor in screen coordinates when the wheel |
| 754 | event occurred. |
| 755 | |
| 756 | \sa pos(), scenePos() |
| 757 | */ |
| 758 | QPoint QGraphicsSceneWheelEvent::screenPos() const |
| 759 | { |
| 760 | Q_D(const QGraphicsSceneWheelEvent); |
| 761 | return d->screenPos; |
| 762 | } |
| 763 | |
| 764 | /*! |
| 765 | \internal |
| 766 | */ |
| 767 | void QGraphicsSceneWheelEvent::setScreenPos(const QPoint &pos) |
| 768 | { |
| 769 | Q_D(QGraphicsSceneWheelEvent); |
| 770 | d->screenPos = pos; |
| 771 | } |
| 772 | |
| 773 | /*! |
| 774 | Returns the mouse buttons that were pressed when the wheel event occurred. |
| 775 | |
| 776 | \sa modifiers() |
| 777 | */ |
| 778 | Qt::MouseButtons QGraphicsSceneWheelEvent::buttons() const |
| 779 | { |
| 780 | Q_D(const QGraphicsSceneWheelEvent); |
| 781 | return d->buttons; |
| 782 | } |
| 783 | |
| 784 | /*! |
| 785 | \internal |
| 786 | */ |
| 787 | void QGraphicsSceneWheelEvent::setButtons(Qt::MouseButtons buttons) |
| 788 | { |
| 789 | Q_D(QGraphicsSceneWheelEvent); |
| 790 | d->buttons = buttons; |
| 791 | } |
| 792 | |
| 793 | /*! |
| 794 | Returns the keyboard modifiers that were active when the wheel event |
| 795 | occurred. |
| 796 | |
| 797 | \sa buttons() |
| 798 | */ |
| 799 | Qt::KeyboardModifiers QGraphicsSceneWheelEvent::modifiers() const |
| 800 | { |
| 801 | Q_D(const QGraphicsSceneWheelEvent); |
| 802 | return d->modifiers; |
| 803 | } |
| 804 | |
| 805 | /*! |
| 806 | \internal |
| 807 | */ |
| 808 | void QGraphicsSceneWheelEvent::setModifiers(Qt::KeyboardModifiers modifiers) |
| 809 | { |
| 810 | Q_D(QGraphicsSceneWheelEvent); |
| 811 | d->modifiers = modifiers; |
| 812 | } |
| 813 | |
| 814 | /*! |
| 815 | Returns the distance that the wheel is rotated, in eighths (1/8s) |
| 816 | of a degree. A positive value indicates that the wheel was |
| 817 | rotated forwards away from the user; a negative value indicates |
| 818 | that the wheel was rotated backwards toward the user. |
| 819 | |
| 820 | Most mouse types work in steps of 15 degrees, in which case the delta |
| 821 | value is a multiple of 120 (== 15 * 8). |
| 822 | */ |
| 823 | int QGraphicsSceneWheelEvent::delta() const |
| 824 | { |
| 825 | Q_D(const QGraphicsSceneWheelEvent); |
| 826 | return d->delta; |
| 827 | } |
| 828 | |
| 829 | /*! |
| 830 | \internal |
| 831 | */ |
| 832 | void QGraphicsSceneWheelEvent::setDelta(int delta) |
| 833 | { |
| 834 | Q_D(QGraphicsSceneWheelEvent); |
| 835 | d->delta = delta; |
| 836 | } |
| 837 | |
| 838 | /*! |
| 839 | Returns the wheel orientation. |
| 840 | */ |
| 841 | Qt::Orientation QGraphicsSceneWheelEvent::orientation() const |
| 842 | { |
| 843 | Q_D(const QGraphicsSceneWheelEvent); |
| 844 | return d->orientation; |
| 845 | } |
| 846 | |
| 847 | /*! |
| 848 | \internal |
| 849 | */ |
| 850 | void QGraphicsSceneWheelEvent::setOrientation(Qt::Orientation orientation) |
| 851 | { |
| 852 | Q_D(QGraphicsSceneWheelEvent); |
| 853 | d->orientation = orientation; |
| 854 | } |
| 855 | |
| 856 | /*! |
| 857 | \since 6.2 |
| 858 | |
| 859 | Returns the scrolling phase of this wheel event. |
| 860 | |
| 861 | \sa QWheelEvent::phase |
| 862 | */ |
| 863 | Qt::ScrollPhase QGraphicsSceneWheelEvent::phase() const |
| 864 | { |
| 865 | Q_D(const QGraphicsSceneWheelEvent); |
| 866 | return d->scrollPhase; |
| 867 | } |
| 868 | |
| 869 | /*! |
| 870 | \internal |
| 871 | */ |
| 872 | void QGraphicsSceneWheelEvent::setPhase(Qt::ScrollPhase scrollPhase) |
| 873 | { |
| 874 | Q_D(QGraphicsSceneWheelEvent); |
| 875 | d->scrollPhase = scrollPhase; |
| 876 | } |
| 877 | |
| 878 | /*! |
| 879 | \since 6.2 |
| 880 | |
| 881 | Returns the scrolling distance in pixels on screen. This value is |
| 882 | provided on platforms that support high-resolution pixel-based |
| 883 | delta values, such as \macos. The value should be used directly |
| 884 | to scroll content on screen. |
| 885 | |
| 886 | \sa QWheelEvent::pixelDelta |
| 887 | */ |
| 888 | QPoint QGraphicsSceneWheelEvent::pixelDelta() const |
| 889 | { |
| 890 | Q_D(const QGraphicsSceneWheelEvent); |
| 891 | return d->pixelDelta; |
| 892 | } |
| 893 | |
| 894 | /*! |
| 895 | \internal |
| 896 | */ |
| 897 | void QGraphicsSceneWheelEvent::setPixelDelta(QPoint pixelDelta) |
| 898 | { |
| 899 | Q_D(QGraphicsSceneWheelEvent); |
| 900 | d->pixelDelta = pixelDelta; |
| 901 | } |
| 902 | |
| 903 | /*! |
| 904 | Returns whether the delta values delivered with the event are inverted. |
| 905 | |
| 906 | \since 6.2 |
| 907 | */ |
| 908 | bool QGraphicsSceneWheelEvent::isInverted() const |
| 909 | { |
| 910 | Q_D(const QGraphicsSceneWheelEvent); |
| 911 | return d->inverted; |
| 912 | } |
| 913 | |
| 914 | /*! |
| 915 | \internal |
| 916 | */ |
| 917 | void QGraphicsSceneWheelEvent::setInverted(bool inverted) |
| 918 | { |
| 919 | Q_D(QGraphicsSceneWheelEvent); |
| 920 | d->inverted = inverted; |
| 921 | } |
| 922 | |
| 923 | class : public QGraphicsSceneEventPrivate |
| 924 | { |
| 925 | Q_DECLARE_PUBLIC(QGraphicsSceneContextMenuEvent) |
| 926 | public: |
| 927 | inline () = default; |
| 928 | |
| 929 | QPointF ; |
| 930 | QPointF ; |
| 931 | QPoint ; |
| 932 | Qt::KeyboardModifiers ; |
| 933 | QGraphicsSceneContextMenuEvent::Reason = QGraphicsSceneContextMenuEvent::Other; |
| 934 | }; |
| 935 | |
| 936 | /*! |
| 937 | \internal |
| 938 | |
| 939 | Constructs a graphics scene context menu event of the specified \a type. |
| 940 | */ |
| 941 | QGraphicsSceneContextMenuEvent::(Type type) |
| 942 | : QGraphicsSceneEvent(*new QGraphicsSceneContextMenuEventPrivate, type) |
| 943 | { |
| 944 | } |
| 945 | |
| 946 | /*! |
| 947 | Destroys the event. |
| 948 | */ |
| 949 | QGraphicsSceneContextMenuEvent::() |
| 950 | { |
| 951 | } |
| 952 | |
| 953 | /*! |
| 954 | Returns the position of the mouse cursor in item coordinates at the moment |
| 955 | the context menu was requested. |
| 956 | |
| 957 | \sa scenePos(), screenPos() |
| 958 | */ |
| 959 | QPointF QGraphicsSceneContextMenuEvent::() const |
| 960 | { |
| 961 | Q_D(const QGraphicsSceneContextMenuEvent); |
| 962 | return d->pos; |
| 963 | } |
| 964 | |
| 965 | /*! |
| 966 | \fn void QGraphicsSceneContextMenuEvent::setPos(const QPointF &point) |
| 967 | \internal |
| 968 | |
| 969 | Sets the position associated with the context menu to the given \a point |
| 970 | in item coordinates. |
| 971 | */ |
| 972 | void QGraphicsSceneContextMenuEvent::(const QPointF &pos) |
| 973 | { |
| 974 | Q_D(QGraphicsSceneContextMenuEvent); |
| 975 | d->pos = pos; |
| 976 | } |
| 977 | |
| 978 | /*! |
| 979 | Returns the position of the mouse cursor in scene coordinates at the moment the |
| 980 | context menu was requested. |
| 981 | |
| 982 | \sa pos(), screenPos() |
| 983 | */ |
| 984 | QPointF QGraphicsSceneContextMenuEvent::() const |
| 985 | { |
| 986 | Q_D(const QGraphicsSceneContextMenuEvent); |
| 987 | return d->scenePos; |
| 988 | } |
| 989 | |
| 990 | /*! |
| 991 | \fn void QGraphicsSceneContextMenuEvent::setScenePos(const QPointF &point) |
| 992 | \internal |
| 993 | |
| 994 | Sets the position associated with the context menu to the given \a point |
| 995 | in scene coordinates. |
| 996 | */ |
| 997 | void QGraphicsSceneContextMenuEvent::(const QPointF &pos) |
| 998 | { |
| 999 | Q_D(QGraphicsSceneContextMenuEvent); |
| 1000 | d->scenePos = pos; |
| 1001 | } |
| 1002 | |
| 1003 | /*! |
| 1004 | Returns the position of the mouse cursor in screen coordinates at the moment the |
| 1005 | context menu was requested. |
| 1006 | |
| 1007 | \sa pos(), scenePos() |
| 1008 | */ |
| 1009 | QPoint QGraphicsSceneContextMenuEvent::() const |
| 1010 | { |
| 1011 | Q_D(const QGraphicsSceneContextMenuEvent); |
| 1012 | return d->screenPos; |
| 1013 | } |
| 1014 | |
| 1015 | /*! |
| 1016 | \fn void QGraphicsSceneContextMenuEvent::setScreenPos(const QPoint &point) |
| 1017 | \internal |
| 1018 | |
| 1019 | Sets the position associated with the context menu to the given \a point |
| 1020 | in screen coordinates. |
| 1021 | */ |
| 1022 | void QGraphicsSceneContextMenuEvent::(const QPoint &pos) |
| 1023 | { |
| 1024 | Q_D(QGraphicsSceneContextMenuEvent); |
| 1025 | d->screenPos = pos; |
| 1026 | } |
| 1027 | |
| 1028 | /*! |
| 1029 | Returns the keyboard modifiers in use when the context menu was requested. |
| 1030 | */ |
| 1031 | Qt::KeyboardModifiers QGraphicsSceneContextMenuEvent::() const |
| 1032 | { |
| 1033 | Q_D(const QGraphicsSceneContextMenuEvent); |
| 1034 | return d->modifiers; |
| 1035 | } |
| 1036 | |
| 1037 | /*! |
| 1038 | \internal |
| 1039 | |
| 1040 | Sets the keyboard modifiers associated with the context menu to the \a |
| 1041 | modifiers specified. |
| 1042 | */ |
| 1043 | void QGraphicsSceneContextMenuEvent::(Qt::KeyboardModifiers modifiers) |
| 1044 | { |
| 1045 | Q_D(QGraphicsSceneContextMenuEvent); |
| 1046 | d->modifiers = modifiers; |
| 1047 | } |
| 1048 | |
| 1049 | /*! |
| 1050 | Returns the reason for the context menu event. |
| 1051 | |
| 1052 | \sa QGraphicsSceneContextMenuEvent::Reason |
| 1053 | */ |
| 1054 | QGraphicsSceneContextMenuEvent::Reason QGraphicsSceneContextMenuEvent::() const |
| 1055 | { |
| 1056 | Q_D(const QGraphicsSceneContextMenuEvent); |
| 1057 | return d->reason; |
| 1058 | } |
| 1059 | |
| 1060 | /*! |
| 1061 | \internal |
| 1062 | Sets the reason for the context menu event to \a reason. |
| 1063 | |
| 1064 | \sa reason() |
| 1065 | */ |
| 1066 | void QGraphicsSceneContextMenuEvent::(Reason reason) |
| 1067 | { |
| 1068 | Q_D(QGraphicsSceneContextMenuEvent); |
| 1069 | d->reason = reason; |
| 1070 | } |
| 1071 | |
| 1072 | class QGraphicsSceneHoverEventPrivate : public QGraphicsSceneEventPrivate |
| 1073 | { |
| 1074 | public: |
| 1075 | QPointF pos; |
| 1076 | QPointF scenePos; |
| 1077 | QPoint screenPos; |
| 1078 | QPointF lastPos; |
| 1079 | QPointF lastScenePos; |
| 1080 | QPoint lastScreenPos; |
| 1081 | Qt::KeyboardModifiers modifiers; |
| 1082 | }; |
| 1083 | |
| 1084 | /*! |
| 1085 | \internal |
| 1086 | |
| 1087 | Constructs a graphics scene hover event of the specified \a type. |
| 1088 | */ |
| 1089 | QGraphicsSceneHoverEvent::QGraphicsSceneHoverEvent(Type type) |
| 1090 | : QGraphicsSceneEvent(*new QGraphicsSceneHoverEventPrivate, type) |
| 1091 | { |
| 1092 | } |
| 1093 | |
| 1094 | /*! |
| 1095 | Destroys the event. |
| 1096 | */ |
| 1097 | QGraphicsSceneHoverEvent::~QGraphicsSceneHoverEvent() |
| 1098 | { |
| 1099 | } |
| 1100 | |
| 1101 | /*! |
| 1102 | Returns the position of the mouse cursor in item coordinates at the moment |
| 1103 | the hover event was sent. |
| 1104 | |
| 1105 | \sa scenePos(), screenPos() |
| 1106 | */ |
| 1107 | QPointF QGraphicsSceneHoverEvent::pos() const |
| 1108 | { |
| 1109 | Q_D(const QGraphicsSceneHoverEvent); |
| 1110 | return d->pos; |
| 1111 | } |
| 1112 | |
| 1113 | /*! |
| 1114 | \fn void QGraphicsSceneHoverEvent::setPos(const QPointF &point) |
| 1115 | \internal |
| 1116 | |
| 1117 | Sets the position associated with the hover event to the given \a point in |
| 1118 | item coordinates. |
| 1119 | */ |
| 1120 | void QGraphicsSceneHoverEvent::setPos(const QPointF &pos) |
| 1121 | { |
| 1122 | Q_D(QGraphicsSceneHoverEvent); |
| 1123 | d->pos = pos; |
| 1124 | } |
| 1125 | |
| 1126 | /*! |
| 1127 | Returns the position of the mouse cursor in scene coordinates at the |
| 1128 | moment the hover event was sent. |
| 1129 | |
| 1130 | \sa pos(), screenPos() |
| 1131 | */ |
| 1132 | QPointF QGraphicsSceneHoverEvent::scenePos() const |
| 1133 | { |
| 1134 | Q_D(const QGraphicsSceneHoverEvent); |
| 1135 | return d->scenePos; |
| 1136 | } |
| 1137 | |
| 1138 | /*! |
| 1139 | \fn void QGraphicsSceneHoverEvent::setScenePos(const QPointF &point) |
| 1140 | \internal |
| 1141 | |
| 1142 | Sets the position associated with the hover event to the given \a point in |
| 1143 | scene coordinates. |
| 1144 | */ |
| 1145 | void QGraphicsSceneHoverEvent::setScenePos(const QPointF &pos) |
| 1146 | { |
| 1147 | Q_D(QGraphicsSceneHoverEvent); |
| 1148 | d->scenePos = pos; |
| 1149 | } |
| 1150 | |
| 1151 | /*! |
| 1152 | Returns the position of the mouse cursor in screen coordinates at the |
| 1153 | moment the hover event was sent. |
| 1154 | |
| 1155 | \sa pos(), scenePos() |
| 1156 | */ |
| 1157 | QPoint QGraphicsSceneHoverEvent::screenPos() const |
| 1158 | { |
| 1159 | Q_D(const QGraphicsSceneHoverEvent); |
| 1160 | return d->screenPos; |
| 1161 | } |
| 1162 | |
| 1163 | /*! |
| 1164 | \fn void QGraphicsSceneHoverEvent::setScreenPos(const QPoint &point) |
| 1165 | \internal |
| 1166 | |
| 1167 | Sets the position associated with the hover event to the given \a point in |
| 1168 | screen coordinates. |
| 1169 | */ |
| 1170 | void QGraphicsSceneHoverEvent::setScreenPos(const QPoint &pos) |
| 1171 | { |
| 1172 | Q_D(QGraphicsSceneHoverEvent); |
| 1173 | d->screenPos = pos; |
| 1174 | } |
| 1175 | |
| 1176 | /*! |
| 1177 | \since 4.4 |
| 1178 | |
| 1179 | Returns the last recorded mouse cursor position in item coordinates. |
| 1180 | |
| 1181 | \sa lastScenePos(), lastScreenPos(), pos() |
| 1182 | */ |
| 1183 | QPointF QGraphicsSceneHoverEvent::lastPos() const |
| 1184 | { |
| 1185 | Q_D(const QGraphicsSceneHoverEvent); |
| 1186 | return d->lastPos; |
| 1187 | } |
| 1188 | |
| 1189 | /*! |
| 1190 | \internal |
| 1191 | */ |
| 1192 | void QGraphicsSceneHoverEvent::setLastPos(const QPointF &pos) |
| 1193 | { |
| 1194 | Q_D(QGraphicsSceneHoverEvent); |
| 1195 | d->lastPos = pos; |
| 1196 | } |
| 1197 | |
| 1198 | /*! |
| 1199 | \since 4.4 |
| 1200 | |
| 1201 | Returns the last recorded, the scene coordinates of the previous mouse or |
| 1202 | hover event received by the view, that created the event mouse cursor |
| 1203 | position in scene coordinates. |
| 1204 | |
| 1205 | \sa lastPos(), lastScreenPos(), scenePos() |
| 1206 | */ |
| 1207 | QPointF QGraphicsSceneHoverEvent::lastScenePos() const |
| 1208 | { |
| 1209 | Q_D(const QGraphicsSceneHoverEvent); |
| 1210 | return d->lastScenePos; |
| 1211 | } |
| 1212 | |
| 1213 | /*! |
| 1214 | \internal |
| 1215 | */ |
| 1216 | void QGraphicsSceneHoverEvent::setLastScenePos(const QPointF &pos) |
| 1217 | { |
| 1218 | Q_D(QGraphicsSceneHoverEvent); |
| 1219 | d->lastScenePos = pos; |
| 1220 | } |
| 1221 | |
| 1222 | /*! |
| 1223 | \since 4.4 |
| 1224 | |
| 1225 | Returns the last recorded mouse cursor position in screen coordinates. The |
| 1226 | last recorded position is the position of the previous mouse or hover |
| 1227 | event received by the view that created the event. |
| 1228 | |
| 1229 | \sa lastPos(), lastScenePos(), screenPos() |
| 1230 | */ |
| 1231 | QPoint QGraphicsSceneHoverEvent::lastScreenPos() const |
| 1232 | { |
| 1233 | Q_D(const QGraphicsSceneHoverEvent); |
| 1234 | return d->lastScreenPos; |
| 1235 | } |
| 1236 | |
| 1237 | /*! |
| 1238 | \internal |
| 1239 | */ |
| 1240 | void QGraphicsSceneHoverEvent::setLastScreenPos(const QPoint &pos) |
| 1241 | { |
| 1242 | Q_D(QGraphicsSceneHoverEvent); |
| 1243 | d->lastScreenPos = pos; |
| 1244 | } |
| 1245 | |
| 1246 | /*! |
| 1247 | \since 4.4 |
| 1248 | |
| 1249 | Returns the keyboard modifiers at the moment the hover event was sent. |
| 1250 | */ |
| 1251 | Qt::KeyboardModifiers QGraphicsSceneHoverEvent::modifiers() const |
| 1252 | { |
| 1253 | Q_D(const QGraphicsSceneHoverEvent); |
| 1254 | return d->modifiers; |
| 1255 | } |
| 1256 | |
| 1257 | /*! |
| 1258 | \fn void QGraphicsSceneHoverEvent::setModifiers(Qt::KeyboardModifiers modifiers) |
| 1259 | \internal |
| 1260 | |
| 1261 | Sets the modifiers for the current hover event to \a modifiers. |
| 1262 | */ |
| 1263 | void QGraphicsSceneHoverEvent::setModifiers(Qt::KeyboardModifiers modifiers) |
| 1264 | { |
| 1265 | Q_D(QGraphicsSceneHoverEvent); |
| 1266 | d->modifiers = modifiers; |
| 1267 | } |
| 1268 | |
| 1269 | class QGraphicsSceneHelpEventPrivate : public QGraphicsSceneEventPrivate |
| 1270 | { |
| 1271 | public: |
| 1272 | QPointF scenePos; |
| 1273 | QPoint screenPos; |
| 1274 | }; |
| 1275 | |
| 1276 | /*! |
| 1277 | \internal |
| 1278 | |
| 1279 | Constructs a graphics scene help event of the specified \a type. |
| 1280 | */ |
| 1281 | QGraphicsSceneHelpEvent::QGraphicsSceneHelpEvent(Type type) |
| 1282 | : QGraphicsSceneEvent(*new QGraphicsSceneHelpEventPrivate, type) |
| 1283 | { |
| 1284 | } |
| 1285 | |
| 1286 | /*! |
| 1287 | Destroys the event. |
| 1288 | */ |
| 1289 | QGraphicsSceneHelpEvent::~QGraphicsSceneHelpEvent() |
| 1290 | { |
| 1291 | } |
| 1292 | |
| 1293 | /*! |
| 1294 | Returns the position of the mouse cursor in scene coordinates at the |
| 1295 | moment the help event was sent. |
| 1296 | |
| 1297 | \sa screenPos() |
| 1298 | */ |
| 1299 | QPointF QGraphicsSceneHelpEvent::scenePos() const |
| 1300 | { |
| 1301 | Q_D(const QGraphicsSceneHelpEvent); |
| 1302 | return d->scenePos; |
| 1303 | } |
| 1304 | |
| 1305 | /*! |
| 1306 | \fn void QGraphicsSceneHelpEvent::setScenePos(const QPointF &point) |
| 1307 | \internal |
| 1308 | |
| 1309 | Sets the position associated with the context menu to the given \a point |
| 1310 | in scene coordinates. |
| 1311 | */ |
| 1312 | void QGraphicsSceneHelpEvent::setScenePos(const QPointF &pos) |
| 1313 | { |
| 1314 | Q_D(QGraphicsSceneHelpEvent); |
| 1315 | d->scenePos = pos; |
| 1316 | } |
| 1317 | |
| 1318 | /*! |
| 1319 | Returns the position of the mouse cursor in screen coordinates at the |
| 1320 | moment the help event was sent. |
| 1321 | |
| 1322 | \sa scenePos() |
| 1323 | */ |
| 1324 | QPoint QGraphicsSceneHelpEvent::screenPos() const |
| 1325 | { |
| 1326 | Q_D(const QGraphicsSceneHelpEvent); |
| 1327 | return d->screenPos; |
| 1328 | } |
| 1329 | |
| 1330 | /*! |
| 1331 | \fn void QGraphicsSceneHelpEvent::setScreenPos(const QPoint &point) |
| 1332 | \internal |
| 1333 | |
| 1334 | Sets the position associated with the context menu to the given \a point |
| 1335 | in screen coordinates. |
| 1336 | */ |
| 1337 | void QGraphicsSceneHelpEvent::setScreenPos(const QPoint &pos) |
| 1338 | { |
| 1339 | Q_D(QGraphicsSceneHelpEvent); |
| 1340 | d->screenPos = pos; |
| 1341 | } |
| 1342 | |
| 1343 | class QGraphicsSceneDragDropEventPrivate : public QGraphicsSceneEventPrivate |
| 1344 | { |
| 1345 | Q_DECLARE_PUBLIC(QGraphicsSceneDragDropEvent) |
| 1346 | public: |
| 1347 | inline QGraphicsSceneDragDropEventPrivate() |
| 1348 | : source(nullptr), mimeData(nullptr) |
| 1349 | { } |
| 1350 | |
| 1351 | QPointF pos; |
| 1352 | QPointF scenePos; |
| 1353 | QPoint screenPos; |
| 1354 | Qt::MouseButtons buttons; |
| 1355 | Qt::KeyboardModifiers modifiers; |
| 1356 | Qt::DropActions possibleActions; |
| 1357 | Qt::DropAction proposedAction; |
| 1358 | Qt::DropAction dropAction; |
| 1359 | QWidget *source; |
| 1360 | const QMimeData *mimeData; |
| 1361 | }; |
| 1362 | |
| 1363 | /*! |
| 1364 | \internal |
| 1365 | |
| 1366 | Constructs a new QGraphicsSceneDragDropEvent of the |
| 1367 | specified \a type. The type can be either |
| 1368 | QEvent::GraphicsSceneDragEnter, QEvent::GraphicsSceneDragLeave, |
| 1369 | QEvent::GraphicsSceneDragMove, or QEvent::GraphicsSceneDrop. |
| 1370 | */ |
| 1371 | QGraphicsSceneDragDropEvent::QGraphicsSceneDragDropEvent(Type type) |
| 1372 | : QGraphicsSceneEvent(*new QGraphicsSceneDragDropEventPrivate, type) |
| 1373 | { |
| 1374 | } |
| 1375 | |
| 1376 | /*! |
| 1377 | Destroys the object. |
| 1378 | */ |
| 1379 | QGraphicsSceneDragDropEvent::~QGraphicsSceneDragDropEvent() |
| 1380 | { |
| 1381 | } |
| 1382 | |
| 1383 | /*! |
| 1384 | Returns the mouse position of the event relative to the |
| 1385 | view that sent the event. |
| 1386 | |
| 1387 | \sa QGraphicsView, screenPos(), scenePos() |
| 1388 | */ |
| 1389 | QPointF QGraphicsSceneDragDropEvent::pos() const |
| 1390 | { |
| 1391 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1392 | return d->pos; |
| 1393 | } |
| 1394 | |
| 1395 | /*! |
| 1396 | \internal |
| 1397 | Sets the position of the mouse to \a pos; this should be |
| 1398 | relative to the widget that generated the event, which normally |
| 1399 | is a QGraphicsView. |
| 1400 | |
| 1401 | \sa pos(), setScenePos(), setScreenPos() |
| 1402 | */ |
| 1403 | |
| 1404 | void QGraphicsSceneDragDropEvent::setPos(const QPointF &pos) |
| 1405 | { |
| 1406 | Q_D(QGraphicsSceneDragDropEvent); |
| 1407 | d->pos = pos; |
| 1408 | } |
| 1409 | |
| 1410 | /*! |
| 1411 | Returns the position of the mouse in scene coordinates. |
| 1412 | |
| 1413 | \sa pos(), screenPos() |
| 1414 | */ |
| 1415 | QPointF QGraphicsSceneDragDropEvent::scenePos() const |
| 1416 | { |
| 1417 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1418 | return d->scenePos; |
| 1419 | } |
| 1420 | |
| 1421 | /*! |
| 1422 | \internal |
| 1423 | Sets the scene position of the mouse to \a pos. |
| 1424 | |
| 1425 | \sa scenePos(), setScreenPos(), setPos() |
| 1426 | */ |
| 1427 | void QGraphicsSceneDragDropEvent::setScenePos(const QPointF &pos) |
| 1428 | { |
| 1429 | Q_D(QGraphicsSceneDragDropEvent); |
| 1430 | d->scenePos = pos; |
| 1431 | } |
| 1432 | |
| 1433 | /*! |
| 1434 | Returns the position of the mouse relative to the screen. |
| 1435 | |
| 1436 | \sa pos(), scenePos() |
| 1437 | */ |
| 1438 | QPoint QGraphicsSceneDragDropEvent::screenPos() const |
| 1439 | { |
| 1440 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1441 | return d->screenPos; |
| 1442 | } |
| 1443 | |
| 1444 | /*! |
| 1445 | \internal |
| 1446 | Sets the mouse position relative to the screen to \a pos. |
| 1447 | |
| 1448 | \sa screenPos(), setScenePos(), setPos() |
| 1449 | */ |
| 1450 | void QGraphicsSceneDragDropEvent::setScreenPos(const QPoint &pos) |
| 1451 | { |
| 1452 | Q_D(QGraphicsSceneDragDropEvent); |
| 1453 | d->screenPos = pos; |
| 1454 | } |
| 1455 | |
| 1456 | /*! |
| 1457 | Returns a Qt::MouseButtons value indicating which buttons |
| 1458 | were pressed on the mouse when this mouse event was |
| 1459 | generated. |
| 1460 | |
| 1461 | \sa Qt::MouseButtons |
| 1462 | */ |
| 1463 | Qt::MouseButtons QGraphicsSceneDragDropEvent::buttons() const |
| 1464 | { |
| 1465 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1466 | return d->buttons; |
| 1467 | } |
| 1468 | |
| 1469 | /*! |
| 1470 | \internal |
| 1471 | Sets the mouse buttons that were pressed when the event was |
| 1472 | created to \a buttons. |
| 1473 | |
| 1474 | \sa Qt::MouseButtons, buttons() |
| 1475 | */ |
| 1476 | void QGraphicsSceneDragDropEvent::setButtons(Qt::MouseButtons buttons) |
| 1477 | { |
| 1478 | Q_D(QGraphicsSceneDragDropEvent); |
| 1479 | d->buttons = buttons; |
| 1480 | } |
| 1481 | |
| 1482 | /*! |
| 1483 | Returns the keyboard modifiers that were pressed when the drag |
| 1484 | and drop event was created. |
| 1485 | |
| 1486 | \sa Qt::KeyboardModifiers |
| 1487 | */ |
| 1488 | Qt::KeyboardModifiers QGraphicsSceneDragDropEvent::modifiers() const |
| 1489 | { |
| 1490 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1491 | return d->modifiers; |
| 1492 | } |
| 1493 | |
| 1494 | /*! |
| 1495 | \internal |
| 1496 | Sets the keyboard modifiers that were pressed when the event |
| 1497 | was created to \a modifiers. |
| 1498 | |
| 1499 | \sa Qt::KeyboardModifiers, modifiers() |
| 1500 | */ |
| 1501 | |
| 1502 | void QGraphicsSceneDragDropEvent::setModifiers(Qt::KeyboardModifiers modifiers) |
| 1503 | { |
| 1504 | Q_D(QGraphicsSceneDragDropEvent); |
| 1505 | d->modifiers = modifiers; |
| 1506 | } |
| 1507 | |
| 1508 | /*! |
| 1509 | Returns the possible drop actions that the drag and |
| 1510 | drop can result in. |
| 1511 | |
| 1512 | \sa Qt::DropActions |
| 1513 | */ |
| 1514 | |
| 1515 | Qt::DropActions QGraphicsSceneDragDropEvent::possibleActions() const |
| 1516 | { |
| 1517 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1518 | return d->possibleActions; |
| 1519 | } |
| 1520 | |
| 1521 | /*! |
| 1522 | \internal |
| 1523 | Sets the possible drop actions that the drag can |
| 1524 | result in to \a actions. |
| 1525 | |
| 1526 | \sa Qt::DropActions, possibleActions() |
| 1527 | */ |
| 1528 | void QGraphicsSceneDragDropEvent::setPossibleActions(Qt::DropActions actions) |
| 1529 | { |
| 1530 | Q_D(QGraphicsSceneDragDropEvent); |
| 1531 | d->possibleActions = actions; |
| 1532 | } |
| 1533 | |
| 1534 | /*! |
| 1535 | Returns the drop action that is proposed, i.e., preferred. |
| 1536 | The action must be one of the possible actions as defined by |
| 1537 | \c possibleActions(). |
| 1538 | |
| 1539 | \sa Qt::DropAction, possibleActions() |
| 1540 | */ |
| 1541 | |
| 1542 | Qt::DropAction QGraphicsSceneDragDropEvent::proposedAction() const |
| 1543 | { |
| 1544 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1545 | return d->proposedAction; |
| 1546 | } |
| 1547 | |
| 1548 | /*! |
| 1549 | \internal |
| 1550 | Sets the proposed action to \a action. The proposed action |
| 1551 | is a Qt::DropAction that is one of the possible actions as |
| 1552 | given by \c possibleActions(). |
| 1553 | |
| 1554 | \sa proposedAction(), Qt::DropAction, possibleActions() |
| 1555 | */ |
| 1556 | |
| 1557 | void QGraphicsSceneDragDropEvent::setProposedAction(Qt::DropAction action) |
| 1558 | { |
| 1559 | Q_D(QGraphicsSceneDragDropEvent); |
| 1560 | d->proposedAction = action; |
| 1561 | } |
| 1562 | |
| 1563 | /*! |
| 1564 | Sets the proposed action as accepted, i.e, the drop action |
| 1565 | is set to the proposed action. This is equal to: |
| 1566 | |
| 1567 | \snippet code/src_gui_graphicsview_qgraphicssceneevent.cpp 0 |
| 1568 | |
| 1569 | When using this function, one should not call \c accept(). |
| 1570 | |
| 1571 | \sa dropAction(), setDropAction(), proposedAction() |
| 1572 | */ |
| 1573 | |
| 1574 | void QGraphicsSceneDragDropEvent::acceptProposedAction() |
| 1575 | { |
| 1576 | Q_D(QGraphicsSceneDragDropEvent); |
| 1577 | d->dropAction = d->proposedAction; |
| 1578 | } |
| 1579 | |
| 1580 | /*! |
| 1581 | Returns the action that was performed in this drag and drop. |
| 1582 | This should be set by the receiver of the drop and is |
| 1583 | returned by QDrag::exec(). |
| 1584 | |
| 1585 | \sa setDropAction(), acceptProposedAction() |
| 1586 | */ |
| 1587 | |
| 1588 | Qt::DropAction QGraphicsSceneDragDropEvent::dropAction() const |
| 1589 | { |
| 1590 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1591 | return d->dropAction; |
| 1592 | } |
| 1593 | |
| 1594 | /*! |
| 1595 | This function lets the receiver of the drop set the drop |
| 1596 | action that was performed to \a action, which should be one |
| 1597 | of the |
| 1598 | \l{QGraphicsSceneDragDropEvent::possibleActions()}{possible |
| 1599 | actions}. Call \c accept() in stead of \c |
| 1600 | acceptProposedAction() if you use this function. |
| 1601 | |
| 1602 | \sa dropAction(), accept(), possibleActions() |
| 1603 | */ |
| 1604 | void QGraphicsSceneDragDropEvent::setDropAction(Qt::DropAction action) |
| 1605 | { |
| 1606 | Q_D(QGraphicsSceneDragDropEvent); |
| 1607 | d->dropAction = action; |
| 1608 | } |
| 1609 | |
| 1610 | /*! |
| 1611 | This function returns the QGraphicsView that created the |
| 1612 | QGraphicsSceneDragDropEvent. |
| 1613 | */ |
| 1614 | QWidget *QGraphicsSceneDragDropEvent::source() const |
| 1615 | { |
| 1616 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1617 | return d->source; |
| 1618 | } |
| 1619 | |
| 1620 | /*! |
| 1621 | \internal |
| 1622 | This function set the source widget, i.e., the widget that |
| 1623 | created the drop event, to \a source. |
| 1624 | */ |
| 1625 | void QGraphicsSceneDragDropEvent::setSource(QWidget *source) |
| 1626 | { |
| 1627 | Q_D(QGraphicsSceneDragDropEvent); |
| 1628 | d->source = source; |
| 1629 | } |
| 1630 | |
| 1631 | /*! |
| 1632 | This function returns the MIME data of the event. |
| 1633 | */ |
| 1634 | const QMimeData *QGraphicsSceneDragDropEvent::mimeData() const |
| 1635 | { |
| 1636 | Q_D(const QGraphicsSceneDragDropEvent); |
| 1637 | return d->mimeData; |
| 1638 | } |
| 1639 | |
| 1640 | /*! |
| 1641 | \internal |
| 1642 | This function sets the MIME data for the event. |
| 1643 | */ |
| 1644 | void QGraphicsSceneDragDropEvent::setMimeData(const QMimeData *data) |
| 1645 | { |
| 1646 | Q_D(QGraphicsSceneDragDropEvent); |
| 1647 | d->mimeData = data; |
| 1648 | } |
| 1649 | |
| 1650 | class QGraphicsSceneResizeEventPrivate : public QGraphicsSceneEventPrivate |
| 1651 | { |
| 1652 | Q_DECLARE_PUBLIC(QGraphicsSceneResizeEvent) |
| 1653 | public: |
| 1654 | inline QGraphicsSceneResizeEventPrivate() |
| 1655 | { } |
| 1656 | |
| 1657 | QSizeF oldSize; |
| 1658 | QSizeF newSize; |
| 1659 | }; |
| 1660 | |
| 1661 | /*! |
| 1662 | Constructs a QGraphicsSceneResizeEvent. |
| 1663 | */ |
| 1664 | QGraphicsSceneResizeEvent::QGraphicsSceneResizeEvent() |
| 1665 | : QGraphicsSceneEvent(*new QGraphicsSceneResizeEventPrivate, QEvent::GraphicsSceneResize) |
| 1666 | { |
| 1667 | } |
| 1668 | |
| 1669 | /*! |
| 1670 | Destroys the QGraphicsSceneResizeEvent. |
| 1671 | */ |
| 1672 | QGraphicsSceneResizeEvent::~QGraphicsSceneResizeEvent() |
| 1673 | { |
| 1674 | } |
| 1675 | |
| 1676 | /*! |
| 1677 | Returns the old size (i.e., the size immediately before the widget was |
| 1678 | resized). |
| 1679 | |
| 1680 | \sa newSize(), QGraphicsWidget::resize() |
| 1681 | */ |
| 1682 | QSizeF QGraphicsSceneResizeEvent::oldSize() const |
| 1683 | { |
| 1684 | Q_D(const QGraphicsSceneResizeEvent); |
| 1685 | return d->oldSize; |
| 1686 | } |
| 1687 | |
| 1688 | /*! |
| 1689 | \internal |
| 1690 | */ |
| 1691 | void QGraphicsSceneResizeEvent::setOldSize(const QSizeF &size) |
| 1692 | { |
| 1693 | Q_D(QGraphicsSceneResizeEvent); |
| 1694 | d->oldSize = size; |
| 1695 | } |
| 1696 | |
| 1697 | /*! |
| 1698 | Returns the new size (i.e., the current size). |
| 1699 | |
| 1700 | \sa oldSize(), QGraphicsWidget::resize() |
| 1701 | */ |
| 1702 | QSizeF QGraphicsSceneResizeEvent::newSize() const |
| 1703 | { |
| 1704 | Q_D(const QGraphicsSceneResizeEvent); |
| 1705 | return d->newSize; |
| 1706 | } |
| 1707 | |
| 1708 | /*! |
| 1709 | \internal |
| 1710 | */ |
| 1711 | void QGraphicsSceneResizeEvent::setNewSize(const QSizeF &size) |
| 1712 | { |
| 1713 | Q_D(QGraphicsSceneResizeEvent); |
| 1714 | d->newSize = size; |
| 1715 | } |
| 1716 | |
| 1717 | class QGraphicsSceneMoveEventPrivate : public QGraphicsSceneEventPrivate |
| 1718 | { |
| 1719 | Q_DECLARE_PUBLIC(QGraphicsSceneMoveEvent) |
| 1720 | public: |
| 1721 | inline QGraphicsSceneMoveEventPrivate() |
| 1722 | { } |
| 1723 | |
| 1724 | QPointF oldPos; |
| 1725 | QPointF newPos; |
| 1726 | }; |
| 1727 | |
| 1728 | /*! |
| 1729 | Constructs a QGraphicsSceneMoveEvent. |
| 1730 | */ |
| 1731 | QGraphicsSceneMoveEvent::QGraphicsSceneMoveEvent() |
| 1732 | : QGraphicsSceneEvent(*new QGraphicsSceneMoveEventPrivate, QEvent::GraphicsSceneMove) |
| 1733 | { |
| 1734 | } |
| 1735 | |
| 1736 | /*! |
| 1737 | Destroys the QGraphicsSceneMoveEvent. |
| 1738 | */ |
| 1739 | QGraphicsSceneMoveEvent::~QGraphicsSceneMoveEvent() |
| 1740 | { |
| 1741 | } |
| 1742 | |
| 1743 | /*! |
| 1744 | Returns the old position (i.e., the position immediately before the widget |
| 1745 | was moved). |
| 1746 | |
| 1747 | \sa newPos(), QGraphicsItem::setPos() |
| 1748 | */ |
| 1749 | QPointF QGraphicsSceneMoveEvent::oldPos() const |
| 1750 | { |
| 1751 | Q_D(const QGraphicsSceneMoveEvent); |
| 1752 | return d->oldPos; |
| 1753 | } |
| 1754 | |
| 1755 | /*! |
| 1756 | \internal |
| 1757 | */ |
| 1758 | void QGraphicsSceneMoveEvent::setOldPos(const QPointF &pos) |
| 1759 | { |
| 1760 | Q_D(QGraphicsSceneMoveEvent); |
| 1761 | d->oldPos = pos; |
| 1762 | } |
| 1763 | |
| 1764 | /*! |
| 1765 | Returns the new position (i.e., the current position). |
| 1766 | |
| 1767 | \sa oldPos(), QGraphicsItem::setPos() |
| 1768 | */ |
| 1769 | QPointF QGraphicsSceneMoveEvent::newPos() const |
| 1770 | { |
| 1771 | Q_D(const QGraphicsSceneMoveEvent); |
| 1772 | return d->newPos; |
| 1773 | } |
| 1774 | |
| 1775 | /*! |
| 1776 | \internal |
| 1777 | */ |
| 1778 | void QGraphicsSceneMoveEvent::setNewPos(const QPointF &pos) |
| 1779 | { |
| 1780 | Q_D(QGraphicsSceneMoveEvent); |
| 1781 | d->newPos = pos; |
| 1782 | } |
| 1783 | |
| 1784 | #ifndef QT_NO_DEBUG_STREAM |
| 1785 | template <class Event> |
| 1786 | static inline void formatPositions(QDebug &debug, const Event *event) |
| 1787 | { |
| 1788 | debug << ", pos=" ; |
| 1789 | QtDebugUtils::formatQPoint(debug, event->pos()); |
| 1790 | debug << ", scenePos=" ; |
| 1791 | QtDebugUtils::formatQPoint(debug, event->scenePos()); |
| 1792 | debug << ", screenPos=" ; |
| 1793 | QtDebugUtils::formatQPoint(debug, event->screenPos()); |
| 1794 | } |
| 1795 | |
| 1796 | QDebug operator<<(QDebug debug, const QGraphicsSceneEvent *event) |
| 1797 | { |
| 1798 | QDebugStateSaver saver(debug); |
| 1799 | debug.nospace(); |
| 1800 | if (!event) { |
| 1801 | debug << "QGraphicsSceneEvent(0)" ; |
| 1802 | return debug; |
| 1803 | } |
| 1804 | |
| 1805 | const QEvent::Type type = event->type(); |
| 1806 | switch (type) { |
| 1807 | case QEvent::GraphicsSceneMouseMove: |
| 1808 | case QEvent::GraphicsSceneMousePress: |
| 1809 | case QEvent::GraphicsSceneMouseRelease: |
| 1810 | case QEvent::GraphicsSceneMouseDoubleClick: { |
| 1811 | const QGraphicsSceneMouseEvent *me = static_cast<const QGraphicsSceneMouseEvent *>(event); |
| 1812 | const Qt::MouseButton button = me->button(); |
| 1813 | const Qt::MouseButtons buttons = me->buttons(); |
| 1814 | debug << "QGraphicsSceneMouseEvent(" ; |
| 1815 | QtDebugUtils::formatQEnum(debug, value: type); |
| 1816 | if (type != QEvent::GraphicsSceneMouseMove) { |
| 1817 | debug << ", " ; |
| 1818 | QtDebugUtils::formatQEnum(debug, value: button); |
| 1819 | } |
| 1820 | if (buttons && button != buttons) { |
| 1821 | debug << ", buttons=" ; |
| 1822 | QtDebugUtils::formatQFlags(debug, value: buttons); |
| 1823 | } |
| 1824 | QtDebugUtils::formatNonNullQFlags(debug, prefix: ", " , value: me->modifiers()); |
| 1825 | formatPositions(debug, event: me); |
| 1826 | QtDebugUtils::formatNonNullQEnum(debug, prefix: ", " , value: me->source()); |
| 1827 | QtDebugUtils::formatNonNullQFlags(debug, prefix: ", flags=" , value: me->flags()); |
| 1828 | debug << ')'; |
| 1829 | } |
| 1830 | break; |
| 1831 | case QEvent::GraphicsSceneContextMenu: { |
| 1832 | const QGraphicsSceneContextMenuEvent *ce = static_cast<const QGraphicsSceneContextMenuEvent *>(event); |
| 1833 | debug << "QGraphicsSceneContextMenuEvent(reason=" << ce->reason(); |
| 1834 | QtDebugUtils::formatNonNullQFlags(debug, prefix: ", " , value: ce->modifiers()); |
| 1835 | formatPositions(debug, event: ce); |
| 1836 | debug << ')'; |
| 1837 | } |
| 1838 | break; |
| 1839 | case QEvent::GraphicsSceneHoverEnter: |
| 1840 | case QEvent::GraphicsSceneHoverMove: |
| 1841 | case QEvent::GraphicsSceneHoverLeave: |
| 1842 | debug << "QGraphicsSceneHoverEvent(" ; |
| 1843 | formatPositions(debug, event: static_cast<const QGraphicsSceneHoverEvent *>(event)); |
| 1844 | debug << ')'; |
| 1845 | break; |
| 1846 | case QEvent::GraphicsSceneHelp: |
| 1847 | break; |
| 1848 | case QEvent::GraphicsSceneDragEnter: |
| 1849 | case QEvent::GraphicsSceneDragMove: |
| 1850 | case QEvent::GraphicsSceneDragLeave: |
| 1851 | case QEvent::GraphicsSceneDrop: { |
| 1852 | const QGraphicsSceneDragDropEvent *de = static_cast<const QGraphicsSceneDragDropEvent *>(event); |
| 1853 | debug << "QGraphicsSceneDragDropEvent(proposedAction=" ; |
| 1854 | QtDebugUtils::formatQEnum(debug, value: de->proposedAction()); |
| 1855 | debug << ", possibleActions=" ; |
| 1856 | QtDebugUtils::formatQFlags(debug, value: de->possibleActions()); |
| 1857 | debug << ", source=" << de->source(); |
| 1858 | QtDebugUtils::formatNonNullQFlags(debug, prefix: ", buttons=" , value: de->buttons()); |
| 1859 | QtDebugUtils::formatNonNullQFlags(debug, prefix: ", " , value: de->modifiers()); |
| 1860 | formatPositions(debug, event: de); |
| 1861 | } |
| 1862 | break; |
| 1863 | case QEvent::GraphicsSceneWheel: { |
| 1864 | const QGraphicsSceneWheelEvent *we = static_cast<const QGraphicsSceneWheelEvent *>(event); |
| 1865 | debug << "QGraphicsSceneWheelEvent(" ; |
| 1866 | QtDebugUtils::formatNonNullQFlags(debug, prefix: ", buttons=" , value: we->buttons()); |
| 1867 | QtDebugUtils::formatNonNullQFlags(debug, prefix: ", " , value: we->modifiers()); |
| 1868 | formatPositions(debug, event: we); |
| 1869 | debug << ')'; |
| 1870 | } |
| 1871 | break; |
| 1872 | default: |
| 1873 | break; |
| 1874 | } |
| 1875 | return debug; |
| 1876 | } |
| 1877 | #endif // !QT_NO_DEBUG_STREAM |
| 1878 | |
| 1879 | QT_END_NAMESPACE |
| 1880 | |