##// END OF EJS Templates
Fixes zoomline chart example
Michal Klocek -
r226:538ea0469912
parent child
Show More
@@ -1,63 +1,63
1 1 #include "chartwidget.h"
2 2 #include <QMouseEvent>
3 3
4 4 ChartWidget::ChartWidget(QWidget *parent)
5 5 : QChartView(parent),
6 6 m_rubberBand(QRubberBand::Rectangle,this)
7 7 {
8 8 }
9 9
10 10 void ChartWidget::mousePressEvent(QMouseEvent *event)
11 11 {
12 12 if(event->button()!=Qt::LeftButton) return;
13 13
14 14 int margin = this->margin();
15 15
16 16 QRect rect(margin,margin,width()-2*margin,height()-2*margin);
17 17
18 18 m_origin = event->pos();
19 19
20 20 if (!rect.contains(m_origin)) return;
21 21
22 22 m_rubberBand.setGeometry(QRect(m_origin, QSize()));
23 23 m_rubberBand.show();
24 24
25 25 event->accept();
26 26 }
27 27
28 28 void ChartWidget::mouseMoveEvent(QMouseEvent *event)
29 29 {
30 30 if(m_rubberBand.isVisible())
31 31 m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized());
32 32 }
33 33
34 34 void ChartWidget::mouseReleaseEvent(QMouseEvent *event)
35 35 {
36 36 if( event->button()==Qt::LeftButton && m_rubberBand.isVisible()) {
37 37 m_rubberBand.hide();
38 38
39 39 QRect rect = m_rubberBand.geometry();
40 zoomInToRect(rect);
40 zoomIn(rect);
41 41 event->accept();
42 42 }
43 43
44 44 if(event->button()==Qt::RightButton) {
45 45 zoomOut();
46 46 }
47 47 }
48 48
49 49
50 50 void ChartWidget::keyPressEvent(QKeyEvent *event)
51 51 {
52 52 switch (event->key()) {
53 53 case Qt::Key_Plus:
54 54 zoomIn();
55 55 break;
56 56 case Qt::Key_Minus:
57 57 zoomOut();
58 58 break;
59 59 default:
60 60 QGraphicsView::keyPressEvent(event);
61 61 break;
62 62 }
63 63 }
General Comments 0
You need to be logged in to leave comments. Login now