~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/widgets/graphicsview/qgraphicssceneevent.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

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