From 5ab15e9282e3a81b2dbdc2e7db6d07f0aae8ec53 Mon Sep 17 00:00:00 2001 From: Rodney Date: Jan 14 2023 13:31:57 +0000 Subject: Merge pull request #4707 from manongjohn/export_scene_enhancement Export Scene enhancements --- diff --git a/stuff/profiles/layouts/rooms/Default/menubar_template.xml b/stuff/profiles/layouts/rooms/Default/menubar_template.xml index 1bec09e..730a3e1 100644 --- a/stuff/profiles/layouts/rooms/Default/menubar_template.xml +++ b/stuff/profiles/layouts/rooms/Default/menubar_template.xml @@ -26,6 +26,7 @@ MI_ImportMagpieFile + MI_ExportCurrentScene MI_SoundTrack MI_ExportXDTS MI_ExportOCA diff --git a/toonz/sources/include/toonzqt/filefield.h b/toonz/sources/include/toonzqt/filefield.h index 5f28d1a..cffa7ce 100644 --- a/toonz/sources/include/toonzqt/filefield.h +++ b/toonz/sources/include/toonzqt/filefield.h @@ -92,6 +92,7 @@ public: void setValidator(const QValidator *v) { m_field->setValidator(v); } QString getPath(); void setPath(const QString &path); + LineEdit *getField() { return m_field; } static void setBrowserPopupController(BrowserPopupController *controller); static BrowserPopupController *getBrowserPopupController(); diff --git a/toonz/sources/toonz/exportscenepopup.cpp b/toonz/sources/toonz/exportscenepopup.cpp index 2a542d7..464cce7 100644 --- a/toonz/sources/toonz/exportscenepopup.cpp +++ b/toonz/sources/toonz/exportscenepopup.cpp @@ -28,9 +28,16 @@ #include #include #include +#include using namespace DVGui; +TFilePath getStdDocumentsPath() { + QString documentsPath = + QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0]; + return TFilePath(documentsPath); +} + //------------------------------------------------------------------------ namespace { //------------------------------------------------------------------------ @@ -526,6 +533,7 @@ ExportScenePopup::ExportScenePopup(std::vector scenes) m_projectTreeView = new ExportSceneTreeView(chooseProjectWidget); m_projectTreeView->setMinimumWidth(200); + m_projectTreeView->setMinimumWidth(400); ret = ret && connect(m_projectTreeView, SIGNAL(focusIn()), this, SLOT(onProjectTreeViweFocusIn())); chooseProjectLayout->addWidget(m_projectTreeView); @@ -552,6 +560,16 @@ ExportScenePopup::ExportScenePopup(std::vector scenes) newProjectLayout->setColumnStretch(1, 5); newProjectLayout->addWidget(m_newProjectName, 1, 1, 1, 1, Qt::AlignLeft); + m_pathFieldLabel = new QLabel(tr("Create In:"), this); + m_projectLocationFld = + new DVGui::FileField(this, getStdDocumentsPath().getQString()); + ret = ret && connect(m_projectLocationFld->getField(), SIGNAL(focusIn()), + this, SLOT(onProjectNameFocusIn())); + + newProjectLayout->addWidget(m_pathFieldLabel, 2, 0, + Qt::AlignRight | Qt::AlignVCenter); + newProjectLayout->addWidget(m_projectLocationFld, 2, 1); + newProjectWidget->setLayout(chooseProjectLayout); layout->addWidget(newProjectWidget); @@ -673,16 +691,16 @@ TFilePath ExportScenePopup::createNewProject() { return TFilePath(); } - TFilePath currentProjectRoot; - DvDirModelFileFolderNode *node = dynamic_cast( - m_projectTreeView->getCurrentNode()); - if (node) - currentProjectRoot = node->getPath(); - else - currentProjectRoot = pm->getCurrentProjectRoot(); - TFilePath projectFolder = currentProjectRoot + projectName; + TFilePath newLocation = TFilePath(m_projectLocationFld->getPath()); + TFilePath projectFolder = newLocation + projectName; TFilePath projectPath = pm->projectFolderToProjectPath(projectFolder); - TProject *project = new TProject(); + + if (TSystem::doesExistFileOrLevel(projectPath)) { + error(tr("Project '%1' already exists").arg(m_newProjectName->text())); + return TFilePath(); + } + + TProject *project = new TProject(); TProjectP currentProject = pm->getCurrentProject(); assert(currentProject); @@ -691,7 +709,7 @@ TFilePath ExportScenePopup::createNewProject() { project->setFolder(currentProject->getFolderName(i), currentProject->getFolder(i)); project->save(projectPath); - DvDirModel::instance()->refreshFolder(currentProjectRoot); + DvDirModel::instance()->refreshFolder(newLocation); return projectPath; } diff --git a/toonz/sources/toonz/exportscenepopup.h b/toonz/sources/toonz/exportscenepopup.h index f9846be..580efd2 100644 --- a/toonz/sources/toonz/exportscenepopup.h +++ b/toonz/sources/toonz/exportscenepopup.h @@ -5,6 +5,7 @@ #include "toonzqt/dvdialog.h" #include "toonzqt/lineedit.h" +#include "toonzqt/filefield.h" #include "tfilepath.h" #include "filebrowsermodel.h" #include "dvdirtreeview.h" @@ -163,6 +164,9 @@ class ExportScenePopup final : public DVGui::Dialog { QRadioButton *m_newProjectButton; QRadioButton *m_chooseProjectButton; + QLabel *m_pathFieldLabel; + DVGui::FileField *m_projectLocationFld; + bool m_createNewProject; public: diff --git a/toonz/sources/toonz/fileselection.cpp b/toonz/sources/toonz/fileselection.cpp index 69958f3..5475b48 100644 --- a/toonz/sources/toonz/fileselection.cpp +++ b/toonz/sources/toonz/fileselection.cpp @@ -33,6 +33,7 @@ #include "toonz/studiopalette.h" #include "toonz/palettecontroller.h" #include "toonz/tpalettehandle.h" +#include "toonz/tscenehandle.h" // TnzCore includes #include "tfiletype.h" @@ -609,6 +610,20 @@ void FileSelection::exportScenes() { //------------------------------------------------------------------------ +void FileSelection::exportScene(TFilePath scenePath) { + if (scenePath.isEmpty()) return; + + std::vector files; + files.push_back(scenePath); + if (!m_exportScenePopup) + m_exportScenePopup = new ExportScenePopup(files); + else + m_exportScenePopup->setScenes(files); + m_exportScenePopup->show(); +} + +//------------------------------------------------------------------------ + void FileSelection::selectAll() { DvItemSelection::selectAll(); const std::set &indices = getSelectedIndices(); @@ -621,3 +636,27 @@ void FileSelection::selectAll() { FileBrowser::updateItemViewerPanel(); } } + +//----------------------------------------------------------------------------- + +class ExportCurrentSceneCommandHandler final : public MenuItemHandler { +public: + ExportCurrentSceneCommandHandler() : MenuItemHandler(MI_ExportCurrentScene) {} + void execute() override { + TApp *app = TApp::instance(); + TSceneHandle *sceneHandle = app->getCurrentScene(); + if (!sceneHandle) return; + ToonzScene *scene = sceneHandle->getScene(); + if (!scene) return; + TFilePath fp = scene->getScenePath(); + + if (sceneHandle->getDirtyFlag() || scene->isUntitled() || + !TSystem::doesExistFileOrLevel(fp)) { + DVGui::warning(tr("You must save the current scene first.")); + return; + } + + FileSelection *fs = new FileSelection(); + fs->exportScene(fp); + } +} ExportCurrentSceneCommandHandler; diff --git a/toonz/sources/toonz/fileselection.h b/toonz/sources/toonz/fileselection.h index f3c76f8..29fd8d5 100644 --- a/toonz/sources/toonz/fileselection.h +++ b/toonz/sources/toonz/fileselection.h @@ -43,6 +43,7 @@ public: void collectAssets(); void importScenes(); void exportScenes(); + void exportScene(TFilePath scenePath); void selectAll(); void separateFilesByColors(); }; diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index d1e31cc..8189a51 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -1731,6 +1731,8 @@ void MainWindow::defineActions() { QT_TR_NOOP("&Clear Recent Flipbook Image List"), ""); createMenuFileAction(MI_ClearCacheFolder, QT_TR_NOOP("&Clear Cache Folder"), "", "clear_cache"); + createMenuFileAction(MI_ExportCurrentScene, + QT_TR_NOOP("&Export Current Scene"), ""); // Menu - Edit diff --git a/toonz/sources/toonz/menubar.cpp b/toonz/sources/toonz/menubar.cpp index e39e898..885355e 100644 --- a/toonz/sources/toonz/menubar.cpp +++ b/toonz/sources/toonz/menubar.cpp @@ -1108,6 +1108,7 @@ QMenuBar *StackedMenuBar::createFullMenuBar() { { addMenuItem(importMenu, MI_ImportMagpieFile); } QMenu *exportMenu = fileMenu->addMenu(tr("Export")); { + addMenuItem(exportMenu, MI_ExportCurrentScene); addMenuItem(exportMenu, MI_SoundTrack); addMenuItem(exportMenu, MI_ExportXDTS); addMenuItem(exportMenu, MI_ExportOCA); diff --git a/toonz/sources/toonz/menubarcommandids.h b/toonz/sources/toonz/menubarcommandids.h index 41cd6d8..b749dee 100644 --- a/toonz/sources/toonz/menubarcommandids.h +++ b/toonz/sources/toonz/menubarcommandids.h @@ -261,6 +261,7 @@ #define MI_CollectAssets "MI_CollectAssets" #define MI_ImportScenes "MI_ImportScenes" #define MI_ExportScenes "MI_ExportScenes" +#define MI_ExportCurrentScene "MI_ExportCurrentScene" #define MI_SelectRowKeyframes "MI_SelectRowKeyframes" #define MI_SelectColumnKeyframes "MI_SelectColumnKeyframes"