Skip to content

Commit 851d862

Browse files
committed
Add all remaining work for sections in tree and to Fountain/HTML
1 parent 4493baf commit 851d862

File tree

9 files changed

+128
-68
lines changed

9 files changed

+128
-68
lines changed

src/act.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,17 @@ Act::Act(const QString &m_data) : Section(m_data)
55

66
}
77

8-
QString Act::toHtml()
9-
{
10-
//TODO Print internal blocks
11-
12-
return QString();
13-
}
14-
158
QString Act::toFountain()
169
{
17-
//TODO Print internal blocks
10+
QString result = "# " + m_data + "\n";
1811

19-
return "# " + m_data;
20-
}
21-
22-
void Act::toTreeWidgetItem(QTreeWidgetItem *parent)
23-
{
24-
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << m_data);
12+
if (!getSynopsis()->getData().isEmpty()) {
13+
result.append(getSynopsis()->toFountain());
14+
}
2515

26-
//TODO Add internal blocks to tree
16+
foreach (Block *block, *getList()) {
17+
result.append(block->toFountain());
18+
}
2719

28-
parent->addChild(item);
20+
return result;
2921
}

src/act.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class Act : public Section
88
public:
99
Act(const QString &m_data);
1010

11-
virtual QString toHtml();
1211
virtual QString toFountain();
13-
virtual void toTreeWidgetItem(QTreeWidgetItem *parent);
1412
};
1513

1614
#endif // ACT_H

src/scenesection.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@ SceneSection::SceneSection(const QString &m_data) : Section(m_data)
55

66
}
77

8-
QString SceneSection::toHtml()
9-
{
10-
//TODO Print internal blocks
11-
12-
return QString();
13-
}
14-
158
QString SceneSection::toFountain()
169
{
17-
//TODO Print internal blocks
10+
QString result = "### " + m_data + "\n";
1811

19-
return "### " + m_data;
20-
}
12+
if (!getSynopsis()->getData().isEmpty()) {
13+
result.append(getSynopsis()->toFountain());
14+
}
2115

22-
void SceneSection::toTreeWidgetItem(QTreeWidgetItem *parent)
23-
{
24-
//TODO Add internal blocks to tree
16+
foreach (Block *block, *getList()) {
17+
result.append(block->toFountain());
18+
}
2519

26-
parent->addChild(new QTreeWidgetItem(QStringList() << m_data));
20+
return result;
2721
}

src/scenesection.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class SceneSection : public Section
88
public:
99
SceneSection(const QString &m_data);
1010

11-
virtual QString toHtml();
1211
virtual QString toFountain();
13-
virtual void toTreeWidgetItem(QTreeWidgetItem *parent);
1412
};
1513

1614
#endif // SCENESECTION_H

src/script.cpp

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
#include "title.h"
2626
#include "transition.h"
2727

28-
#define BLOCK_MAIN 0
29-
#define BLOCK_ACT 1
30-
#define BLOCK_SEQUENCE 2
31-
#define BLOCK_SCENE 3
32-
#define BLOCK_SCENEHEADER 4
28+
#define BLOCK_MAIN 1
29+
#define BLOCK_ACT 2
30+
#define BLOCK_SEQUENCE 4
31+
#define BLOCK_SCENESECTION 8
32+
#define BLOCK_SCENE 16
3333

3434
Script::Script()
3535
{
@@ -113,7 +113,7 @@ void Script::parseFromFountain(const QString& script)
113113
qDeleteAll(m_content);
114114
m_content.clear();
115115

116-
quint8 currentBlock = BLOCK_MAIN;
116+
quint8 currentBlockType = BLOCK_MAIN;
117117
QList<Block *> *blocklist = &m_content;
118118

119119
while (i < blockcount) {
@@ -158,16 +158,71 @@ void Script::parseFromFountain(const QString& script)
158158
} else if (text.left(8) == "Contact:") { //Contact
159159
TitlePageElement *contact = new Contact(text.mid(8).trimmed());
160160
parseTitlePageData(i, lines, contact);
161-
} else if (text.left(4) == "### ") { //Scene
162-
blocklist->append(new SceneSection(text.mid(4)));
161+
} else if (text.left(4) == "### ") { //Scene Section
162+
SceneSection *scenesection = new SceneSection(text.mid(4));
163+
164+
if (currentBlockType & (BLOCK_SCENE | BLOCK_SCENESECTION)) {
165+
Act *act = dynamic_cast<Act*>(m_content.last());
166+
167+
if (act != nullptr) {
168+
if (act->getList()->size() > 0) {
169+
Sequence *sequence = dynamic_cast<Sequence*>(act->getList()->last());
170+
171+
if (sequence != nullptr) {
172+
sequence->addBlock(scenesection);
173+
} else {
174+
act->addBlock(scenesection);
175+
}
176+
} else {
177+
act->addBlock(scenesection);
178+
}
179+
} else {
180+
Sequence *sequence = dynamic_cast<Sequence*>(m_content.last());
181+
182+
if (sequence != nullptr) {
183+
sequence->addBlock(scenesection);
184+
} else {
185+
m_content.append(scenesection);
186+
}
187+
}
188+
} else {
189+
blocklist->append(scenesection);
190+
}
191+
192+
blocklist = scenesection->getList();
193+
currentBlockType = BLOCK_SCENESECTION;
163194
} else if (text.left(3) == "## ") { //Sequence
164-
blocklist->append(new Sequence(text.mid(3)));
195+
Sequence *sequence = new Sequence(text.mid(3));
196+
197+
if (currentBlockType & (BLOCK_SEQUENCE | BLOCK_SCENE | BLOCK_SCENESECTION)) {
198+
Act *act = dynamic_cast<Act*>(m_content.last());
199+
if (act != nullptr) {
200+
act->addBlock(sequence);
201+
} else {
202+
m_content.append(sequence);
203+
}
204+
} else {
205+
blocklist->append(sequence);
206+
}
207+
208+
blocklist = sequence->getList();
209+
currentBlockType = BLOCK_SEQUENCE;
165210
} else if (text.left(2) == "# ") { //Act
166-
blocklist->append(new Act(text.mid(2)));
211+
Act *act = new Act(text.mid(2));
212+
m_content.append(act);
213+
blocklist = act->getList();
214+
currentBlockType = BLOCK_ACT;
167215
} else if ((validStartHeaders.indexOf(text.split(".").first().toUpper()) >= 0 || validStartHeaders.indexOf(text.split(" ").first().toUpper()) >= 0) && isABlankLine(i-1, lines) && isABlankLine(i+1, lines)) { //Scene heading
168216
Scene *scene = new Scene(text);
169-
m_content.append(scene);
217+
218+
if (currentBlockType != BLOCK_SCENE) {
219+
blocklist->append(scene);
220+
} else {
221+
m_content.append(scene);
222+
}
223+
170224
blocklist = scene->getList();
225+
currentBlockType = BLOCK_SCENE;
171226
} else if (text.left(1) == ">") {
172227
if (text.right(1) == "<") { //Centered text
173228
Action *action = new Action(text.mid(1, text.size()-2).trimmed());

src/section.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,39 @@ void Section::setSynopsis(Synopsis *synopsis)
1010
m_synopsis = synopsis;
1111
}
1212

13+
Synopsis *Section::getSynopsis()
14+
{
15+
return &m_synopsis;
16+
}
17+
1318
void Section::addBlock(Block *block)
1419
{
15-
QSharedPointer<Block> ptr(block);
16-
m_content.append(ptr);
20+
m_content.append(block);
21+
}
22+
23+
QList<Block *> *Section::getList()
24+
{
25+
return &m_content;
26+
}
27+
28+
QString Section::toHtml()
29+
{
30+
QString result;
31+
32+
foreach (Block *block, m_content) {
33+
result.append(block->toHtml());
34+
}
35+
36+
return result;
37+
}
38+
39+
void Section::toTreeWidgetItem(QTreeWidgetItem *parent)
40+
{
41+
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << m_data);
42+
43+
foreach (Block *block, m_content) {
44+
block->toTreeWidgetItem(item);
45+
}
46+
47+
parent->addChild(item);
1748
}

src/section.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef SECTION_H
22
#define SECTION_H
33

4-
#include <QSharedPointer>
5-
64
#include "block.h"
75
#include "synopsis.h"
86

@@ -11,14 +9,16 @@ class Section : public Block
119
public:
1210
Section(const QString &m_data);
1311
void setSynopsis(Synopsis *synopsis);
12+
Synopsis *getSynopsis();
1413
void addBlock(Block *block);
14+
QList<Block *> *getList();
1515

16-
virtual QString toHtml() = 0;
16+
virtual QString toHtml();
1717
virtual QString toFountain() = 0;
18-
virtual void toTreeWidgetItem(QTreeWidgetItem *parent) = 0;
18+
virtual void toTreeWidgetItem(QTreeWidgetItem *parent);
1919
private:
2020
Synopsis m_synopsis;
21-
QList<QSharedPointer<Block>> m_content;
21+
QList<Block *> m_content;
2222
};
2323

2424
#endif // SECTION_H

src/sequence.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@ Sequence::Sequence(const QString &m_data) : Section(m_data)
55

66
}
77

8-
QString Sequence::toHtml()
9-
{
10-
//TODO Print internal blocks
11-
12-
return QString();
13-
}
14-
158
QString Sequence::toFountain()
169
{
17-
//TODO Print internal blocks
10+
QString result = "## " + m_data + "\n";
1811

19-
return "## " + m_data;
20-
}
12+
if (!getSynopsis()->getData().isEmpty()) {
13+
result.append(getSynopsis()->toFountain());
14+
}
2115

22-
void Sequence::toTreeWidgetItem(QTreeWidgetItem *parent)
23-
{
24-
//TODO Add internal blocks to tree
16+
foreach (Block *block, *getList()) {
17+
result.append(block->toFountain());
18+
}
2519

26-
parent->addChild(new QTreeWidgetItem(QStringList() << m_data));
20+
return result;
2721
}

src/sequence.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class Sequence : public Section
88
public:
99
Sequence(const QString &m_data);
1010

11-
virtual QString toHtml();
1211
virtual QString toFountain();
13-
virtual void toTreeWidgetItem(QTreeWidgetItem *parent);
1412
};
1513

1614
#endif // SEQUENCE_H

0 commit comments

Comments
 (0)