@@ -1,75 +1,74 | |||||
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 = |
|
14 | int margin = 25; | |
15 |
|
||||
16 | QRect rect(margin,margin,width()-2*margin,height()-2*margin); |
|
15 | QRect rect(margin,margin,width()-2*margin,height()-2*margin); | |
17 |
|
16 | |||
18 | m_origin = event->pos(); |
|
17 | m_origin = event->pos(); | |
19 |
|
18 | |||
20 | if (!rect.contains(m_origin)) return; |
|
19 | if (!rect.contains(m_origin)) return; | |
21 |
|
20 | |||
22 | m_rubberBand.setGeometry(QRect(m_origin, QSize())); |
|
21 | m_rubberBand.setGeometry(QRect(m_origin, QSize())); | |
23 | m_rubberBand.show(); |
|
22 | m_rubberBand.show(); | |
24 |
|
23 | |||
25 | event->accept(); |
|
24 | event->accept(); | |
26 | } |
|
25 | } | |
27 |
|
26 | |||
28 | void ChartWidget::mouseMoveEvent(QMouseEvent *event) |
|
27 | void ChartWidget::mouseMoveEvent(QMouseEvent *event) | |
29 | { |
|
28 | { | |
30 | if(m_rubberBand.isVisible()) |
|
29 | if(m_rubberBand.isVisible()) | |
31 | m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized()); |
|
30 | m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized()); | |
32 | } |
|
31 | } | |
33 |
|
32 | |||
34 | void ChartWidget::mouseReleaseEvent(QMouseEvent *event) |
|
33 | void ChartWidget::mouseReleaseEvent(QMouseEvent *event) | |
35 | { |
|
34 | { | |
36 | if( event->button()==Qt::LeftButton && m_rubberBand.isVisible()) { |
|
35 | if( event->button()==Qt::LeftButton && m_rubberBand.isVisible()) { | |
37 | m_rubberBand.hide(); |
|
36 | m_rubberBand.hide(); | |
38 |
|
37 | |||
39 | QRect rect = m_rubberBand.geometry(); |
|
38 | QRect rect = m_rubberBand.geometry(); | |
40 | zoomIn(rect); |
|
39 | zoomIn(rect); | |
41 | event->accept(); |
|
40 | event->accept(); | |
42 | } |
|
41 | } | |
43 |
|
42 | |||
44 | if(event->button()==Qt::RightButton) { |
|
43 | if(event->button()==Qt::RightButton) { | |
45 | zoomOut(); |
|
44 | zoomOut(); | |
46 | } |
|
45 | } | |
47 | } |
|
46 | } | |
48 |
|
47 | |||
49 |
|
48 | |||
50 | void ChartWidget::keyPressEvent(QKeyEvent *event) |
|
49 | void ChartWidget::keyPressEvent(QKeyEvent *event) | |
51 | { |
|
50 | { | |
52 | switch (event->key()) { |
|
51 | switch (event->key()) { | |
53 | case Qt::Key_Plus: |
|
52 | case Qt::Key_Plus: | |
54 | zoomIn(); |
|
53 | zoomIn(); | |
55 | break; |
|
54 | break; | |
56 | case Qt::Key_Minus: |
|
55 | case Qt::Key_Minus: | |
57 | zoomOut(); |
|
56 | zoomOut(); | |
58 | break; |
|
57 | break; | |
59 | case Qt::Key_Left: |
|
58 | case Qt::Key_Left: | |
60 | scrollLeft(); |
|
59 | scrollLeft(); | |
61 | break; |
|
60 | break; | |
62 | case Qt::Key_Right: |
|
61 | case Qt::Key_Right: | |
63 | scrollRight(); |
|
62 | scrollRight(); | |
64 | break; |
|
63 | break; | |
65 | case Qt::Key_Up: |
|
64 | case Qt::Key_Up: | |
66 | scrollUp(); |
|
65 | scrollUp(); | |
67 | break; |
|
66 | break; | |
68 | case Qt::Key_Down: |
|
67 | case Qt::Key_Down: | |
69 | scrollDown(); |
|
68 | scrollDown(); | |
70 | break; |
|
69 | break; | |
71 | default: |
|
70 | default: | |
72 | QGraphicsView::keyPressEvent(event); |
|
71 | QGraphicsView::keyPressEvent(event); | |
73 | break; |
|
72 | break; | |
74 | } |
|
73 | } | |
75 | } |
|
74 | } |
@@ -1,38 +1,28 | |||||
1 | #include "declarativechart.h" |
|
1 | #include "declarativechart.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
5 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
6 | : QDeclarativeItem(parent), |
|
6 | : QDeclarativeItem(parent), | |
7 | m_chart(new QChart(this)) |
|
7 | m_chart(new QChart(this)) | |
8 | { |
|
8 | { | |
9 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
9 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | DeclarativeChart::ChartTheme DeclarativeChart::theme() |
|
12 | DeclarativeChart::ChartTheme DeclarativeChart::theme() | |
13 | { |
|
13 | { | |
14 | return (ChartTheme) m_chart->chartTheme(); |
|
14 | return (ChartTheme) m_chart->chartTheme(); | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
17 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
18 | { |
|
18 | { | |
19 | qDebug() << "geometryChanged " << this << " old geometry: " << oldGeometry; |
|
|||
20 | if (newGeometry.isValid()) { |
|
19 | if (newGeometry.isValid()) { | |
21 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
20 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
22 | // TODO: setting margin should not be needed to make axis visible? |
|
|||
23 | const int margin = 30; |
|
|||
24 | if (m_chart->margin() == 0 |
|
|||
25 | && newGeometry.width() > (margin * 2) |
|
|||
26 | && newGeometry.height() > (margin * 2)) { |
|
|||
27 | m_chart->setMargin(margin); |
|
|||
28 |
|
|
21 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
29 | } else { |
|
|||
30 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
|||
31 | } |
|
|||
32 | } |
|
22 | } | |
33 | } |
|
23 | } | |
34 | } |
|
24 | } | |
35 |
|
25 | |||
36 | #include "moc_declarativechart.cpp" |
|
26 | #include "moc_declarativechart.cpp" | |
37 |
|
27 | |||
38 | QTCOMMERCIALCHART_END_NAMESPACE |
|
28 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now