tahoma2d/toonz/sources/toonzlib/txshsoundtextlevel.cpp

81 lines
2.3 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "toonz/txshsoundtextlevel.h"
#include "toonz/txshleveltypes.h"
#include "tstream.h"
//-----------------------------------------------------------------------------
DEFINE_CLASS_CODE(TXshSoundTextLevel, 54)
PERSIST_IDENTIFIER(TXshSoundTextLevel, "soundTextLevel")
//=============================================================================
TXshSoundTextLevel::TXshSoundTextLevel(std::wstring name)
2016-06-15 18:43:10 +12:00
: TXshLevel(m_classCode, name), m_framesText() {}
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TXshSoundTextLevel::~TXshSoundTextLevel() {}
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TXshSoundTextLevel *TXshSoundTextLevel::clone() const {
TXshSoundTextLevel *sound = new TXshSoundTextLevel(m_name);
return sound;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TXshSoundTextLevel::setFrameText(int frameIndex, QString text) {
while (frameIndex >= m_framesText.size()) {
m_framesText.append(QString(" "));
}
2016-06-15 18:43:10 +12:00
m_framesText.replace(frameIndex, text);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
QString TXshSoundTextLevel::getFrameText(int frameIndex) const {
if (frameIndex >= m_framesText.size()) return QString();
return m_framesText[frameIndex];
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TXshSoundTextLevel::loadData(TIStream &is) {
is >> m_name;
setName(m_name);
std::string tagName;
int type = UNKNOWN_XSHLEVEL;
while (is.matchTag(tagName)) {
if (tagName == "type") {
std::string v;
is >> v;
if (v == "textSound") type = SND_TXT_XSHLEVEL;
is.matchEndTag();
} else if (tagName == "frame") {
2017-11-16 21:36:43 +13:00
std::wstring text;
2016-06-15 18:43:10 +12:00
is >> text;
2017-11-16 21:36:43 +13:00
m_framesText.push_back(QString::fromStdWString(text));
2016-06-15 18:43:10 +12:00
is.matchEndTag();
} else
throw TException("unexpected tag " + tagName);
}
setType(type);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TXshSoundTextLevel::saveData(TOStream &os) {
os << m_name;
int i;
for (i = 0; i < m_framesText.size(); i++) {
os.openChild("frame");
os << m_framesText[i];
os.closeChild();
}
os.child("type") << L"textSound";
2016-03-19 06:57:51 +13:00
}