]> git.sesse.net Git - kdenlive/blob - src/definitions.cpp
Cleaning code style of Definitions.
[kdenlive] / src / definitions.cpp
1 #include "definitions.h"
2
3 QDebug operator << (QDebug qd, const ItemInfo &info)
4 {
5     qd << "ItemInfo " << &info;
6     qd << "\tTrack" << info.track;
7     qd << "\tStart pos: " << info.startPos.toString();
8     qd << "\tEnd pos: " << info.endPos.toString();
9     qd << "\tCrop start: " << info.cropStart.toString();
10     qd << "\tCrop duration: " << info.cropDuration.toString();
11     return qd.maybeSpace();
12 }
13
14
15 MltVideoProfile::MltVideoProfile() :
16     frame_rate_num(0),
17     frame_rate_den(0),
18     width(0),
19     height(0),
20     progressive(0),
21     sample_aspect_num(0),
22     sample_aspect_den(0),
23     display_aspect_num(0),
24     display_aspect_den(0),
25     colorspace(0)
26 {
27 }
28
29 bool MltVideoProfile::operator==(const MltVideoProfile &point) const
30 {
31     if (!description.isEmpty() && point.description  == description) {
32         return true;
33     }
34     return      point.frame_rate_num == frame_rate_num &&
35             point.frame_rate_den  == frame_rate_den  &&
36             point.width == width &&
37             point.height == height &&
38             point.progressive == progressive &&
39             point.sample_aspect_num == sample_aspect_num &&
40             point.sample_aspect_den == sample_aspect_den &&
41             point.display_aspect_den == display_aspect_den &&
42             point.colorspace == colorspace;
43 }
44
45 bool MltVideoProfile::operator!=(const MltVideoProfile &other) const {
46     return !(*this == other);
47 }
48
49
50 EffectInfo::EffectInfo() {isCollapsed = false; groupIndex = -1; groupIsCollapsed = false;}
51
52 QString EffectInfo::toString() const {
53     QStringList data;
54     // effect collapsed state: 0 = effect not collapsed, 1 = effect collapsed,
55     // 2 = group collapsed - effect not, 3 = group and effect collapsed
56     int collapsedState = (int) isCollapsed;
57     if (groupIsCollapsed) collapsedState += 2;
58     data << QString::number(collapsedState) << QString::number(groupIndex) << groupName;
59     return data.join(QLatin1String("/"));
60 }
61
62 void EffectInfo::fromString(QString value) {
63     if (value.isEmpty()) return;
64     QStringList data = value.split(QLatin1String("/"));
65     isCollapsed = data.at(0).toInt() == 1 || data.at(0).toInt() == 3;
66     groupIsCollapsed = data.at(0).toInt() >= 2;
67     if (data.count() > 1) groupIndex = data.at(1).toInt();
68     if (data.count() > 2) groupName = data.at(2);
69 }
70
71
72 EffectParameter::EffectParameter(const QString &name, const QString &value): m_name(name), m_value(value) {}
73
74 QString EffectParameter::name() const          {
75     return m_name;
76 }
77
78 QString EffectParameter::value() const          {
79     return m_value;
80 }
81
82 void EffectParameter::setValue(const QString &value) {
83     m_value = value;
84 }
85
86
87 EffectsParameterList::EffectsParameterList(): QList < EffectParameter >() {}
88
89 bool EffectsParameterList::hasParam(const QString &name) const {
90     for (int i = 0; i < size(); ++i)
91         if (at(i).name() == name) return true;
92     return false;
93 }
94
95 void EffectsParameterList::setParamValue(const QString &name, const QString &value) {
96     bool found = false;
97     for (int i = 0; i < size(); ++i)
98         if (at(i).name() == name) {
99             // update value
100             replace(i, EffectParameter(name, value));
101             found = true;
102         }
103     if (!found) addParam(name, value);
104 }
105
106 QString EffectsParameterList::paramValue(const QString &name, const QString &defaultValue) const {
107     for (int i = 0; i < size(); ++i) {
108         if (at(i).name() == name) return at(i).value();
109     }
110     return defaultValue;
111 }
112
113 void EffectsParameterList::addParam(const QString &name, const QString &value) {
114     if (name.isEmpty()) return;
115     append(EffectParameter(name, value));
116 }
117
118 void EffectsParameterList::removeParam(const QString &name) {
119     for (int i = 0; i < size(); ++i)
120         if (at(i).name() == name) {
121             removeAt(i);
122             break;
123         }
124 }
125
126
127 CommentedTime::CommentedTime(): t(GenTime(0)), type(0) {}
128
129
130 CommentedTime::CommentedTime(const GenTime &time, const QString &comment, int markerType)
131     : t(time), c(comment), type(markerType) { }
132
133 QString CommentedTime::comment() const          {
134     return (c.isEmpty() ? i18n("Marker") : c);
135 }
136
137 GenTime CommentedTime::time() const          {
138     return t;
139 }
140
141 void CommentedTime::setComment(const QString &comm) {
142     c = comm;
143 }
144
145 void CommentedTime::setMarkerType(int t) {
146     type = t;
147 }
148
149 int CommentedTime::markerType() const {
150     return type;
151 }
152
153 QColor CommentedTime::markerColor(int type) {
154     switch (type) {
155     case 0:
156         return Qt::red;
157         break;
158     case 1:
159         return Qt::blue;
160         break;
161     case 2:
162         return Qt::green;
163         break;
164     case 3:
165         return Qt::yellow;
166         break;
167     default:
168         return Qt::cyan;
169         break;
170     }
171 }
172
173 bool CommentedTime::operator>(CommentedTime op) const {
174     return t > op.time();
175 }
176
177 bool CommentedTime::operator<(CommentedTime op) const {
178     return t < op.time();
179 }
180
181 bool CommentedTime::operator>=(CommentedTime op) const {
182     return t >= op.time();
183 }
184
185 bool CommentedTime::operator<=(CommentedTime op) const {
186     return t <= op.time();
187 }
188
189 bool CommentedTime::operator==(CommentedTime op) const {
190     return t == op.time();
191 }
192
193 bool CommentedTime::operator!=(CommentedTime op) const {
194     return t != op.time();
195 }