Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txshnoteset.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TXshNoteSet
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshNoteSet::TXshNoteSet()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TXshNoteSet::addNote(Note note)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_notes.push_back(note);
Toshihiro Shimizu 890ddd
	return getCount() - 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::removeNote(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_notes.empty() || index >= (int)m_notes.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_notes.removeAt(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TXshNoteSet::getCount() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_notes.empty())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return m_notes.size();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TXshNoteSet::getNoteColorIndex(int noteIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return m_notes[noteIndex].m_colorIndex;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::setNoteColorIndex(int noteIndex, int colorIndex)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_notes[noteIndex].m_colorIndex = colorIndex;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QString TXshNoteSet::getNoteHtmlText(int noteIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return QString();
Toshihiro Shimizu 890ddd
	return m_notes[noteIndex].m_text;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::setNoteHtmlText(int noteIndex, QString text)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_notes[noteIndex].m_text = text;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TXshNoteSet::getNoteRow(int noteIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return m_notes[noteIndex].m_row;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::setNoteRow(int noteIndex, int row)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_notes[noteIndex].m_row = row;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TXshNoteSet::getNoteCol(int noteIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return m_notes[noteIndex].m_col;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::setNoteCol(int noteIndex, int col)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_notes[noteIndex].m_col = col;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPointD TXshNoteSet::getNotePos(int noteIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return TPointD(5, 5);
Toshihiro Shimizu 890ddd
	return m_notes[noteIndex].m_pos;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::setNotePos(int noteIndex, TPointD pos)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(noteIndex < m_notes.size());
Toshihiro Shimizu 890ddd
	if (noteIndex >= m_notes.size())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_notes[noteIndex].m_pos = pos;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::loadData(TIStream &is)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	while (!is.eos()) {
Shinya Kitaoka 3bfa54
		std::string tagName;
Toshihiro Shimizu 890ddd
		if (is.matchTag(tagName)) {
Toshihiro Shimizu 890ddd
			if (tagName == "notes") {
Toshihiro Shimizu 890ddd
				while (!is.eos()) {
Shinya Kitaoka 3bfa54
					std::string tagName;
Toshihiro Shimizu 890ddd
					if (is.matchTag(tagName)) {
Toshihiro Shimizu 890ddd
						if (tagName == "note") {
Toshihiro Shimizu 890ddd
							Note note;
Toshihiro Shimizu 890ddd
							is >> note.m_colorIndex;
Toshihiro Shimizu 890ddd
							std::wstring text;
Toshihiro Shimizu 890ddd
							is >> text;
Toshihiro Shimizu 890ddd
							note.m_text = QString::fromStdWString(text);
Toshihiro Shimizu 890ddd
							is >> note.m_row;
Toshihiro Shimizu 890ddd
							is >> note.m_col;
Toshihiro Shimizu 890ddd
							is >> note.m_pos.x;
Toshihiro Shimizu 890ddd
							is >> note.m_pos.y;
Toshihiro Shimizu 890ddd
							m_notes.push_back(note);
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
					} else
Toshihiro Shimizu 890ddd
						throw TException("expected <note>");</note>
Toshihiro Shimizu 890ddd
					is.closeChild();
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				throw TException("expected <defaultcolor> or <notes>");</notes></defaultcolor>
Toshihiro Shimizu 890ddd
			is.closeChild();
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			throw TException("expected tag");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshNoteSet::saveData(TOStream &os)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	os.openChild("notes");
Toshihiro Shimizu 890ddd
	for (i = 0; i < getCount(); i++) {
Toshihiro Shimizu 890ddd
		os.openChild("note");
Toshihiro Shimizu 890ddd
		Note note = m_notes.at(i);
Toshihiro Shimizu 890ddd
		os << note.m_colorIndex;
Toshihiro Shimizu 890ddd
		os << note.m_text.toStdWString();
Toshihiro Shimizu 890ddd
		os << note.m_row;
Toshihiro Shimizu 890ddd
		os << note.m_col;
Toshihiro Shimizu 890ddd
		os << note.m_pos.x;
Toshihiro Shimizu 890ddd
		os << note.m_pos.y;
Toshihiro Shimizu 890ddd
		os.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	os.closeChild();
Toshihiro Shimizu 890ddd
}