Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txshsoundtextcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsoundtextlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshSoundTextColumn::TXshSoundTextColumn() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshSoundTextColumn::~TXshSoundTextColumn() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn::ColumnType TXshSoundTextColumn::getColumnType() const {
Shinya Kitaoka 120a6e
  return eSoundTextType;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshSoundTextColumn::createSoundTextLevel(int row,
Shinya Kitaoka 120a6e
                                               QList<qstring> textList) {</qstring>
Shinya Kitaoka 120a6e
  TXshSoundTextLevel *level = new TXshSoundTextLevel();
Shinya Kitaoka 120a6e
  level->setType(SND_TXT_XSHLEVEL);
Shinya Kitaoka 120a6e
  TXshCell cell;
Shinya Kitaoka 120a6e
  for (int i = 0; i < textList.size(); i++, row++) {
Shinya Kitaoka 120a6e
    QString str     = textList.at(i);
Shinya Kitaoka 120a6e
    QString precStr = (i > 0) ? level->getFrameText(i - 1) : QString();
Shinya Kitaoka 120a6e
    if (str == QString("<none>")) {</none>
Shinya Kitaoka 120a6e
      if (i > 0) {
Shinya Kitaoka 120a6e
        setCell(row, cell);
Shinya Kitaoka 120a6e
        continue;
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        str = QString();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    level->setFrameText(i, str);
Shinya Kitaoka 120a6e
    TFrameId fid(i + 1);
Shinya Kitaoka 120a6e
    cell = TXshCell(level, fid);
Shinya Kitaoka 120a6e
    setCell(row, cell);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXshSoundTextColumn::canSetCell(const TXshCell &cell) const {
manongjohn 5bceaa
  return cell.isEmpty() || cell.m_level->getSoundTextLevel() != 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn *TXshSoundTextColumn::clone() const {
Shinya Kitaoka 120a6e
  TXshSoundTextColumn *column = new TXshSoundTextColumn();
Shinya Kitaoka 120a6e
  column->setXsheet(getXsheet());
Shinya Kitaoka 120a6e
  column->setStatusWord(getStatusWord());
Shinya Kitaoka 120a6e
  column->m_cells = m_cells;
Shinya Kitaoka 120a6e
  column->m_first = m_first;
Shinya Kitaoka 120a6e
  return column;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshSoundTextColumn::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.openChild(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "cells") {
Shinya Kitaoka 120a6e
      while (is.openChild(tagName)) {
Shinya Kitaoka 120a6e
        if (tagName == "cell") {
shun-iwasawa 428fe6
          TPersist *p             = 0;
shun-iwasawa 428fe6
          std::string rowRangeStr = "1";
shun-iwasawa 428fe6
          int fidNumber           = 1;
Shinya Kitaoka 120a6e
          TFilePath path;
shun-iwasawa 428fe6
          is >> rowRangeStr >> fidNumber >> p;
Shinya Kitaoka 120a6e
          TXshLevel *xshLevel = dynamic_cast<txshlevel *="">(p);</txshlevel>
Shinya Kitaoka 120a6e
          TXshCell cell(xshLevel, TFrameId(fidNumber));
shun-iwasawa 428fe6
shun-iwasawa 428fe6
          QString _rowRangeStr = QString::fromStdString(rowRangeStr);
shun-iwasawa 428fe6
          QStringList rows     = _rowRangeStr.split('-');
shun-iwasawa 428fe6
          if (rows.size() == 1)
shun-iwasawa 428fe6
            setCell(rows[0].toInt(), cell);
shun-iwasawa 428fe6
          else if (rows.size() == 2) {
shun-iwasawa 428fe6
            for (int r = rows[0].toInt(); r <= rows[1].toInt(); r++)
shun-iwasawa 428fe6
              setCell(r, cell);
shun-iwasawa 428fe6
          }
Shinya Kitaoka 120a6e
        } else
Shinya Kitaoka 120a6e
          throw TException("TXshLevelColumn, unknown tag(2): " + tagName);
Shinya Kitaoka 120a6e
        is.closeChild();
Shinya Kitaoka 120a6e
      }
shun-iwasawa f84c65
    } else if (loadCellMarks(tagName, is)) {
shun-iwasawa f84c65
      // do nothing
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      throw TException("TXshLevelColumn, unknown tag: " + tagName);
Shinya Kitaoka 120a6e
    is.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshSoundTextColumn::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  int r0, r1;
Shinya Kitaoka 120a6e
  if (getRange(r0, r1)) {
Shinya Kitaoka 120a6e
    os.openChild("cells");
shun-iwasawa 428fe6
    TXshCell prevCell;
shun-iwasawa 428fe6
    int fromR = r0;
Shinya Kitaoka 120a6e
    for (int r = r0; r <= r1; r++) {
Shinya Kitaoka 120a6e
      TXshCell cell = getCell(r);
shun-iwasawa 428fe6
shun-iwasawa 428fe6
      if (cell != prevCell) {
shun-iwasawa 428fe6
        if (!prevCell.isEmpty()) {
shun-iwasawa 428fe6
          int toR      = r - 1;
shun-iwasawa 428fe6
          TFrameId fid = prevCell.m_frameId;
shun-iwasawa 428fe6
          if (fromR == toR)
shun-iwasawa 428fe6
            os.child("cell")
shun-iwasawa 428fe6
                << toR << fid.getNumber() << prevCell.m_level.getPointer();
shun-iwasawa 428fe6
          else {
shun-iwasawa 428fe6
            QString rangeStr = QString("%1-%2").arg(fromR).arg(toR);
shun-iwasawa 428fe6
            os.child("cell") << rangeStr.toStdString() << fid.getNumber()
shun-iwasawa 428fe6
                             << prevCell.m_level.getPointer();
shun-iwasawa 428fe6
          }
shun-iwasawa 428fe6
        }
shun-iwasawa 428fe6
        prevCell = cell;
shun-iwasawa 428fe6
        fromR    = r;
shun-iwasawa 428fe6
      }
shun-iwasawa 428fe6
      assert(cell == prevCell);
shun-iwasawa 428fe6
      if (r == r1) {
shun-iwasawa 428fe6
        if (!cell.isEmpty()) {
shun-iwasawa 428fe6
          int toR      = r;
shun-iwasawa 428fe6
          TFrameId fid = cell.m_frameId;
shun-iwasawa 428fe6
          if (fromR == toR)
shun-iwasawa 428fe6
            os.child("cell")
shun-iwasawa 428fe6
                << toR << fid.getNumber() << cell.m_level.getPointer();
shun-iwasawa 428fe6
          else {
shun-iwasawa 428fe6
            QString rangeStr = QString("%1-%2").arg(fromR).arg(toR);
shun-iwasawa 428fe6
            os.child("cell") << rangeStr.toStdString() << fid.getNumber()
shun-iwasawa 428fe6
                             << cell.m_level.getPointer();
shun-iwasawa 428fe6
          }
shun-iwasawa 428fe6
        }
shun-iwasawa 428fe6
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
shun-iwasawa f84c65
  // cell marks
shun-iwasawa f84c65
  saveCellMarks(os);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TXshSoundTextColumn, "soundTextColumn")