1
2
3 #include "toonz/txshnoteset.h"
4 #include "tstream.h"
5 #include "texception.h"
6
7 #include <QString>
8
9 //=============================================================================
10 // TXshNoteSet
11
TXshNoteSet()12 TXshNoteSet::TXshNoteSet() {}
13
14 //-----------------------------------------------------------------------------
15
addNote(Note note)16 int TXshNoteSet::addNote(Note note) {
17 m_notes.push_back(note);
18 return getCount() - 1;
19 }
20
21 //-----------------------------------------------------------------------------
22
removeNote(int index)23 void TXshNoteSet::removeNote(int index) {
24 if (m_notes.empty() || index >= (int)m_notes.size()) return;
25 m_notes.removeAt(index);
26 }
27
28 //-----------------------------------------------------------------------------
29
getCount() const30 int TXshNoteSet::getCount() const {
31 if (m_notes.empty()) return 0;
32 return m_notes.size();
33 }
34
35 //-----------------------------------------------------------------------------
36
getNoteColorIndex(int noteIndex) const37 int TXshNoteSet::getNoteColorIndex(int noteIndex) const {
38 assert(noteIndex < m_notes.size());
39 if (noteIndex >= m_notes.size()) return 0;
40 return m_notes[noteIndex].m_colorIndex;
41 }
42
43 //-----------------------------------------------------------------------------
44
setNoteColorIndex(int noteIndex,int colorIndex)45 void TXshNoteSet::setNoteColorIndex(int noteIndex, int colorIndex) {
46 assert(noteIndex < m_notes.size());
47 if (noteIndex >= m_notes.size()) return;
48 m_notes[noteIndex].m_colorIndex = colorIndex;
49 }
50
51 //-----------------------------------------------------------------------------
52
getNoteHtmlText(int noteIndex) const53 QString TXshNoteSet::getNoteHtmlText(int noteIndex) const {
54 assert(noteIndex < m_notes.size());
55 if (noteIndex >= m_notes.size()) return QString();
56 return m_notes[noteIndex].m_text;
57 }
58
59 //-----------------------------------------------------------------------------
60
setNoteHtmlText(int noteIndex,QString text)61 void TXshNoteSet::setNoteHtmlText(int noteIndex, QString text) {
62 assert(noteIndex < m_notes.size());
63 if (noteIndex >= m_notes.size()) return;
64 m_notes[noteIndex].m_text = text;
65 }
66
67 //-----------------------------------------------------------------------------
68
getNoteRow(int noteIndex) const69 int TXshNoteSet::getNoteRow(int noteIndex) const {
70 assert(noteIndex < m_notes.size());
71 if (noteIndex >= m_notes.size()) return 0;
72 return m_notes[noteIndex].m_row;
73 }
74
75 //-----------------------------------------------------------------------------
76
setNoteRow(int noteIndex,int row)77 void TXshNoteSet::setNoteRow(int noteIndex, int row) {
78 assert(noteIndex < m_notes.size());
79 if (noteIndex >= m_notes.size()) return;
80 m_notes[noteIndex].m_row = row;
81 }
82
83 //-----------------------------------------------------------------------------
84
getNoteCol(int noteIndex) const85 int TXshNoteSet::getNoteCol(int noteIndex) const {
86 assert(noteIndex < m_notes.size());
87 if (noteIndex >= m_notes.size()) return 0;
88 return m_notes[noteIndex].m_col;
89 }
90
91 //-----------------------------------------------------------------------------
92
setNoteCol(int noteIndex,int col)93 void TXshNoteSet::setNoteCol(int noteIndex, int col) {
94 assert(noteIndex < m_notes.size());
95 if (noteIndex >= m_notes.size()) return;
96 m_notes[noteIndex].m_col = col;
97 }
98
99 //-----------------------------------------------------------------------------
100
getNotePos(int noteIndex) const101 TPointD TXshNoteSet::getNotePos(int noteIndex) const {
102 assert(noteIndex < m_notes.size());
103 if (noteIndex >= m_notes.size()) return TPointD(5, 5);
104 return m_notes[noteIndex].m_pos;
105 }
106
107 //-----------------------------------------------------------------------------
108
setNotePos(int noteIndex,TPointD pos)109 void TXshNoteSet::setNotePos(int noteIndex, TPointD pos) {
110 assert(noteIndex < m_notes.size());
111 if (noteIndex >= m_notes.size()) return;
112 m_notes[noteIndex].m_pos = pos;
113 }
114
115 //-----------------------------------------------------------------------------
116
loadData(TIStream & is)117 void TXshNoteSet::loadData(TIStream &is) {
118 while (!is.eos()) {
119 std::string tagName;
120 if (is.matchTag(tagName)) {
121 if (tagName == "notes") {
122 while (!is.eos()) {
123 std::string tagName;
124 if (is.matchTag(tagName)) {
125 if (tagName == "note") {
126 Note note;
127 is >> note.m_colorIndex;
128 std::wstring text;
129 is >> text;
130 note.m_text = QString::fromStdWString(text);
131 is >> note.m_row;
132 is >> note.m_col;
133 is >> note.m_pos.x;
134 is >> note.m_pos.y;
135 m_notes.push_back(note);
136 }
137 } else
138 throw TException("expected <note>");
139 is.closeChild();
140 }
141 } else
142 throw TException("expected <defaultColor> or <notes>");
143 is.closeChild();
144 } else
145 throw TException("expected tag");
146 }
147 }
148
149 //-----------------------------------------------------------------------------
150
saveData(TOStream & os)151 void TXshNoteSet::saveData(TOStream &os) {
152 int i;
153 os.openChild("notes");
154 for (i = 0; i < getCount(); i++) {
155 os.openChild("note");
156 Note note = m_notes.at(i);
157 os << note.m_colorIndex;
158 os << note.m_text.toStdWString();
159 os << note.m_row;
160 os << note.m_col;
161 os << note.m_pos.x;
162 os << note.m_pos.y;
163 os.closeChild();
164 }
165 os.closeChild();
166 }
167