1 #include "timeaxiswidget.h"
7 TimeAxisWidget::TimeAxisWidget(QWidget* parent) :
8 GraphAxisWidget(parent)
12 void TimeAxisWidget::paintEvent(QPaintEvent *)
14 /* TODO: Support selections? */
15 /* TODO: Vertical scrolling? */
17 QPainter painter(this);
18 painter.setPen(Qt::black);
19 painter.setBrush(Qt::lightGray);
20 painter.drawRect(0, 0, width() - 1, height() - 1);
22 if (m_orientation == GraphAxisWidget::Vertical) {
23 int axisHeight = height() - 1;
24 int fontHeight = painter.fontMetrics().height();
25 int ticks = axisHeight / (fontHeight * 2);
27 double range = m_valueMax - m_valueMin;
28 double step = range / (double)ticks;
29 double step10 = qPow(10.0, qFloor(qLn(step) / qLn(10.0)));
30 step = qFloor((step / step10) * 2) * (step10 / 2);
36 painter.resetTransform();
38 for (double tick = 0; tick <= range; tick += step) {
39 int y = axisHeight - ((tick / range) * axisHeight);
41 painter.drawLine(width() - 8, y, width(), y);
44 qBound(0, y - fontHeight / 2, axisHeight - fontHeight),
47 Qt::AlignRight | Qt::AlignVCenter,
48 Profiling::getTimeString(tick, m_valueMax));
51 int axisWidth = width() - 1;
52 int fontWidth = painter.fontMetrics().width("0.000 ns");
53 int fontHeight= painter.fontMetrics().height();
54 int ticks = axisWidth / (fontWidth * 2);
56 double range = m_valueMax - m_valueMin;
57 double step = range / (double)ticks;
58 double step10 = qPow(10.0, qFloor(qLn(step) / qLn(10.0)));
59 step = qFloor((step / step10) * 2) * (step10 / 2);
65 painter.resetTransform();
67 for (double tick = 0; tick <= range; tick += step) {
68 int x = (tick / range) * axisWidth;
70 painter.drawLine(x, 0, x, 8);
72 painter.drawText(qBound(0, x - fontWidth / 2, axisWidth - fontWidth),
76 Qt::AlignHCenter | Qt::AlignTop,
77 Profiling::getTimeString(tick, m_valueMax));