chart.cpp
61 lines
| 1.9 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r1187 | /**************************************************************************** | ||
** | ||||
Titta Heikkala
|
r2776 | ** Copyright (C) 2015 The Qt Company Ltd | ||
Jani Honkonen
|
r1187 | ** All rights reserved. | ||
Titta Heikkala
|
r2776 | ** For any questions to The Qt Company, please use contact form at http://qt.io | ||
Jani Honkonen
|
r1187 | ** | ||
Titta Heikkala
|
r2740 | ** This file is part of the Qt Charts module. | ||
Jani Honkonen
|
r1187 | ** | ||
Titta Heikkala
|
r2740 | ** Licensees holding valid commercial license for Qt may use this file in | ||
** accordance with the Qt License Agreement provided with the Software | ||||
** or, alternatively, in accordance with the terms contained in a written | ||||
Titta Heikkala
|
r2776 | ** agreement between you and The Qt Company. | ||
Jani Honkonen
|
r1187 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
Titta Heikkala
|
r2740 | ** contact form at http://qt.io | ||
Jani Honkonen
|
r1187 | ** | ||
****************************************************************************/ | ||||
#include "chart.h" | ||||
Titta Heikkala
|
r2714 | #include <QtWidgets/QGesture> | ||
#include <QtWidgets/QGraphicsScene> | ||||
#include <QtWidgets/QGraphicsView> | ||||
Jani Honkonen
|
r1187 | |||
Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | ||||
Miikka Heikkinen
|
r2483 | : QChart(QChart::ChartTypeCartesian, parent, wFlags) | ||
Jani Honkonen
|
r1187 | { | ||
// Seems that QGraphicsView (QChartView) does not grab gestures. | ||||
// They can only be grabbed here in the QGraphicsWidget (QChart). | ||||
grabGesture(Qt::PanGesture); | ||||
grabGesture(Qt::PinchGesture); | ||||
} | ||||
Chart::~Chart() | ||||
{ | ||||
} | ||||
Jani Honkonen
|
r1388 | //![1] | ||
Jani Honkonen
|
r1187 | bool Chart::sceneEvent(QEvent *event) | ||
{ | ||||
if (event->type() == QEvent::Gesture) | ||||
Jani Honkonen
|
r2102 | return gestureEvent(static_cast<QGestureEvent *>(event)); | ||
Jani Honkonen
|
r1187 | return QChart::event(event); | ||
} | ||||
Jani Honkonen
|
r2102 | bool Chart::gestureEvent(QGestureEvent *event) | ||
Jani Honkonen
|
r1187 | { | ||
if (QGesture *gesture = event->gesture(Qt::PanGesture)) { | ||||
QPanGesture *pan = static_cast<QPanGesture *>(gesture); | ||||
Miikka Heikkinen
|
r2579 | QChart::scroll(-(pan->delta().x()), pan->delta().y()); | ||
Jani Honkonen
|
r1187 | } | ||
if (QGesture *gesture = event->gesture(Qt::PinchGesture)) { | ||||
QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture); | ||||
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) | ||||
Jani Honkonen
|
r1388 | QChart::zoom(pinch->scaleFactor()); | ||
Jani Honkonen
|
r1187 | } | ||
return true; | ||||
} | ||||
Jani Honkonen
|
r1388 | //![1] | ||