]> git.cworth.org Git - apitrace/blob - gui/timelinewidget.h
Add gui support for trace profiling.
[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 struct VisibleItem {
10     QRect rect;
11     const trace::Profile::Frame* frame;
12     const trace::Profile::Call* call;
13 };
14
15 class TimelineWidget : public QWidget
16 {
17     Q_OBJECT
18
19     enum MousePressMode {
20         NoMousePress,
21         DragView,
22         RulerZoom,
23         RulerSelect
24     };
25
26 public:
27     TimelineWidget(QWidget *parent = 0);
28
29     void setProfile(trace::Profile* profile);
30
31 protected:
32     virtual void wheelEvent(QWheelEvent *e);
33     virtual void mousePressEvent(QMouseEvent *e);
34     virtual void mouseMoveEvent(QMouseEvent *e);
35     virtual void mouseReleaseEvent(QMouseEvent *e);
36     virtual void mouseDoubleClickEvent(QMouseEvent *e);
37
38     virtual void paintEvent(QPaintEvent *e);
39     virtual void resizeEvent(QResizeEvent *e);
40
41 public slots:
42     void setHorizontalScrollValue(int value);
43     void setVerticalScrollValue(int value);
44
45 signals:
46     void verticalScrollMaxChanged(int max);
47     void verticalScrollValueChanged(int value);
48
49     void horizontalScrollMaxChanged(int max);
50     void horizontalScrollValueChanged(int value);
51
52     void jumpToCall(int call);
53
54     void selectionChanged(int64_t start, int64_t end);
55
56 private:
57     void setSelection(int64_t start, int64_t end, bool notify = false);
58     void setRowScroll(int position, bool notify = true);
59     void setTimeScroll(int64_t time, bool notify = true);
60
61     void paintHeatmapColumn(int x, QPainter& painter, QVector<uint64_t>& rows);
62
63     double timeToPosition(int64_t time);
64     int64_t positionToTime(int pos);
65
66     const VisibleItem* itemAtPosition(const QPoint& pos);
67
68     void calculateRows();
69
70 private:
71     /* Data */
72     trace::Profile* m_profile;
73     QList<int> m_programRowMap;
74     QList<VisibleItem> m_visibleItems;
75
76     /* Scrollbars */
77     int m_scrollX;
78     int m_scrollY;
79     int m_maxScrollX;
80     int m_maxScrollY;
81
82     /* Viewport */
83     int m_viewWidth;
84     int m_viewHeight;
85
86     /* Visible Times */
87     int64_t m_time;
88     int64_t m_timeMin;
89     int64_t m_timeMax;
90     int64_t m_timeWidth;
91     int64_t m_timeWidthMin;
92     int64_t m_timeWidthMax;
93     int64_t m_timeSelectionStart;
94     int64_t m_timeSelectionEnd;
95
96     /* Visible Rows */
97     int m_row;
98     int m_rowCount;
99
100     /* Mouse data */
101     int m_mousePressRow;
102     int64_t m_mousePressTime;
103     QPoint m_mousePosition;
104     QPoint m_mousePressPosition;
105     MousePressMode m_mousePressMode;
106
107     /* Style */
108     int m_rowHeight;
109     int m_axisWidth;
110     int m_axisHeight;
111     QPen m_axisBorder;
112     QBrush m_axisBackground;
113     QPen m_itemBorder;
114     QPen m_itemForeground;
115     QBrush m_itemBackground;
116     QPen m_selectionBorder;
117     QBrush m_selectionBackground;
118     QPen m_zoomBorder;
119     QBrush m_zoomBackground;
120 };
121
122 #endif // TIMELINEWIDGET_H