diff --git a/bin/toucan-filmstrip/App.cpp b/bin/toucan-filmstrip/App.cpp index fb19d48..7a9efeb 100644 --- a/bin/toucan-filmstrip/App.cpp +++ b/bin/toucan-filmstrip/App.cpp @@ -15,10 +15,10 @@ namespace toucan const std::shared_ptr& context, std::vector& argv) { - _cmdLine.input = ftk::CmdLineValueArg::create( + _cmdLine.input = ftk::CmdLineArg::create( "input", "Input .otio file."); - _cmdLine.output = ftk::CmdLineValueArg::create( + _cmdLine.output = ftk::CmdLineArg::create( "output", "Output image file."); diff --git a/bin/toucan-filmstrip/App.h b/bin/toucan-filmstrip/App.h index f3fac70..e009ec9 100644 --- a/bin/toucan-filmstrip/App.h +++ b/bin/toucan-filmstrip/App.h @@ -30,13 +30,13 @@ namespace toucan const std::shared_ptr&, std::vector&); - void run() override; + void run(); private: struct CmdLine { - std::shared_ptr > input; - std::shared_ptr > output; + std::shared_ptr > input; + std::shared_ptr > output; }; CmdLine _cmdLine; diff --git a/bin/toucan-filmstrip/main.cpp b/bin/toucan-filmstrip/main.cpp index 91c82c8..788482d 100644 --- a/bin/toucan-filmstrip/main.cpp +++ b/bin/toucan-filmstrip/main.cpp @@ -21,9 +21,11 @@ int main(int argc, char** argv) { auto context = ftk::Context::create(); auto app = App::create(context, args); - if (0 == app->getExit()) + if (!app->hasCmdLineHelp()) + { app->run(); - out = app->getExit(); + } + out = 0; } catch (const std::exception& e) { diff --git a/bin/toucan-render/App.cpp b/bin/toucan-render/App.cpp index 83f658e..563f9c8 100644 --- a/bin/toucan-render/App.cpp +++ b/bin/toucan-render/App.cpp @@ -47,10 +47,10 @@ namespace toucan const std::shared_ptr& context, std::vector& argv) { - _cmdLine.input = ftk::CmdLineValueArg::create( + _cmdLine.input = ftk::CmdLineArg::create( "input", "Input .otio file."); - _cmdLine.output = ftk::CmdLineValueArg::create( + _cmdLine.output = ftk::CmdLineArg::create( "output", "Output image or movie file. Use a dash ('-') to write raw frames or y4m to stdout."); @@ -64,37 +64,37 @@ namespace toucan { y4mList.push_back(spec.first); } - _cmdLine.videoCodec = ftk::CmdLineValueOption::create( + _cmdLine.videoCodec = ftk::CmdLineOption::create( std::vector{ "-vcodec" }, "Set the video codec.", "", "MJPEG", ftk::join(ffmpeg::getVideoCodecStrings(), ", ")); - _cmdLine.printStart = ftk::CmdLineFlagOption::create( + _cmdLine.printStart = ftk::CmdLineFlag::create( std::vector{ "-print_start" }, "Print the timeline start time and exit."); - _cmdLine.printDuration = ftk::CmdLineFlagOption::create( + _cmdLine.printDuration = ftk::CmdLineFlag::create( std::vector{ "-print_duration" }, "Print the timeline duration and exit."); - _cmdLine.printRate = ftk::CmdLineFlagOption::create( + _cmdLine.printRate = ftk::CmdLineFlag::create( std::vector{ "-print_rate" }, "Print the timeline frame rate and exit."); - _cmdLine.printSize = ftk::CmdLineFlagOption::create( + _cmdLine.printSize = ftk::CmdLineFlag::create( std::vector{ "-print_size" }, "Print the timeline image size."); - _cmdLine.raw = ftk::CmdLineValueOption::create( + _cmdLine.raw = ftk::CmdLineOption::create( std::vector{ "-raw" }, "Raw pixel format to send to stdout.", "", std::optional(), ftk::join(rawList, ", ")); - _cmdLine.y4m = ftk::CmdLineValueOption::create( + _cmdLine.y4m = ftk::CmdLineOption::create( std::vector{ "-y4m" }, "y4m format to send to stdout.", "", std::optional(), ftk::join(y4mList, ", ")); - _cmdLine.verbose = ftk::CmdLineFlagOption::create( + _cmdLine.verbose = ftk::CmdLineFlag::create( std::vector{ "-v" }, "Print verbose output."); diff --git a/bin/toucan-render/App.h b/bin/toucan-render/App.h index c73a206..5f46452 100644 --- a/bin/toucan-render/App.h +++ b/bin/toucan-render/App.h @@ -36,7 +36,7 @@ namespace toucan const std::shared_ptr&, std::vector&); - void run() override; + void run(); private: void _writeRawFrame(const OIIO::ImageBuf&); @@ -45,18 +45,18 @@ namespace toucan struct CmdLine { - std::shared_ptr > input; - std::shared_ptr > output; + std::shared_ptr > input; + std::shared_ptr > output; bool outputRaw = false; - std::shared_ptr > videoCodec; - std::shared_ptr printStart; - std::shared_ptr printDuration; - std::shared_ptr printRate; - std::shared_ptr printSize; - std::shared_ptr > raw; - std::shared_ptr > y4m; - std::shared_ptr verbose; + std::shared_ptr > videoCodec; + std::shared_ptr printStart; + std::shared_ptr printDuration; + std::shared_ptr printRate; + std::shared_ptr printSize; + std::shared_ptr > raw; + std::shared_ptr > y4m; + std::shared_ptr verbose; }; CmdLine _cmdLine; diff --git a/bin/toucan-render/main.cpp b/bin/toucan-render/main.cpp index 9d07b0c..788482d 100644 --- a/bin/toucan-render/main.cpp +++ b/bin/toucan-render/main.cpp @@ -21,11 +21,11 @@ int main(int argc, char** argv) { auto context = ftk::Context::create(); auto app = App::create(context, args); - if (0 == app->getExit()) + if (!app->hasCmdLineHelp()) { app->run(); } - out = app->getExit(); + out = 0; } catch (const std::exception& e) { diff --git a/bin/toucan-view/main.cpp b/bin/toucan-view/main.cpp index f891482..7bb48b3 100644 --- a/bin/toucan-view/main.cpp +++ b/bin/toucan-view/main.cpp @@ -14,8 +14,8 @@ FTK_MAIN() auto context = ftk::Context::create(); auto args = ftk::convert(argc, argv); auto app = toucan::App::create(context, args); - if (app->getExit() != 0) - return app->getExit(); + if (app->hasCmdLineHelp()) + return 0; app->run(); } catch (const std::exception& e) diff --git a/cmake/SuperBuild/Buildftk.cmake b/cmake/SuperBuild/Buildftk.cmake index e814ec9..a4e95f6 100644 --- a/cmake/SuperBuild/Buildftk.cmake +++ b/cmake/SuperBuild/Buildftk.cmake @@ -1,7 +1,7 @@ include(ExternalProject) set(ftk_GIT_REPOSITORY "https://github.com/grizzlypeak3d/feather-tk.git") -set(ftk_GIT_TAG "2de0861f19326dab562b189e2988a49304475dc3") +set(ftk_GIT_TAG "d673afdb2d4a29dbfd7c98d5eefc3324b5e90241") set(ftk_DEPS ZLIB nlohmann_json PNG Freetype lunasvg) diff --git a/lib/toucanResource/CMakeLists.txt b/lib/toucanResource/CMakeLists.txt index c4fdcbe..9eaeb53 100644 --- a/lib/toucanResource/CMakeLists.txt +++ b/lib/toucanResource/CMakeLists.txt @@ -16,10 +16,9 @@ target_link_libraries(toucanResource) set_target_properties(toucanResource PROPERTIES FOLDER lib) set_target_properties(toucanResource PROPERTIES PUBLIC_HEADER "${HEADERS}") -if(BUILD_SHARED_LIBS) - install( - TARGETS toucanResource - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -endif() +install( + TARGETS toucanResource + EXPORT toucanRenderTargets + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) diff --git a/lib/toucanView/App.cpp b/lib/toucanView/App.cpp index bec4e12..078bf31 100644 --- a/lib/toucanView/App.cpp +++ b/lib/toucanView/App.cpp @@ -26,7 +26,7 @@ namespace toucan const std::shared_ptr& context, std::vector& argv) { - _input = ftk::CmdLineValueArg::create( + _input = ftk::CmdLineArg::create( "input", "Input timeline.", true); @@ -36,27 +36,26 @@ namespace toucan argv, "toucan-view", "Toucan viewer", - { _input }); + { _input }, + {}, + ftk::AppFiles{ "toucan", "toucan-view" }); - _settings = ftk::Settings::create(context, ftk::getSettingsPath("toucan", "toucan-view.settings")); - - _timeUnitsModel = std::make_shared(context, _settings); + _timeUnitsModel = std::make_shared(context, getSettings()); _host = std::make_shared(context, getOpenFXPluginPaths(getExeName())); auto fileBrowserSystem = context->getSystem(); fileBrowserSystem->setNativeFileDialog(false); - _filesModel = std::make_shared(context, _settings, _host); - _globalViewModel = std::make_shared(context, _settings); - _windowModel = std::make_shared(context, _settings); + _filesModel = std::make_shared(context, getSettings(), _host); + _globalViewModel = std::make_shared(context, getSettings()); + _windowModel = std::make_shared(context, getSettings()); _window = MainWindow::create( context, std::dynamic_pointer_cast(shared_from_this()), "toucan-view", ftk::Size2I(1920, 1080)); - addWindow(_window); _window->show(); if (_input->hasValue()) @@ -77,11 +76,6 @@ namespace toucan return out; } - const std::shared_ptr& App::getSettings() const - { - return _settings; - } - const std::shared_ptr& App::getTimeUnitsModel() const { return _timeUnitsModel; diff --git a/lib/toucanView/App.h b/lib/toucanView/App.h index ba7406a..ce43b22 100644 --- a/lib/toucanView/App.h +++ b/lib/toucanView/App.h @@ -33,9 +33,6 @@ namespace toucan const std::shared_ptr&, std::vector&); - //! Get the settings. - const std::shared_ptr& getSettings() const; - //! Get the time units model. const std::shared_ptr& getTimeUnitsModel() const; @@ -55,8 +52,7 @@ namespace toucan void open(const std::filesystem::path&); private: - std::shared_ptr > _input; - std::shared_ptr _settings; + std::shared_ptr > _input; std::shared_ptr _timeUnitsModel; std::shared_ptr _host; std::shared_ptr _filesModel; diff --git a/lib/toucanView/AudioClipItem.cpp b/lib/toucanView/AudioClipItem.cpp index 5402dce..a57d962 100644 --- a/lib/toucanView/AudioClipItem.cpp +++ b/lib/toucanView/AudioClipItem.cpp @@ -125,7 +125,11 @@ namespace toucan _size.displayScale = event.displayScale; _size.border = event.style->getSizeRole(ftk::SizeRole::Border, event.displayScale); } - _setSizeHint(_layout->getSizeHint()); + } + + ftk::Size2I AudioClipItem::getSizeHint() const + { + return _layout->getSizeHint(); } void AudioClipItem::drawEvent( diff --git a/lib/toucanView/AudioClipItem.h b/lib/toucanView/AudioClipItem.h index 9ebfc85..222a04f 100644 --- a/lib/toucanView/AudioClipItem.h +++ b/lib/toucanView/AudioClipItem.h @@ -39,6 +39,7 @@ namespace toucan void setGeometry(const ftk::Box2I&) override; ftk::Box2I getChildrenClipRect() const override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; diff --git a/lib/toucanView/BackgroundTool.cpp b/lib/toucanView/BackgroundTool.cpp index 4539335..fc8b4a0 100644 --- a/lib/toucanView/BackgroundTool.cpp +++ b/lib/toucanView/BackgroundTool.cpp @@ -97,7 +97,7 @@ namespace toucan } }); - _optionsObserver = ftk::ValueObserver::create( + _optionsObserver = ftk::Observer::create( _model->observeOptions(), [this](const GlobalViewOptions& value) { @@ -125,10 +125,9 @@ namespace toucan _scrollWidget->setGeometry(value); } - void BackgroundTool::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I BackgroundTool::getSizeHint() const { - IToolWidget::sizeHintEvent(event); - _setSizeHint(_scrollWidget->getSizeHint()); + return _scrollWidget->getSizeHint(); } void BackgroundTool::_widgetUpdate() diff --git a/lib/toucanView/BackgroundTool.h b/lib/toucanView/BackgroundTool.h index c93c31f..e1c6548 100644 --- a/lib/toucanView/BackgroundTool.h +++ b/lib/toucanView/BackgroundTool.h @@ -36,7 +36,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _widgetUpdate(); @@ -52,7 +52,7 @@ namespace toucan std::shared_ptr _checkersColor1Widget; std::shared_ptr _checkersSizeSlider; - std::shared_ptr > _optionsObserver; + std::shared_ptr > _optionsObserver; }; } diff --git a/lib/toucanView/CompareMenu.cpp b/lib/toucanView/CompareMenu.cpp index ae5c9d3..87a1122 100644 --- a/lib/toucanView/CompareMenu.cpp +++ b/lib/toucanView/CompareMenu.cpp @@ -24,8 +24,7 @@ namespace toucan _actions["Compare/A"] = ftk::Action::create( "A", - ftk::Key::A, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::A, ftk::KeyModifier::Shift), [this](bool) { CompareOptions options = _filesModel->getCompareOptions(); @@ -36,8 +35,7 @@ namespace toucan _actions["Compare/B"] = ftk::Action::create( "B", - ftk::Key::B, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::B, ftk::KeyModifier::Shift), [this](bool) { CompareOptions options = _filesModel->getCompareOptions(); @@ -48,8 +46,7 @@ namespace toucan _actions["Compare/Split"] = ftk::Action::create( "Split", - ftk::Key::S, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::S, ftk::KeyModifier::Shift), [this](bool) { CompareOptions options = _filesModel->getCompareOptions(); @@ -60,8 +57,7 @@ namespace toucan _actions["Compare/Overlay"] = ftk::Action::create( "Overlay", - ftk::Key::E, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::E, ftk::KeyModifier::Shift), [this](bool) { CompareOptions options = _filesModel->getCompareOptions(); @@ -72,8 +68,7 @@ namespace toucan _actions["Compare/Horizontal"] = ftk::Action::create( "Horizontal", - ftk::Key::H, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::H, ftk::KeyModifier::Shift), [this](bool) { CompareOptions options = _filesModel->getCompareOptions(); @@ -84,8 +79,7 @@ namespace toucan _actions["Compare/Vertical"] = ftk::Action::create( "Vertical", - ftk::Key::V, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::V, ftk::KeyModifier::Shift), [this](bool) { CompareOptions options = _filesModel->getCompareOptions(); @@ -94,7 +88,7 @@ namespace toucan }); addAction(_actions["Compare/Vertical"]); - _modeObserver = ftk::ValueObserver::create( + _modeObserver = ftk::Observer::create( app->getFilesModel()->observeCompareOptions(), [this](const CompareOptions& value) { @@ -126,7 +120,7 @@ namespace toucan } }); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -134,7 +128,7 @@ namespace toucan _menuUpdate(); }); - _bIndexObserver = ftk::ValueObserver::create( + _bIndexObserver = ftk::Observer::create( _filesModel->observeBIndex(), [this](int index) { diff --git a/lib/toucanView/CompareMenu.h b/lib/toucanView/CompareMenu.h index 9eb5d2c..2f4e96f 100644 --- a/lib/toucanView/CompareMenu.h +++ b/lib/toucanView/CompareMenu.h @@ -45,8 +45,8 @@ namespace toucan std::vector > _bFileActions; std::shared_ptr > > _filesObserver; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _bIndexObserver; - std::shared_ptr > _modeObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _bIndexObserver; + std::shared_ptr > _modeObserver; }; } diff --git a/lib/toucanView/CompareTool.cpp b/lib/toucanView/CompareTool.cpp index c1e26a7..33582f0 100644 --- a/lib/toucanView/CompareTool.cpp +++ b/lib/toucanView/CompareTool.cpp @@ -78,10 +78,9 @@ namespace toucan _layout->setGeometry(value); } - void CompareWidget::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I CompareWidget::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void CompareTool::_init( @@ -164,7 +163,7 @@ namespace toucan _indexUpdate(); }); - _fileIndexObserver = ftk::ValueObserver::create( + _fileIndexObserver = ftk::Observer::create( _filesModel->observeCurrentIndex(), [this](int value) { @@ -172,7 +171,7 @@ namespace toucan _indexUpdate(); }); - _bIndexObserver = ftk::ValueObserver::create( + _bIndexObserver = ftk::Observer::create( _filesModel->observeBIndex(), [this](int value) { @@ -180,7 +179,7 @@ namespace toucan _indexUpdate(); }); - _compareOptionsObserver = ftk::ValueObserver::create( + _compareOptionsObserver = ftk::Observer::create( _filesModel->observeCompareOptions(), [this](const CompareOptions& value) { @@ -209,10 +208,9 @@ namespace toucan _layout->setGeometry(value); } - void CompareTool::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I CompareTool::getSizeHint() const { - IToolWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void CompareTool::_widgetUpdate() diff --git a/lib/toucanView/CompareTool.h b/lib/toucanView/CompareTool.h index b5c9185..db4f880 100644 --- a/lib/toucanView/CompareTool.h +++ b/lib/toucanView/CompareTool.h @@ -43,7 +43,7 @@ namespace toucan void setBCallback(const std::function&); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: bool _current = false; @@ -73,7 +73,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _widgetUpdate(); @@ -94,9 +94,9 @@ namespace toucan std::shared_ptr _resizeCheckBox; std::shared_ptr > > _filesObserver; - std::shared_ptr > _fileIndexObserver; - std::shared_ptr > _bIndexObserver; - std::shared_ptr > _compareOptionsObserver; + std::shared_ptr > _fileIndexObserver; + std::shared_ptr > _bIndexObserver; + std::shared_ptr > _compareOptionsObserver; }; } diff --git a/lib/toucanView/DetailsTool.cpp b/lib/toucanView/DetailsTool.cpp index 71737ca..1a1b442 100644 --- a/lib/toucanView/DetailsTool.cpp +++ b/lib/toucanView/DetailsTool.cpp @@ -71,7 +71,7 @@ namespace toucan }); } - _timeUnitsObserver = ftk::ValueObserver::create( + _timeUnitsObserver = ftk::Observer::create( app->getTimeUnitsModel()->observeTimeUnits(), [this](TimeUnits value) { @@ -115,10 +115,9 @@ namespace toucan _bellows->setGeometry(value); } - void DetailsWidget::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I DetailsWidget::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_bellows->isVisible(false) ? _bellows->getSizeHint() : ftk::Size2I()); + return _bellows->isVisible(false) ? _bellows->getSizeHint() : ftk::Size2I(); } void DetailsWidget::_textUpdate() @@ -234,6 +233,9 @@ namespace toucan _scrollLayout->setSpacingRole(ftk::SizeRole::None); _scrollWidget->setWidget(_scrollLayout); + _nothingLabel = ftk::Label::create(context, "Nothing selected", _scrollLayout); + _nothingLabel->setMarginRole(ftk::SizeRole::Margin); + ftk::Divider::create(context, ftk::Orientation::Vertical, _layout); _bottomLayout = ftk::HorizontalLayout::create(context, _layout); @@ -280,7 +282,7 @@ namespace toucan } }); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -310,6 +312,7 @@ namespace toucan } _openButton->setEnabled(!_widgets.empty()); _closeButton->setEnabled(!_widgets.empty()); + _nothingLabel->setVisible(_widgets.empty()); }); } else @@ -321,6 +324,7 @@ namespace toucan _widgets.clear(); _openButton->setEnabled(false); _closeButton->setEnabled(false); + _nothingLabel->setVisible(true); _selectionObserver.reset(); } }); @@ -345,9 +349,8 @@ namespace toucan _layout->setGeometry(value); } - void DetailsTool::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I DetailsTool::getSizeHint() const { - IToolWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } } diff --git a/lib/toucanView/DetailsTool.h b/lib/toucanView/DetailsTool.h index c52bc7a..d4704c9 100644 --- a/lib/toucanView/DetailsTool.h +++ b/lib/toucanView/DetailsTool.h @@ -55,7 +55,7 @@ namespace toucan void setSearch(const std::string&); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _textUpdate(); @@ -74,7 +74,7 @@ namespace toucan std::shared_ptr _inOutButton; std::vector, std::shared_ptr > > _labels; - std::shared_ptr > _timeUnitsObserver; + std::shared_ptr > _timeUnitsObserver; }; //! Details tool. @@ -96,19 +96,20 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _layout; std::shared_ptr _scrollWidget; std::shared_ptr _scrollLayout; + std::shared_ptr _nothingLabel; std::vector > _widgets; std::shared_ptr _bottomLayout; std::shared_ptr _searchBox; std::shared_ptr _openButton; std::shared_ptr _closeButton; - std::shared_ptr > > _fileObserver; + std::shared_ptr > > _fileObserver; std::shared_ptr > _selectionObserver; }; } diff --git a/lib/toucanView/ExportTool.cpp b/lib/toucanView/ExportTool.cpp index 51090ce..402fa7a 100644 --- a/lib/toucanView/ExportTool.cpp +++ b/lib/toucanView/ExportTool.cpp @@ -46,7 +46,7 @@ namespace toucan _timer = ftk::Timer::create(context); _timer->setRepeating(true); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -60,10 +60,10 @@ namespace toucan ExportWidget::~ExportWidget() { nlohmann::json json; - json["Dir"] = _dirEdit->getPath().string(); + json["Dir"] = _dirEdit->getPath().get(); json["SizeChoice"] = _sizeComboBox->getCurrentIndex(); json["CustomSize"] = { _widthEdit->getValue(), _heightEdit->getValue() }; - json["CurrentTab"] = _tabWidget->getCurrentTab(); + json["CurrentTab"] = _tabWidget->getCurrent(); json["ImageBaseName"] = _imageBaseNameEdit->getText(); json["ImagePadding"] = _imagePaddingEdit->getValue(); json["ImageExtension"] = _imageExtensionEdit->getText(); @@ -91,10 +91,9 @@ namespace toucan _layout->setGeometry(value); } - void ExportWidget::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I ExportWidget::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void ExportWidget::_initSettings( @@ -180,7 +179,7 @@ namespace toucan auto label = ftk::Label::create(context, "Directory:", gridLayout); gridLayout->setGridPos(label, 0, 0); _dirEdit = ftk::FileEdit::create(context, gridLayout); - _dirEdit->setPath(settingsValues.dir); + _dirEdit->setPath(ftk::Path(settingsValues.dir)); _dirEdit->setHStretch(ftk::Stretch::Expanding); gridLayout->setGridPos(_dirEdit, 0, 1); @@ -300,7 +299,7 @@ namespace toucan auto vLayout = ftk::VerticalLayout::create(context); vLayout->setMarginRole(ftk::SizeRole::Margin); _tabWidget->addTab("Movie", vLayout); - _tabWidget->setCurrentTab(settingsValues.currentTab); + _tabWidget->setCurrent(settingsValues.currentTab); auto gridLayout = ftk::GridLayout::create(context, vLayout); @@ -392,7 +391,7 @@ namespace toucan _timeRange = _file->getPlaybackModel()->getInOutRange(); const std::string baseName = _movieBaseNameEdit->getText(); const std::string extension = _movieExtensionEdit->getText(); - const std::filesystem::path path = _dirEdit->getPath() / (baseName + extension); + const std::filesystem::path path = std::filesystem::path(_dirEdit->getPath().get()) / (baseName + extension); ffmpeg::VideoCodec videoCodec = ffmpeg::VideoCodec::First; ffmpeg::fromString(_movieCodecs[_movieCodecComboBox->getCurrentIndex()], videoCodec); _ffWrite = std::make_shared( @@ -457,7 +456,7 @@ namespace toucan else { const std::string fileName = getSequenceFrame( - _dirEdit->getPath().string(), + _dirEdit->getPath().get(), _imageBaseNameEdit->getText(), _time.to_frames(), _imagePaddingEdit->getValue(), @@ -507,7 +506,7 @@ namespace toucan _heightEdit->setVisible(index != 0); _imageFilenameLabel->setText(getSequenceFrame( - _dirEdit->getPath().string(), + _dirEdit->getPath().get(), _imageBaseNameEdit->getText(), 0, _imagePaddingEdit->getValue(), @@ -551,9 +550,8 @@ namespace toucan _scrollWidget->setGeometry(value); } - void ExportTool::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I ExportTool::getSizeHint() const { - IToolWidget::sizeHintEvent(event); - _setSizeHint(_scrollWidget->getSizeHint()); + return _scrollWidget->getSizeHint(); } } diff --git a/lib/toucanView/ExportTool.h b/lib/toucanView/ExportTool.h index 1f9a737..ec043ff 100644 --- a/lib/toucanView/ExportTool.h +++ b/lib/toucanView/ExportTool.h @@ -46,7 +46,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: struct SettingsValues @@ -112,7 +112,7 @@ namespace toucan std::shared_ptr _timer; - std::shared_ptr > > _fileObserver; + std::shared_ptr > > _fileObserver; }; //! Export tool. @@ -134,7 +134,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _scrollWidget; diff --git a/lib/toucanView/File.cpp b/lib/toucanView/File.cpp index 8410f96..e828f5a 100644 --- a/lib/toucanView/File.cpp +++ b/lib/toucanView/File.cpp @@ -31,17 +31,17 @@ namespace toucan _selectionModel = std::make_shared(); - _currentImage = ftk::ObservableValue >::create(); + _currentImage = ftk::Observable >::create(); - _rootNode = ftk::ObservableValue >::create(); - _currentNode = ftk::ObservableValue >::create(); + _rootNode = ftk::Observable >::create(); + _currentNode = ftk::Observable >::create(); _graph = std::make_shared( context, path.parent_path(), _timelineWrapper); - _currentTimeObserver = ftk::ValueObserver::create( + _currentTimeObserver = ftk::Observer::create( _playbackModel->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { @@ -101,17 +101,17 @@ namespace toucan return _graph->getImageDataType(); } - std::shared_ptr > > File::observeCurrentImage() const + std::shared_ptr > > File::observeCurrentImage() const { return _currentImage; } - std::shared_ptr > > File::observeRootNode() const + std::shared_ptr > > File::observeRootNode() const { return _rootNode; } - std::shared_ptr > > File::observeCurrentNode() const + std::shared_ptr > > File::observeCurrentNode() const { return _currentNode; } diff --git a/lib/toucanView/File.h b/lib/toucanView/File.h index c8c1613..45a28f1 100644 --- a/lib/toucanView/File.h +++ b/lib/toucanView/File.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include @@ -58,13 +58,13 @@ namespace toucan const std::string& getImageDataType() const; //! Observe the current image. - std::shared_ptr > > observeCurrentImage() const; + std::shared_ptr > > observeCurrentImage() const; //! Observe the root node. - std::shared_ptr > > observeRootNode() const; + std::shared_ptr > > observeRootNode() const; //! Observe the current node. - std::shared_ptr > > observeCurrentNode() const; + std::shared_ptr > > observeCurrentNode() const; //! Set the current node. void setCurrentNode(const std::shared_ptr&); @@ -78,14 +78,14 @@ namespace toucan std::shared_ptr _playbackModel; std::shared_ptr _viewModel; std::shared_ptr _selectionModel; - std::shared_ptr > > _currentImage; + std::shared_ptr > > _currentImage; OTIO_NS::RationalTime _currentTime; std::shared_ptr _graph; - std::shared_ptr > > _rootNode; - std::shared_ptr > > _currentNode; + std::shared_ptr > > _rootNode; + std::shared_ptr > > _currentNode; OIIO::ImageBuf _imageBuf; - std::shared_ptr > _currentTimeObserver; + std::shared_ptr > _currentTimeObserver; }; } diff --git a/lib/toucanView/FileMenu.cpp b/lib/toucanView/FileMenu.cpp index 9cd1d7b..c6eebc3 100644 --- a/lib/toucanView/FileMenu.cpp +++ b/lib/toucanView/FileMenu.cpp @@ -32,8 +32,7 @@ namespace toucan _actions["File/Open"] = ftk::Action::create( "Open", "FileOpen", - ftk::Key::O, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::O, ftk::commandKeyModifier), [this, appWeak, windowWeak] { auto context = getContext(); @@ -55,16 +54,18 @@ namespace toucan extensions.push_back(".otio"); extensions.push_back(".otiod"); extensions.push_back(".otioz"); - fileBrowserSystem->getModel()->setExtensions(extensions); fileBrowserSystem->setRecentFilesModel(_filesModel->getRecentFilesModel()); + ftk::FileBrowserOpenOptions options; + options.extensions = extensions; fileBrowserSystem->open( windowWeak.lock(), - [appWeak](const std::filesystem::path& path) + [appWeak](const ftk::Path& path) { - appWeak.lock()->open(path); - }); + appWeak.lock()->open(path.get()); + }, + options); }); _actions["File/Open"]->setTooltip("Open a file"); addAction(_actions["File/Open"]); @@ -72,8 +73,7 @@ namespace toucan _actions["File/Close"] = ftk::Action::create( "Close", "FileClose", - ftk::Key::E, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::E, ftk::commandKeyModifier), [this] { _filesModel->close(); }); _actions["File/Close"]->setTooltip("Close the current file"); addAction(_actions["File/Close"]); @@ -81,8 +81,7 @@ namespace toucan _actions["File/CloseAll"] = ftk::Action::create( "Close All", "FileCloseAll", - ftk::Key::E, - static_cast(ftk::KeyModifier::Shift) | static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::E, ftk::KeyModifier::Shift, ftk::commandKeyModifier), [this] { _filesModel->closeAll(); }); _actions["File/CloseAll"]->setTooltip("Close all files"); addAction(_actions["File/CloseAll"]); @@ -97,16 +96,14 @@ namespace toucan _actions["File/Next"] = ftk::Action::create( "Next", - ftk::Key::PageDown, - 0, + ftk::KeyShortcut(ftk::Key::PageDown), [this] { _filesModel->next(); }); _actions["File/Next"]->setTooltip("Switch to the next file"); addAction(_actions["File/Next"]); _actions["File/Prev"] = ftk::Action::create( "Previous", - ftk::Key::PageUp, - 0, + ftk::KeyShortcut(ftk::Key::PageUp), [this] { _filesModel->prev(); }); _actions["File/Prev"]->setTooltip("Switch to the previous file"); addAction(_actions["File/Prev"]); @@ -115,8 +112,7 @@ namespace toucan _actions["File/Exit"] = ftk::Action::create( "Exit", - ftk::Key::Q, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::Q, ftk::commandKeyModifier), [appWeak] { if (auto app = appWeak.lock()) @@ -146,7 +142,7 @@ namespace toucan } }); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( _filesModel->observeCurrent(), [this](const std::shared_ptr& file) { @@ -154,7 +150,7 @@ namespace toucan _menuUpdate(); }); - _fileIndexObserver = ftk::ValueObserver::create( + _fileIndexObserver = ftk::Observer::create( _filesModel->observeCurrentIndex(), [this](int index) { @@ -164,9 +160,9 @@ namespace toucan } }); - _recentFilesObserver = ftk::ListObserver::create( + _recentFilesObserver = ftk::ListObserver::create( _filesModel->getRecentFilesModel()->observeRecent(), - [this, appWeak](const std::vector& files) + [this, appWeak](const std::vector& files) { _menus["RecentFiles"]->clear(); _recentFilesActions.clear(); @@ -174,10 +170,10 @@ namespace toucan { auto file = *i; auto action = ftk::Action::create( - file.string(), + file.get(), [this, appWeak, file] { - appWeak.lock()->open(file); + appWeak.lock()->open(file.get()); close(); }); _menus["RecentFiles"]->addAction(action); diff --git a/lib/toucanView/FileMenu.h b/lib/toucanView/FileMenu.h index 14cf2f6..da0a768 100644 --- a/lib/toucanView/FileMenu.h +++ b/lib/toucanView/FileMenu.h @@ -4,8 +4,10 @@ #pragma once #include + +#include #include -#include +#include #include #include @@ -52,9 +54,9 @@ namespace toucan std::vector > _recentFilesActions; std::shared_ptr > > _filesObserver; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _fileIndexObserver; - std::shared_ptr > _recentFilesObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _fileIndexObserver; + std::shared_ptr > _recentFilesObserver; }; } diff --git a/lib/toucanView/FileTab.cpp b/lib/toucanView/FileTab.cpp index c19ee1f..2d33c1d 100644 --- a/lib/toucanView/FileTab.cpp +++ b/lib/toucanView/FileTab.cpp @@ -22,7 +22,7 @@ namespace toucan _hudWidget = HUDWidget::create(context, app, file, shared_from_this()); - _viewOptionsObserver = ftk::ValueObserver::create( + _viewOptionsObserver = ftk::Observer::create( app->getGlobalViewModel()->observeOptions(), [this](const GlobalViewOptions& value) { @@ -51,9 +51,8 @@ namespace toucan _hudWidget->setGeometry(value); } - void FileTab::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I FileTab::getSizeHint() const { - ftk::IWidget::sizeHintEvent(event); - _setSizeHint(_viewport->getSizeHint()); + return _viewport->getSizeHint(); } } diff --git a/lib/toucanView/FileTab.h b/lib/toucanView/FileTab.h index 1630833..9dcbf2e 100644 --- a/lib/toucanView/FileTab.h +++ b/lib/toucanView/FileTab.h @@ -35,12 +35,12 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _viewport; std::shared_ptr _hudWidget; - std::shared_ptr > _viewOptionsObserver; + std::shared_ptr > _viewOptionsObserver; }; } diff --git a/lib/toucanView/FileToolBar.cpp b/lib/toucanView/FileToolBar.cpp index b31d415..4e11f41 100644 --- a/lib/toucanView/FileToolBar.cpp +++ b/lib/toucanView/FileToolBar.cpp @@ -65,10 +65,9 @@ namespace toucan _layout->setGeometry(value); } - void FileToolBar::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I FileToolBar::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void FileToolBar::_widgetUpdate() diff --git a/lib/toucanView/FileToolBar.h b/lib/toucanView/FileToolBar.h index 6eb0fe6..becaa30 100644 --- a/lib/toucanView/FileToolBar.h +++ b/lib/toucanView/FileToolBar.h @@ -34,7 +34,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _widgetUpdate(); diff --git a/lib/toucanView/FilesModel.cpp b/lib/toucanView/FilesModel.cpp index 4ba00f1..ff234c8 100644 --- a/lib/toucanView/FilesModel.cpp +++ b/lib/toucanView/FilesModel.cpp @@ -47,7 +47,7 @@ namespace toucan { CompareOptions compareOptions; size_t recentMax = 10; - std::vector recent; + std::vector recent; if (_settings) { try @@ -57,8 +57,7 @@ namespace toucan auto i = json.find("CompareMode"); if (i != json.end() && i->is_string()) { - std::stringstream ss(i->get()); - ss >> compareOptions.mode; + from_string(i->get(), compareOptions.mode); } i = json.find("StartTime"); if (i != json.end() && i->is_boolean()) @@ -82,7 +81,7 @@ namespace toucan { if (j->is_string()) { - recent.push_back(std::filesystem::u8path(j->get())); + recent.push_back(ftk::Path(j->get())); } } } @@ -92,13 +91,13 @@ namespace toucan } _files = ftk::ObservableList< std::shared_ptr >::create(); - _add = ftk::ObservableValue::create(-1); - _remove = ftk::ObservableValue::create(-1); - _current = ftk::ObservableValue< std::shared_ptr >::create(nullptr); - _currentIndex = ftk::ObservableValue::create(-1); - _bFile = ftk::ObservableValue >::create(); - _bIndex = ftk::ObservableValue::create(-1); - _compareOptions = ftk::ObservableValue::create(compareOptions); + _add = ftk::Observable::create(-1); + _remove = ftk::Observable::create(-1); + _current = ftk::Observable< std::shared_ptr >::create(nullptr); + _currentIndex = ftk::Observable::create(-1); + _bFile = ftk::Observable >::create(); + _bIndex = ftk::Observable::create(-1); + _compareOptions = ftk::Observable::create(compareOptions); _recentFilesModel = ftk::RecentFilesModel::create(context); _recentFilesModel->setRecentMax(recentMax); _recentFilesModel->setRecent(recent); @@ -120,7 +119,7 @@ namespace toucan nlohmann::json json2; for (const auto& path : _recentFilesModel->getRecent()) { - json2.push_back(path.u8string()); + json2.push_back(path.get()); } json["Recent"] = json2; _settings->set("/FilesModel", json); @@ -142,7 +141,7 @@ namespace toucan _current->setIfChanged(files[index]); _currentIndex->setIfChanged(index); - _recentFilesModel->addRecent(path); + _recentFilesModel->addRecent(ftk::Path(path.u8string())); _fileUpdate(); } @@ -203,22 +202,22 @@ namespace toucan return _files; } - std::shared_ptr > FilesModel::observeAdd() const + std::shared_ptr > FilesModel::observeAdd() const { return _add; } - std::shared_ptr > FilesModel::observeRemove() const + std::shared_ptr > FilesModel::observeRemove() const { return _remove; } - std::shared_ptr > > FilesModel::observeCurrent() const + std::shared_ptr > > FilesModel::observeCurrent() const { return _current; } - std::shared_ptr > FilesModel::observeCurrentIndex() const + std::shared_ptr > FilesModel::observeCurrentIndex() const { return _currentIndex; } @@ -265,7 +264,7 @@ namespace toucan return _bFile->get(); } - std::shared_ptr > > FilesModel::observeBFile() const + std::shared_ptr > > FilesModel::observeBFile() const { return _bFile; } @@ -275,7 +274,7 @@ namespace toucan return _bIndex->get(); } - std::shared_ptr > FilesModel::observeBIndex() const + std::shared_ptr > FilesModel::observeBIndex() const { return _bIndex; } @@ -305,7 +304,7 @@ namespace toucan return _compareOptions->get(); } - std::shared_ptr > FilesModel::observeCompareOptions() const + std::shared_ptr > FilesModel::observeCompareOptions() const { return _compareOptions; } @@ -361,7 +360,7 @@ namespace toucan { if (auto file = _current->get()) { - _currentTimeObserver = ftk::ValueObserver::create( + _currentTimeObserver = ftk::Observer::create( file->getPlaybackModel()->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { diff --git a/lib/toucanView/FilesModel.h b/lib/toucanView/FilesModel.h index b847323..a35398e 100644 --- a/lib/toucanView/FilesModel.h +++ b/lib/toucanView/FilesModel.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace toucan { @@ -30,7 +30,7 @@ namespace toucan Count, First = A }; - FTK_ENUM(CompareMode); + FTK_ENUM(, CompareMode); //! Compare options. struct CompareOptions @@ -70,16 +70,16 @@ namespace toucan std::shared_ptr > > observeFiles() const; //! Observe when a file is added. - std::shared_ptr > observeAdd() const; + std::shared_ptr > observeAdd() const; //! Observe when a file is removed. - std::shared_ptr > observeRemove() const; + std::shared_ptr > observeRemove() const; //! Observe the current file. - std::shared_ptr > > observeCurrent() const; + std::shared_ptr > > observeCurrent() const; //! Observe the current file index. - std::shared_ptr > observeCurrentIndex() const; + std::shared_ptr > observeCurrentIndex() const; //! Set the current file index. void setCurrentIndex(int); @@ -94,13 +94,13 @@ namespace toucan const std::shared_ptr& getBFile() const; //! Observe the B file. - std::shared_ptr > > observeBFile() const; + std::shared_ptr > > observeBFile() const; //! Get the B file index. int getBIndex() const; //! Observe the B file index. - std::shared_ptr > observeBIndex() const; + std::shared_ptr > observeBIndex() const; //! Set the B file index. void setBIndex(int); @@ -109,7 +109,7 @@ namespace toucan const CompareOptions& getCompareOptions() const; //! Observe the compare options. - std::shared_ptr > observeCompareOptions() const; + std::shared_ptr > observeCompareOptions() const; //! Set the compare options. void setCompareOptions(const CompareOptions&); @@ -127,16 +127,16 @@ namespace toucan std::shared_ptr _settings; std::shared_ptr _host; std::shared_ptr > > _files; - std::shared_ptr > _add; - std::shared_ptr > _remove; - std::shared_ptr > > _current; - std::shared_ptr > _currentIndex; - std::shared_ptr > > _bFile; - std::shared_ptr > _bIndex; - std::shared_ptr > _compareOptions; + std::shared_ptr > _add; + std::shared_ptr > _remove; + std::shared_ptr > > _current; + std::shared_ptr > _currentIndex; + std::shared_ptr > > _bFile; + std::shared_ptr > _bIndex; + std::shared_ptr > _compareOptions; std::shared_ptr _recentFilesModel; - std::shared_ptr > _currentTimeObserver; + std::shared_ptr > _currentTimeObserver; }; } diff --git a/lib/toucanView/GapItem.cpp b/lib/toucanView/GapItem.cpp index 424cc57..d6f54a6 100644 --- a/lib/toucanView/GapItem.cpp +++ b/lib/toucanView/GapItem.cpp @@ -116,7 +116,11 @@ namespace toucan _size.displayScale = event.displayScale; _size.border = event.style->getSizeRole(ftk::SizeRole::Border, event.displayScale); } - _setSizeHint(_layout->getSizeHint()); + } + + ftk::Size2I GapItem::getSizeHint() const + { + return _layout->getSizeHint(); } void GapItem::drawEvent( diff --git a/lib/toucanView/GapItem.h b/lib/toucanView/GapItem.h index b20671e..c72516c 100644 --- a/lib/toucanView/GapItem.h +++ b/lib/toucanView/GapItem.h @@ -35,6 +35,7 @@ namespace toucan void setGeometry(const ftk::Box2I&) override; ftk::Box2I getChildrenClipRect() const override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; diff --git a/lib/toucanView/GraphTool.cpp b/lib/toucanView/GraphTool.cpp index e1717ba..3cef771 100644 --- a/lib/toucanView/GraphTool.cpp +++ b/lib/toucanView/GraphTool.cpp @@ -36,14 +36,14 @@ namespace toucan } }); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { _file = file; if (file) { - _rootNodeObserver = ftk::ValueObserver >::create( + _rootNodeObserver = ftk::Observer >::create( file->observeRootNode(), [this](const std::shared_ptr& node) { @@ -52,7 +52,7 @@ namespace toucan _graphUpdate(); }); - _currentNodeObserver = ftk::ValueObserver >::create( + _currentNodeObserver = ftk::Observer >::create( file->observeCurrentNode(), [this](const std::shared_ptr& node) { @@ -105,7 +105,11 @@ namespace toucan _size.displayScale = event.displayScale; _size.lineWidth = 2 * event.displayScale; } - _setSizeHint(_layout->getSizeHint()); + } + + ftk::Size2I GraphWidget::getSizeHint() const + { + return _layout->getSizeHint(); } void GraphWidget::drawEvent(const ftk::Box2I& drawRect, const ftk::DrawEvent& event) @@ -253,9 +257,8 @@ namespace toucan _scrollWidget->setGeometry(value); } - void GraphTool::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I GraphTool::getSizeHint() const { - IToolWidget::sizeHintEvent(event); - _setSizeHint(_scrollWidget->getSizeHint()); + return _scrollWidget->getSizeHint(); } } diff --git a/lib/toucanView/GraphTool.h b/lib/toucanView/GraphTool.h index 5f62183..ea40e26 100644 --- a/lib/toucanView/GraphTool.h +++ b/lib/toucanView/GraphTool.h @@ -35,6 +35,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; @@ -74,9 +75,9 @@ namespace toucan }; SizeData _size; - std::shared_ptr > > _fileObserver; - std::shared_ptr > > _rootNodeObserver; - std::shared_ptr > > _currentNodeObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > > _rootNodeObserver; + std::shared_ptr > > _currentNodeObserver; }; //! Image graph tool. @@ -98,7 +99,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _scrollWidget; diff --git a/lib/toucanView/HUDWidget.cpp b/lib/toucanView/HUDWidget.cpp index f882be0..8bd0ac5 100644 --- a/lib/toucanView/HUDWidget.cpp +++ b/lib/toucanView/HUDWidget.cpp @@ -32,7 +32,7 @@ namespace toucan context, file->getPath().filename().string(), hLayout); - _labels["Path"]->setFontRole(ftk::FontRole::Mono); + _labels["Path"]->setFont(ftk::FontType::Mono); _labels["Path"]->setMarginRole(ftk::SizeRole::MarginInside); _labels["Path"]->setBackgroundRole(ftk::ColorRole::Overlay); @@ -48,7 +48,7 @@ namespace toucan arg(file->getImageChannels()). arg(file->getImageDataType()), hLayout); - _labels["Image"]->setFontRole(ftk::FontRole::Mono); + _labels["Image"]->setFont(ftk::FontType::Mono); _labels["Image"]->setMarginRole(ftk::SizeRole::MarginInside); _labels["Image"]->setBackgroundRole(ftk::ColorRole::Overlay); @@ -62,11 +62,11 @@ namespace toucan spacer->setHStretch(ftk::Stretch::Expanding); _labels["Time"] = ftk::Label::create(context, hLayout); - _labels["Time"]->setFontRole(ftk::FontRole::Mono); + _labels["Time"]->setFont(ftk::FontType::Mono); _labels["Time"]->setMarginRole(ftk::SizeRole::MarginInside); _labels["Time"]->setBackgroundRole(ftk::ColorRole::Overlay); - _currentTimeObserver = ftk::ValueObserver::create( + _currentTimeObserver = ftk::Observer::create( file->getPlaybackModel()->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { @@ -74,7 +74,7 @@ namespace toucan _widgetUpdate(); }); - _timeRangeObserver = ftk::ValueObserver::create( + _timeRangeObserver = ftk::Observer::create( file->getPlaybackModel()->observeTimeRange(), [this](const OTIO_NS::TimeRange& value) { diff --git a/lib/toucanView/HUDWidget.h b/lib/toucanView/HUDWidget.h index 8634eaf..d5fb85a 100644 --- a/lib/toucanView/HUDWidget.h +++ b/lib/toucanView/HUDWidget.h @@ -45,8 +45,8 @@ namespace toucan std::shared_ptr _layout; std::map > _labels; - std::shared_ptr > _currentTimeObserver; - std::shared_ptr > _timeRangeObserver; + std::shared_ptr > _currentTimeObserver; + std::shared_ptr > _timeRangeObserver; }; } diff --git a/lib/toucanView/IItem.cpp b/lib/toucanView/IItem.cpp index e514212..6ed39ba 100644 --- a/lib/toucanView/IItem.cpp +++ b/lib/toucanView/IItem.cpp @@ -23,7 +23,7 @@ namespace toucan _file = data.file; _object = object; - _timeUnitsObserver = ftk::ValueObserver::create( + _timeUnitsObserver = ftk::Observer::create( data.app->getTimeUnitsModel()->observeTimeUnits(), [this](TimeUnits value) { @@ -56,8 +56,8 @@ namespace toucan void IItem::mousePressEvent(ftk::MouseClickEvent& event) { ITimeWidget::mousePressEvent(event); - if ((3 == event.button && 0 == event.modifiers) || - (1 == event.button && static_cast(ftk::KeyModifier::Super) == event.modifiers)) + if ((ftk::MouseButton::Right == event.button && 0 == event.modifiers) || + (ftk::MouseButton::Left == event.button && static_cast(ftk::KeyModifier::Super) == event.modifiers)) { event.accept = true; _menu = ftk::Menu::create(getContext()); diff --git a/lib/toucanView/IItem.h b/lib/toucanView/IItem.h index feef60c..b686723 100644 --- a/lib/toucanView/IItem.h +++ b/lib/toucanView/IItem.h @@ -66,6 +66,6 @@ namespace toucan std::shared_ptr _menu; private: - std::shared_ptr > _timeUnitsObserver; + std::shared_ptr > _timeUnitsObserver; }; } diff --git a/lib/toucanView/InfoBar.cpp b/lib/toucanView/InfoBar.cpp index 3cf7eee..4f163af 100644 --- a/lib/toucanView/InfoBar.cpp +++ b/lib/toucanView/InfoBar.cpp @@ -23,7 +23,7 @@ namespace toucan _label = ftk::Label::create(context, _layout); _label->setMarginRole(ftk::SizeRole::MarginInside); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -76,9 +76,8 @@ namespace toucan _layout->setGeometry(value); } - void InfoBar::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I InfoBar::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } } diff --git a/lib/toucanView/InfoBar.h b/lib/toucanView/InfoBar.h index 5924d8a..490be5e 100644 --- a/lib/toucanView/InfoBar.h +++ b/lib/toucanView/InfoBar.h @@ -33,13 +33,13 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _layout; std::shared_ptr _label; - std::shared_ptr > > _fileObserver; + std::shared_ptr > > _fileObserver; }; } diff --git a/lib/toucanView/ItemLabel.cpp b/lib/toucanView/ItemLabel.cpp index 6b917c1..1f833ea 100644 --- a/lib/toucanView/ItemLabel.cpp +++ b/lib/toucanView/ItemLabel.cpp @@ -66,7 +66,7 @@ namespace toucan _size.displayScale = event.displayScale; _size.margin = event.style->getSizeRole(_marginRole, event.displayScale); _size.margin2 = event.style->getSizeRole(ftk::SizeRole::MarginInside, event.displayScale); - _size.fontInfo = event.style->getFontRole(ftk::FontRole::Label, event.displayScale); + _size.fontInfo = event.style->getFont(ftk::FontType::Regular, event.displayScale); _size.fontMetrics = event.fontSystem->getMetrics(_size.fontInfo); _size.nameSize = event.fontSystem->getSize(_name, _size.fontInfo); _size.durationSize = event.fontSystem->getSize(_duration, _size.fontInfo); @@ -79,7 +79,12 @@ namespace toucan _size.durationSize.w + _size.margin2 * 2 + _size.margin * 2; sizeHint.h = std::max(_size.nameSize.h, _size.durationSize.h) + _size.margin * 2; - _setSizeHint(sizeHint); + _size.sizeHint = sizeHint; + } + + ftk::Size2I ItemLabel::getSizeHint() const + { + return _size.sizeHint; } void ItemLabel::clipEvent(const ftk::Box2I& clipRect, bool clipped) diff --git a/lib/toucanView/ItemLabel.h b/lib/toucanView/ItemLabel.h index dd27498..a97d4e1 100644 --- a/lib/toucanView/ItemLabel.h +++ b/lib/toucanView/ItemLabel.h @@ -33,6 +33,7 @@ namespace toucan void setMarginRole(ftk::SizeRole); void setGeometry(const ftk::Box2I&) override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void clipEvent(const ftk::Box2I&, bool) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; @@ -46,6 +47,7 @@ namespace toucan { bool init = true; float displayScale = 0.F; + ftk::Size2I sizeHint; int margin = 0; int margin2 = 0; ftk::FontInfo fontInfo; diff --git a/lib/toucanView/JSONTool.cpp b/lib/toucanView/JSONTool.cpp index 3400eda..f217ba6 100644 --- a/lib/toucanView/JSONTool.cpp +++ b/lib/toucanView/JSONTool.cpp @@ -37,12 +37,12 @@ namespace toucan _lineNumbersLabel = ftk::Label::create(context, hLayout); _lineNumbersLabel->setBackgroundRole(ftk::ColorRole::Base); - _lineNumbersLabel->setFontRole(ftk::FontRole::Mono); + _lineNumbersLabel->setFont(ftk::FontType::Mono); _lineNumbersLabel->setMarginRole(ftk::SizeRole::MarginSmall); _lineNumbersLabel->setHStretch(ftk::Stretch::Fixed); _textLabel = ftk::Label::create(context, hLayout); - _textLabel->setFontRole(ftk::FontRole::Mono); + _textLabel->setFont(ftk::FontType::Mono); _textLabel->setMarginRole(ftk::SizeRole::MarginSmall); _textLabel->setHStretch(ftk::Stretch::Expanding); @@ -81,10 +81,9 @@ namespace toucan _bellows->setGeometry(value); } - void JSONWidget::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I JSONWidget::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_bellows->getSizeHint()); + return _bellows->getSizeHint(); } void JSONWidget::_textUpdate() @@ -129,6 +128,9 @@ namespace toucan _scrollLayout->setSpacingRole(ftk::SizeRole::None); _scrollWidget->setWidget(_scrollLayout); + _nothingLabel = ftk::Label::create(context, "Nothing selected", _scrollLayout); + _nothingLabel->setMarginRole(ftk::SizeRole::Margin); + ftk::Divider::create(context, ftk::Orientation::Vertical, _layout); _bottomLayout = ftk::HorizontalLayout::create(context, _layout); @@ -175,7 +177,7 @@ namespace toucan } }); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -203,6 +205,7 @@ namespace toucan } _openButton->setEnabled(!_widgets.empty()); _closeButton->setEnabled(!_widgets.empty()); + _nothingLabel->setVisible(_widgets.empty()); }); } else @@ -214,6 +217,7 @@ namespace toucan _widgets.clear(); _openButton->setEnabled(false); _closeButton->setEnabled(false); + _nothingLabel->setVisible(true); _selectionObserver.reset(); } }); @@ -238,9 +242,8 @@ namespace toucan _layout->setGeometry(value); } - void JSONTool::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I JSONTool::getSizeHint() const { - IToolWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } } diff --git a/lib/toucanView/JSONTool.h b/lib/toucanView/JSONTool.h index 7a64a14..04f40db 100644 --- a/lib/toucanView/JSONTool.h +++ b/lib/toucanView/JSONTool.h @@ -45,7 +45,7 @@ namespace toucan void setSearch(const std::string&); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _textUpdate(); @@ -78,7 +78,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _file; @@ -86,13 +86,14 @@ namespace toucan std::shared_ptr _layout; std::shared_ptr _scrollWidget; std::shared_ptr _scrollLayout; + std::shared_ptr _nothingLabel; std::vector > _widgets; std::shared_ptr _bottomLayout; std::shared_ptr _searchBox; std::shared_ptr _openButton; std::shared_ptr _closeButton; - std::shared_ptr > > _fileObserver; + std::shared_ptr > > _fileObserver; std::shared_ptr > _selectionObserver; }; } diff --git a/lib/toucanView/LogTool.cpp b/lib/toucanView/LogTool.cpp index f6c0035..be06371 100644 --- a/lib/toucanView/LogTool.cpp +++ b/lib/toucanView/LogTool.cpp @@ -32,7 +32,7 @@ namespace toucan _label = ftk::Label::create(context); _label->setVAlign(ftk::VAlign::Top); - _label->setFontRole(ftk::FontRole::Mono); + _label->setFont(ftk::FontType::Mono); _label->setMarginRole(ftk::SizeRole::MarginSmall); _scrollWidget->setWidget(_label); @@ -71,7 +71,7 @@ namespace toucan { for (const auto& item : items) { - for (const auto& line : ftk::split(ftk::toString(item), '\n')) + for (const auto& line : ftk::split(ftk::getLabel(item), '\n')) { _text.push_back(line); } @@ -99,10 +99,9 @@ namespace toucan _layout->setGeometry(value); } - void LogTool::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I LogTool::getSizeHint() const { - IToolWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void LogTool::_textUpdate() diff --git a/lib/toucanView/LogTool.h b/lib/toucanView/LogTool.h index aad30c1..9a9b968 100644 --- a/lib/toucanView/LogTool.h +++ b/lib/toucanView/LogTool.h @@ -33,7 +33,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _textUpdate(); diff --git a/lib/toucanView/MainWindow.cpp b/lib/toucanView/MainWindow.cpp index 462edb2..0361c5c 100644 --- a/lib/toucanView/MainWindow.cpp +++ b/lib/toucanView/MainWindow.cpp @@ -39,7 +39,7 @@ namespace toucan const std::string& name, const ftk::Size2I& size) { - ftk::Window::_init(context, name, size); + ftk::Window::_init(context, app, name, size); _app = app; _settings = app->getSettings(); @@ -57,7 +57,10 @@ namespace toucan } catch (const std::exception&) {} - setDisplayScale(displayScale); + if (displayScale > 0.F) + { + setDisplayScale(displayScale); + } auto iconSystem = context->getSystem(); iconSystem->add("toucan_64", toucan_resource::toucan_64); @@ -88,7 +91,7 @@ namespace toucan _hSplitter->setSplit({ .75F }); _tabWidget = ftk::TabWidget::create(context, _hSplitter); - _tabWidget->setTabsClosable(true); + _tabWidget->setClosable(true); _tabWidget->setVStretch(ftk::Stretch::Expanding); _toolWidget = ftk::TabWidget::create(context, _hSplitter); @@ -119,7 +122,7 @@ namespace toucan _infoBar = InfoBar::create(context, app, _layout); std::weak_ptr appWeak(app); - _tabWidget->setCurrentTabCallback( + _tabWidget->setCallback( [appWeak](int index) { if (auto app = appWeak.lock()) @@ -127,7 +130,7 @@ namespace toucan app->getFilesModel()->setCurrentIndex(index); } }); - _tabWidget->setTabCloseCallback( + _tabWidget->setCloseCallback( [appWeak](int index) { if (auto app = appWeak.lock()) @@ -143,7 +146,7 @@ namespace toucan _files = files; }); - _addObserver = ftk::ValueObserver::create( + _addObserver = ftk::Observer::create( app->getFilesModel()->observeAdd(), [this, appWeak](int index) { @@ -161,7 +164,7 @@ namespace toucan } }); - _removeObserver = ftk::ValueObserver::create( + _removeObserver = ftk::Observer::create( app->getFilesModel()->observeRemove(), [this, appWeak](int index) { @@ -177,11 +180,11 @@ namespace toucan } }); - _fileObserver = ftk::ValueObserver::create( + _fileObserver = ftk::Observer::create( app->getFilesModel()->observeCurrentIndex(), [this](int index) { - _tabWidget->setCurrentTab(index); + _tabWidget->setCurrent(index); }); _componentsObserver = ftk::MapObserver::create( @@ -203,7 +206,7 @@ namespace toucan _infoBar->setVisible(i->second); }); - _tooltipsObserver = ftk::ValueObserver::create( + _tooltipsObserver = ftk::Observer::create( app->getWindowModel()->observeTooltips(), [this](bool value) { @@ -235,10 +238,9 @@ namespace toucan _layout->setGeometry(value); } - void MainWindow::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I MainWindow::getSizeHint() const { - ftk::Window::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void MainWindow::keyPressEvent(ftk::KeyEvent& event) @@ -251,32 +253,34 @@ namespace toucan event.accept = true; } - void MainWindow::_drop(const std::vector& value) + void MainWindow::dropEvent(ftk::DragDropEvent& event) { - if (auto context = getContext()) + ftk::Window::dropEvent(event); + auto data = std::dynamic_pointer_cast(event.data); + auto context = getContext(); + auto app = _app.lock(); + if (data && context && app) { - if (auto app = _app.lock()) + event.accept = true; + std::vector errors; + for (const auto& i : data->getText()) { - std::vector errors; - for (const auto& i : value) + try { - try - { - app->getFilesModel()->open(i); - } - catch (const std::exception& e) - { - errors.push_back(e.what()); - } + app->getFilesModel()->open(i); } - if (!errors.empty()) + catch (const std::exception& e) { - context->getSystem()->message( - "ERROR", - ftk::join(errors, '\n'), - getWindow()); + errors.push_back(e.what()); } } + if (!errors.empty()) + { + context->getSystem()->message( + "ERROR", + ftk::join(errors, '\n'), + getWindow()); + } } } } diff --git a/lib/toucanView/MainWindow.h b/lib/toucanView/MainWindow.h index 70667f7..1289d98 100644 --- a/lib/toucanView/MainWindow.h +++ b/lib/toucanView/MainWindow.h @@ -45,12 +45,11 @@ namespace toucan const ftk::Size2I&); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; void keyPressEvent(ftk::KeyEvent&) override; void keyReleaseEvent(ftk::KeyEvent&) override; - protected: - void _drop(const std::vector&) override; + void dropEvent(ftk::DragDropEvent&) override; private: std::weak_ptr _app; @@ -74,11 +73,11 @@ namespace toucan std::shared_ptr _infoBar; std::shared_ptr > > _filesObserver; - std::shared_ptr > _addObserver; - std::shared_ptr > _removeObserver; - std::shared_ptr > _fileObserver; + std::shared_ptr > _addObserver; + std::shared_ptr > _removeObserver; + std::shared_ptr > _fileObserver; std::shared_ptr > _componentsObserver; - std::shared_ptr > _tooltipsObserver; + std::shared_ptr > _tooltipsObserver; }; } diff --git a/lib/toucanView/MarkerItem.cpp b/lib/toucanView/MarkerItem.cpp index de0a850..9b3a8a6 100644 --- a/lib/toucanView/MarkerItem.cpp +++ b/lib/toucanView/MarkerItem.cpp @@ -123,10 +123,15 @@ namespace toucan } ftk::Size2I sizeHint = _label->getSizeHint(); sizeHint.h += _size.border * 2; - _setSizeHint(sizeHint); + _size.sizeHint = sizeHint; _minWidth = sizeHint.h; } + ftk::Size2I MarkerItem::getSizeHint() const + { + return _size.sizeHint; + } + void MarkerItem::drawEvent( const ftk::Box2I& drawRect, const ftk::DrawEvent& event) diff --git a/lib/toucanView/MarkerItem.h b/lib/toucanView/MarkerItem.h index c07be87..6d68974 100644 --- a/lib/toucanView/MarkerItem.h +++ b/lib/toucanView/MarkerItem.h @@ -38,6 +38,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; @@ -58,6 +59,7 @@ namespace toucan { bool init = true; float displayScale = 0.F; + ftk::Size2I sizeHint; int margin = 0; int border = 0; }; diff --git a/lib/toucanView/PlaybackBar.cpp b/lib/toucanView/PlaybackBar.cpp index d7aa635..28a2892 100644 --- a/lib/toucanView/PlaybackBar.cpp +++ b/lib/toucanView/PlaybackBar.cpp @@ -75,14 +75,14 @@ namespace toucan } }); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { _file = file; if (file) { - _timeRangeObserver = ftk::ValueObserver::create( + _timeRangeObserver = ftk::Observer::create( file->getPlaybackModel()->observeTimeRange(), [this](const OTIO_NS::TimeRange& value) { @@ -90,7 +90,7 @@ namespace toucan _timeRangeUpdate(); }); - _currentTimeObserver = ftk::ValueObserver::create( + _currentTimeObserver = ftk::Observer::create( file->getPlaybackModel()->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { @@ -98,7 +98,7 @@ namespace toucan _currentTimeUpdate(); }); - _playbackObserver = ftk::ValueObserver::create( + _playbackObserver = ftk::Observer::create( file->getPlaybackModel()->observePlayback(), [this](Playback value) { @@ -127,7 +127,7 @@ namespace toucan _durationLabel->setEnabled(file.get()); }); - _timeUnitsObserver = ftk::ValueObserver::create( + _timeUnitsObserver = ftk::Observer::create( app->getTimeUnitsModel()->observeTimeUnits(), [this](TimeUnits value) { @@ -154,10 +154,9 @@ namespace toucan _layout->setGeometry(value); } - void PlaybackBar::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I PlaybackBar::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void PlaybackBar::_timelineUpdate() diff --git a/lib/toucanView/PlaybackBar.h b/lib/toucanView/PlaybackBar.h index 3faf451..b5499a4 100644 --- a/lib/toucanView/PlaybackBar.h +++ b/lib/toucanView/PlaybackBar.h @@ -34,7 +34,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _timelineUpdate(); @@ -54,11 +54,11 @@ namespace toucan std::shared_ptr _durationLabel; std::shared_ptr _timeUnitsComboBox; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _timeRangeObserver; - std::shared_ptr > _currentTimeObserver; - std::shared_ptr > _playbackObserver; - std::shared_ptr > _timeUnitsObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _timeRangeObserver; + std::shared_ptr > _currentTimeObserver; + std::shared_ptr > _playbackObserver; + std::shared_ptr > _timeUnitsObserver; }; } diff --git a/lib/toucanView/PlaybackMenu.cpp b/lib/toucanView/PlaybackMenu.cpp index 2f3ddac..d5caaff 100644 --- a/lib/toucanView/PlaybackMenu.cpp +++ b/lib/toucanView/PlaybackMenu.cpp @@ -20,8 +20,7 @@ namespace toucan _actions["Playback/Stop"] = ftk::Action::create( "Stop", "PlaybackStop", - ftk::Key::K, - 0, + ftk::KeyShortcut(ftk::Key::K), [this] { if (_file) @@ -34,8 +33,7 @@ namespace toucan _actions["Playback/Forward"] = ftk::Action::create( "Forward", "PlaybackForward", - ftk::Key::L, - 0, + ftk::KeyShortcut(ftk::Key::L), [this] { if (_file) @@ -48,8 +46,7 @@ namespace toucan _actions["Playback/Reverse"] = ftk::Action::create( "Reverse", "PlaybackReverse", - ftk::Key::J, - 0, + ftk::KeyShortcut(ftk::Key::J), [this] { if (_file) @@ -63,8 +60,7 @@ namespace toucan _actions["Playback/Toggle"] = ftk::Action::create( "Toggle Playback", - ftk::Key::Space, - 0, + ftk::KeyShortcut(ftk::Key::Space), [this] { if (_file) @@ -74,7 +70,7 @@ namespace toucan }); addAction(_actions["Playback/Toggle"]); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -106,7 +102,7 @@ namespace toucan const bool file = _file.get(); if (file) { - _playbackObserver = ftk::ValueObserver::create( + _playbackObserver = ftk::Observer::create( _file->getPlaybackModel()->observePlayback(), [this](Playback value) { diff --git a/lib/toucanView/PlaybackMenu.h b/lib/toucanView/PlaybackMenu.h index fadc943..3c70862 100644 --- a/lib/toucanView/PlaybackMenu.h +++ b/lib/toucanView/PlaybackMenu.h @@ -42,8 +42,8 @@ namespace toucan std::map > _actions; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _playbackObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _playbackObserver; }; } diff --git a/lib/toucanView/PlaybackModel.cpp b/lib/toucanView/PlaybackModel.cpp index 774a127..eb39813 100644 --- a/lib/toucanView/PlaybackModel.cpp +++ b/lib/toucanView/PlaybackModel.cpp @@ -11,10 +11,10 @@ namespace toucan { PlaybackModel::PlaybackModel(const std::shared_ptr& context) { - _timeRange = ftk::ObservableValue::create(); - _currentTime = ftk::ObservableValue::create(OTIO_NS::RationalTime(-1.0, -1.0)); - _inOutRange = ftk::ObservableValue::create(); - _playback = ftk::ObservableValue::create(Playback::Stop); + _timeRange = ftk::Observable::create(); + _currentTime = ftk::Observable::create(OTIO_NS::RationalTime(-1.0, -1.0)); + _inOutRange = ftk::Observable::create(); + _playback = ftk::Observable::create(Playback::Stop); _timer = ftk::Timer::create(context); _timer->setRepeating(true); } @@ -27,7 +27,7 @@ namespace toucan return _timeRange->get(); } - std::shared_ptr > PlaybackModel::observeTimeRange() const + std::shared_ptr > PlaybackModel::observeTimeRange() const { return _timeRange; } @@ -46,7 +46,7 @@ namespace toucan return _currentTime->get(); } - std::shared_ptr > PlaybackModel::observeCurrentTime() const + std::shared_ptr > PlaybackModel::observeCurrentTime() const { return _currentTime; } @@ -252,7 +252,7 @@ namespace toucan return _inOutRange->get(); } - std::shared_ptr > PlaybackModel::observeInOutRange() const + std::shared_ptr > PlaybackModel::observeInOutRange() const { return _inOutRange; } @@ -317,7 +317,7 @@ namespace toucan return _playback->get(); } - std::shared_ptr > PlaybackModel::observePlayback() const + std::shared_ptr > PlaybackModel::observePlayback() const { return _playback; } diff --git a/lib/toucanView/PlaybackModel.h b/lib/toucanView/PlaybackModel.h index b059f5e..2e6ae89 100644 --- a/lib/toucanView/PlaybackModel.h +++ b/lib/toucanView/PlaybackModel.h @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -64,7 +64,7 @@ namespace toucan const OTIO_NS::TimeRange& getTimeRange() const; //! Observe the time range. - std::shared_ptr > observeTimeRange() const; + std::shared_ptr > observeTimeRange() const; //! Set the time range. void setTimeRange(const OTIO_NS::TimeRange&); @@ -73,7 +73,7 @@ namespace toucan const OTIO_NS::RationalTime& getCurrentTime() const; //! Observe the current time. - std::shared_ptr > observeCurrentTime() const; + std::shared_ptr > observeCurrentTime() const; //! Set the current time. void setCurrentTime( @@ -89,7 +89,7 @@ namespace toucan const OTIO_NS::TimeRange& getInOutRange() const; //! Observe the in/out range. - std::shared_ptr > observeInOutRange() const; + std::shared_ptr > observeInOutRange() const; //! Set the in/out range. void setInOutRange(const OTIO_NS::TimeRange&); @@ -113,7 +113,7 @@ namespace toucan Playback getPlayback() const; //! Observe the playback. - std::shared_ptr > observePlayback() const; + std::shared_ptr > observePlayback() const; //! Set the playback. void setPlayback(Playback); @@ -130,10 +130,10 @@ namespace toucan private: void _timeUpdate(); - std::shared_ptr > _timeRange; - std::shared_ptr > _currentTime; - std::shared_ptr > _inOutRange; - std::shared_ptr > _playback; + std::shared_ptr > _timeRange; + std::shared_ptr > _currentTime; + std::shared_ptr > _inOutRange; + std::shared_ptr > _playback; Playback _playbackPrev = Playback::Forward; std::optional _viewState; std::shared_ptr _timer; diff --git a/lib/toucanView/SelectMenu.cpp b/lib/toucanView/SelectMenu.cpp index 73559e2..f24a126 100644 --- a/lib/toucanView/SelectMenu.cpp +++ b/lib/toucanView/SelectMenu.cpp @@ -20,8 +20,7 @@ namespace toucan _actions["Select/All"] = ftk::Action::create( "All", - ftk::Key::A, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::A, ftk::commandKeyModifier), [this] { if (_file) @@ -72,9 +71,7 @@ namespace toucan _actions["Select/None"] = ftk::Action::create( "None", - ftk::Key::A, - static_cast(ftk::KeyModifier::Shift) | - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::A, ftk::KeyModifier::Shift, ftk::commandKeyModifier), [this] { if (_file) @@ -86,8 +83,7 @@ namespace toucan _actions["Select/Invert"] = ftk::Action::create( "Invert", - ftk::Key::I, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::I, ftk::commandKeyModifier), [this] { if (_file) @@ -97,7 +93,7 @@ namespace toucan }); addAction(_actions["Select/Invert"]); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { diff --git a/lib/toucanView/SelectMenu.h b/lib/toucanView/SelectMenu.h index 6253d24..8bdf434 100644 --- a/lib/toucanView/SelectMenu.h +++ b/lib/toucanView/SelectMenu.h @@ -40,7 +40,7 @@ namespace toucan std::map > _actions; - std::shared_ptr > > _fileObserver; + std::shared_ptr > > _fileObserver; }; } diff --git a/lib/toucanView/StackItem.cpp b/lib/toucanView/StackItem.cpp index ca62c38..a84d2ee 100644 --- a/lib/toucanView/StackItem.cpp +++ b/lib/toucanView/StackItem.cpp @@ -92,7 +92,7 @@ namespace toucan _textUpdate(); - _thumbnailsObserver = ftk::ValueObserver::create( + _thumbnailsObserver = ftk::Observer::create( data.app->getWindowModel()->observeThumbnails(), [this](bool value) { @@ -148,7 +148,11 @@ namespace toucan _size.displayScale = event.displayScale; _size.border = event.style->getSizeRole(ftk::SizeRole::Border, event.displayScale); } - _setSizeHint(_layout->getSizeHint()); + } + + ftk::Size2I StackItem::getSizeHint() const + { + return _layout->getSizeHint(); } void StackItem::drawEvent( diff --git a/lib/toucanView/StackItem.h b/lib/toucanView/StackItem.h index a0200bf..ebeb3bd 100644 --- a/lib/toucanView/StackItem.h +++ b/lib/toucanView/StackItem.h @@ -37,6 +37,7 @@ namespace toucan void setGeometry(const ftk::Box2I&) override; ftk::Box2I getChildrenClipRect() const override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; @@ -57,7 +58,7 @@ namespace toucan std::vector > _markerItems; std::shared_ptr _timeLayout; - std::shared_ptr > _thumbnailsObserver; + std::shared_ptr > _thumbnailsObserver; struct SizeData { diff --git a/lib/toucanView/ThumbnailsWidget.cpp b/lib/toucanView/ThumbnailsWidget.cpp index a540a54..9475fbb 100644 --- a/lib/toucanView/ThumbnailsWidget.cpp +++ b/lib/toucanView/ThumbnailsWidget.cpp @@ -106,7 +106,12 @@ namespace toucan _thumbnailRequests.clear(); _thumbnailGenerator->cancelThumbnails(ids); } - _setSizeHint(ftk::Size2I(0, _size.thumbnailHeight)); + _size.sizeHint = ftk::Size2I(0, _size.thumbnailHeight); + } + + ftk::Size2I ThumbnailsWidget::getSizeHint() const + { + return _size.sizeHint; } void ThumbnailsWidget::clipEvent(const ftk::Box2I& clipRect, bool clipped) diff --git a/lib/toucanView/ThumbnailsWidget.h b/lib/toucanView/ThumbnailsWidget.h index 02b3fcb..cf85fb9 100644 --- a/lib/toucanView/ThumbnailsWidget.h +++ b/lib/toucanView/ThumbnailsWidget.h @@ -46,6 +46,7 @@ namespace toucan bool parentsVisible, bool parentsEnabled, const ftk::TickEvent&) override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void clipEvent(const ftk::Box2I&, bool clipped) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; @@ -65,6 +66,7 @@ namespace toucan { bool init = true; float displayScale = 0.F; + ftk::Size2I sizeHint; int thumbnailHeight = 0; }; SizeData _size; diff --git a/lib/toucanView/TimeLayout.cpp b/lib/toucanView/TimeLayout.cpp index e1c0f50..ad38f25 100644 --- a/lib/toucanView/TimeLayout.cpp +++ b/lib/toucanView/TimeLayout.cpp @@ -136,7 +136,12 @@ namespace toucan } } sizeHint.w = _timeRange.duration().rescaled_to(1.0).value() * _scale; - _setSizeHint(sizeHint); + _sizeHint = sizeHint; + } + + ftk::Size2I TimeLayout::getSizeHint() const + { + return _sizeHint; } void TimeStackLayout::_init( @@ -204,6 +209,11 @@ namespace toucan sizeHint.h += (children.size() - 1) * _size.spacing; } sizeHint.w = _timeRange.duration().rescaled_to(1.0).value() * _scale; - _setSizeHint(sizeHint); + _size.sizeHint = sizeHint; + } + + ftk::Size2I TimeStackLayout::getSizeHint() const + { + return _size.sizeHint; } } diff --git a/lib/toucanView/TimeLayout.h b/lib/toucanView/TimeLayout.h index f86600b..4fa58ce 100644 --- a/lib/toucanView/TimeLayout.h +++ b/lib/toucanView/TimeLayout.h @@ -65,7 +65,11 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; + + private: + ftk::Size2I _sizeHint; }; //! Time stack layout. @@ -87,6 +91,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; private: @@ -94,6 +99,7 @@ namespace toucan { bool init = true; float displayScale = 0.F; + ftk::Size2I sizeHint; int spacing = 0; }; SizeData _size; diff --git a/lib/toucanView/TimeMenu.cpp b/lib/toucanView/TimeMenu.cpp index cbf0d1a..27a8030 100644 --- a/lib/toucanView/TimeMenu.cpp +++ b/lib/toucanView/TimeMenu.cpp @@ -21,8 +21,7 @@ namespace toucan _actions["Time/FrameStart"] = ftk::Action::create( "Start Frame", "FrameStart", - ftk::Key::Up, - 0, + ftk::KeyShortcut(ftk::Key::Up), [this] { if (_file) @@ -37,8 +36,7 @@ namespace toucan _actions["Time/FramePrev"] = ftk::Action::create( "Previous Frame", "FramePrev", - ftk::Key::Left, - 0, + ftk::KeyShortcut(ftk::Key::Left), [this] { if (_file) @@ -52,8 +50,7 @@ namespace toucan _actions["Time/FramePrevX10"] = ftk::Action::create( "Previous Frame X10", - ftk::Key::Left, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::Left, ftk::KeyModifier::Shift), [this] { if (_file) @@ -67,8 +64,7 @@ namespace toucan _actions["Time/FramePrevX100"] = ftk::Action::create( "Previous Frame X100", - ftk::Key::Left, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::Left, ftk::commandKeyModifier), [this] { if (_file) @@ -83,8 +79,7 @@ namespace toucan _actions["Time/FrameNext"] = ftk::Action::create( "Next Frame", "FrameNext", - ftk::Key::Right, - 0, + ftk::KeyShortcut(ftk::Key::Right), [this] { if (_file) @@ -98,8 +93,7 @@ namespace toucan _actions["Time/FrameNextX10"] = ftk::Action::create( "Next Frame X10", - ftk::Key::Right, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::Right, ftk::KeyModifier::Shift), [this] { if (_file) @@ -113,8 +107,7 @@ namespace toucan _actions["Time/FrameNextX100"] = ftk::Action::create( "Next Frame X100", - ftk::Key::Right, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::Right, ftk::commandKeyModifier), [this] { if (_file) @@ -129,8 +122,7 @@ namespace toucan _actions["Time/FrameEnd"] = ftk::Action::create( "End Frame", "FrameEnd", - ftk::Key::Down, - 0, + ftk::KeyShortcut(ftk::Key::Down), [this] { if (_file) @@ -146,8 +138,7 @@ namespace toucan _actions["Time/ClipNext"] = ftk::Action::create( "Next Clip", - ftk::Key::Right, - static_cast(ftk::KeyModifier::Alt), + ftk::KeyShortcut(ftk::Key::Right, ftk::KeyModifier::Alt), [this] { if (_file) @@ -161,8 +152,7 @@ namespace toucan _actions["Time/ClipPrev"] = ftk::Action::create( "Previous Clip", - ftk::Key::Left, - static_cast(ftk::KeyModifier::Alt), + ftk::KeyShortcut(ftk::Key::Left, ftk::KeyModifier::Alt), [this] { if (_file) @@ -178,8 +168,7 @@ namespace toucan _actions["Time/InPointSet"] = ftk::Action::create( "Set In Point", - ftk::Key::I, - 0, + ftk::KeyShortcut(ftk::Key::I), [this] { if (_file) @@ -192,8 +181,7 @@ namespace toucan _actions["Time/InPointReset"] = ftk::Action::create( "Reset In Point", - ftk::Key::I, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::I, ftk::KeyModifier::Shift), [this] { if (_file) @@ -205,8 +193,7 @@ namespace toucan _actions["Time/OutPointSet"] = ftk::Action::create( "Set Out Point", - ftk::Key::O, - 0, + ftk::KeyShortcut(ftk::Key::O), [this] { if (_file) @@ -219,8 +206,7 @@ namespace toucan _actions["Time/OutPointReset"] = ftk::Action::create( "Reset Out Point", - ftk::Key::O, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::O, ftk::KeyModifier::Shift), [this] { if (_file) @@ -232,8 +218,7 @@ namespace toucan _actions["Time/InOutPointReset"] = ftk::Action::create( "Reset In/Out Points", - ftk::Key::P, - static_cast(ftk::KeyModifier::Shift), + ftk::KeyShortcut(ftk::Key::P, ftk::KeyModifier::Shift), [this] { if (_file) @@ -245,8 +230,7 @@ namespace toucan _actions["Time/InOutPointSelection"] = ftk::Action::create( "Set In/Out Points To Selection", - ftk::Key::P, - static_cast(ftk::KeyModifier::Shift) | static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::P, ftk::KeyModifier::Shift, ftk::commandKeyModifier), [this] { if (_file) @@ -270,21 +254,21 @@ namespace toucan }); addAction(_actions["Time/InOutPointSelection"]); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { _file = file; if (_file) { - _timeRangeObserver = ftk::ValueObserver::create( + _timeRangeObserver = ftk::Observer::create( _file->getPlaybackModel()->observeTimeRange(), [this](const OTIO_NS::TimeRange& value) { _timeRange = value; _menuUpdate(); }); - _inOutRangeObserver = ftk::ValueObserver::create( + _inOutRangeObserver = ftk::Observer::create( _file->getPlaybackModel()->observeInOutRange(), [this](const OTIO_NS::TimeRange& value) { diff --git a/lib/toucanView/TimeMenu.h b/lib/toucanView/TimeMenu.h index 0d8bee4..11ef71c 100644 --- a/lib/toucanView/TimeMenu.h +++ b/lib/toucanView/TimeMenu.h @@ -47,9 +47,9 @@ namespace toucan std::map > _actions; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _timeRangeObserver; - std::shared_ptr > _inOutRangeObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _timeRangeObserver; + std::shared_ptr > _inOutRangeObserver; std::shared_ptr > _selectionObserver; }; } diff --git a/lib/toucanView/TimeUnitsModel.cpp b/lib/toucanView/TimeUnitsModel.cpp index fe2a85c..2b3e056 100644 --- a/lib/toucanView/TimeUnitsModel.cpp +++ b/lib/toucanView/TimeUnitsModel.cpp @@ -90,14 +90,13 @@ namespace toucan auto i = json.find("Units"); if (i != json.end() && i->is_string()) { - std::stringstream ss(i->get()); - ss >> value; + from_string(i->get(), value); } } catch (const std::exception&) {} - _timeUnits = ftk::ObservableValue::create(value); + _timeUnits = ftk::Observable::create(value); } TimeUnitsModel::~TimeUnitsModel() @@ -114,7 +113,7 @@ namespace toucan return _timeUnits->get(); } - std::shared_ptr > TimeUnitsModel::observeTimeUnits() const + std::shared_ptr > TimeUnitsModel::observeTimeUnits() const { return _timeUnits; } diff --git a/lib/toucanView/TimeUnitsModel.h b/lib/toucanView/TimeUnitsModel.h index c1944e0..f7b865a 100644 --- a/lib/toucanView/TimeUnitsModel.h +++ b/lib/toucanView/TimeUnitsModel.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include @@ -21,7 +21,7 @@ namespace toucan Count, First = Timecode }; - FTK_ENUM(TimeUnits); + FTK_ENUM(, TimeUnits); //! Convert a time to a string. std::string toString(const OTIO_NS::RationalTime&, TimeUnits); @@ -46,13 +46,13 @@ namespace toucan TimeUnits getTimeUnits() const; //! Observe the time units. - std::shared_ptr > observeTimeUnits() const; + std::shared_ptr > observeTimeUnits() const; //! Set the time units. void setTimeUnits(TimeUnits); private: std::shared_ptr _settings; - std::shared_ptr > _timeUnits; + std::shared_ptr > _timeUnits; }; } diff --git a/lib/toucanView/TimeWidgets.cpp b/lib/toucanView/TimeWidgets.cpp index 039bb2d..cfff250 100644 --- a/lib/toucanView/TimeWidgets.cpp +++ b/lib/toucanView/TimeWidgets.cpp @@ -82,10 +82,9 @@ namespace toucan _layout->setGeometry(value); } - void FrameButtons::sizeHintEvent(const ftk::SizeHintEvent& value) + ftk::Size2I FrameButtons::getSizeHint() const { - IWidget::sizeHintEvent(value); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void PlaybackButtons::_init( @@ -160,10 +159,9 @@ namespace toucan _layout->setGeometry(value); } - void PlaybackButtons::sizeHintEvent(const ftk::SizeHintEvent& value) + ftk::Size2I PlaybackButtons::getSizeHint() const { - IWidget::sizeHintEvent(value); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void PlaybackButtons::_playbackUpdate() @@ -182,14 +180,14 @@ namespace toucan _layout->setSpacingRole(ftk::SizeRole::SpacingTool); _lineEdit = ftk::LineEdit::create(context, _layout); - _lineEdit->setFontRole(ftk::FontRole::Mono); + _lineEdit->setFont(ftk::FontType::Mono); _lineEdit->setFormat("00:00:00:00"); _incButtons = ftk::IncButtons::create(context, _layout); _timeUpdate(); - _lineEdit->setTextCallback( + _lineEdit->setCallback( [this](const std::string& text) { if (_callback) @@ -209,7 +207,7 @@ namespace toucan _timeDec(); }); - _timeUnitsObserver = ftk::ValueObserver::create( + _timeUnitsObserver = ftk::Observer::create( timeUnitsModel->observeTimeUnits(), [this](TimeUnits value) { @@ -259,10 +257,9 @@ namespace toucan _layout->setGeometry(value); } - void TimeEdit::sizeHintEvent(const ftk::SizeHintEvent& value) + ftk::Size2I TimeEdit::getSizeHint() const { - IWidget::sizeHintEvent(value); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void TimeEdit::keyPressEvent(ftk::KeyEvent& event) @@ -338,12 +335,12 @@ namespace toucan IWidget::_init(context, "toucan::TimeLabel", parent); _label = ftk::Label::create(context, shared_from_this()); - _label->setFontRole(ftk::FontRole::Mono); + _label->setFont(ftk::FontType::Mono); _label->setMarginRole(ftk::SizeRole::MarginInside); _timeUpdate(); - _timeUnitsObserver = ftk::ValueObserver::create( + _timeUnitsObserver = ftk::Observer::create( timeUnitsModel->observeTimeUnits(), [this](TimeUnits value) { @@ -384,10 +381,9 @@ namespace toucan _label->setGeometry(value); } - void TimeLabel::sizeHintEvent(const ftk::SizeHintEvent& value) + ftk::Size2I TimeLabel::getSizeHint() const { - IWidget::sizeHintEvent(value); - _setSizeHint(_label->getSizeHint()); + return _label->getSizeHint(); } void TimeLabel::_timeUpdate() diff --git a/lib/toucanView/TimeWidgets.h b/lib/toucanView/TimeWidgets.h index 95906a0..371b235 100644 --- a/lib/toucanView/TimeWidgets.h +++ b/lib/toucanView/TimeWidgets.h @@ -36,7 +36,7 @@ namespace toucan void setCallback(const std::function&); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::function _callback; @@ -67,7 +67,7 @@ namespace toucan void setCallback(const std::function&); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _playbackUpdate(); @@ -106,7 +106,7 @@ namespace toucan void setCallback(const std::function&); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; void keyPressEvent(ftk::KeyEvent&) override; void keyReleaseEvent(ftk::KeyEvent&) override; @@ -124,7 +124,7 @@ namespace toucan std::shared_ptr _incButtons; std::function _callback; - std::shared_ptr > _timeUnitsObserver; + std::shared_ptr > _timeUnitsObserver; }; //! Time label. @@ -152,7 +152,7 @@ namespace toucan void setMarginRole(ftk::SizeRole); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _timeUpdate(); @@ -162,7 +162,7 @@ namespace toucan std::shared_ptr _label; - std::shared_ptr > _timeUnitsObserver; + std::shared_ptr > _timeUnitsObserver; }; } diff --git a/lib/toucanView/TimelineItem.cpp b/lib/toucanView/TimelineItem.cpp index 3f746ee..fdaeca4 100644 --- a/lib/toucanView/TimelineItem.cpp +++ b/lib/toucanView/TimelineItem.cpp @@ -29,7 +29,7 @@ namespace toucan _setMouseHoverEnabled(true); _setMousePressEnabled( true, - 0, + ftk::MouseButton::Left, 0 | static_cast(ftk::KeyModifier::Shift) | static_cast(ftk::commandKeyModifier)); _timeline = data.file->getTimeline(); @@ -121,7 +121,7 @@ namespace toucan _size.border = event.style->getSizeRole(ftk::SizeRole::Border, event.displayScale); _size.handle = event.style->getSizeRole(ftk::SizeRole::Handle, event.displayScale); _size.thumbnailHeight = 2 * event.style->getSizeRole(ftk::SizeRole::SwatchLarge, event.displayScale); - _size.fontInfo = event.style->getFontRole(ftk::FontRole::Mono, event.displayScale); + _size.fontInfo = event.style->getFont(ftk::FontType::Mono, event.displayScale); _size.fontMetrics = event.fontSystem->getMetrics(_size.fontInfo); } int childSizeHint = 0; @@ -133,7 +133,12 @@ namespace toucan _timeRange.duration().rescaled_to(1.0).value() * _scale, _size.fontMetrics.lineHeight + _size.margin * 2); sizeHint.h += childSizeHint; - _setSizeHint(sizeHint); + _size.sizeHint = sizeHint; + } + + ftk::Size2I TimelineItem::getSizeHint() const + { + return _size.sizeHint; } void TimelineItem::drawOverlayEvent(const ftk::Box2I& drawRect, const ftk::DrawEvent& event) @@ -207,7 +212,7 @@ namespace toucan void TimelineItem::mousePressEvent(ftk::MouseClickEvent& event) { IItem::mousePressEvent(event); - if (1 == event.button && + if (ftk::MouseButton::Left == event.button && (0 == event.modifiers || static_cast(ftk::KeyModifier::Shift) == event.modifiers || static_cast(ftk::commandKeyModifier) == event.modifiers)) diff --git a/lib/toucanView/TimelineItem.h b/lib/toucanView/TimelineItem.h index b1914a4..89def99 100644 --- a/lib/toucanView/TimelineItem.h +++ b/lib/toucanView/TimelineItem.h @@ -43,6 +43,7 @@ namespace toucan void setInOutRange(const OTIO_NS::TimeRange&); void setGeometry(const ftk::Box2I&) override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawOverlayEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; void mouseMoveEvent(ftk::MouseMoveEvent&) override; @@ -86,6 +87,7 @@ namespace toucan { bool init = true; float displayScale = 0.F; + ftk::Size2I sizeHint; int margin = 0; int border = 0; int handle = 0; diff --git a/lib/toucanView/TimelineWidget.cpp b/lib/toucanView/TimelineWidget.cpp index dfe91f3..bc229ba 100644 --- a/lib/toucanView/TimelineWidget.cpp +++ b/lib/toucanView/TimelineWidget.cpp @@ -25,17 +25,17 @@ namespace toucan _setMouseHoverEnabled(true); _setMousePressEnabled( true, - 0, + ftk::MouseButton::Left, static_cast(ftk::KeyModifier::Alt)); - _frameView = ftk::ObservableValue::create(true); + _frameView = ftk::Observable::create(true); _scrollWidget = ftk::ScrollWidget::create(context, ftk::ScrollType::Both, shared_from_this()); _scrollWidget->setScrollEventsEnabled(false); _scrollWidget->setBorder(false); auto appWeak = std::weak_ptr(app); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this, appWeak](const std::shared_ptr& file) { @@ -87,7 +87,7 @@ namespace toucan }); _scrollWidget->setWidget(_timelineItem); - _currentTimeObserver = ftk::ValueObserver::create( + _currentTimeObserver = ftk::Observer::create( file->getPlaybackModel()->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { @@ -99,7 +99,7 @@ namespace toucan _scrollUpdate(); }); - _inOutRangeObserver = ftk::ValueObserver::create( + _inOutRangeObserver = ftk::Observer::create( file->getPlaybackModel()->observeInOutRange(), [this](const OTIO_NS::TimeRange& value) { @@ -156,7 +156,7 @@ namespace toucan return _frameView->get(); } - std::shared_ptr > TimelineWidget::observeFrameView() const + std::shared_ptr > TimelineWidget::observeFrameView() const { return _frameView; } @@ -188,10 +188,10 @@ namespace toucan void TimelineWidget::setGeometry(const ftk::Box2I& value) { - const ftk::Box2I viewportPrev = _scrollWidget->getViewport(); + const ftk::Box2I viewportPrev = _scrollWidget->getScrollInfo().viewport; IMouseWidget::setGeometry(value); _scrollWidget->setGeometry(value); - const bool changed = _scrollWidget->getViewport() != viewportPrev; + const bool changed = _scrollWidget->getScrollInfo().viewport != viewportPrev; if (_sizeInit) { _sizeInit = false; @@ -209,16 +209,16 @@ namespace toucan } else if (_timelineItem && _timelineItem->getSizeHint().w < - _scrollWidget->getViewport().w()) + _scrollWidget->getScrollInfo().viewport.w()) { setFrameView(true); frameView(); } } - void TimelineWidget::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I TimelineWidget::getSizeHint() const { - _setSizeHint(_scrollWidget->getSizeHint()); + return _scrollWidget->getSizeHint(); } void TimelineWidget::mouseMoveEvent(ftk::MouseMoveEvent& event) @@ -240,7 +240,7 @@ namespace toucan void TimelineWidget::mousePressEvent(ftk::MouseClickEvent& event) { IMouseWidget::mousePressEvent(event); - if (1 == event.button && + if (ftk::MouseButton::Left == event.button && static_cast(ftk::KeyModifier::Alt) == event.modifiers) { event.accept = true; @@ -337,7 +337,7 @@ namespace toucan const double duration = _timeRange.duration().rescaled_to(1.0).value(); if (duration > 0.0) { - const ftk::Box2I scrollViewport = _scrollWidget->getViewport(); + const ftk::Box2I scrollViewport = _scrollWidget->getScrollInfo().viewport; out = scrollViewport.w() / duration; } return out; @@ -346,7 +346,7 @@ namespace toucan double TimelineWidget::_getTimelineScaleMax() const { double out = 1.0; - const ftk::Box2I scrollViewport = _scrollWidget->getViewport(); + const ftk::Box2I scrollViewport = _scrollWidget->getScrollInfo().viewport; const double duration = _timeRange.duration().rescaled_to(1.0).value(); if (duration < 1.0) { @@ -368,7 +368,7 @@ namespace toucan MouseMode::None == _mouse.mode) { const int pos = _timelineItem->timeToPos(_currentTime); - const ftk::Box2I vp = _scrollWidget->getViewport(); + const ftk::Box2I vp = _scrollWidget->getScrollInfo().viewport; const int margin = vp.w() * marginPercentage; if (pos < (vp.min.x + margin) || pos >(vp.max.x - margin)) { diff --git a/lib/toucanView/TimelineWidget.h b/lib/toucanView/TimelineWidget.h index 5a958eb..cf76ff8 100644 --- a/lib/toucanView/TimelineWidget.h +++ b/lib/toucanView/TimelineWidget.h @@ -47,7 +47,7 @@ namespace toucan bool hasFrameView() const; //! Observe whether frame view is enabled. - std::shared_ptr > observeFrameView() const; + std::shared_ptr > observeFrameView() const; //! Set whether frame view is enabled. void setFrameView(bool); @@ -56,7 +56,7 @@ namespace toucan void frameView(); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; void mouseMoveEvent(ftk::MouseMoveEvent&) override; void mousePressEvent(ftk::MouseClickEvent&) override; void mouseReleaseEvent(ftk::MouseClickEvent&) override; @@ -81,7 +81,7 @@ namespace toucan OTIO_NS::RationalTime _currentTime; OTIO_NS::TimeRange _inOutRange; double _scale = 100.0; - std::shared_ptr > _frameView; + std::shared_ptr > _frameView; bool _sizeInit = true; std::optional _viewState; std::shared_ptr _thumbnailGenerator; @@ -102,8 +102,8 @@ namespace toucan }; MouseData _mouse; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _currentTimeObserver; - std::shared_ptr > _inOutRangeObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _currentTimeObserver; + std::shared_ptr > _inOutRangeObserver; }; } diff --git a/lib/toucanView/ToolBar.cpp b/lib/toucanView/ToolBar.cpp index 1a544c6..098d118 100644 --- a/lib/toucanView/ToolBar.cpp +++ b/lib/toucanView/ToolBar.cpp @@ -55,9 +55,8 @@ namespace toucan _layout->setGeometry(value); } - void ToolBar::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I ToolBar::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } } diff --git a/lib/toucanView/ToolBar.h b/lib/toucanView/ToolBar.h index 7ac5329..2789420 100644 --- a/lib/toucanView/ToolBar.h +++ b/lib/toucanView/ToolBar.h @@ -34,7 +34,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _layout; diff --git a/lib/toucanView/TrackItem.cpp b/lib/toucanView/TrackItem.cpp index 88ef3f3..5b68878 100644 --- a/lib/toucanView/TrackItem.cpp +++ b/lib/toucanView/TrackItem.cpp @@ -157,7 +157,11 @@ namespace toucan _size.displayScale = event.displayScale; _size.border = event.style->getSizeRole(ftk::SizeRole::Border, event.displayScale); } - _setSizeHint(_layout->getSizeHint()); + } + + ftk::Size2I TrackItem::getSizeHint() const + { + return _layout->getSizeHint(); } void TrackItem::drawEvent( diff --git a/lib/toucanView/TrackItem.h b/lib/toucanView/TrackItem.h index 179862a..1fe9fc6 100644 --- a/lib/toucanView/TrackItem.h +++ b/lib/toucanView/TrackItem.h @@ -35,6 +35,7 @@ namespace toucan void setGeometry(const ftk::Box2I&) override; ftk::Box2I getChildrenClipRect() const override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; diff --git a/lib/toucanView/VideoClipItem.cpp b/lib/toucanView/VideoClipItem.cpp index 6893349..89d5b1d 100644 --- a/lib/toucanView/VideoClipItem.cpp +++ b/lib/toucanView/VideoClipItem.cpp @@ -88,7 +88,7 @@ namespace toucan _textUpdate(); - _thumbnailsObserver = ftk::ValueObserver::create( + _thumbnailsObserver = ftk::Observer::create( data.app->getWindowModel()->observeThumbnails(), [this](bool value) { @@ -142,8 +142,11 @@ namespace toucan _size.displayScale = event.displayScale; _size.border = event.style->getSizeRole(ftk::SizeRole::Border, event.displayScale); } - ftk::Size2I sizeHint = _layout->getSizeHint(); - _setSizeHint(sizeHint); + } + + ftk::Size2I VideoClipItem::getSizeHint() const + { + return _layout->getSizeHint(); } void VideoClipItem::drawEvent( diff --git a/lib/toucanView/VideoClipItem.h b/lib/toucanView/VideoClipItem.h index eed412b..6871531 100644 --- a/lib/toucanView/VideoClipItem.h +++ b/lib/toucanView/VideoClipItem.h @@ -40,6 +40,7 @@ namespace toucan void setGeometry(const ftk::Box2I&) override; ftk::Box2I getChildrenClipRect() const override; + ftk::Size2I getSizeHint() const override; void sizeHintEvent(const ftk::SizeHintEvent&) override; void drawEvent(const ftk::Box2I&, const ftk::DrawEvent&) override; @@ -61,7 +62,7 @@ namespace toucan std::shared_ptr _markerLayout; std::vector > _markerItems; - std::shared_ptr > _thumbnailsObserver; + std::shared_ptr > _thumbnailsObserver; struct SizeData { diff --git a/lib/toucanView/ViewMenu.cpp b/lib/toucanView/ViewMenu.cpp index 6b79c69..27b7415 100644 --- a/lib/toucanView/ViewMenu.cpp +++ b/lib/toucanView/ViewMenu.cpp @@ -18,8 +18,7 @@ namespace toucan _actions["View/ZoomIn"] = ftk::Action::create( "Zoom In", "ViewZoomIn", - ftk::Key::Equals, - 0, + ftk::KeyShortcut(ftk::Key::Equals), [this] { if (_file) @@ -33,8 +32,7 @@ namespace toucan _actions["View/ZoomOut"] = ftk::Action::create( "Zoom Out", "ViewZoomOut", - ftk::Key::Minus, - 0, + ftk::KeyShortcut(ftk::Key::Minus), [this] { if (_file) @@ -48,8 +46,7 @@ namespace toucan _actions["View/ZoomReset"] = ftk::Action::create( "Zoom Reset", "ViewZoomReset", - ftk::Key::_0, - 0, + ftk::KeyShortcut(ftk::Key::_0), [this] { if (_file) @@ -65,8 +62,7 @@ namespace toucan _actions["View/Frame"] = ftk::Action::create( "Frame View", "ViewFrame", - ftk::Key::Backspace, - 0, + ftk::KeyShortcut(ftk::Key::Backspace), [this](bool value) { if (_file) @@ -81,8 +77,7 @@ namespace toucan _actions["View/Flip"] = ftk::Action::create( "Flip Vertical", - ftk::Key::V, - 0, + ftk::KeyShortcut(ftk::Key::V), [this](bool value) { if (_file) @@ -96,8 +91,7 @@ namespace toucan _actions["View/Flop"] = ftk::Action::create( "Flop Horizontal", - ftk::Key::H, - 0, + ftk::KeyShortcut(ftk::Key::H), [this](bool value) { if (_file) @@ -113,8 +107,7 @@ namespace toucan _actions["View/Red"] = ftk::Action::create( "Red", - ftk::Key::R, - 0, + ftk::KeyShortcut(ftk::Key::R), [this](bool value) { if (_file) @@ -128,8 +121,7 @@ namespace toucan _actions["View/Green"] = ftk::Action::create( "Green", - ftk::Key::G, - 0, + ftk::KeyShortcut(ftk::Key::G), [this](bool value) { if (_file) @@ -143,8 +135,7 @@ namespace toucan _actions["View/Blue"] = ftk::Action::create( "Blue", - ftk::Key::B, - 0, + ftk::KeyShortcut(ftk::Key::B), [this](bool value) { if (_file) @@ -158,8 +149,7 @@ namespace toucan _actions["View/Alpha"] = ftk::Action::create( "Alpha", - ftk::Key::A, - 0, + ftk::KeyShortcut(ftk::Key::A), [this](bool value) { if (_file) @@ -176,8 +166,7 @@ namespace toucan std::weak_ptr appWeak(app); _actions["View/HUD"] = ftk::Action::create( "HUD", - ftk::Key::H, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::H, ftk::commandKeyModifier), [appWeak](bool value) { if (auto app = appWeak.lock()) @@ -190,7 +179,7 @@ namespace toucan _actions["View/HUD"]->setTooltip("Toggle the HUD (Heads Up Display)"); addAction(_actions["View/HUD"]); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -198,7 +187,7 @@ namespace toucan _menuUpdate(); }); - _globalOptionsObserver = ftk::ValueObserver::create( + _globalOptionsObserver = ftk::Observer::create( app->getGlobalViewModel()->observeOptions(), [this](const GlobalViewOptions& value) { @@ -229,14 +218,14 @@ namespace toucan const bool file = _file.get(); if (file) { - _frameViewObserver = ftk::ValueObserver::create( + _frameViewObserver = ftk::Observer::create( _file->getViewModel()->observeFrameView(), [this](bool value) { setChecked(_actions["View/Frame"], value); }); - _optionsObserver = ftk::ValueObserver::create( + _optionsObserver = ftk::Observer::create( _file->getViewModel()->observeOptions(), [this](const ViewOptions& value) { diff --git a/lib/toucanView/ViewMenu.h b/lib/toucanView/ViewMenu.h index 212b089..1579f3a 100644 --- a/lib/toucanView/ViewMenu.h +++ b/lib/toucanView/ViewMenu.h @@ -6,7 +6,7 @@ #include #include -#include +#include namespace toucan { @@ -41,10 +41,10 @@ namespace toucan std::map > _actions; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _frameViewObserver; - std::shared_ptr > _optionsObserver; - std::shared_ptr > _globalOptionsObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _frameViewObserver; + std::shared_ptr > _optionsObserver; + std::shared_ptr > _globalOptionsObserver; }; } diff --git a/lib/toucanView/ViewModel.cpp b/lib/toucanView/ViewModel.cpp index 40f1d4d..c6e8f0d 100644 --- a/lib/toucanView/ViewModel.cpp +++ b/lib/toucanView/ViewModel.cpp @@ -27,11 +27,11 @@ namespace toucan ViewModel::ViewModel(const std::shared_ptr& context) { - _zoomIn = ftk::ObservableValue::create(false); - _zoomOut = ftk::ObservableValue::create(false); - _zoomReset = ftk::ObservableValue::create(false); - _frameView = ftk::ObservableValue::create(true); - _options = ftk::ObservableValue::create(); + _zoomIn = ftk::Observable::create(false); + _zoomOut = ftk::Observable::create(false); + _zoomReset = ftk::Observable::create(false); + _frameView = ftk::Observable::create(true); + _options = ftk::Observable::create(); } ViewModel::~ViewModel() @@ -52,17 +52,17 @@ namespace toucan _zoomReset->setAlways(true); } - std::shared_ptr > ViewModel::observeZoomIn() const + std::shared_ptr > ViewModel::observeZoomIn() const { return _zoomIn; } - std::shared_ptr > ViewModel::observeZoomOut() const + std::shared_ptr > ViewModel::observeZoomOut() const { return _zoomOut; } - std::shared_ptr > ViewModel::observeZoomReset() const + std::shared_ptr > ViewModel::observeZoomReset() const { return _zoomReset; } @@ -72,7 +72,7 @@ namespace toucan return _frameView->get(); } - std::shared_ptr > ViewModel::observeFrameView() const + std::shared_ptr > ViewModel::observeFrameView() const { return _frameView; } @@ -87,7 +87,7 @@ namespace toucan return _options->get(); } - std::shared_ptr > ViewModel::observeOptions() const + std::shared_ptr > ViewModel::observeOptions() const { return _options; } @@ -136,8 +136,7 @@ namespace toucan i = json.find("Background"); if (i != json.end() && i->is_string()) { - std::stringstream ss(i->get()); - ss >> options.background; + from_string(i->get(), options.background); } i = json.find("SolidColor"); if (i != json.end() && i->is_array() && 4 == i->size()) @@ -175,7 +174,7 @@ namespace toucan catch (const std::exception&) {} - _options = ftk::ObservableValue::create(options); + _options = ftk::Observable::create(options); } GlobalViewModel::~GlobalViewModel() @@ -217,7 +216,7 @@ namespace toucan return _options->get(); } - std::shared_ptr > GlobalViewModel::observeOptions() const + std::shared_ptr > GlobalViewModel::observeOptions() const { return _options; } diff --git a/lib/toucanView/ViewModel.h b/lib/toucanView/ViewModel.h index 54ed737..886485e 100644 --- a/lib/toucanView/ViewModel.h +++ b/lib/toucanView/ViewModel.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -41,19 +41,19 @@ namespace toucan void zoomReset(); //! Observe the zoom in. - std::shared_ptr > observeZoomIn() const; + std::shared_ptr > observeZoomIn() const; //! Observe the zoom out. - std::shared_ptr > observeZoomOut() const; + std::shared_ptr > observeZoomOut() const; //! Observe the zoom reset. - std::shared_ptr > observeZoomReset() const; + std::shared_ptr > observeZoomReset() const; //! Get whether frame view is enabled. bool getFrameView() const; //! Observe whether frame view is enabled. - std::shared_ptr > observeFrameView() const; + std::shared_ptr > observeFrameView() const; //! Set whether frame view is enabled. void setFrameView(bool); @@ -62,17 +62,17 @@ namespace toucan const ViewOptions& getOptions() const; //! Observe the view options. - std::shared_ptr > observeOptions() const; + std::shared_ptr > observeOptions() const; //! Set the view options. void setOptions(const ViewOptions&); private: - std::shared_ptr > _zoomIn; - std::shared_ptr > _zoomOut; - std::shared_ptr > _zoomReset; - std::shared_ptr > _frameView; - std::shared_ptr > _options; + std::shared_ptr > _zoomIn; + std::shared_ptr > _zoomOut; + std::shared_ptr > _zoomReset; + std::shared_ptr > _frameView; + std::shared_ptr > _options; }; //! View background options. @@ -84,7 +84,7 @@ namespace toucan Count, First = Solid }; - FTK_ENUM(ViewBackground); + FTK_ENUM(, ViewBackground); //! Global view options. struct GlobalViewOptions @@ -114,13 +114,13 @@ namespace toucan const GlobalViewOptions& getOptions() const; //! Observe the view options. - std::shared_ptr > observeOptions() const; + std::shared_ptr > observeOptions() const; //! Set the view options. void setOptions(const GlobalViewOptions&); private: std::shared_ptr _settings; - std::shared_ptr > _options; + std::shared_ptr > _options; }; } diff --git a/lib/toucanView/ViewToolBar.cpp b/lib/toucanView/ViewToolBar.cpp index b3a9f43..2710bd7 100644 --- a/lib/toucanView/ViewToolBar.cpp +++ b/lib/toucanView/ViewToolBar.cpp @@ -49,7 +49,7 @@ namespace toucan _widgetUpdate(); }); - _fileObserver = ftk::ValueObserver >::create( + _fileObserver = ftk::Observer >::create( app->getFilesModel()->observeCurrent(), [this](const std::shared_ptr& file) { @@ -78,10 +78,9 @@ namespace toucan _layout->setGeometry(value); } - void ViewToolBar::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I ViewToolBar::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } void ViewToolBar::_widgetUpdate() @@ -93,7 +92,7 @@ namespace toucan if (_file) { - _frameViewObserver = ftk::ValueObserver::create( + _frameViewObserver = ftk::Observer::create( _file->getViewModel()->observeFrameView(), [this](bool value) { diff --git a/lib/toucanView/ViewToolBar.h b/lib/toucanView/ViewToolBar.h index fdf1503..df73fe9 100644 --- a/lib/toucanView/ViewToolBar.h +++ b/lib/toucanView/ViewToolBar.h @@ -34,7 +34,7 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: void _widgetUpdate(); @@ -46,8 +46,8 @@ namespace toucan std::map > _buttons; std::shared_ptr > > _filesObserver; - std::shared_ptr > > _fileObserver; - std::shared_ptr > _frameViewObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _frameViewObserver; }; } diff --git a/lib/toucanView/Viewport.cpp b/lib/toucanView/Viewport.cpp index c7f6435..935aa99 100644 --- a/lib/toucanView/Viewport.cpp +++ b/lib/toucanView/Viewport.cpp @@ -21,16 +21,16 @@ namespace toucan IMouseWidget::_init(context, "toucan::Viewport", parent); _setMouseHoverEnabled(true); - _setMousePressEnabled(true, 0, 0); + _setMousePressEnabled(true, ftk::MouseButton::Left, 0); _viewModel = file->getViewModel(); _imageSize.w = file->getImageSize().x; _imageSize.h = file->getImageSize().y; - _viewPos = ftk::ObservableValue::create(); - _viewZoom = ftk::ObservableValue::create(1.F); - _frameView = ftk::ObservableValue::create(true); + _viewPos = ftk::Observable::create(); + _viewZoom = ftk::Observable::create(1.F); + _frameView = ftk::Observable::create(true); - _imageObserver = ftk::ValueObserver >::create( + _imageObserver = ftk::Observer >::create( file->observeCurrentImage(), [this](const std::shared_ptr& value) { @@ -38,7 +38,7 @@ namespace toucan setDrawUpdate(); }); - _bObserver = ftk::ValueObserver >::create( + _bObserver = ftk::Observer >::create( app->getFilesModel()->observeBFile(), [this](const std::shared_ptr& value) { @@ -47,7 +47,7 @@ namespace toucan const auto& imageSize = value->getImageSize(); _bImageSize.w = imageSize.x; _bImageSize.h = imageSize.y; - _bImageObserver = ftk::ValueObserver >::create( + _bImageObserver = ftk::Observer >::create( value->observeCurrentImage(), [this](const std::shared_ptr& value) { @@ -64,7 +64,7 @@ namespace toucan } }); - _compareOptionsObserver = ftk::ValueObserver::create( + _compareOptionsObserver = ftk::Observer::create( app->getFilesModel()->observeCompareOptions(), [this](const CompareOptions& value) { @@ -72,7 +72,7 @@ namespace toucan setDrawUpdate(); }); - _zoomInObserver = ftk::ValueObserver::create( + _zoomInObserver = ftk::Observer::create( _viewModel->observeZoomIn(), [this](bool value) { @@ -82,7 +82,7 @@ namespace toucan } }); - _zoomOutObserver = ftk::ValueObserver::create( + _zoomOutObserver = ftk::Observer::create( _viewModel->observeZoomOut(), [this](bool value) { @@ -92,7 +92,7 @@ namespace toucan } }); - _zoomResetObserver = ftk::ValueObserver::create( + _zoomResetObserver = ftk::Observer::create( _viewModel->observeZoomReset(), [this](bool value) { @@ -102,14 +102,14 @@ namespace toucan } }); - _frameObserver = ftk::ValueObserver::create( + _frameObserver = ftk::Observer::create( _viewModel->observeFrameView(), [this](bool value) { setFrameView(value); }); - _optionsObserver = ftk::ValueObserver::create( + _optionsObserver = ftk::Observer::create( _viewModel->observeOptions(), [this](const ViewOptions& value) { @@ -117,7 +117,7 @@ namespace toucan setDrawUpdate(); }); - _globalOptionsObserver = ftk::ValueObserver::create( + _globalOptionsObserver = ftk::Observer::create( app->getGlobalViewModel()->observeOptions(), [this](const GlobalViewOptions& value) { @@ -150,12 +150,12 @@ namespace toucan return _viewZoom->get(); } - std::shared_ptr > Viewport::observeViewPos() const + std::shared_ptr > Viewport::observeViewPos() const { return _viewPos; } - std::shared_ptr > Viewport::observeViewZoom() const + std::shared_ptr > Viewport::observeViewZoom() const { return _viewZoom; } @@ -207,7 +207,7 @@ namespace toucan return _frameView->get(); } - std::shared_ptr > Viewport::observeFrameView() const + std::shared_ptr > Viewport::observeFrameView() const { return _frameView; } @@ -490,7 +490,7 @@ namespace toucan void Viewport::mousePressEvent(ftk::MouseClickEvent& event) { IMouseWidget::mousePressEvent(event); - if (1 == event.button && 0 == event.modifiers) + if (ftk::MouseButton::Left == event.button && 0 == event.modifiers) { event.accept = true; setFrameView(false); diff --git a/lib/toucanView/Viewport.h b/lib/toucanView/Viewport.h index 579b87b..92f98be 100644 --- a/lib/toucanView/Viewport.h +++ b/lib/toucanView/Viewport.h @@ -43,10 +43,10 @@ namespace toucan float getViewZoom() const; //! Observe the view position. - std::shared_ptr > observeViewPos() const; + std::shared_ptr > observeViewPos() const; //! Observe the view zoom. - std::shared_ptr > observeViewZoom() const; + std::shared_ptr > observeViewZoom() const; //! Set the view position and zoom. void setViewPosZoom(const ftk::V2I&, float); @@ -70,7 +70,7 @@ namespace toucan bool getFrameView() const; //! Observe whether frame view is enabled. - std::shared_ptr > observeFrameView() const; + std::shared_ptr > observeFrameView() const; //! Set whether frame view is enabled. void setFrameView(bool); @@ -93,23 +93,23 @@ namespace toucan ftk::Size2I _bImageSize; std::shared_ptr _bImage; CompareOptions _compareOptions; - std::shared_ptr > _viewPos; - std::shared_ptr > _viewZoom; - std::shared_ptr > _frameView; + std::shared_ptr > _viewPos; + std::shared_ptr > _viewZoom; + std::shared_ptr > _frameView; ViewOptions _options; GlobalViewOptions _globalOptions; ftk::V2I _viewMousePress; - std::shared_ptr > > _imageObserver; - std::shared_ptr > > _bObserver; - std::shared_ptr > > _bImageObserver; - std::shared_ptr > _compareOptionsObserver; - std::shared_ptr > _zoomInObserver; - std::shared_ptr > _zoomOutObserver; - std::shared_ptr > _zoomResetObserver; - std::shared_ptr > _frameObserver; - std::shared_ptr > _optionsObserver; - std::shared_ptr > _globalOptionsObserver; + std::shared_ptr > > _imageObserver; + std::shared_ptr > > _bObserver; + std::shared_ptr > > _bImageObserver; + std::shared_ptr > _compareOptionsObserver; + std::shared_ptr > _zoomInObserver; + std::shared_ptr > _zoomOutObserver; + std::shared_ptr > _zoomResetObserver; + std::shared_ptr > _frameObserver; + std::shared_ptr > _optionsObserver; + std::shared_ptr > _globalOptionsObserver; }; } diff --git a/lib/toucanView/WindowMenu.cpp b/lib/toucanView/WindowMenu.cpp index 3c5b590..11802c5 100644 --- a/lib/toucanView/WindowMenu.cpp +++ b/lib/toucanView/WindowMenu.cpp @@ -30,8 +30,7 @@ namespace toucan _actions["Window/FullScreen"] = ftk::Action::create( "Full Screen", "WindowFullScreen", - ftk::Key::U, - static_cast(ftk::commandKeyModifier), + ftk::KeyShortcut(ftk::Key::U, ftk::commandKeyModifier), [windowWeak](bool value) { if (auto window = windowWeak.lock()) @@ -118,55 +117,55 @@ namespace toucan _actions["Window/DisplayScale/1.0"] = ftk::Action::create( "1.0", - [windowWeak](bool value) + [appWeak](bool value) { - if (auto window = windowWeak.lock()) + if (auto app = appWeak.lock()) { - window->setDisplayScale(1.F); + app->setDisplayScale(1.F); } }); _menus["Window/DisplayScale"]->addAction(_actions["Window/DisplayScale/1.0"]); _actions["Window/DisplayScale/1.5"] = ftk::Action::create( "1.5", - [windowWeak](bool value) + [appWeak](bool value) { - if (auto window = windowWeak.lock()) + if (auto app = appWeak.lock()) { - window->setDisplayScale(1.5F); + app->setDisplayScale(1.5F); } }); _menus["Window/DisplayScale"]->addAction(_actions["Window/DisplayScale/1.5"]); _actions["Window/DisplayScale/2.0"] = ftk::Action::create( "2.0", - [windowWeak](bool value) + [appWeak](bool value) { - if (auto window = windowWeak.lock()) + if (auto app = appWeak.lock()) { - window->setDisplayScale(2.F); + app->setDisplayScale(2.F); } }); _menus["Window/DisplayScale"]->addAction(_actions["Window/DisplayScale/2.0"]); _actions["Window/DisplayScale/2.5"] = ftk::Action::create( "2.5", - [windowWeak](bool value) + [appWeak](bool value) { - if (auto window = windowWeak.lock()) + if (auto app = appWeak.lock()) { - window->setDisplayScale(2.5F); + app->setDisplayScale(2.5F); } }); _menus["Window/DisplayScale"]->addAction(_actions["Window/DisplayScale/2.5"]); _actions["Window/DisplayScale/3.0"] = ftk::Action::create( "3.0", - [windowWeak](bool value) + [appWeak](bool value) { - if (auto window = windowWeak.lock()) + if (auto app = appWeak.lock()) { - window->setDisplayScale(3.F); + app->setDisplayScale(3.F); } }); _menus["Window/DisplayScale"]->addAction(_actions["Window/DisplayScale/3.0"]); @@ -193,7 +192,7 @@ namespace toucan }); addAction(_actions["Window/Tooltips"]); - _fullScreenObserver = ftk::ValueObserver::create( + _fullScreenObserver = ftk::Observer::create( window->observeFullScreen(), [this](bool value) { @@ -214,7 +213,7 @@ namespace toucan setChecked(_actions["Window/InfoBar"], i->second); }); - _displayScaleObserver = ftk::ValueObserver::create( + _displayScaleObserver = ftk::Observer::create( window->observeDisplayScale(), [this](float value) { @@ -225,14 +224,14 @@ namespace toucan _menus["Window/DisplayScale"]->setChecked(_actions["Window/DisplayScale/3.0"], 3.F == value); }); - _thumbnailsObserver = ftk::ValueObserver::create( + _thumbnailsObserver = ftk::Observer::create( app->getWindowModel()->observeThumbnails(), [this](bool value) { setChecked(_actions["Window/Thumbnails"], value); }); - _tooltipsObserver = ftk::ValueObserver::create( + _tooltipsObserver = ftk::Observer::create( app->getWindowModel()->observeTooltips(), [this](bool value) { diff --git a/lib/toucanView/WindowMenu.h b/lib/toucanView/WindowMenu.h index c624bbf..1ffa197 100644 --- a/lib/toucanView/WindowMenu.h +++ b/lib/toucanView/WindowMenu.h @@ -41,11 +41,11 @@ namespace toucan std::map > _menus; std::map > _actions; - std::shared_ptr > _fullScreenObserver; + std::shared_ptr > _fullScreenObserver; std::shared_ptr > _componentsObserver; - std::shared_ptr > _displayScaleObserver; - std::shared_ptr > _thumbnailsObserver; - std::shared_ptr > _tooltipsObserver; + std::shared_ptr > _displayScaleObserver; + std::shared_ptr > _thumbnailsObserver; + std::shared_ptr > _tooltipsObserver; }; } diff --git a/lib/toucanView/WindowModel.cpp b/lib/toucanView/WindowModel.cpp index 1487eb8..fcde926 100644 --- a/lib/toucanView/WindowModel.cpp +++ b/lib/toucanView/WindowModel.cpp @@ -67,8 +67,8 @@ namespace toucan } _components = ftk::ObservableMap::create(components); - _thumbnails = ftk::ObservableValue::create(thumbnails); - _tooltips = ftk::ObservableValue::create(tooltips); + _thumbnails = ftk::Observable::create(thumbnails); + _tooltips = ftk::Observable::create(tooltips); } WindowModel::~WindowModel() @@ -118,7 +118,7 @@ namespace toucan return _thumbnails->get(); } - std::shared_ptr > WindowModel::observeThumbnails() const + std::shared_ptr > WindowModel::observeThumbnails() const { return _thumbnails; } @@ -133,7 +133,7 @@ namespace toucan return _tooltips->get(); } - std::shared_ptr > WindowModel::observeTooltips() const + std::shared_ptr > WindowModel::observeTooltips() const { return _tooltips; } diff --git a/lib/toucanView/WindowModel.h b/lib/toucanView/WindowModel.h index b64cc6b..f6fd96d 100644 --- a/lib/toucanView/WindowModel.h +++ b/lib/toucanView/WindowModel.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include namespace toucan { @@ -21,7 +21,7 @@ namespace toucan Count, First = ToolBar }; - FTK_ENUM(WindowComponent); + FTK_ENUM(, WindowComponent); //! Window model. class WindowModel : public std::enable_shared_from_this @@ -52,7 +52,7 @@ namespace toucan bool getThumbnails() const; //! Observe whether thumbnails are enabled. - std::shared_ptr > observeThumbnails() const; + std::shared_ptr > observeThumbnails() const; //! Set whether thumbnails are enabled. void setThumbnails(bool); @@ -61,7 +61,7 @@ namespace toucan bool getTooltips() const; //! Observe whether tooltips are enabled. - std::shared_ptr > observeTooltips() const; + std::shared_ptr > observeTooltips() const; //! Set whether tooltips are enabled. void setTooltips(bool); @@ -69,7 +69,7 @@ namespace toucan private: std::shared_ptr _settings; std::shared_ptr > _components; - std::shared_ptr > _thumbnails; - std::shared_ptr > _tooltips; + std::shared_ptr > _thumbnails; + std::shared_ptr > _tooltips; }; } diff --git a/lib/toucanView/WindowToolBar.cpp b/lib/toucanView/WindowToolBar.cpp index c1e1cf0..8604187 100644 --- a/lib/toucanView/WindowToolBar.cpp +++ b/lib/toucanView/WindowToolBar.cpp @@ -37,7 +37,7 @@ namespace toucan button = ftk::ToolButton::create(context, i->second, hLayout); _buttons["Window/Playback"] = button; - _fullScreenObserver = ftk::ValueObserver::create( + _fullScreenObserver = ftk::Observer::create( window->observeFullScreen(), [this](bool value) { @@ -76,9 +76,8 @@ namespace toucan _layout->setGeometry(value); } - void WindowToolBar::sizeHintEvent(const ftk::SizeHintEvent& event) + ftk::Size2I WindowToolBar::getSizeHint() const { - IWidget::sizeHintEvent(event); - _setSizeHint(_layout->getSizeHint()); + return _layout->getSizeHint(); } } diff --git a/lib/toucanView/WindowToolBar.h b/lib/toucanView/WindowToolBar.h index 4def544..2ab2b84 100644 --- a/lib/toucanView/WindowToolBar.h +++ b/lib/toucanView/WindowToolBar.h @@ -39,14 +39,14 @@ namespace toucan const std::shared_ptr& parent = nullptr); void setGeometry(const ftk::Box2I&) override; - void sizeHintEvent(const ftk::SizeHintEvent&) override; + ftk::Size2I getSizeHint() const override; private: std::shared_ptr _layout; std::map > _buttons; - std::shared_ptr > _frameViewObserver; - std::shared_ptr > _fullScreenObserver; + std::shared_ptr > _frameViewObserver; + std::shared_ptr > _fullScreenObserver; std::shared_ptr > _componentObserver; }; } diff --git a/tests/toucanViewTest/FilesModelTest.cpp b/tests/toucanViewTest/FilesModelTest.cpp index 3c97c73..a8de507 100644 --- a/tests/toucanViewTest/FilesModelTest.cpp +++ b/tests/toucanViewTest/FilesModelTest.cpp @@ -28,49 +28,49 @@ namespace toucan files = value; }); - addObserver = ftk::ValueObserver::create( + addObserver = ftk::Observer::create( model->observeAdd(), [this](int value) { add = value; }); - removeObserver = ftk::ValueObserver::create( + removeObserver = ftk::Observer::create( model->observeRemove(), [this](int value) { remove = value; }); - currentObserver = ftk::ValueObserver>::create( + currentObserver = ftk::Observer>::create( model->observeCurrent(), [this](const std::shared_ptr& value) { current = value; }); - currentIndexObserver = ftk::ValueObserver::create( + currentIndexObserver = ftk::Observer::create( model->observeCurrentIndex(), [this](int value) { currentIndex = value; }); - bFileObserver = ftk::ValueObserver >::create( + bFileObserver = ftk::Observer >::create( model->observeBFile(), [this](const std::shared_ptr& value) { bFile = value; }); - bIndexObserver = ftk::ValueObserver::create( + bIndexObserver = ftk::Observer::create( model->observeBIndex(), [this](int value) { bIndex = value; }); - compareOptionsObserver = ftk::ValueObserver::create( + compareOptionsObserver = ftk::Observer::create( model->observeCompareOptions(), [this](const CompareOptions& value) { @@ -89,13 +89,13 @@ namespace toucan CompareOptions compareOptions; std::shared_ptr > > filesObserver; - std::shared_ptr > addObserver; - std::shared_ptr > removeObserver; - std::shared_ptr > > currentObserver; - std::shared_ptr > currentIndexObserver; - std::shared_ptr > > bFileObserver; - std::shared_ptr > bIndexObserver; - std::shared_ptr > compareOptionsObserver; + std::shared_ptr > addObserver; + std::shared_ptr > removeObserver; + std::shared_ptr > > currentObserver; + std::shared_ptr > currentIndexObserver; + std::shared_ptr > > bFileObserver; + std::shared_ptr > bIndexObserver; + std::shared_ptr > compareOptionsObserver; }; } diff --git a/tests/toucanViewTest/PlaybackModelTest.cpp b/tests/toucanViewTest/PlaybackModelTest.cpp index 13238a3..4877f68 100644 --- a/tests/toucanViewTest/PlaybackModelTest.cpp +++ b/tests/toucanViewTest/PlaybackModelTest.cpp @@ -21,28 +21,28 @@ namespace toucan { model = std::make_shared(context); - timeRangeObserver = ftk::ValueObserver::create( + timeRangeObserver = ftk::Observer::create( model->observeTimeRange(), [this](const OTIO_NS::TimeRange& value) { timeRange = value; }); - currentTimeObserver = ftk::ValueObserver::create( + currentTimeObserver = ftk::Observer::create( model->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { currentTime = value; }); - inOutRangeObserver = ftk::ValueObserver::create( + inOutRangeObserver = ftk::Observer::create( model->observeInOutRange(), [this](const OTIO_NS::TimeRange& value) { inOutRange = value; }); - playbackObserver = ftk::ValueObserver::create( + playbackObserver = ftk::Observer::create( model->observePlayback(), [this](Playback value) { @@ -56,10 +56,10 @@ namespace toucan OTIO_NS::TimeRange inOutRange; Playback playback = Playback::Stop; - std::shared_ptr > timeRangeObserver; - std::shared_ptr > currentTimeObserver; - std::shared_ptr > inOutRangeObserver; - std::shared_ptr > playbackObserver; + std::shared_ptr > timeRangeObserver; + std::shared_ptr > currentTimeObserver; + std::shared_ptr > inOutRangeObserver; + std::shared_ptr > playbackObserver; }; } diff --git a/tests/toucanViewTest/ViewModelTest.cpp b/tests/toucanViewTest/ViewModelTest.cpp index f77bbe1..556126b 100644 --- a/tests/toucanViewTest/ViewModelTest.cpp +++ b/tests/toucanViewTest/ViewModelTest.cpp @@ -19,28 +19,28 @@ namespace toucan { model = std::make_shared(context); - zoomInObserver = ftk::ValueObserver::create( + zoomInObserver = ftk::Observer::create( model->observeZoomIn(), [this](bool value) { zoomIn = value; }); - zoomOutObserver = ftk::ValueObserver::create( + zoomOutObserver = ftk::Observer::create( model->observeZoomOut(), [this](bool value) { zoomOut = value; }); - zoomResetObserver = ftk::ValueObserver::create( + zoomResetObserver = ftk::Observer::create( model->observeZoomReset(), [this](bool value) { zoomReset = value; }); - frameViewObserver = ftk::ValueObserver::create( + frameViewObserver = ftk::Observer::create( model->observeFrameView(), [this](bool value) { @@ -54,10 +54,10 @@ namespace toucan bool zoomReset = false; bool frameView = false; - std::shared_ptr > zoomInObserver; - std::shared_ptr > zoomOutObserver; - std::shared_ptr > zoomResetObserver; - std::shared_ptr > frameViewObserver; + std::shared_ptr > zoomInObserver; + std::shared_ptr > zoomOutObserver; + std::shared_ptr > zoomResetObserver; + std::shared_ptr > frameViewObserver; }; } diff --git a/tests/toucanViewTest/WindowModelTest.cpp b/tests/toucanViewTest/WindowModelTest.cpp index 4bf09fa..e278eee 100644 --- a/tests/toucanViewTest/WindowModelTest.cpp +++ b/tests/toucanViewTest/WindowModelTest.cpp @@ -26,7 +26,7 @@ namespace toucan components = value; }); - tooltipsObserver = ftk::ValueObserver::create( + tooltipsObserver = ftk::Observer::create( model->observeTooltips(), [this](bool value) { @@ -39,7 +39,7 @@ namespace toucan bool tooltips = false; std::shared_ptr > componentsObserver; - std::shared_ptr > tooltipsObserver; + std::shared_ptr > tooltipsObserver; }; }