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