1 #include "graphaxiswidget.h"
5 GraphAxisWidget::GraphAxisWidget(QWidget* parent) :
13 bool GraphAxisWidget::hasSelection()
15 if (!m_selectionState) {
19 if (m_selectionState->type == SelectionState::Horizontal && m_orientation == GraphAxisWidget::Horizontal) {
23 if (m_selectionState->type == SelectionState::Vertical && m_orientation == GraphAxisWidget::Vertical) {
31 void GraphAxisWidget::setSelectable(SelectionStyle selectable)
33 m_selectable = selectable;
37 void GraphAxisWidget::setSelectionState(SelectionState* state)
39 m_selectionState = state;
43 void GraphAxisWidget::setOrientation(Orientation v)
47 if (m_orientation == Horizontal) {
55 void GraphAxisWidget::mouseMoveEvent(QMouseEvent *e)
57 if (m_selectable == None) {
63 if (m_orientation == Horizontal) {
71 double value = m_valueEnd - m_valueBegin;
72 value *= pos / (double)max;
73 value += m_valueBegin;
75 if (e->buttons().testFlag(Qt::LeftButton)) {
76 m_selectionState->start = qMin<qint64>(m_mousePressValue, value);
77 m_selectionState->end = qMax<qint64>(m_mousePressValue, value);
78 m_selectionState->type = m_orientation == Horizontal ? SelectionState::Horizontal : SelectionState::Vertical;
79 emit selectionChanged();
85 void GraphAxisWidget::mousePressEvent(QMouseEvent *e)
87 if (m_selectable == None) {
93 if (m_orientation == Horizontal) {
101 double value = m_valueEnd - m_valueBegin;
102 value *= pos / (double)max;
103 value += m_valueBegin;
105 m_mousePressPosition = e->pos();
106 m_mousePressValue = value;
110 void GraphAxisWidget::mouseReleaseEvent(QMouseEvent *e)
112 if (m_selectable == None) {
116 int dx = qAbs(m_mousePressPosition.x() - e->x());
117 int dy = qAbs(m_mousePressPosition.y() - e->y());
120 m_selectionState->type = SelectionState::None;
121 emit selectionChanged();
126 void GraphAxisWidget::setRange(qint64 min, qint64 max)
134 void GraphAxisWidget::setView(qint64 start, qint64 end)
136 m_valueBegin = start;
141 #include "graphaxiswidget.moc"