File: frameaxiswidget.cpp

package info (click to toggle)
apitrace 7.1%2Bgit20170623.d38a69d6%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,992 kB
  • sloc: cpp: 179,347; ansic: 62,439; python: 33,058; java: 377; makefile: 105; sh: 26; xml: 26
file content (99 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (5)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "frameaxiswidget.h"

#include <QPainter>

FrameAxisWidget::FrameAxisWidget(QWidget* parent) :
    GraphAxisWidget(parent),
    m_data(NULL)
{
    setSelectable(GraphAxisWidget::Range);
}

void FrameAxisWidget::setDataProvider(FrameDataProvider* data)
{
    delete m_data;
    m_data = data;
}

void FrameAxisWidget::paintEvent(QPaintEvent *)
{
    if (!m_data || m_orientation != GraphAxisWidget::Horizontal) {
        /* TODO: Vertical axis support */
        return;
    }

    QPainter painter(this);
    painter.setPen(Qt::black);
    painter.setBrush(Qt::lightGray);
    painter.drawRect(0, 0, width() - 1, height() - 1);

    qint64 range = m_valueEnd - m_valueBegin;
    double dxdv = width() / (double)range;
    double scroll = dxdv * m_valueBegin;
    int lastLabel = -9999;

    /* Iterate over frames, drawing a label when there is space to do so */
    for (unsigned i = 0; i < m_data->size(); ++i) {
        static const int padding = 4;
        qint64 start = m_data->frameStart(i);
        qint64 end = m_data->frameEnd(i);
        bool visible = false;

        if (start > m_valueEnd) {
            break;
        }

        if (end < m_valueBegin) {
            visible = false;
        }

        double left = dxdv * start;
        double right = dxdv * end;
        QString text = QString("%1").arg(i);

        int width = painter.fontMetrics().width(text) + padding * 2;

        if (right > scroll) {
            visible = true;
        }

        if (left - lastLabel > width) {
            lastLabel = left + width;

            if (visible) {
                int textX;

                if (left < scroll && right - left > width) {
                    if (right - scroll > width) {
                        textX = 0;
                    } else {
                        textX = right - scroll - width;
                    }
                } else {
                    textX = left - scroll;
                }

                painter.drawText(textX + padding, 0, width - padding, height() - 5, Qt::AlignLeft | Qt::AlignVCenter, text);
                painter.drawLine(left - scroll, height() / 2, left - scroll, height() - 1);
            }
        } else if (visible) {
            painter.drawLine(left - scroll, height() * 3/4.0, left - scroll, height() - 1);
        }
    }

    /* Draw selection */
    if (hasSelection()) {
        double left = (dxdv * m_selectionState->start) - scroll;
        double right = (dxdv * m_selectionState->end) - scroll;

        painter.setPen(Qt::green);

        if (left >= 0 && left <= width()) {
            painter.drawLine(left, 0, left, height());
        }

        if (right >= 0 && right <= width()) {
            painter.drawLine(right, 0, right, height());
        }
    }
}