Пример #1
0
TFrameId Level::getFid(const QScriptValue &arg, QString &err) {
  if (arg.isNumber() || arg.isString()) {
    QString s = arg.toString();
    QRegExp re("(-?\\d+)(\\w?)");
    if (re.exactMatch(s)) {
      int d     = re.cap(1).toInt();
      QString c = re.cap(2);
      TFrameId fid;
      if (c.length() == 1)
#if QT_VERSION >= 0x050500
        fid = TFrameId(d, c[0].unicode());
#else
        fid = TFrameId(d, c[0].toAscii());
#endif
      else
Пример #2
0
void ColumnCmd::resequence(int index) {
  if (!canResequence(index)) return;
  TXsheet *xsh       = TApp::instance()->getCurrentXsheet()->getXsheet();
  TXshColumn *column = xsh->getColumn(index);
  assert(column);
  TXshLevelColumn *lcolumn = column->getLevelColumn();
  assert(lcolumn);
  int r0 = 0, r1 = -1;
  lcolumn->getRange(r0, r1);
  assert(r0 <= r1);
  TXshCell cell = lcolumn->getCell(r0);
  assert(!cell.isEmpty());
  TXshChildLevel *xl = cell.m_level->getChildLevel();
  assert(xl);
  TXsheet *childXsh              = xl->getXsheet();
  int frameCount                 = childXsh->getFrameCount();
  if (frameCount < 1) frameCount = 1;

  TUndoManager::manager()->add(new ResequenceUndo(index, frameCount));

  lcolumn->clearCells(r0, r1 - r0 + 1);
  for (int i = 0; i < frameCount; i++) {
    cell.m_frameId = TFrameId(i + 1);
    lcolumn->setCell(r0 + i, cell);
  }

  xsh->updateFrameCount();

  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
}
void TXshZeraryFxColumn::loadData(TIStream &is)
{
	TPersist *p = 0;
	is >> p;
	if (!p)
		return;

	TZeraryColumnFx *fx = dynamic_cast<TZeraryColumnFx *>(p);
	fx->addRef();
	if (m_zeraryColumnFx) {
		m_zeraryColumnFx->setColumn(0);
		m_zeraryColumnFx->release();
	}
	m_zeraryColumnFx = fx;
	m_zeraryColumnFx->setColumn(this);

	int r0, r1;
	bool touched = false;
	const TXshCell cell(m_zeraryFxLevel, TFrameId(1));
	string tagName;
	while (is.matchTag(tagName)) {
		if (tagName == "status") {
			int status;
			is >> status;
			setStatusWord(status);
		} else if (tagName == "cells") {
Пример #4
0
void TFrameHandle::setFrameIndexByName(const QString &str) {
  int num = str.toInt();
  if (m_frameType == LevelFrame) {
    setFid(TFrameId(num));
  } else
    setFrame(num - 1);
}
Пример #5
0
TFrameId TFilePath::getFrame() const {
  int i = getLastSlash(m_path);       // cerco l'ultimo slash
  string str = m_path.substr(i + 1);  // str e' il path senza parentdir
  i          = str.rfind('.');
  if (i == string::npos || str == "." || str == "..")
    return TFrameId(TFrameId::NO_FRAME);
  int j = str.substr(0, i).rfind('.');
  if (j == string::npos) return TFrameId(TFrameId::NO_FRAME);
  if (i == j + 1) return TFrameId(TFrameId::EMPTY_FRAME);

  int k, number = 0;
  for (k = j + 1; k < i && isdigit(str[k]); k++)
    number                    = number * 10 + str[k] - '0';
  char letter                 = '\0';
  if (isalpha(str[k])) letter = str[k++];
  if (number == 0 || k < i) throw TMalformedFrameException();
  return TFrameId(number, letter);
}
void FilmstripFrameHeadGadget::setCurrentFrame(int index) const
{
	TXshSimpleLevel *level = m_filmstrip->getLevel();
	if (!level)
		return;
	TFrameId fid = level->index2fid(index);
	if (fid >= TFrameId(1))
		TApp::instance()->getCurrentFrame()->setFid(fid);
}
Пример #7
0
 void redo() const override {
   TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
   xsh->insertColumn(m_columnIndex);
   int frameCount                 = m_childLevel->getXsheet()->getFrameCount();
   if (frameCount < 1) frameCount = 1;
   for (int r = 0; r < frameCount; r++)
     xsh->setCell(r, m_columnIndex,
                  TXshCell(m_childLevel.getPointer(), TFrameId(r + 1)));
   TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
 }
void MagpieFileImportPopup::onOkPressed()
{
	if (m_levelPath.isEmpty() || m_levelPath.getUndottedType().empty() || !TSystem::doesExistFileOrLevel(m_levelPath)) {
		DVGui::error(tr("The file path is missing."));
		return;
	}

	QList<QString> actorActs = m_info->getActorActs();
	QList<QString> comments = m_info->getComments();
	int from = m_fromField->getValue() - 1;
	int to = m_toField->getValue() - 1;
	assert(to < m_info->getFrameCount());

	QList<TFrameId> frameList;
	QList<QString> commentList;
	int commentCount = comments.size();
	int actorActsCount = actorActs.size();
	int i = from;
	for (i; i <= to; i++) {
		if (commentCount <= i || actorActsCount <= i)
			continue;
		commentList.append(comments.at(i));
		QString actorAct = actorActs.at(i);
		if (actorAct == QString("<none>")) {
			frameList.push_back(TFrameId());
			continue;
		}
		int j;
		for (j = 0; j < m_actFields.size(); j++) {
			IntLineEdit *field = m_actFields.at(j).second;
			QString act = field->property("act").toString();
			if (actorAct != act)
				continue;
			frameList.push_back(TFrameId(field->getValue()));
			break;
		}
	}

	bool ret = IoCmd::importLipSync(m_levelPath, frameList, commentList, m_info->getFileName());
	if (!ret)
		return;
	accept();
}
TXshZeraryFxColumn::TXshZeraryFxColumn(int frameCount)
	: m_zeraryColumnFx(new TZeraryColumnFx()), m_zeraryFxLevel(new TXshZeraryFxLevel())
{
	m_zeraryColumnFx->addRef();
	m_zeraryColumnFx->setColumn(this);
	m_zeraryFxLevel->addRef();
	m_zeraryFxLevel->setColumn(this);
	for (int i = 0; i < frameCount; i++)
		setCell(i, TXshCell(m_zeraryFxLevel, TFrameId(1)));
}
Пример #10
0
TFrameId TTool::getCurrentFid() const {
  if (!m_application) return TFrameId();

  TFrameHandle *fh = m_application->getCurrentFrame();

  if (fh->isEditingLevel()) return fh->getFid();

  int row = m_application->getCurrentFrame()->getFrame();
  int col = m_application->getCurrentColumn()->getColumnIndex();
  TXshCell cell =
      m_application->getCurrentXsheet()->getXsheet()->getCell(row, col);
  if (cell.isEmpty()) return TFrameId::NO_FRAME;

  return cell.getFrameId();
}
Пример #11
0
 void redo() const override {
   TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
   int r0, r1;
   xsh->getCellRange(m_index, r0, r1);
   assert(r0 <= r1);
   if (r0 > r1) return;
   TXshCell cell = xsh->getCell(r0, m_index);
   assert(!cell.isEmpty());
   assert(cell.m_level->getChildLevel());
   xsh->clearCells(r0, m_index, r1 - r0 + 1);
   for (int i = 0; i < m_newFramesCount; i++) {
     cell.m_frameId = TFrameId(i + 1);
     xsh->setCell(m_r0 + i, m_index, cell);
   }
   TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
 }
void TXshSoundTextColumn::loadData(TIStream &is)
{
	string tagName;
	while (is.openChild(tagName)) {
		if (tagName == "cells") {
			while (is.openChild(tagName)) {
				if (tagName == "cell") {
					TPersist *p = 0;
					int row = 1;
					int fidNumber = 1;
					TFilePath path;
					is >> row >> fidNumber >> p;
					TXshLevel *xshLevel = dynamic_cast<TXshLevel *>(p);
					TXshCell cell(xshLevel, TFrameId(fidNumber));
					setCell(row, cell);
				} else
					throw TException("TXshLevelColumn, unknown tag(2): " + tagName);
				is.closeChild();
			}
		} else
Пример #13
0
void FilmstripFrames::mousePressEvent(QMouseEvent *event) {
  m_selecting  = false;
  int index    = y2index(event->pos().y());
  TFrameId fid = index2fid(index);

  TXshSimpleLevel *sl = getLevel();
  int i0              = y2index(0);
  int frameHeight = m_iconSize.height() + fs_frameSpacing + fs_iconMarginTop +
                    fs_iconMarginBottom;
  QPoint clickedPos = event->pos() - QPoint(0, (index - i0) * frameHeight);

  if (event->button() == Qt::LeftButton) {
    if (fid == TFrameId()) return;

    ComboViewerPanel *inknPaintViewerPanel =
        TApp::instance()->getInknPaintViewerPanel();

    // navigator pan
    if (fid == TApp::instance()->getCurrentFrame()->getFid() &&
        sl->getType() == TZP_XSHLEVEL && inknPaintViewerPanel &&
        inknPaintViewerPanel->isVisible() &&
        QRect(QPoint(fs_leftMargin + fs_iconMarginLR,
                     fs_frameSpacing / 2 +
                         fs_iconMarginTop)  //<- top-left position of the icon
              ,
              m_iconSize)
            .contains(clickedPos)) {
      m_isNavigatorPanning = true;
      execNavigatorPan(event->pos());
      QApplication::setOverrideCursor(Qt::ClosedHandCursor);
    } else
      m_isNavigatorPanning = false;

    if (event->modifiers() & Qt::ShiftModifier) {
      select(index, SHIFT_SELECT);
      if (m_selection->isSelected(fid)) {
        // click su di un frame gia' selezionato. Puo' essere l'inizio di un
        // drag'n'drop
        m_dragDropArmed = true;
        m_pos           = event->pos();
      }
    } else if (event->modifiers() & Qt::ControlModifier)
      select(index, CTRL_SELECT);
    // inbetween
    else if (sl->getType() == PLI_XSHLEVEL &&
             m_selection->isInInbetweenRange(fid) &&
             event->pos().x() > width() - 20 - fs_rightMargin) {
      inbetween();
    } else {
      // move current frame when clicked without modifier
      TApp *tapp = TApp::instance();
      std::vector<TFrameId> fids;
      TXshLevel *level = tapp->getCurrentLevel()->getLevel();
      level->getFids(fids);

      tapp->getCurrentFrame()->setFrameIds(fids);
      tapp->getCurrentFrame()->setFid(fid);

      if (!m_selection->isSelected(fid))  // selezione semplice
      {
        // click su un frame non selezionato
        m_selecting = true;  // posso estendere la selezione con il drag
        select(index, START_DRAG_SELECT);
      } else if (m_selection->isSelected(fid)) {
        // click su di un frame gia' selezionato. Puo' essere l'inizio di un
        // drag'n'drop
        m_dragDropArmed = true;
        m_pos           = event->pos();
      }
    }
    update();
  } else if (event->button() == Qt::MidButton) {
    m_pos = event->globalPos();
    return;
  } else if (event->button() == Qt::RightButton) {
    select(index);
  }
}
Пример #14
0
TFrameId FilmstripFrames::index2fid(int index) const {
  TXshSimpleLevel *sl = getLevel();
  if (!sl || index < 0) return TFrameId();
  return sl->index2fid(index);
}
Пример #15
0
TImage *TTool::touchImage() {
  if (!m_application) return 0;

  m_cellsData.clear();

  m_isLevelCreated  = false;
  m_isFrameCreated  = false;
  Preferences *pref = Preferences::instance();

  bool isAutoCreateEnabled   = pref->isAutoCreateEnabled();
  bool animationSheetEnabled = pref->isAnimationSheetEnabled();
  bool isAutoStretchEnabled  = pref->isAutoStretchEnabled();

  TFrameHandle *currentFrame    = m_application->getCurrentFrame();
  TXshLevelHandle *currentLevel = m_application->getCurrentLevel();

  if (currentFrame->isEditingLevel()) {
    // Editing level

    // no level => return 0
    TXshLevel *xl = currentLevel->getLevel();
    if (!xl) return 0;
    TXshSimpleLevel *sl = xl->getSimpleLevel();
    if (!sl || sl->isEmpty()) return 0;

    TFrameId fid = currentFrame->getFid();
    TImageP img  = sl->getFrame(fid, true);
    if (!img) {
      // no drawing found
      if (sl->isSubsequence() || sl->isReadOnly() || !isAutoCreateEnabled)
        return 0;

      // create a new drawing
      img = sl->createEmptyFrame();
      sl->setFrame(fid, img);
      currentLevel->notifyLevelChange();
      m_isFrameCreated = true;
    }
    return img.getPointer();
  } else {
    // editing xsheet
    if (m_application->getCurrentObject()->isSpline()) return 0;

    TSceneHandle *currentScene = m_application->getCurrentScene();
    ToonzScene *scene          = currentScene->getScene();
    int row                    = currentFrame->getFrame();
    int col = m_application->getCurrentColumn()->getColumnIndex();
    if (col < 0) return 0;

    TXsheetHandle *currentXsheet = m_application->getCurrentXsheet();
    TXsheet *xsh                 = currentXsheet->getXsheet();
    if (!xsh) return 0;

    TXshCell cell       = xsh->getCell(row, col);
    TXshSimpleLevel *sl = cell.getSimpleLevel();

    if (sl != 0) {
      // current cell is not empty
      if (isAutoCreateEnabled && animationSheetEnabled && row > 0 &&
          xsh->getCell(row - 1, col) == xsh->getCell(row, col)) {
        // animationSheet is enabled and the current cell is a "hold". We must
        // create a new drawing.
        // measure the hold length (starting from the current row) : r0-r1
        int r0 = row, r1 = row;
        if (isAutoStretchEnabled)
          while (xsh->getCell(r1 + 1, col) == cell) r1++;
        // find the proper frameid (possibly addisng suffix, in order to avoid a
        // fid already used)
        TFrameId fid = getNewFrameId(sl, row);
        // create the new drawing
        TImageP img      = sl->createEmptyFrame();
        m_isFrameCreated = true;
        // insert the drawing in the level
        sl->setFrame(fid, img);
        // update the cell
        cell = TXshCell(sl, fid);
        // update the xsheet (change the current cell and possibly all the
        // following "hold")
        for (int r = r0; r <= r1; r++) xsh->setCell(r, col, cell);
        // notify
        currentXsheet->notifyXsheetChanged();
        currentScene->notifyCastChange();
        currentLevel->notifyLevelChange();
        m_cellsData.push_back(r0);
        m_cellsData.push_back(r1);
        m_cellsData.push_back(0);
      }
      // we've found the image. return it.
      return cell.getImage(true).getPointer();
    }

    // current cell is empty.
    if (!isAutoCreateEnabled) return 0;

    // get the column range
    int r0, r1;
    xsh->getCellRange(col, r0, r1);

    if (animationSheetEnabled && r0 <= r1) {
      // animation sheet enabled and not empty column. We must create a new
      // drawing in the column level and possibly add "holds"

      // find the last not-empty cell before the current one (a) and the first
      // after (b)
      int a = row - 1, b = row + 1;
      while (a >= r0 && xsh->getCell(a, col).isEmpty()) a--;
      while (b <= r1 && xsh->getCell(b, col).isEmpty()) b++;

      // find the level we must attach to
      if (a >= r0) {
        // there is a not-emtpy cell before the current one
        sl = xsh->getCell(a, col).getSimpleLevel();
      } else if (b <= r1) {
        sl = xsh->getCell(b, col).getSimpleLevel();
      }
      if (sl) {
        // note: sl should be always !=0 (the column is not empty)
        // if - for some reason - it is ==0 then we skip to the standard (i.e.
        // !animationSheetEnabled) beahviour

        // create the drawing
        // find the proper frameid (possibly addisng suffix, in order to avoid a
        // fid already used)
        TFrameId fid = getNewFrameId(sl, row);
        // create the new drawing
        TImageP img      = sl->createEmptyFrame();
        m_isFrameCreated = true;
        // insert the drawing in the level
        sl->setFrame(fid, img);
        // update the cell
        cell = TXshCell(sl, fid);
        xsh->setCell(row, col, cell);

        // create holds
        if (!isAutoStretchEnabled) {
          m_cellsData.push_back(row);
          m_cellsData.push_back(row);
          m_cellsData.push_back(2);  // vuoto => nuovo
        } else {
          if (a >= r0) {
            // create a hold before : [a+1, row-1]
            TXshCell aCell = xsh->getCell(a, col);
            for (int i = a + 1; i < row; i++) xsh->setCell(i, col, aCell);
            m_cellsData.push_back(a + 1);
            m_cellsData.push_back(row - 1);
            m_cellsData.push_back(1);  // vuoto => vecchio

            if (b <= r1 && xsh->getCell(b, col).getSimpleLevel() == sl) {
              // create also a hold after
              for (int i = row + 1; i < b; i++) xsh->setCell(i, col, cell);
              m_cellsData.push_back(row);
              m_cellsData.push_back(b - 1);
              m_cellsData.push_back(2);  // vuoto => nuovo
            } else {
              m_cellsData.push_back(row);
              m_cellsData.push_back(row);
              m_cellsData.push_back(2);  // vuoto => nuovo
            }
          } else if (b <= r1) {
            // create a hold after
            for (int i = row + 1; i < b; i++) xsh->setCell(i, col, cell);
            m_cellsData.push_back(row);
            m_cellsData.push_back(b - 1);
            m_cellsData.push_back(2);  // vuoto => nuovo
          }
        }
      }
      // notify & return
      currentXsheet->notifyXsheetChanged();
      currentScene->notifyCastChange();
      currentLevel->notifyLevelChange();
      return cell.getImage(true).getPointer();
    }

    if (row > 0 && xsh->getCell(row - 1, col).getSimpleLevel() != 0 &&
        !animationSheetEnabled) {
      sl = xsh->getCell(row - 1, col).getSimpleLevel();
      if (sl->getType() != OVL_XSHLEVEL ||
          sl->getPath().getFrame() != TFrameId::NO_FRAME) {
        // la cella precedente contiene un drawing di un livello. animationSheet
        // e' disabilitato
        // creo un nuovo frame
        currentLevel->setLevel(sl);
        if (sl->isSubsequence() || sl->isReadOnly()) return 0;
        TFrameId fid     = sl->index2fid(sl->getFrameCount());
        TImageP img      = sl->createEmptyFrame();
        m_isFrameCreated = true;
        sl->setFrame(fid, img);
        cell = TXshCell(sl, fid);
        xsh->setCell(row, col, cell);
        currentXsheet->notifyXsheetChanged();
        currentScene->notifyCastChange();
        currentLevel->notifyLevelChange();
        return img.getPointer();
      }
    }

    // animation sheet disabled or empty column. autoCreate is enabled: we must
    // create a new level
    int levelType    = pref->getDefLevelType();
    TXshLevel *xl    = scene->createNewLevel(levelType);
    sl               = xl->getSimpleLevel();
    m_isLevelCreated = true;

    // create the drawing
    TFrameId fid = animationSheetEnabled ? getNewFrameId(sl, row) : TFrameId(1);
    TImageP img  = sl->createEmptyFrame();
    m_isFrameCreated = true;
    sl->setFrame(fid, img);
    cell = TXshCell(sl, fid);
    xsh->setCell(row, col, cell);
    if (animationSheetEnabled) {
      m_cellsData.push_back(row);
      m_cellsData.push_back(row);
      m_cellsData.push_back(2);  // vuoto => nuovo
    }

    currentXsheet->notifyXsheetChanged();
    currentScene->notifyCastChange();
    currentLevel->notifyLevelChange();
    return img.getPointer();
  }
}
Пример #16
0
TFrameId Level::getFid(const QScriptValue &arg, QString &err) {
  if (arg.isNumber() || arg.isString()) {
    QString s = arg.toString();
    QRegExp re("(-?\\d+)(\\w?)");
    if (re.exactMatch(s)) {
      int d     = re.cap(1).toInt();
      QString c = re.cap(2);
      TFrameId fid;
      if (c.length() == 1)
#if QT_VERSION >= 0x050500
        fid = TFrameId(d, c[0].unicode());
#else
        fid = TFrameId(d, c[0].toAscii());
#endif
      else
        fid = TFrameId(d);
      err   = "";
      return fid;
    }
  }
  err = QObject::tr("Argument '%1' does not look like a FrameId")
            .arg(arg.toString());
  return TFrameId();
}

TImageP Level::getImg(const TFrameId &fid) {
  if (m_sl)
    return m_sl->getFrame(fid, false);
  else
    return TImageP();
}