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