From adb6c7ccc004d53303c780f2b7c6865f05cbfbd8 Mon Sep 17 00:00:00 2001 From: Anthony Rabine Date: Sun, 23 Apr 2023 22:32:38 +0200 Subject: [PATCH] Vitepress: try language, add image chooser for media node --- .gitignore | 2 + docs/.vitepress/config.ts | 20 +- docs/fr/index.md | 25 ++ story-editor/CMakeLists.txt | 1 + story-editor/CMakeLists.txt.user | 432 ------------------------- story-editor/src/choose-file.ui | 84 +++++ story-editor/src/main_window.cpp | 23 ++ story-editor/src/main_window.h | 5 +- story-editor/src/media-node.ui | 14 + story-editor/src/media_node_model.cpp | 51 ++- story-editor/src/media_node_model.h | 5 +- story-editor/src/ost-resources.ui | 12 +- story-editor/src/ost-vm.ui | 2 +- story-editor/src/resource_model.h | 11 + story-editor/src/resources_dock.h | 2 + story-editor/src/story_graph_model.cpp | 4 +- story-editor/src/story_graph_model.h | 3 + story-editor/src/story_node_base.h | 22 +- 18 files changed, 235 insertions(+), 483 deletions(-) create mode 100644 docs/fr/index.md delete mode 100644 story-editor/CMakeLists.txt.user create mode 100644 story-editor/src/choose-file.ui diff --git a/.gitignore b/.gitignore index 3eedcd1..80844ec 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ build-story-editor-Desktop_Qt_6_4_1_GCC_64bit-Debug/ docs/resources/ docs/node_modules/ + +story-editor/CMakeLists.txt.user diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index ff53878..234ebe0 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -11,6 +11,10 @@ export default defineConfig({ { text: 'Examples', link: '/markdown-examples' } ], + search: { + provider: 'local' + }, + sidebar: [ { text: 'Examples', @@ -22,7 +26,21 @@ export default defineConfig({ ], socialLinks: [ - { icon: 'github', link: 'https://github.com/vuejs/vitepress' } + { icon: 'github', link: 'https://github.com/arabine/open-story-teller' } ] + }, + locales: { + root: { + label: 'English', + lang: 'en' + }, + fr: { + label: 'French', + lang: 'fr', // optional, will be added as `lang` attribute on `html` tag + link: '/fr' // default /fr/ -- shows on navbar translations menu, can be external + + // other locale specific properties... + } } }) + diff --git a/docs/fr/index.md b/docs/fr/index.md new file mode 100644 index 0000000..d01f5fc --- /dev/null +++ b/docs/fr/index.md @@ -0,0 +1,25 @@ +--- +# https://vitepress.dev/reference/default-theme-home-page +layout: home + +hero: + name: "Open Story Teller" + text: "Fabriquez votre propre boîte à histoire" + tagline: My great project tagline + actions: + - theme: brand + text: Markdown Examples + link: /markdown-examples + - theme: alt + text: API Examples + link: /api-examples + +features: + - title: Feature A + details: Lorem ipsum dolor sit amet, consectetur adipiscing elit + - title: Feature B + details: Lorem ipsum dolor sit amet, consectetur adipiscing elit + - title: Feature C + details: Lorem ipsum dolor sit amet, consectetur adipiscing elit +--- + diff --git a/story-editor/CMakeLists.txt b/story-editor/CMakeLists.txt index a024755..063e6e9 100644 --- a/story-editor/CMakeLists.txt +++ b/story-editor/CMakeLists.txt @@ -61,6 +61,7 @@ set(PROJECT_SOURCES src/ost-log.ui src/media-node.ui src/event-node.ui + src/choose-file.ui ../software/chip32/chip32_assembler.cpp ../software/chip32/chip32_vm.c ) diff --git a/story-editor/CMakeLists.txt.user b/story-editor/CMakeLists.txt.user deleted file mode 100644 index 67ced81..0000000 --- a/story-editor/CMakeLists.txt.user +++ /dev/null @@ -1,432 +0,0 @@ - - - - - - EnvironmentId - {75eff57d-71d0-4697-b143-c9d65b3913b6} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - true - Builtin.DefaultTidyAndClazy - 6 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.4.1 GCC 64bit - Desktop Qt 6.4.1 GCC 64bit - qt.qt6.641.gcc_64_kit - 0 - 0 - 0 - - Debug - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Debug --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - /mnt/data/git/open-story-teller/build-story-editor-Desktop_Qt_6_4_1_GCC_64bit-Debug - - - - - all - - false - - true - Compilation - CMakeProjectManager.MakeStep - - 1 - Compiler - Compiler - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - Compilation - CMakeProjectManager.MakeStep - - 1 - Nettoyer - Nettoyer - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - Release - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - /mnt/data/git/open-story-teller/build-story-editor-Desktop_Qt_6_4_1_GCC_64bit-Release - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - Compiler - Compiler - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - Nettoyer - Nettoyer - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - CMakeProjectManager.CMakeBuildConfiguration - - - RelWithDebInfo - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - /mnt/data/git/open-story-teller/build-story-editor-Desktop_Qt_6_4_1_GCC_64bit-RelWithDebInfo - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - Compiler - Compiler - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - Nettoyer - Nettoyer - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release with Debug Information - CMakeProjectManager.CMakeBuildConfiguration - - - RelWithDebInfo - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - 0 - /mnt/data/git/open-story-teller/build-story-editor-Desktop_Qt_6_4_1_GCC_64bit-Profile - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - Compiler - Compiler - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - Nettoyer - Nettoyer - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - CMakeProjectManager.CMakeBuildConfiguration - - - MinSizeRel - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=MinSizeRel --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - /mnt/data/git/open-story-teller/build-story-editor-Desktop_Qt_6_4_1_GCC_64bit-MinSizeRel - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - Compiler - Compiler - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - Nettoyer - Nettoyer - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Minimum Size Release - CMakeProjectManager.CMakeBuildConfiguration - - 5 - - - 0 - Déploiement - Déploiement - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - 2 - - story-editor - CMakeProjectManager.CMakeRunConfiguration.story-editor - story-editor - false - true - true - false - true - /mnt/data/git/open-story-teller/build-story-editor-Desktop_Qt_6_4_1_GCC_64bit-Debug - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/story-editor/src/choose-file.ui b/story-editor/src/choose-file.ui new file mode 100644 index 0000000..5d92b3d --- /dev/null +++ b/story-editor/src/choose-file.ui @@ -0,0 +1,84 @@ + + + chooseFileDIalog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + Choisissez le fichier + + + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + chooseFileDIalog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + chooseFileDIalog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/story-editor/src/main_window.cpp b/story-editor/src/main_window.cpp index c70e074..e304a52 100644 --- a/story-editor/src/main_window.cpp +++ b/story-editor/src/main_window.cpp @@ -101,6 +101,29 @@ MainWindow::MainWindow() m_romView = new MemoryViewDock("RomViewDock", "ROM"); addDockWidget(Qt::DockWidgetArea::RightDockWidgetArea, m_romView); + + m_chooseFileDialog = new QDialog(this); + m_chooseFileUi.setupUi(m_chooseFileDialog); + m_chooseFileDialog->close(); + + connect(&m_model, &StoryGraphModel::sigChooseFile, [&](NodeId id) { + m_chooseFileUi.tableView->setModel(&m_resourcesDock->getModel()); + m_chooseFileDialog->exec(); + + // Get the file choosen + QModelIndexList selection = m_chooseFileUi.tableView->selectionModel()->selectedRows(); + + if (selection.count() > 0) + { + // Take first + QModelIndex index = selection.at(0); + QString fn = m_resourcesDock->getModel().GetFileName(index.row()); + QJsonObject obj; + obj["image"] = fn; + m_model.setNodeData(id, NodeRole::InternalData, obj.toVariantMap()); + } + }); + // TODO: merge both m_model.registerNode("MediaNode"); m_model.addModel("MediaNode", "Story Teller"); diff --git a/story-editor/src/main_window.h b/story-editor/src/main_window.h index a296671..f121902 100644 --- a/story-editor/src/main_window.h +++ b/story-editor/src/main_window.h @@ -30,7 +30,7 @@ using QtNodes::StyleCollection; using QtNodes::DataFlowGraphModel; using QtNodes::NodeDelegateModelRegistry; -#include "ui_ost-log.h" +#include "ui_choose-file.h" #include "story_project.h" #include "story_graph_model.h" #include "story_graph_scene.h" @@ -133,6 +133,9 @@ private: MemoryViewDock *m_ramView{nullptr}; MemoryViewDock *m_romView{nullptr}; + QDialog *m_chooseFileDialog; + Ui::chooseFileDIalog m_chooseFileUi; + // VM uint8_t m_rom_data[16*1024]; uint8_t m_ram_data[16*1024]; diff --git a/story-editor/src/media-node.ui b/story-editor/src/media-node.ui index f1065c6..b28db08 100644 --- a/story-editor/src/media-node.ui +++ b/story-editor/src/media-node.ui @@ -58,6 +58,13 @@ + + + + TextLabel + + + @@ -89,6 +96,13 @@ + + + + TextLabel + + + diff --git a/story-editor/src/media_node_model.cpp b/story-editor/src/media_node_model.cpp index a7ffc24..1a0023d 100644 --- a/story-editor/src/media_node_model.cpp +++ b/story-editor/src/media_node_model.cpp @@ -14,9 +14,7 @@ MediaNodeModel::MediaNodeModel(StoryGraphModel &model) , m_widget(new QWidget()) { m_ui.setupUi(m_widget); - m_ui.image->setText("Image will appear here"); - m_ui.image->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); QFont f = m_ui.image->font(); @@ -44,24 +42,11 @@ MediaNodeModel::MediaNodeModel(StoryGraphModel &model) }); connect(m_ui.selectImageButton, &QPushButton::clicked, [&](bool enable) { - ShowContextMenu(QCursor::pos()); + //m_contextMenu->exec(m_widget->mapFromGlobal(QCursor::pos())); + emit m_model.sigChooseFile(getNodeId()); }); } -void MediaNodeModel::ShowContextMenu(const QPoint &pos) -{ - QMenu contextMenu(tr("Context menu"), m_widget); - - QAction action1("Remove Data Point", this); - // connect(&action1, SIGNAL(triggered()), this, SLOT(removeDataPoint())); - contextMenu.addAction(&action1); - contextMenu.addAction(&action1); - contextMenu.addAction(&action1); - contextMenu.addAction(&action1); - - contextMenu.exec(m_widget->mapFromGlobal(pos)); -} - QJsonObject MediaNodeModel::save() const { QJsonObject obj = NodeDelegateModel::save(); @@ -83,18 +68,30 @@ void MediaNodeModel::load(const QJsonObject &mediaData) if (!imagePath.isEmpty()) { - std::cout << "Loading " << m_mediaData["image"].toString().toStdString() << std::endl; - QPixmap pix(imagePath); + setImage(imagePath); + } +} - if (pix.isNull()) - { - std::cout << "!!!!!!! " << m_mediaData["image"].toString().toStdString() << std::endl; - } +void MediaNodeModel::setImage(const QString &imagePath) +{ + QPixmap pix(imagePath); - int w = m_ui.image->width(); - int h = m_ui.image->height(); - pix.scaled(w, h, Qt::KeepAspectRatio); - m_ui.image->setPixmap(pix); + if (pix.isNull()) + { + std::cout << "!!!!!!! " << m_mediaData["image"].toString().toStdString() << std::endl; + } + + int w = m_ui.image->width(); + int h = m_ui.image->height(); + pix.scaled(w, h, Qt::KeepAspectRatio); + m_ui.image->setPixmap(pix); +} + +void MediaNodeModel::setInternalData(const QVariant &value) +{ + QJsonObject obj = value.toJsonObject(); + if (obj.contains("image")) { + setImage(obj.value("image").toString()); } } diff --git a/story-editor/src/media_node_model.h b/story-editor/src/media_node_model.h index 2dfe919..5c26928 100644 --- a/story-editor/src/media_node_model.h +++ b/story-editor/src/media_node_model.h @@ -40,6 +40,8 @@ public: void load(QJsonObject const &mediaData) override; + void setInternalData(const QVariant &value) override; + public: virtual QString modelName() const { return QString("MediaNode"); } @@ -63,9 +65,10 @@ private: unsigned int m_ports{1}; QWidget *m_widget; + Ui::mediaNodeUi m_ui; std::shared_ptr m_nodeData; QJsonObject m_mediaData; - void ShowContextMenu(const QPoint &pos); + void setImage(const QString &fileName); }; diff --git a/story-editor/src/ost-resources.ui b/story-editor/src/ost-resources.ui index 1fb41e7..4083aa2 100644 --- a/story-editor/src/ost-resources.ui +++ b/story-editor/src/ost-resources.ui @@ -41,7 +41,17 @@ - + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + diff --git a/story-editor/src/ost-vm.ui b/story-editor/src/ost-vm.ui index 8afbf54..5c595b6 100644 --- a/story-editor/src/ost-vm.ui +++ b/story-editor/src/ost-vm.ui @@ -42,7 +42,7 @@ - Play + Step diff --git a/story-editor/src/resource_model.h b/story-editor/src/resource_model.h index 0010c01..a62f3c4 100644 --- a/story-editor/src/resource_model.h +++ b/story-editor/src/resource_model.h @@ -64,6 +64,17 @@ public: endInsertRows(); } + QString GetFileName(int row) { + QString n; + + if (row < m_data.size()) + { + n = m_data.at(row).file.c_str(); + } + + return n; + } + QList GetData() const { return m_data; } private: diff --git a/story-editor/src/resources_dock.h b/story-editor/src/resources_dock.h index 3c2ad8e..1a06fcb 100644 --- a/story-editor/src/resources_dock.h +++ b/story-editor/src/resources_dock.h @@ -13,6 +13,8 @@ public: QList GetResources() const { return m_resourcesModel.GetData(); } + ResourceModel &getModel() { return m_resourcesModel; } + private: // Resources Ui::ostResources m_uiOstResources; diff --git a/story-editor/src/story_graph_model.cpp b/story-editor/src/story_graph_model.cpp index 69291f4..a303733 100644 --- a/story-editor/src/story_graph_model.cpp +++ b/story-editor/src/story_graph_model.cpp @@ -212,8 +212,10 @@ bool StoryGraphModel::setNodeData(NodeId nodeId, NodeRole role, QVariant value) break; case NodeRole::InternalData: + { + model->setInternalData(value); break; - + } case NodeRole::InPortCount: break; diff --git a/story-editor/src/story_graph_model.h b/story-editor/src/story_graph_model.h index 4b68919..c8b0cce 100644 --- a/story-editor/src/story_graph_model.h +++ b/story-editor/src/story_graph_model.h @@ -132,6 +132,9 @@ public: StoryProject &GetProject() { return m_project; }; +signals: + void sigChooseFile(NodeId id); + private: StoryProject &m_project; diff --git a/story-editor/src/story_node_base.h b/story-editor/src/story_node_base.h index 8f185f7..bbb6aab 100644 --- a/story-editor/src/story_node_base.h +++ b/story-editor/src/story_node_base.h @@ -24,28 +24,14 @@ public: QSize size; QPointF pos; }; -/* - typedef ::Factory Factory; - virtual ~StoryNodeBase() {} - virtual int answer() const = 0; - - static Factory::Type create(Factory::Key const& name) { - return m_factory.create(name); - } - template - static void define(Factory::Key const& name) { - bool new_key = m_factory.define(name, - &Factory::template create_func); - if (not new_key) { - throw std::logic_error(std::string(__PRETTY_FUNCTION__) + - ": name already registered"); - } - } - */ void setNodeId(NodeId id) { m_nodeId = id; } NodeId getNodeId() { return m_nodeId; } + virtual void setInternalData(const QVariant &value) { + // default impl + } + NodeGeometryData &geometryData() { return m_geometryData; } private: