Repository navigation
Expand file tree
/
Copy pathTitle.cpp
More file actions
167 lines (136 loc) · 3.03 KB
/
Copy pathTitle.cpp
File metadata and controls
167 lines (136 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "Title.h"
Title::Title(int start, int length, string text)
{
this->title_serial = 0;
this->title_selected = false;
this->time_begin = new Time(start);
this->time_end = new Time(start+length);
this->title_text = text;
this->title_error = (this->time_begin->getTimeLength() > this->time_end->getTimeLength());
}
Title::Title(string str, int& pos)
{
this->title_serial = readSerial(str, pos);
if (this->title_serial == -1) {
this->title_error = true;
}
string beginTime = readTime(str, pos);
this->time_begin = new Time(beginTime);
pos += 5; // da proguta " --> "
string endTime = readTime(str, pos);
this->time_end = new Time(endTime);
pos++;
this->title_text = readText(str, pos);
this->title_selected = false;
this->title_error = this->title_error || (this->time_begin->getTimeLength() > this->time_end->getTimeLength());
}
Title::~Title()
{
delete this->time_begin;
delete this->time_end;
}
void Title::selectTitle()
{
this->title_selected = true;
}
void Title::deselectTitle()
{
this->title_selected = false;
}
void Title::changeTitleTime(int ms)
{
this->time_begin->changeTime(ms);
this->time_end->changeTime(ms);
}
void Title::setTitleSerial(int serial)
{
this->title_serial = serial;
}
void Title::setText(string text)
{
this->title_text = text;
}
void Title::setEndingTime(int ms)
{
int endingTime = this->time_begin->getTimeLength() + ms;
this->time_end->setTime(endingTime);
}
int Title::getSerial()
{
return this->title_serial;
}
string Title::getText()
{
int stringSize = this->title_text.length();
if (this->title_text[stringSize - 1] == '\n') {
string fixedText = "";
for (int i = 0; i < (stringSize - 1); i++) fixedText += this->title_text[i];
return fixedText;
}
else return this->title_text;
}
string Title::getTitleTimes()
{
string str;
str.append(this->time_begin->getTime());
str.append(" --> ");
str.append(this->time_end->getTime());
str.append("\n");
return str;
}
bool Title::getError()
{
return this->title_error;
}
int Title::getTitleBeginningTime()
{
return this->time_begin->getTimeLength();;
}
int Title::getTitleEndingTime()
{
return this->time_end->getTimeLength();
}
int Title::getTitleTimeLength()
{
return (this->getTitleEndingTime() - this->getTitleBeginningTime());
}
bool Title::getSelection()
{
return this->title_selected;
}
int Title::readSerial(string str, int& pos)
{
int num = 0;
while (str[pos] != '\n') {
if (str[pos] >= '0' && str[pos] <= '9') {
num = num * 10 + (str[pos] - '0');
pos++;
}
else {
this->title_error = true;
return -1;
}
}
pos++;
return num;
}
string Title::readTime(string str, int& pos)
{
string time = "";
for (int i = 0; i < 12; i++) {
time += str[pos];
pos++;
}
return time;
}
string Title::readText(string str, int& pos)
{
string s;
while (str[pos] != '\n' || str[pos + 1] != '\n')
{
s.push_back(str[pos]);
pos++;
}
pos += 2;
return s;
}