@@ -0,0 +1,108 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE:BSD$ | |||
|
10 | ** You may use this file under the terms of the BSD license as follows: | |||
|
11 | ** | |||
|
12 | ** "Redistribution and use in source and binary forms, with or without | |||
|
13 | ** modification, are permitted provided that the following conditions are | |||
|
14 | ** met: | |||
|
15 | ** * Redistributions of source code must retain the above copyright | |||
|
16 | ** notice, this list of conditions and the following disclaimer. | |||
|
17 | ** * Redistributions in binary form must reproduce the above copyright | |||
|
18 | ** notice, this list of conditions and the following disclaimer in | |||
|
19 | ** the documentation and/or other materials provided with the | |||
|
20 | ** distribution. | |||
|
21 | ** * Neither the name of Digia nor the names of its contributors | |||
|
22 | ** may be used to endorse or promote products derived from this | |||
|
23 | ** software without specific prior written permission. | |||
|
24 | ** | |||
|
25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |||
|
26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |||
|
27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |||
|
28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |||
|
29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
|
30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
|
31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
|
32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
|
33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
|
34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
|
35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | |||
|
36 | ** $QT_END_LICENSE$ | |||
|
37 | ** | |||
|
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | |||
|
39 | ** | |||
|
40 | ****************************************************************************/ | |||
|
41 | ||||
|
42 | #include "chartview.h" | |||
|
43 | #include <QMouseEvent> | |||
|
44 | ||||
|
45 | ChartView::ChartView(QChart *chart, QWidget *parent) : | |||
|
46 | QChartView(chart, parent), m_rubberBand(QRubberBand::Rectangle, this), m_chart(chart) | |||
|
47 | { | |||
|
48 | } | |||
|
49 | ||||
|
50 | void ChartView::mousePressEvent(QMouseEvent *event) | |||
|
51 | { | |||
|
52 | if (event->button() != Qt::LeftButton) | |||
|
53 | return; | |||
|
54 | ||||
|
55 | m_origin = event->pos(); | |||
|
56 | m_rubberBand.setGeometry(QRect(m_origin, QSize())); | |||
|
57 | m_rubberBand.show(); | |||
|
58 | ||||
|
59 | event->accept(); | |||
|
60 | } | |||
|
61 | ||||
|
62 | void ChartView::mouseMoveEvent(QMouseEvent *event) | |||
|
63 | { | |||
|
64 | if (m_rubberBand.isVisible()) | |||
|
65 | m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized()); | |||
|
66 | } | |||
|
67 | ||||
|
68 | void ChartView::mouseReleaseEvent(QMouseEvent *event) | |||
|
69 | { | |||
|
70 | if (event->button() == Qt::LeftButton && m_rubberBand.isVisible()) { | |||
|
71 | m_rubberBand.hide(); | |||
|
72 | ||||
|
73 | QRect rect = m_rubberBand.geometry(); | |||
|
74 | m_chart->zoomIn(rect); | |||
|
75 | event->accept(); | |||
|
76 | } | |||
|
77 | ||||
|
78 | if (event->button() == Qt::RightButton) { | |||
|
79 | m_chart->zoomOut(); | |||
|
80 | } | |||
|
81 | } | |||
|
82 | ||||
|
83 | void ChartView::keyPressEvent(QKeyEvent *event) | |||
|
84 | { | |||
|
85 | switch (event->key()) { | |||
|
86 | case Qt::Key_Plus: | |||
|
87 | m_chart->zoomIn(); | |||
|
88 | break; | |||
|
89 | case Qt::Key_Minus: | |||
|
90 | m_chart->zoomOut(); | |||
|
91 | break; | |||
|
92 | case Qt::Key_Left: | |||
|
93 | m_chart->scrollLeft(); | |||
|
94 | break; | |||
|
95 | case Qt::Key_Right: | |||
|
96 | m_chart->scrollRight(); | |||
|
97 | break; | |||
|
98 | case Qt::Key_Up: | |||
|
99 | m_chart->scrollUp(); | |||
|
100 | break; | |||
|
101 | case Qt::Key_Down: | |||
|
102 | m_chart->scrollDown(); | |||
|
103 | break; | |||
|
104 | default: | |||
|
105 | QGraphicsView::keyPressEvent(event); | |||
|
106 | break; | |||
|
107 | } | |||
|
108 | } |
@@ -0,0 +1,68 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE:BSD$ | |||
|
10 | ** You may use this file under the terms of the BSD license as follows: | |||
|
11 | ** | |||
|
12 | ** "Redistribution and use in source and binary forms, with or without | |||
|
13 | ** modification, are permitted provided that the following conditions are | |||
|
14 | ** met: | |||
|
15 | ** * Redistributions of source code must retain the above copyright | |||
|
16 | ** notice, this list of conditions and the following disclaimer. | |||
|
17 | ** * Redistributions in binary form must reproduce the above copyright | |||
|
18 | ** notice, this list of conditions and the following disclaimer in | |||
|
19 | ** the documentation and/or other materials provided with the | |||
|
20 | ** distribution. | |||
|
21 | ** * Neither the name of Digia nor the names of its contributors | |||
|
22 | ** may be used to endorse or promote products derived from this | |||
|
23 | ** software without specific prior written permission. | |||
|
24 | ** | |||
|
25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |||
|
26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |||
|
27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |||
|
28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |||
|
29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
|
30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
|
31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
|
32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
|
33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
|
34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
|
35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | |||
|
36 | ** $QT_END_LICENSE$ | |||
|
37 | ** | |||
|
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | |||
|
39 | ** | |||
|
40 | ****************************************************************************/ | |||
|
41 | ||||
|
42 | #ifndef CHARTVIEW_H | |||
|
43 | #define CHARTVIEW_H | |||
|
44 | #include <QChartView> | |||
|
45 | #include <QRubberBand> | |||
|
46 | ||||
|
47 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
48 | ||||
|
49 | class ChartView : public QChartView | |||
|
50 | { | |||
|
51 | public: | |||
|
52 | ChartView(QChart *chart, QWidget *parent = 0); | |||
|
53 | ||||
|
54 | protected: | |||
|
55 | void mousePressEvent(QMouseEvent *event); | |||
|
56 | void mouseMoveEvent(QMouseEvent *event); | |||
|
57 | void mouseReleaseEvent(QMouseEvent *event); | |||
|
58 | void keyPressEvent(QKeyEvent *event); | |||
|
59 | ||||
|
60 | private: | |||
|
61 | bool rubberBandIsShown; | |||
|
62 | QRubberBand m_rubberBand; | |||
|
63 | QPoint m_origin; | |||
|
64 | QChart* m_chart; | |||
|
65 | ||||
|
66 | }; | |||
|
67 | ||||
|
68 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now