]> git.cworth.org Git - apitrace/blob - gui/timelinewidget.h
Combine timeline and histogram tabs.
[apitrace] / gui / timelinewidget.h
1 #ifndef TIMELINEWIDGET_H
2 #define TIMELINEWIDGET_H
3
4 #include <QWidget>
5 #include <QList>
6 #include <QPen>
7 #include "trace_profiler.hpp"
8
9 class TimelineWidget : public QWidget
10 {
11     Q_OBJECT
12
13     enum MousePressMode {
14         NoMousePress,
15         DragView,
16         RulerZoom,
17         RulerSelect
18     };
19
20     enum SelectType {
21         SelectNone,
22         SelectTime,
23         SelectProgram
24     };
25
26 public:
27     TimelineWidget(QWidget *parent = 0);
28
29     void setProfile(trace::Profile* profile);
30
31     void selectNone(bool notify = false);
32     void selectProgram(unsigned program, bool notify = false);
33     void selectTime(int64_t start, int64_t end, bool notify = false);
34
35 protected:
36     virtual void wheelEvent(QWheelEvent *e);
37     virtual void mousePressEvent(QMouseEvent *e);
38     virtual void mouseMoveEvent(QMouseEvent *e);
39     virtual void mouseReleaseEvent(QMouseEvent *e);
40     virtual void mouseDoubleClickEvent(QMouseEvent *e);
41
42     virtual void paintEvent(QPaintEvent *e);
43     virtual void resizeEvent(QResizeEvent *e);
44
45 public slots:
46     void setHorizontalScrollValue(int value);
47     void setVerticalScrollValue(int value);
48
49 signals:
50     void verticalScrollMaxChanged(int max);
51     void verticalScrollValueChanged(int value);
52
53     void horizontalScrollMaxChanged(int max);
54     void horizontalScrollValueChanged(int value);
55
56     void jumpToCall(int call);
57
58     void selectedNone();
59     void selectedProgram(unsigned program);
60     void selectedTime(int64_t start, int64_t end);
61
62 private:
63     void setRowScroll(int position, bool notify = true);
64     void setTimeScroll(int64_t time, bool notify = true);
65
66     bool drawCall(QPainter& painter, const trace::Profile::Call& call, int &lastX, int64_t &heat, bool gpu);
67     void drawHeat(QPainter& painter, int x, int64_t heat, bool gpu, bool selected);
68
69     double timeToPosition(int64_t time);
70     int64_t positionToTime(int pos);
71
72     void calculateRows();
73
74     const trace::Profile::Frame* frameAtTime(int64_t time);
75     const trace::Profile::Call* cpuCallAtTime(int64_t time);
76     const trace::Profile::Call* drawCallAtTime(int64_t time);
77     const trace::Profile::Call* drawCallAtTime(int64_t time, int program);
78
79 private:
80     /* Data */
81     trace::Profile* m_profile;
82     std::vector<int> m_rowPrograms;
83
84     /* Scrollbars */
85     int m_scrollX;
86     int m_scrollY;
87     int m_maxScrollX;
88     int m_maxScrollY;
89
90     /* Viewport */
91     int m_viewWidth;
92     int m_viewHeight;
93
94     /* Visible Times */
95     int64_t m_time;
96     int64_t m_timeEnd;
97     int64_t m_timeMin;
98     int64_t m_timeMax;
99     int64_t m_timeWidth;
100     int64_t m_timeWidthMin;
101     int64_t m_timeWidthMax;
102
103     int m_selectionLeft;
104     int m_selectionRight;
105
106     /* Visible Rows */
107     int m_row;
108     int m_rowCount;
109
110     /* Mouse data */
111     int m_mousePressRow;
112     int64_t m_mousePressTime;
113     QPoint m_mousePosition;
114     QPoint m_mousePressPosition;
115     MousePressMode m_mousePressMode;
116
117     /* Style */
118     int m_rowHeight;
119     int m_axisWidth;
120     int m_axisHeight;
121     QPen m_axisLine;
122     QPen m_axisBorder;
123     QPen m_axisForeground;
124     QBrush m_axisBackground;
125     QPen m_itemBorder;
126     QPen m_itemGpuForeground;
127     QBrush m_itemGpuBackground;
128     QPen m_itemCpuForeground;
129     QBrush m_itemCpuBackground;
130     QPen m_itemDeselectedForeground;
131     QBrush m_itemDeselectedBackground;
132     QPen m_selectionBorder;
133     QBrush m_selectionBackground;
134     QPen m_zoomBorder;
135     QBrush m_zoomBackground;
136
137     /* Selection */
138     struct {
139         SelectType type;
140
141         unsigned program;
142
143         int64_t timeStart;
144         int64_t timeEnd;
145     } m_selection;
146 };
147
148 #endif // TIMELINEWIDGET_H