void Filmstrip::updateWindowTitle() { updateCurrentLevelComboItem(); TXshSimpleLevel *level = m_frames->getLevel(); QString levelName; if (!level) { parentWidget()->setWindowTitle(tr("Level Strip")); return; } else { levelName = QString::fromStdWString(level->getName()); if (level->getProperties()->getDirtyFlag()) levelName += " *"; } // parentWidget() is TPanel parentWidget()->setWindowTitle(tr("Level: ") + levelName); TFrameHandle *fh = TApp::instance()->getCurrentFrame(); if (fh->isEditingLevel() && fh->getFid().getNumber() >= 0) levelName += QString(" [#") + QString::number(fh->getFid().getNumber()) + QString("]"); m_chooseLevelCombo->setItemText(m_chooseLevelCombo->currentIndex(), levelName); }
/*! update combo items when the contents of scene cast are changed */ void Filmstrip::updateChooseLevelComboItems() { // clear items m_chooseLevelCombo->clear(); m_levels.clear(); std::map<TXshSimpleLevel *, TFrameId> new_workingFrames; // correct and register items ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); if (scene) { std::vector<TXshLevel *> levels; scene->getLevelSet()->listLevels(levels); std::vector<TXshLevel *>::iterator it; for (it = levels.begin(); it != levels.end(); ++it) { // register only TLV and PLI TXshSimpleLevel *sl = (*it)->getSimpleLevel(); if (sl) { // register only used level in xsheet if (!scene->getTopXsheet()->isLevelUsed(sl)) continue; m_levels.push_back(sl); // create new m_workingFrames map with the new levelset TFrameId fId; std::map<TXshSimpleLevel *, TFrameId>::iterator WFit = m_workingFrames.find(sl); if (WFit != m_workingFrames.end()) fId = WFit->second; else fId = sl->getFirstFid(); new_workingFrames.insert(std::make_pair(sl, fId)); QString levelName = QString::fromStdWString(sl->getName()); if (sl->getProperties()->getDirtyFlag()) levelName += " *"; // append the current working frame number to the item name if (fId != sl->getFirstFid() && fId.getNumber() >= 0) levelName += QString(" [#") + QString::number(fId.getNumber()) + QString("]"); m_chooseLevelCombo->addItem(levelName); } } } m_chooseLevelCombo->addItem(tr("- No Current Level -")); // swap the list m_workingFrames.clear(); m_workingFrames = new_workingFrames; // synchronize the current index of combo to the current level updateCurrentLevelComboItem(); }
void Filmstrip::onFrameSwitched() { TFrameHandle *fh = TApp::instance()->getCurrentFrame(); if (!fh->isEditingLevel()) return; TXshSimpleLevel *level = m_frames->getLevel(); std::map<TXshSimpleLevel *, TFrameId>::iterator WFit; WFit = m_workingFrames.find(level); if (WFit == m_workingFrames.end()) return; WFit->second = fh->getFid(); QString levelName = QString::fromStdWString(level->getName()); if (level->getProperties()->getDirtyFlag()) levelName += " *"; if (fh->getFid().getNumber() >= 0) levelName += QString(" [#") + QString::number(fh->getFid().getNumber()) + QString("]"); m_chooseLevelCombo->setItemText(m_chooseLevelCombo->currentIndex(), levelName); }
/*! synchronize the current index of combo to the current level */ void Filmstrip::updateCurrentLevelComboItem() { if (m_chooseLevelCombo->count() == 1) { m_chooseLevelCombo->setCurrentIndex(0); return; } TXshSimpleLevel *currentLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel(); if (!currentLevel) { int noLevelIndex = m_chooseLevelCombo->findText(tr("- No Current Level -")); m_chooseLevelCombo->setCurrentIndex(noLevelIndex); return; } for (int i = 0; i < m_levels.size(); i++) { if (currentLevel->getName() == m_levels[i]->getName()) { m_chooseLevelCombo->setCurrentIndex(i); return; } } int noLevelIndex = m_chooseLevelCombo->findText(tr("- No Current Level -")); m_chooseLevelCombo->setCurrentIndex(noLevelIndex); }
bool VectorizerPopup::apply() { std::set<TXshLevel *> levels; ToonzScene *scene = m_sceneHandle->getScene(); if (!scene) { assert(scene); return false; } TSceneProperties *sceneProp = scene->getProperties(); if (!sceneProp) return false; VectorizerParameters *vectorizerParameters = sceneProp->getVectorizerParameters(); if (!vectorizerParameters) return false; int r0 = 0; int c0 = 0; int r1 = 0; int c1 = 0; bool isCellSelection = getSelectedLevels(levels, r0, c0, r1, c1); if (levels.empty()) { error(tr("The current selection is invalid.")); return false; } //Initialize Progress bar m_progressDialog = new DVGui::ProgressDialog("", "Cancel", 0, 1); m_progressDialog->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); //Don't show ? and X buttons m_progressDialog->setWindowTitle(QString("Convert To Vector...")); m_progressDialog->setAttribute(Qt::WA_DeleteOnClose); m_progressDialog->setWindowModality(Qt::WindowModal); //No user interaction is allowed during vectorization m_progressDialog->setFixedSize(200, 100); //Initialize vectorizer m_vectorizer = new Vectorizer; m_vectorizer->setParameters(*vectorizerParameters); connect(m_vectorizer, SIGNAL(frameName(QString)), this, SLOT(onFrameName(QString)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(frameDone(int)), this, SLOT(onFrameDone(int)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(partialDone(int, int)), this, SLOT(onPartialDone(int, int)), Qt::QueuedConnection); //We DON'T want the progress bar to be hidden at cancel press - since its modal //behavior prevents the user to interfere with a possibly still active vectorization. disconnect(m_progressDialog, SIGNAL(canceled()), m_progressDialog, SLOT(onCancel())); //We first inform the vectorizer of a cancel press; bool ret = connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SLOT(cancel())); //which eventually transmits the command to vectorization core, allowing full-time cancels ret = ret && connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SIGNAL(transmitCancel())); //Only after the vectorizer has terminated its process - or got cancelled, we are allowed //to proceed here. ret = ret && connect(m_vectorizer, SIGNAL(finished()), this, SLOT(onFinished()), Qt::QueuedConnection); assert(ret); int newIndexColumn = c1 + 1; std::set<TXshLevel *>::iterator it = levels.begin(); for (it; it != levels.end(); it++) { TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(*it); if (!sl || !sl->getSimpleLevel() || !isLevelToConvert(sl)) { QString levelName = tr(toString(sl->getName()).c_str()); QString errorMsg = tr("Cannot convert to vector the current selection.") + levelName; error(errorMsg); continue; } std::vector<TFrameId> fids; if (isCellSelection) getSelectedFids(fids, sl, r0, c0, r1, c1); else sl->getFids(fids); assert(fids.size() > 0); close(); // Re-initialize progress Bar m_progressDialog->setMaximum(fids.size() * 100); m_progressDialog->setValue(0); m_currFrame = 0; // Re-initialize vectorizer m_vectorizer->setLevel(sl); m_vectorizer->setFids(fids); // Start vectorizing m_vectorizer->start(); m_progressDialog->show(); // Wait the vectorizer... while (!l_quitLoop) QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents); l_quitLoop = false; // Assign output X-sheet cells TXshSimpleLevel *vl = m_vectorizer->getVectorizedLevel(); if (isCellSelection && vl) { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); xsheet->insertColumn(newIndexColumn); int r, c; for (c = c0; c <= c1; c++) { for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TXshSimpleLevel *level = (!cell.isEmpty()) ? cell.getSimpleLevel() : 0; if (level != sl) continue; TFrameId curFid = cell.getFrameId(); std::vector<TFrameId> newFids; vl->getFids(newFids); std::vector<TFrameId>::iterator it1 = newFids.begin(); for (it1; it1 != newFids.end(); it1++) { TFrameId id = *it1; if (id.getNumber() == curFid.getNumber() || // Hanno stesso numero di frame (id.getNumber() == 1 && curFid.getNumber() == -2)) // La vecchia cella non ha numero di frame xsheet->setCell(r, newIndexColumn, TXshCell(vl, id)); } } } newIndexColumn += 1; } else if (vl) { std::vector<TFrameId> gomi; scene->getXsheet()->exposeLevel(0, scene->getXsheet()->getFirstFreeColumnIndex(), vl, gomi); } if (m_vectorizer->isCanceled()) break; } m_progressDialog->close(); delete m_vectorizer; TApp::instance()->getCurrentScene()->notifyCastChange(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); return true; }
void Vectorizer::setLevel(const TXshSimpleLevelP &level) { m_level = level; //Creo il livello pli TXshSimpleLevel *sl = m_level.getPointer(); if (!sl) return; int rowCount = sl->getFrameCount(); if (rowCount <= 0 || sl->isEmpty()) return; TXshLevel *xl; ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); // Build the new level name wstring levelName = sl->getName() + L"v"; { std::auto_ptr<NameBuilder> nameBuilder(NameBuilder::getBuilder(levelName)); for (;;) { levelName = nameBuilder->getNext(); if (scene->getLevelSet()->getLevel(levelName) == 0) break; } } TFilePath dstPath = sl->getPath().withName(levelName).withType("pli"); dstPath = scene->decodeFilePath(dstPath); bool overWrite = false; if (TSystem::doesExistFileOrLevel(dstPath)) { m_dialogShown = true; std::wstring name = m_dialog->execute(scene, dstPath, true); if (m_dialog->cancelPressed()) return; switch (m_dialog->getChoice()) { case OverwriteDialog::KEEP_OLD: { xl = scene->getLevelSet()->getLevel(levelName); if (!xl) xl = scene->loadLevel(dstPath); m_vLevel = xl->getSimpleLevel(); return; } CASE OverwriteDialog::OVERWRITE : overWrite = true; DEFAULT: levelName = name; } } xl = scene->createNewLevel(PLI_XSHLEVEL, levelName); TXshSimpleLevel *vl = xl->getSimpleLevel(); assert(vl); if (overWrite) { vl->setPath(scene->codeFilePath(dstPath)); vl->setName(levelName); } TPalette *palette = 0; if (sl->getType() == TZP_XSHLEVEL) palette = sl->getPalette(); palette = palette ? palette->clone() : new TPalette; palette->setPaletteName(vl->getName()); vl->setPalette(palette); m_vLevel = vl; }
void LevelSettingsPopup::onPathChanged() { QString text = m_pathFld->getPath(); TFilePath newPath(text.toStdWString()); newPath = TApp::instance()->getCurrentScene()->getScene()->codeFilePath(newPath); m_pathFld->setPath(QString::fromStdWString(newPath.getWideString())); if (!m_sl && !!m_sdl) { // old level is a sound level TFileType::Type levelType = TFileType::getInfo(newPath); if (levelType == TFileType::AUDIO_LEVEL) { TFilePath oldPath = m_sdl->getPath(); if (oldPath == newPath) return; m_sdl->setPath(newPath); m_sdl->loadSoundTrack(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged(); } else { error(tr("The file %1 is not a sound level.") .arg(QString::fromStdWString(newPath.getLevelNameW()))); updateLevelSettings(); } return; } if (!m_sl) return; TFilePath oldPath = m_sl->getPath(); if (oldPath == newPath) return; TLevelSet *levelSet = TApp::instance()->getCurrentScene()->getScene()->getLevelSet(); TXshSimpleLevel *sl = 0; for (int i = 0; i < levelSet->getLevelCount(); i++) { TXshLevel *xl = levelSet->getLevel(i); if (!xl) continue; sl = xl->getSimpleLevel(); if (!sl) continue; if (sl == m_sl.getPointer()) { sl = 0; continue; } if (sl->getPath() == newPath) break; sl = 0; } if (sl) { QString question; question = "The path you entered for the level " + QString(::to_string(sl->getName()).c_str()) + "is already used: this may generate some conflicts in the file " "management.\nAre you sure you want to assign the same path to " "two different levels?"; int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No")); if (ret == 0 || ret == 2) { m_pathFld->setPath(toQString(m_sl->getPath())); return; } } TFileType::Type oldType = TFileType::getInfo(oldPath); TFileType::Type newType = TFileType::getInfo(newPath); if (m_sl->getType() == TZP_XSHLEVEL && m_sl->getScannedPath() != TFilePath()) { if (newPath == TFilePath() || newPath == m_sl->getScannedPath()) { newPath = m_sl->getScannedPath(); m_sl->setType(OVL_XSHLEVEL); m_sl->setScannedPath(TFilePath()); m_sl->setPath(newPath); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); TApp::instance()->getCurrentScene()->notifyCastChange(); updateLevelSettings(); m_sl->invalidateFrames(); std::vector<TFrameId> frames; m_sl->getFids(frames); for (auto const &fid : frames) { IconGenerator::instance()->invalidate(m_sl.getPointer(), fid); } return; } } if (oldType != newType || m_sl->getType() == TZP_XSHLEVEL && newPath.getType() != "tlv" || m_sl->getType() != TZP_XSHLEVEL && newPath.getType() == "tlv") { error("Wrong path"); m_pathFld->setPath(toQString(m_sl->getPath())); return; } /*-- ここでPathを更新 --*/ m_sl->setPath(newPath); TApp::instance() ->getPaletteController() ->getCurrentLevelPalette() ->setPalette(m_sl->getPalette()); TApp::instance()->getCurrentLevel()->notifyLevelChange(); TApp::instance()->getCurrentScene()->notifySceneChanged(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); m_sl->invalidateFrames(); std::vector<TFrameId> frames; m_sl->getFids(frames); for (auto const &fid : frames) { IconGenerator::instance()->invalidate(m_sl.getPointer(), fid); } updateLevelSettings(); }