Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings #30

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/SuperBuild/Builddtk-deps.cmake
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 1 addition & 1 deletion cmake/SuperBuild/Builddtk.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/toucanView/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <dtk/ui/FileBrowser.h>
#include <dtk/ui/MessageDialog.h>
#include <dtk/ui/RecentFilesModel.h>
#include <dtk/ui/Settings.h>

#include <dtk/core/CmdLine.h>

Expand All @@ -25,8 +26,6 @@ namespace toucan
{
_messageLog = std::make_shared<MessageLog>();

_settings = dtk::Settings::create(dtk::getSettingsPath("toucan", "toucan-view.settings"));

dtk::App::_init(
context,
argv,
Expand All @@ -40,9 +39,9 @@ namespace toucan
true)
},
{},
_settings);
dtk::getSettingsPath("toucan", "toucan-view.settings").string());

_timeUnitsModel = std::make_shared<TimeUnitsModel>(_settings);
_timeUnitsModel = std::make_shared<TimeUnitsModel>(context);

std::vector<std::filesystem::path> searchPath;
const std::filesystem::path parentPath = std::filesystem::path(argv[0]).parent_path();
Expand All @@ -59,7 +58,7 @@ namespace toucan
auto fileBrowserSystem = context->getSystem<dtk::FileBrowserSystem>();
fileBrowserSystem->setNativeFileDialog(false);

_filesModel = std::make_shared<FilesModel>(context, _settings, _host);
_filesModel = std::make_shared<FilesModel>(context, _host);

_windowModel = std::make_shared<WindowModel>();

Expand Down
1 change: 0 additions & 1 deletion lib/toucanView/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace toucan

private:
std::shared_ptr<MessageLog> _messageLog;
std::shared_ptr<dtk::Settings> _settings;
std::string _path;
std::shared_ptr<TimeUnitsModel> _timeUnitsModel;
std::shared_ptr<ImageEffectHost> _host;
Expand Down
1 change: 1 addition & 0 deletions lib/toucanView/ExportTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace toucan
_host = app->getHost();
_formats =
{
".exr",
".tiff",
".png"
};
Expand Down
3 changes: 1 addition & 2 deletions lib/toucanView/FilesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace toucan
{
FilesModel::FilesModel(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<dtk::Settings>& settings,
const std::shared_ptr<ImageEffectHost>& host) :
_context(context),
_host(host)
Expand All @@ -21,7 +20,7 @@ namespace toucan
_remove = dtk::ObservableValue<int>::create(-1);
_current = dtk::ObservableValue< std::shared_ptr<File> >::create(nullptr);
_currentIndex = dtk::ObservableValue<int>::create(-1);
_recentFilesModel = dtk::RecentFilesModel::create(context, settings);
_recentFilesModel = dtk::RecentFilesModel::create(context);
}

FilesModel::~FilesModel()
Expand Down
2 changes: 0 additions & 2 deletions lib/toucanView/FilesModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "File.h"

#include <dtk/ui/RecentFilesModel.h>
#include <dtk/ui/Settings.h>
#include <dtk/core/Context.h>
#include <dtk/core/ObservableList.h>
#include <dtk/core/ObservableValue.h>
Expand All @@ -22,7 +21,6 @@ namespace toucan
public:
FilesModel(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<dtk::Settings>&,
const std::shared_ptr<ImageEffectHost>&);

virtual ~FilesModel();
Expand Down
2 changes: 1 addition & 1 deletion lib/toucanView/GraphTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 0 additions & 2 deletions lib/toucanView/JSONTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
5 changes: 4 additions & 1 deletion lib/toucanView/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
19 changes: 14 additions & 5 deletions lib/toucanView/TimeUnitsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "TimeUnitsModel.h"

#include <dtk/ui/Settings.h>

#include <nlohmann/json.hpp>

#include <array>
Expand Down Expand Up @@ -33,16 +35,21 @@ namespace toucan
TimeUnits::Timecode;
}

TimeUnitsModel::TimeUnitsModel(const std::shared_ptr<dtk::Settings>& settings)
TimeUnitsModel::TimeUnitsModel(const std::shared_ptr<dtk::Context>& context)
{
_settings = settings;
_context = context;
TimeUnits value = TimeUnits::Timecode;
try
{
const auto json = std::any_cast<nlohmann::json>(_settings->get("TimeUnits"));
auto settings = context->getSystem<dtk::Settings>();
const auto json = std::any_cast<nlohmann::json>(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<std::string>());
}
}
}
catch (const std::exception&)
Expand All @@ -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<dtk::Settings>();
settings->set("TimeUnits", json);
}

TimeUnits TimeUnitsModel::getTimeUnits() const
Expand Down
6 changes: 3 additions & 3 deletions lib/toucanView/TimeUnitsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <dtk/ui/Settings.h>
#include <dtk/core/Context.h>
#include <dtk/core/ObservableValue.h>

#include <opentimelineio/version.h>
Expand All @@ -28,7 +28,7 @@ namespace toucan
class TimeUnitsModel : public std::enable_shared_from_this<TimeUnitsModel>
{
public:
TimeUnitsModel(const std::shared_ptr<dtk::Settings>&);
TimeUnitsModel(const std::shared_ptr<dtk::Context>&);

virtual ~TimeUnitsModel();

Expand All @@ -48,7 +48,7 @@ namespace toucan
OTIO_NS::RationalTime fromString(const std::string&, double rate) const;

private:
std::shared_ptr<dtk::Settings> _settings;
std::weak_ptr<dtk::Context> _context;
std::shared_ptr<dtk::ObservableValue<TimeUnits> > _timeUnits;
};
}
18 changes: 11 additions & 7 deletions lib/toucanView/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> actionNames =
{
"File/Open",
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -104,8 +110,6 @@ namespace toucan
});
_buttons["View/Frame"] = button;

dtk::Divider::create(context, dtk::Orientation::Horizontal, _layout);

_widgetUpdate();

_filesObserver = dtk::ListObserver<std::shared_ptr<File> >::create(
Expand Down
Loading