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