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