replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.
[metze/wireshark/wip.git] / ui / qt / models / timeline_delegate.h
1 /* timeline_delegate.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later*/
8
9 #ifndef TIMELINE_DELEGATE_H
10 #define TIMELINE_DELEGATE_H
11
12 /*
13  * @file Timeline delegate.
14  *
15  * QStyledItemDelegate subclass that will draw a timeline indicator for
16  * the specified value.
17  *
18  * This is intended to be used in QTreeWidgets to show timelines, e.g. for
19  * conversations.
20  * To use it, first call setItemDelegate:
21  *
22  *   myTreeWidget()->setItemDelegateForColumn(col_time_start_, new TimelineDelegate());
23  *
24  * Then, for each QTreeWidgetItem, set or return a timeline_span for the start and end
25  * of the timeline in pixels relative to the column width.
26  *
27  *   setData(col_start_, Qt::UserRole, start_span);
28  *   setData(col_end_, Qt::UserRole, end_span);
29  *
30  */
31
32 #include <QStyledItemDelegate>
33
34 // Pixels are relative to item rect and will be clipped.
35 struct timeline_span {
36     int start;
37     int width;
38 };
39
40 Q_DECLARE_METATYPE(timeline_span)
41
42 class TimelineDelegate : public QStyledItemDelegate
43 {
44     Q_OBJECT
45
46 public:
47     TimelineDelegate(QWidget *parent = 0);
48
49     // Make sure QStyledItemDelegate::paint doesn't draw any text.
50     virtual QString displayText(const QVariant &, const QLocale &) const { return QString(); }
51
52 protected:
53     void paint(QPainter *painter, const QStyleOptionViewItem &option,
54                const QModelIndex &index) const;
55 private:
56 };
57
58 #endif // TIMELINE_DELEGATE_H
59
60 /*
61  * Editor modelines
62  *
63  * Local Variables:
64  * c-basic-offset: 4
65  * tab-width: 8
66  * indent-tabs-mode: nil
67  * End:
68  *
69  * ex: set shiftwidth=4 tabstop=8 expandtab:
70  * :indentSize=4:tabSize=8:noTabs=true:
71  */