From 8613de5fb6e4b1f970818822814d2ef54210617e Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Mon, 2 Dec 2024 16:48:10 -0800 Subject: [PATCH] Add settings Signed-off-by: Darby Johnston --- cmake/SuperBuild/Builddtk-deps.cmake | 2 +- cmake/SuperBuild/Builddtk.cmake | 2 +- lib/toucanView/App.cpp | 9 ++++----- lib/toucanView/App.h | 1 - lib/toucanView/ExportTool.cpp | 1 + lib/toucanView/FilesModel.cpp | 3 +-- lib/toucanView/FilesModel.h | 2 -- lib/toucanView/GraphTool.cpp | 2 +- lib/toucanView/JSONTool.cpp | 2 -- lib/toucanView/MenuBar.cpp | 5 ++++- lib/toucanView/TimeUnitsModel.cpp | 19 ++++++++++++++----- lib/toucanView/TimeUnitsModel.h | 6 +++--- lib/toucanView/ToolBar.cpp | 18 +++++++++++------- 13 files changed, 41 insertions(+), 31 deletions(-) diff --git a/cmake/SuperBuild/Builddtk-deps.cmake b/cmake/SuperBuild/Builddtk-deps.cmake index a9d454f..ac0c09e 100644 --- a/cmake/SuperBuild/Builddtk-deps.cmake +++ b/cmake/SuperBuild/Builddtk-deps.cmake @@ -1,7 +1,7 @@ include(ExternalProject) set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git") -set(dtk_GIT_TAG "3f569280b3ea1c9cf37241f80be7847b6105d12c") +set(dtk_GIT_TAG "b9515ed232f27dbba1398a81d25dad0d2caf231a") set(dtk-deps_ARGS ${toucan_EXTERNAL_PROJECT_ARGS} diff --git a/cmake/SuperBuild/Builddtk.cmake b/cmake/SuperBuild/Builddtk.cmake index ae2a82c..8e66eaa 100644 --- a/cmake/SuperBuild/Builddtk.cmake +++ b/cmake/SuperBuild/Builddtk.cmake @@ -1,7 +1,7 @@ include(ExternalProject) set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git") -set(dtk_GIT_TAG "3f569280b3ea1c9cf37241f80be7847b6105d12c") +set(dtk_GIT_TAG "b9515ed232f27dbba1398a81d25dad0d2caf231a") set(dtk_DEPS dtk-deps) set(dtk_ARGS diff --git a/lib/toucanView/App.cpp b/lib/toucanView/App.cpp index dbfe84b..05ffae9 100644 --- a/lib/toucanView/App.cpp +++ b/lib/toucanView/App.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -25,8 +26,6 @@ namespace toucan { _messageLog = std::make_shared(); - _settings = dtk::Settings::create(dtk::getSettingsPath("toucan", "toucan-view.settings")); - dtk::App::_init( context, argv, @@ -40,9 +39,9 @@ namespace toucan true) }, {}, - _settings); + dtk::getSettingsPath("toucan", "toucan-view.settings").string()); - _timeUnitsModel = std::make_shared(_settings); + _timeUnitsModel = std::make_shared(context); std::vector searchPath; const std::filesystem::path parentPath = std::filesystem::path(argv[0]).parent_path(); @@ -59,7 +58,7 @@ namespace toucan auto fileBrowserSystem = context->getSystem(); fileBrowserSystem->setNativeFileDialog(false); - _filesModel = std::make_shared(context, _settings, _host); + _filesModel = std::make_shared(context, _host); _windowModel = std::make_shared(); diff --git a/lib/toucanView/App.h b/lib/toucanView/App.h index a253ad9..61651cb 100644 --- a/lib/toucanView/App.h +++ b/lib/toucanView/App.h @@ -35,7 +35,6 @@ namespace toucan private: std::shared_ptr _messageLog; - std::shared_ptr _settings; std::string _path; std::shared_ptr _timeUnitsModel; std::shared_ptr _host; diff --git a/lib/toucanView/ExportTool.cpp b/lib/toucanView/ExportTool.cpp index 18f39b2..5d9450a 100644 --- a/lib/toucanView/ExportTool.cpp +++ b/lib/toucanView/ExportTool.cpp @@ -25,6 +25,7 @@ namespace toucan _host = app->getHost(); _formats = { + ".exr", ".tiff", ".png" }; diff --git a/lib/toucanView/FilesModel.cpp b/lib/toucanView/FilesModel.cpp index 0cee7a9..f815b01 100644 --- a/lib/toucanView/FilesModel.cpp +++ b/lib/toucanView/FilesModel.cpp @@ -11,7 +11,6 @@ namespace toucan { FilesModel::FilesModel( const std::shared_ptr& context, - const std::shared_ptr& settings, const std::shared_ptr& host) : _context(context), _host(host) @@ -21,7 +20,7 @@ namespace toucan _remove = dtk::ObservableValue::create(-1); _current = dtk::ObservableValue< std::shared_ptr >::create(nullptr); _currentIndex = dtk::ObservableValue::create(-1); - _recentFilesModel = dtk::RecentFilesModel::create(context, settings); + _recentFilesModel = dtk::RecentFilesModel::create(context); } FilesModel::~FilesModel() diff --git a/lib/toucanView/FilesModel.h b/lib/toucanView/FilesModel.h index 0df3baf..2d88bec 100644 --- a/lib/toucanView/FilesModel.h +++ b/lib/toucanView/FilesModel.h @@ -6,7 +6,6 @@ #include "File.h" #include -#include #include #include #include @@ -22,7 +21,6 @@ namespace toucan public: FilesModel( const std::shared_ptr&, - const std::shared_ptr&, const std::shared_ptr&); virtual ~FilesModel(); diff --git a/lib/toucanView/GraphTool.cpp b/lib/toucanView/GraphTool.cpp index c900561..bfcc2f9 100644 --- a/lib/toucanView/GraphTool.cpp +++ b/lib/toucanView/GraphTool.cpp @@ -103,7 +103,7 @@ namespace toucan { _size.init = false; _size.displayScale = event.displayScale; - _size.lineWidth = event.style->getSizeRole(dtk::SizeRole::BorderFocus, event.displayScale); + _size.lineWidth = 2 * event.displayScale; } _setSizeHint(_layout->getSizeHint()); } diff --git a/lib/toucanView/JSONTool.cpp b/lib/toucanView/JSONTool.cpp index bddcd9b..e87568c 100644 --- a/lib/toucanView/JSONTool.cpp +++ b/lib/toucanView/JSONTool.cpp @@ -127,11 +127,9 @@ namespace toucan auto hLayout = dtk::HorizontalLayout::create(context, _bottomLayout); hLayout->setSpacingRole(dtk::SizeRole::SpacingTool); auto openButton = dtk::ToolButton::create(context, hLayout); - openButton->setMarginRole(dtk::SizeRole::MarginSmall); openButton->setIcon("BellowsOpen"); openButton->setTooltip("Open all"); auto closeButton = dtk::ToolButton::create(context, hLayout); - closeButton->setMarginRole(dtk::SizeRole::MarginSmall); closeButton->setIcon("BellowsClosed"); closeButton->setTooltip("Close all"); diff --git a/lib/toucanView/MenuBar.cpp b/lib/toucanView/MenuBar.cpp index fb03294..7f3f615 100644 --- a/lib/toucanView/MenuBar.cpp +++ b/lib/toucanView/MenuBar.cpp @@ -145,8 +145,11 @@ namespace toucan { fileBrowserSystem->setPath(_file->getPath().parent_path()); } - dtk::FileBrowserOptions options; + dtk::FileBrowserOptions options = fileBrowserSystem->getOptions(); + options.extensions.clear(); options.extensions.push_back(".otio"); + options.extensions.push_back(".otiod"); + options.extensions.push_back(".otioz"); fileBrowserSystem->setOptions(options); fileBrowserSystem->open( getWindow(), diff --git a/lib/toucanView/TimeUnitsModel.cpp b/lib/toucanView/TimeUnitsModel.cpp index 2b3f37e..e9d96d4 100644 --- a/lib/toucanView/TimeUnitsModel.cpp +++ b/lib/toucanView/TimeUnitsModel.cpp @@ -3,6 +3,8 @@ #include "TimeUnitsModel.h" +#include + #include #include @@ -33,16 +35,21 @@ namespace toucan TimeUnits::Timecode; } - TimeUnitsModel::TimeUnitsModel(const std::shared_ptr& settings) + TimeUnitsModel::TimeUnitsModel(const std::shared_ptr& context) { - _settings = settings; + _context = context; TimeUnits value = TimeUnits::Timecode; try { - const auto json = std::any_cast(_settings->get("TimeUnits")); + auto settings = context->getSystem(); + const auto json = std::any_cast(settings->get("TimeUnits")); if (json.is_object()) { - value = toucan::fromString(json["Units"]); + auto i = json.find("Units"); + if (i != json.end()) + { + value = toucan::fromString(i->get()); + } } } catch (const std::exception&) @@ -55,7 +62,9 @@ namespace toucan { nlohmann::json json; json["Units"] = toucan::toString(_timeUnits->get()); - _settings->set("TimeUnits", json); + auto context = _context.lock(); + auto settings = context->getSystem(); + settings->set("TimeUnits", json); } TimeUnits TimeUnitsModel::getTimeUnits() const diff --git a/lib/toucanView/TimeUnitsModel.h b/lib/toucanView/TimeUnitsModel.h index 4b82558..5303e06 100644 --- a/lib/toucanView/TimeUnitsModel.h +++ b/lib/toucanView/TimeUnitsModel.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include @@ -28,7 +28,7 @@ namespace toucan class TimeUnitsModel : public std::enable_shared_from_this { public: - TimeUnitsModel(const std::shared_ptr&); + TimeUnitsModel(const std::shared_ptr&); virtual ~TimeUnitsModel(); @@ -48,7 +48,7 @@ namespace toucan OTIO_NS::RationalTime fromString(const std::string&, double rate) const; private: - std::shared_ptr _settings; + std::weak_ptr _context; std::shared_ptr > _timeUnits; }; } diff --git a/lib/toucanView/ToolBar.cpp b/lib/toucanView/ToolBar.cpp index be597b4..7457fae 100644 --- a/lib/toucanView/ToolBar.cpp +++ b/lib/toucanView/ToolBar.cpp @@ -22,8 +22,10 @@ namespace toucan dtk::IWidget::_init(context, "toucan::ToolBar", parent); _layout = dtk::HorizontalLayout::create(context, shared_from_this()); - _layout->setSpacingRole(dtk::SizeRole::SpacingTool); + _layout->setSpacingRole(dtk::SizeRole::SpacingSmall); + auto hLayout = dtk::HorizontalLayout::create(context, _layout); + hLayout->setSpacingRole(dtk::SizeRole::SpacingTool); std::vector actionNames = { "File/Open", @@ -33,7 +35,7 @@ namespace toucan for (const auto& name : actionNames) { auto i = actions.find(name); - auto button = dtk::ToolButton::create(context, _layout); + auto button = dtk::ToolButton::create(context, hLayout); button->setIcon(i->second->icon); button->setTooltip(i->second->toolTip); button->setClickedCallback( @@ -49,8 +51,10 @@ namespace toucan dtk::Divider::create(context, dtk::Orientation::Horizontal, _layout); + hLayout = dtk::HorizontalLayout::create(context, _layout); + hLayout->setSpacingRole(dtk::SizeRole::SpacingTool); auto i = actions.find("Window/FullScreen"); - auto button = dtk::ToolButton::create(context, _layout); + auto button = dtk::ToolButton::create(context, hLayout); button->setIcon(i->second->icon); button->setCheckable(true); button->setTooltip(i->second->toolTip); @@ -66,6 +70,8 @@ namespace toucan dtk::Divider::create(context, dtk::Orientation::Horizontal, _layout); + hLayout = dtk::HorizontalLayout::create(context, _layout); + hLayout->setSpacingRole(dtk::SizeRole::SpacingTool); actionNames = { "View/ZoomIn", @@ -75,7 +81,7 @@ namespace toucan for (const auto& name : actionNames) { i = actions.find(name); - button = dtk::ToolButton::create(context, _layout); + button = dtk::ToolButton::create(context, hLayout); button->setIcon(i->second->icon); button->setTooltip(i->second->toolTip); button->setClickedCallback( @@ -90,7 +96,7 @@ namespace toucan } i = actions.find("View/Frame"); - button = dtk::ToolButton::create(context, _layout); + button = dtk::ToolButton::create(context, hLayout); button->setIcon(i->second->icon); button->setCheckable(true); button->setTooltip(i->second->toolTip); @@ -104,8 +110,6 @@ namespace toucan }); _buttons["View/Frame"] = button; - dtk::Divider::create(context, dtk::Orientation::Horizontal, _layout); - _widgetUpdate(); _filesObserver = dtk::ListObserver >::create(