@@ -1,63 +1,63 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chart.h" |
|
22 | 22 | #include <QGesture> |
|
23 | 23 | #include <QGraphicsScene> |
|
24 | 24 | #include <QGraphicsView> |
|
25 | 25 | |
|
26 | 26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
27 | 27 | : QChart(QChart::ChartTypeCartesian, parent, wFlags) |
|
28 | 28 | { |
|
29 | 29 | // Seems that QGraphicsView (QChartView) does not grab gestures. |
|
30 | 30 | // They can only be grabbed here in the QGraphicsWidget (QChart). |
|
31 | 31 | grabGesture(Qt::PanGesture); |
|
32 | 32 | grabGesture(Qt::PinchGesture); |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | Chart::~Chart() |
|
36 | 36 | { |
|
37 | 37 | |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | //![1] |
|
41 | 41 | bool Chart::sceneEvent(QEvent *event) |
|
42 | 42 | { |
|
43 | 43 | if (event->type() == QEvent::Gesture) |
|
44 | 44 | return gestureEvent(static_cast<QGestureEvent *>(event)); |
|
45 | 45 | return QChart::event(event); |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | bool Chart::gestureEvent(QGestureEvent *event) |
|
49 | 49 | { |
|
50 | 50 | if (QGesture *gesture = event->gesture(Qt::PanGesture)) { |
|
51 | 51 | QPanGesture *pan = static_cast<QPanGesture *>(gesture); |
|
52 | QChart::scroll(pan->delta().x(), pan->delta().y()); | |
|
52 | QChart::scroll(-(pan->delta().x()), pan->delta().y()); | |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | if (QGesture *gesture = event->gesture(Qt::PinchGesture)) { |
|
56 | 56 | QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture); |
|
57 | 57 | if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) |
|
58 | 58 | QChart::zoom(pinch->scaleFactor()); |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | return true; |
|
62 | 62 | } |
|
63 | 63 | //![1] |
General Comments 0
You need to be logged in to leave comments.
Login now