]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_timelineitem.cpp
Initial vogl checkin
[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 }
56
57 void vogleditor_timelineItem::appendChild(vogleditor_timelineItem* child)
58 {
59     childItems.append(child);
60
61     if (childItems.size() == 1)
62     {
63         // just added the first child, so overwrite the current maxChildDuration
64         m_maxChildDuration = child->getMaxChildDuration();
65     }
66     else
67     {
68         // update the maxChildDuration if needed
69         m_maxChildDuration = std::max(m_maxChildDuration, child->getMaxChildDuration());
70     }
71 }
72
73 vogleditor_timelineItem* vogleditor_timelineItem::child(int row)
74 {
75    return childItems[row];
76 }
77
78 int vogleditor_timelineItem::childCount() const
79 {
80    return childItems.size();
81 }
82
83 vogleditor_timelineItem* vogleditor_timelineItem::parent()
84 {
85    return m_parentItem;
86 }
87
88 QBrush* vogleditor_timelineItem::getBrush()
89 {
90    // if a local brush isn't set, use the parent's brush as a default
91    if (m_brush == NULL)
92    {
93       if (parent() != NULL)
94       {
95          return parent()->getBrush();
96       }
97       else
98       {
99          return NULL;
100       }
101    }
102
103    return m_brush;
104 }
105
106 void vogleditor_timelineItem::setBrush(QBrush* brush)
107 {
108    m_brush = brush;
109 }
110
111 float vogleditor_timelineItem::getBeginTime() const
112 {
113    return m_beginTime;
114 }
115
116 float vogleditor_timelineItem::getEndTime() const
117 {
118    return m_endTime;
119 }
120
121 float vogleditor_timelineItem::getDuration() const
122 {
123    return m_duration;
124 }
125
126 bool vogleditor_timelineItem::isSpan() const
127 {
128    return m_isSpan;
129 }
130
131 bool vogleditor_timelineItem::isMarker() const
132 {
133    return !m_isSpan;
134 }
135
136 float vogleditor_timelineItem::getMaxChildDuration() const
137 {
138     return m_maxChildDuration;
139 }