-
Notifications
You must be signed in to change notification settings - Fork 7
/
candlesticksview.cpp
45 lines (36 loc) · 1.14 KB
/
candlesticksview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "candlesticksview.h"
candleSticksView::candleSticksView(QChart *chart, QWidget *parent) :
QChartView(chart, parent)
, _ready(false)
{
setRubberBand(QChartView::RectangleRubberBand);
QCursor cursor;
cursor.setShape(Qt::CrossCursor);
setCursor(cursor);
}
void candleSticksView::setReady(bool ready)
{
_ready = ready;
}
void candleSticksView::mouseMoveEvent(QMouseEvent *event)
{
if(_ready)
{
QPointF point = chart()->mapToValue(event->pos());
QBarCategoryAxis *axisX = qobject_cast<QBarCategoryAxis *>(chart()->axes(Qt::Horizontal).at(0));
QToolTip::showText(event->globalPos(),
QString((point.x() > 0 && qRound(point.x()) < axisX->categories().size()) ? axisX->categories().at(qRound(point.x())) : "")
+ "\r\n" +
QString::number(point.y()),
this, rect() );
}
QChartView::mouseMoveEvent(event);
}
void candleSticksView::wheelEvent(QWheelEvent *event)
{
if(event->angleDelta().y() > 0)
chart()->zoomIn();
else
chart()->zoomOut();
event->accept();
}