-
Notifications
You must be signed in to change notification settings - Fork 0
/
producer.cpp
213 lines (174 loc) · 5.58 KB
/
producer.cpp
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <QtCore/QDebug>
#include <QtCore/QDateTime>
#include "producer.h"
Producer::Producer(ChyronPointer chyron,
IReporterPointer reporter,
StoryInfoPointer story_info,
StyleListPointer style_list,
QObject *parent)
: QObject(parent),
reporter(reporter),
chyron(chyron),
story_info(story_info),
style_list(style_list)
{
auto reporter_draw = dynamic_cast<IReporter2*>(reporter.data());
if(reporter_draw && reporter_draw->UseReporterDraw())
connect(chyron.data(), &Chyron::signal_headline_going_out_of_scope, this, &Producer::slot_headline_going_out_of_scope);
}
Producer::~Producer()
{
if(covering_story)
stop_covering_story();
chyron.clear();
reporter.clear();
}
bool Producer::start_covering_story()
{
if(story_shelved)
{
chyron->display();
story_shelved = false;
return true;
}
if(covering_story)
return true;
if(reporter.isNull() || chyron.isNull())
return false;
connect(this, &Producer::signal_new_headline, chyron.data(), &Chyron::slot_file_headline);
chyron->display();
connect(reporter.data(), &IReporter::signal_new_data, this, &Producer::slot_new_data);
reporter->SetStory(story_info->story);
if(!reporter->CoverStory())
{
disconnect(reporter.data(), &IReporter::signal_new_data, this, &Producer::slot_new_data);
return false;
}
covering_story = true;
return covering_story;
}
bool Producer::stop_covering_story()
{
if(!covering_story)
return true;
if(reporter.isNull() || chyron.isNull())
return false;
disconnect(this, &Producer::signal_new_headline, chyron.data(), &Chyron::slot_file_headline);
if(!story_shelved)
chyron->hide();
story_shelved = false;
disconnect(reporter.data(), &IReporter::signal_new_data, this, &Producer::slot_new_data);
covering_story = !reporter->FinishStory();
return !covering_story;
}
bool Producer::shelve_story()
{
// we have to already be covering a story to go into
// 'shelved' mode
if(!covering_story)
return false;
if(reporter.isNull() || chyron.isNull())
return false;
chyron->shelve();
story_shelved = true;
return story_shelved;
}
void Producer::file_headline(const QString& data)
{
// check for keyword triggers, and select the stylesheet appropriately
auto lower_headline = data.toLower();
QString stylesheet, default_stylesheet;
foreach(const auto& style, (*style_list.data()))
{
if(!style.name.compare("Default"))
default_stylesheet = style.stylesheet;
else if(stylesheet.isEmpty())
{
foreach(const auto& trigger, style.triggers)
{
if(lower_headline.contains(trigger.toLower()))
{
stylesheet = style.stylesheet;
break;
}
}
}
}
if(stylesheet.isEmpty())
stylesheet = default_stylesheet; // set to Default
// file a headline with the new content
auto w{0};
auto h{0};
story_info->get_dimensions(w, h);
HeadlineGenerator generator(w, h, story_info, data);
auto headline = generator.get_headline();
headline->set_stylesheet(stylesheet);
auto reporter_draw = dynamic_cast<IReporter2*>(reporter.data());
if(reporter_draw && reporter_draw->UseReporterDraw())
{
headline->set_reporter_draw(true);
connect(headline.data(), &Headline::signal_reporter_draw, reporter_draw, &IReporter2::ReporterDraw);
connect(reporter_draw, &IReporter2::signal_highlight, this, &Producer::slot_headline_highlight);
headlines.append(headline);
connect(reporter_draw, &IReporter2::signal_shelve_story, this, &Producer::signal_shelve_story);
connect(reporter_draw, &IReporter2::signal_unshelve_story, this, &Producer::signal_unshelve_story);
}
emit signal_new_headline(headline);
}
void Producer::slot_headline_going_out_of_scope(HeadlinePointer headline)
{
foreach(auto hp, headlines)
{
if(hp.data() == headline.data())
{
headlines.removeAll(hp);
break;
}
}
}
void Producer::slot_headline_highlight(qreal opacity, int timeout)
{
chyron->highlight_headline(headlines.front(), opacity, timeout);
}
void Producer::slot_start_covering_story()
{
(void)start_covering_story();
}
void Producer::slot_new_data(const QByteArray& data)
{
if(story_shelved)
return;
if(!story_info->limit_content)
{
file_headline(QString(data));
return;
}
auto has_breaks = data.contains("<br>");
QStringList lines;
if(has_breaks)
lines = QString(data).split("<br>");
else
lines = QString(data).split('\n');
QString new_line;
auto current_limit{0};
foreach(const auto& line, lines)
{
if(new_line.length())
{
if(has_breaks)
new_line += "<br>";
else
new_line += "\n";
}
new_line += line;
++current_limit;
if((current_limit % story_info->limit_content_to) == 0)
{
if(!new_line.isEmpty())
file_headline(new_line);
new_line.clear();
}
}
if(!new_line.isEmpty())
file_headline(new_line);
}