]> git.cworth.org Git - apitrace/blob - gui/graphwidget.h
Combine timeline and histogram tabs.
[apitrace] / gui / graphwidget.h
1 #ifndef GRAPHWIDGET_H
2 #define GRAPHWIDGET_H
3
4 #include <QPen>
5 #include <QWidget>
6 #include <QPainter>
7 #include <QLinearGradient>
8 #include "trace_profiler.hpp"
9
10 enum GraphType {
11     GraphGpu,
12     GraphCpu
13 };
14
15 enum SelectType {
16     SelectNone,
17     SelectTime,
18     SelectProgram
19 };
20
21 class GraphWidget : public QWidget
22 {
23     Q_OBJECT
24
25 public:
26     GraphWidget(QWidget *parent = 0);
27
28     void setProfile(trace::Profile* profile, GraphType type);
29     const trace::Profile::Call* callAtPosition(const QPoint& pos);
30
31     void selectNone(bool notify = false);
32     void selectTime(int64_t start, int64_t end, bool notify = false);
33     void selectProgram(unsigned program, bool notify = false);
34
35 protected:
36     virtual void paintEvent(QPaintEvent *e);
37     virtual void resizeEvent(QResizeEvent *e);
38
39     virtual void wheelEvent(QWheelEvent *e);
40     virtual void mouseMoveEvent(QMouseEvent *e);
41     virtual void mousePressEvent(QMouseEvent *e);
42     virtual void mouseReleaseEvent(QMouseEvent *e);
43     virtual void mouseDoubleClickEvent(QMouseEvent *e);
44
45 signals:
46     void jumpToCall(int no);
47     void viewChanged(int call, int width);
48
49     void selectedNone();
50     void selectedProgram(unsigned program);
51     void selectedTime(int64_t start, int64_t end);
52
53 public slots:
54     void changeView(int call, int width);
55
56 private:
57     void update();
58
59     void paintVerticalAxis(QPainter& painter);
60     void paintHorizontalAxis(QPainter& painter);
61
62 private:
63     /* Data */
64     trace::Profile* m_profile;
65     GraphType m_type;
66
67     /* Vertical Axis */
68     int64_t m_timeMax;
69
70     /* Horizontal axis */
71     int m_call;
72     int m_callMin;
73     int m_callMax;
74     int m_callWidth;
75     int m_callWidthMin;
76     int m_callWidthMax;
77
78     /* Viewport */
79     int m_graphWidth;
80     int m_graphHeight;
81
82     /* Mouse track data */
83     int m_mousePressCall;
84     QPoint m_mousePressPosition;
85
86     /* Style */
87     int m_axisWidth;
88     int m_axisHeight;
89     QPen m_axisForeground;
90     QBrush m_axisBackground;
91     QLinearGradient m_graphGradientGpu;
92     QLinearGradient m_graphGradientCpu;
93     QLinearGradient m_graphGradientDeselected;
94
95     struct {
96         SelectType type;
97
98         unsigned program;
99
100         int64_t timeStart;
101         int64_t timeEnd;
102     } m_selection;
103 };
104
105 #endif // GRAPHWIDGET_H