QScriptValue getLevel(QScriptContext *ctx, QScriptEngine *eng)
{
	QString levelName = ctx->argument(0).toString();

	ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
	TXshLevel *level = scene->getLevelSet()->getLevel(levelName.toStdWString());
	if (!level) {
		level = scene->createNewLevel(PLI_XSHLEVEL, levelName.toStdWString());
		levelName = QString::fromStdWString(level->getName());
	}
	if (level->getSimpleLevel())
		return eng->newQObject(new ScriptWrapper::Level(level->getSimpleLevel()), QScriptEngine::ScriptOwnership);
	else
		return QScriptValue();
}
void CastTreeViewer::dropEvent(QDropEvent *event)
{
	m_dropTargetItem = 0;
	if (m_dropFilePath != TFilePath()) {
		IoCmd::loadScene(m_dropFilePath);
		m_dropFilePath = TFilePath();
		m_dropTargetItem = 0;
		update();
		return;
	}

	if (!event->mimeData()->hasFormat("application/vnd.toonz.levels"))
		return;
	m_dropTargetItem = itemAt(event->pos());
	if (!m_dropTargetItem)
		return;
	TFilePath folderPath(m_dropTargetItem->data(1, Qt::DisplayRole).toString().toStdWString());
	m_dropTargetItem = 0;
	update();

	if (folderPath.getName() == AudioFolderName) {
		event->ignore();
		return;
	}
	event->acceptProposedAction();

	TLevelSet *levelSet = getLevelSet();

	const CastItems *castItems = dynamic_cast<const CastItems *>(event->mimeData());
	assert(castItems);
	if (!castItems)
		return;
	int i;
	TUndoManager::manager()->beginBlock();
	for (i = 0; i < castItems->getItemCount(); i++) {
		CastItem *item = castItems->getItem(i);
		if (LevelCastItem *li = dynamic_cast<LevelCastItem *>(item)) {
			TXshLevel *level = li->getLevel();
			wstring levelName = level->getName();
			MoveLevelToFolderUndo *undo = new MoveLevelToFolderUndo(levelSet, levelName, folderPath);
			levelSet->moveLevelToFolder(folderPath, level);
			TUndoManager::manager()->add(undo);
		} else if (SoundCastItem *si = dynamic_cast<SoundCastItem *>(item)) {
		}
	}
	TUndoManager::manager()->endBlock();
	emit itemMovedToFolder();
}
void LevelSettingsPopup::onNameChanged() {
  QString text     = m_nameFld->text();
  TXshLevel *level = 0;
  if (m_sl)
    level = m_sl.getPointer();
  else if (m_cl)
    level = m_cl.getPointer();
  else
    return;

  if (text.length() == 0) {
    error("The name " + text +
          " you entered for the level is not valid.\n Please enter a different "
          "name.");
    m_nameFld->setFocus();
    return;
  }

  /*-- Level名に変更がない場合 --*/
  if (level->getName() == text.toStdWString()) {
    // warning("Level name unchanged.");
    return;
  }

  TLevelSet *levelSet =
      TApp::instance()->getCurrentScene()->getScene()->getLevelSet();

  if (!levelSet->renameLevel(level, text.toStdWString())) {
    error("The name " + text +
          " you entered for the level is already used.\nPlease enter a "
          "different name.");
    m_nameFld->setFocus();
    return;
  }

  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
  TApp::instance()->getCurrentScene()->notifyCastChange();
}
Exemple #4
0
void ComboViewerPanel::changeWindowTitle() {
  TApp *app         = TApp::instance();
  ToonzScene *scene = app->getCurrentScene()->getScene();
  if (!scene) return;
  int frame = app->getCurrentFrame()->getFrame();

  // put the titlebar texts in this string
  QString name;

  // if the frame type is "scene editing"
  if (app->getCurrentFrame()->isEditingScene()) {
    QString sceneName = QString::fromStdWString(scene->getSceneName());
    if (sceneName.isEmpty()) sceneName = tr("Untitled");

    if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString(" *");
    name = tr("Scene: ") + sceneName;
    if (frame >= 0)
      name =
          name + tr("   ::   Frame: ") + tr(std::to_string(frame + 1).c_str());
    int col = app->getCurrentColumn()->getColumnIndex();
    if (col < 0) {
      setWindowTitle(name);
      return;
    }
    TXsheet *xsh  = app->getCurrentXsheet()->getXsheet();
    TXshCell cell = xsh->getCell(frame, col);
    if (cell.isEmpty()) {
      setWindowTitle(name);
      return;
    }
    assert(cell.m_level.getPointer());
    TFilePath fp(cell.m_level->getName());
    QString imageName =
        QString::fromStdWString(fp.withFrame(cell.m_frameId).getWideString());
    name = name + tr("   ::   Level: ") + imageName;

    if (m_sceneViewer->isPreviewEnabled()) {
      name = name + "  ::  Zoom : " +
             QString::number((int)(100.0 *
                                   sqrt(m_sceneViewer->getViewMatrix().det()) *
                                   m_sceneViewer->getDpiFactor())) +
             "%";
    }

    // If the current level exists and some option is set in the preference,
    // set the zoom value to the current level's dpi
    else if (Preferences::instance()
                 ->isActualPixelViewOnSceneEditingModeEnabled() &&
             TApp::instance()->getCurrentLevel()->getSimpleLevel() &&
             !CleanupPreviewCheck::instance()
                  ->isEnabled()  // cleanup preview must be OFF
             &&
             !CameraTestCheck::instance()
                  ->isEnabled())  // camera test mode must be OFF neither
    {
      name = name + "  ::  Zoom : " +
             QString::number((int)(100.0 *
                                   sqrt(m_sceneViewer->getViewMatrix().det()) *
                                   m_sceneViewer->getDpiFactor())) +
             "%";
    }

  }
  // if the frame type is "level editing"
  else {
    TXshLevel *level = app->getCurrentLevel()->getLevel();
    if (level) {
      TFilePath fp(level->getName());
      QString imageName = QString::fromStdWString(
          fp.withFrame(app->getCurrentFrame()->getFid()).getWideString());

      name = name + tr("Level: ") + imageName;

      name = name + "  ::  Zoom : " +
             QString::number((int)(100.0 *
                                   sqrt(m_sceneViewer->getViewMatrix().det()) *
                                   m_sceneViewer->getDpiFactor())) +
             "%";
    }
  }
  setWindowTitle(name);
}