]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_timelineitem.cpp
UI: Fix issue #21: Resizing of vogleditor window is slow depending on trace size
[vogl] / src / vogleditor / vogleditor_timelineitem.cpp
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26
27 #include "vogleditor_timelineitem.h"
28
29 vogleditor_timelineItem::vogleditor_timelineItem(float time, vogleditor_timelineItem* parent)
30    :  m_beginTime(time),
31       m_endTime(time),
32       m_duration(0),
33       m_isSpan(false),
34       m_maxChildDuration(0),
35       m_parentItem(parent),
36       m_pFrameItem(NULL),
37       m_pApiCallItem(NULL)
38 {
39 }
40
41 vogleditor_timelineItem::vogleditor_timelineItem(float begin, float end, vogleditor_timelineItem* parent)
42    :  m_beginTime(begin),
43       m_endTime(end),
44       m_duration(end - begin),
45       m_isSpan(true),
46       m_maxChildDuration(end - begin),
47       m_parentItem(parent),
48       m_pFrameItem(NULL),
49       m_pApiCallItem(NULL)
50 {
51 }
52
53 vogleditor_timelineItem::~vogleditor_timelineItem()
54 {
55     for (int i = 0; i < m_childItems.size(); i++)
56     {
57         delete m_childItems[i];
58         m_childItems[i] = NULL;
59     }
60     m_childItems.clear();
61 }
62
63 void vogleditor_timelineItem::appendChild(vogleditor_timelineItem* child)
64 {
65     m_childItems.append(child);
66
67     if (m_childItems.size() == 1)
68     {
69         // just added the first child, so overwrite the current maxChildDuration
70         m_maxChildDuration = child->getMaxChildDuration();
71     }
72     else
73     {
74         // update the maxChildDuration if needed
75         m_maxChildDuration = std::max(m_maxChildDuration, child->getMaxChildDuration());
76     }
77 }
78
79 vogleditor_timelineItem* vogleditor_timelineItem::child(int row)
80 {
81    return m_childItems[row];
82 }
83
84 int vogleditor_timelineItem::childCount() const
85 {
86    return m_childItems.size();
87 }
88
89 vogleditor_timelineItem* vogleditor_timelineItem::parent()
90 {
91    return m_parentItem;
92 }
93
94 QBrush* vogleditor_timelineItem::getBrush()
95 {
96    // if a local brush isn't set, use the parent's brush as a default
97    if (m_brush == NULL)
98    {
99       if (parent() != NULL)
100       {
101          return parent()->getBrush();
102       }
103       else
104       {
105          return NULL;
106       }
107    }
108
109    return m_brush;
110 }
111
112 void vogleditor_timelineItem::setBrush(QBrush* brush)
113 {
114    m_brush = brush;
115 }
116
117 float vogleditor_timelineItem::getBeginTime() const
118 {
119    return m_beginTime;
120 }
121
122 float vogleditor_timelineItem::getEndTime() const
123 {
124    return m_endTime;
125 }
126
127 float vogleditor_timelineItem::getDuration() const
128 {
129    return m_duration;
130 }
131
132 bool vogleditor_timelineItem::isSpan() const
133 {
134    return m_isSpan;
135 }
136
137 bool vogleditor_timelineItem::isMarker() const
138 {
139    return !m_isSpan;
140 }
141
142 float vogleditor_timelineItem::getMaxChildDuration() const
143 {
144     return m_maxChildDuration;
145 }