1 #include "frameaxiswidget.h"
5 FrameAxisWidget::FrameAxisWidget(QWidget* parent) :
6 GraphAxisWidget(parent),
9 setSelectable(GraphAxisWidget::Range);
12 void FrameAxisWidget::setDataProvider(FrameDataProvider* data)
18 void FrameAxisWidget::paintEvent(QPaintEvent *)
20 if (!m_data || m_orientation != GraphAxisWidget::Horizontal) {
21 /* TODO: Vertical axis support */
25 QPainter painter(this);
26 painter.setPen(Qt::black);
27 painter.setBrush(Qt::lightGray);
28 painter.drawRect(0, 0, width() - 1, height() - 1);
30 qint64 range = m_valueEnd - m_valueBegin;
31 double dxdv = width() / (double)range;
32 double scroll = dxdv * m_valueBegin;
33 int lastLabel = -9999;
35 /* Iterate over frames, drawing a label when there is space to do so */
36 for (unsigned i = 0; i < m_data->size(); ++i) {
37 static const int padding = 4;
38 qint64 start = m_data->frameStart(i);
39 qint64 end = m_data->frameEnd(i);
42 if (start > m_valueEnd) {
46 if (end < m_valueBegin) {
50 double left = dxdv * start;
51 double right = dxdv * end;
52 QString text = QString("%1").arg(i);
54 int width = painter.fontMetrics().width(text) + padding * 2;
60 if (left - lastLabel > width) {
61 lastLabel = left + width;
66 if (left < scroll && right - left > width) {
67 if (right - scroll > width) {
70 textX = right - scroll - width;
73 textX = left - scroll;
76 painter.drawText(textX + padding, 0, width - padding, height() - 5, Qt::AlignLeft | Qt::AlignVCenter, text);
77 painter.drawLine(left - scroll, height() / 2, left - scroll, height() - 1);
80 painter.drawLine(left - scroll, height() * 3/4.0, left - scroll, height() - 1);
86 double left = (dxdv * m_selectionState->start) - scroll;
87 double right = (dxdv * m_selectionState->end) - scroll;
89 painter.setPen(Qt::green);
91 if (left >= 0 && left <= width()) {
92 painter.drawLine(left, 0, left, height());
95 if (right >= 0 && right <= width()) {
96 painter.drawLine(right, 0, right, height());