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