Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed May 26, 2024
1 parent 2ac598e commit 9c05f15
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
22 changes: 12 additions & 10 deletions lib/tlPlayApp/CompareMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ namespace tl
std::weak_ptr<App> app;

std::map<std::string, std::shared_ptr<ui::Action> > actions;
std::shared_ptr<Menu> bMenu;
std::vector<std::shared_ptr<ui::Action> > bActions;
std::shared_ptr<Menu> timeMenu;
std::map<std::string, std::shared_ptr<ui::Menu> > menus;

std::shared_ptr<observer::ListObserver<std::shared_ptr<play::FilesModelItem> > > filesObserver;
std::shared_ptr<observer::ListObserver<int> > bIndexesObserver;
Expand All @@ -37,7 +36,7 @@ namespace tl
p.app = app;
p.actions = actions;

p.bMenu = addSubMenu("B");
p.menus["B"] = addSubMenu("B");
addItem(p.actions["Next"]);
addItem(p.actions["Prev"]);
addDivider();
Expand All @@ -47,11 +46,11 @@ namespace tl
addItem(p.actions[label]);
}
addDivider();
p.timeMenu = addSubMenu("Time");
p.menus["Time"] = addSubMenu("Time");
const auto timeLabels = timeline::getCompareTimeModeLabels();
for (const auto& label : timeLabels)
{
p.timeMenu->addItem(p.actions[label]);
p.menus["Time"]->addItem(p.actions[label]);
}

p.filesObserver = observer::ListObserver<std::shared_ptr<play::FilesModelItem> >::create(
Expand Down Expand Up @@ -105,7 +104,10 @@ namespace tl
{
Menu::close();
TLRENDER_P();
p.bMenu->close();
for (const auto& menu : p.menus)
{
menu.second->close();
}
}

void CompareMenu::_filesUpdate(
Expand All @@ -116,7 +118,7 @@ namespace tl
setItemEnabled(p.actions["Next"], value.size() > 1);
setItemEnabled(p.actions["Prev"], value.size() > 1);

p.bMenu->clear();
p.menus["B"]->clear();
p.bActions.clear();
if (auto app = p.app.lock())
{
Expand All @@ -135,7 +137,7 @@ namespace tl
});
const auto j = std::find(bIndexes.begin(), bIndexes.end(), i);
action->checked = j != bIndexes.end();
p.bMenu->addItem(action);
p.menus["B"]->addItem(action);
p.bActions.push_back(action);
}
}
Expand All @@ -147,7 +149,7 @@ namespace tl
for (int i = 0; i < p.bActions.size(); ++i)
{
const auto j = std::find(value.begin(), value.end(), i);
p.bMenu->setItemChecked(
p.menus["B"]->setItemChecked(
p.bActions[i],
j != value.end());
}
Expand All @@ -171,7 +173,7 @@ namespace tl
const auto labels = timeline::getCompareTimeModeLabels();
for (size_t i = 0; i < enums.size(); ++i)
{
p.timeMenu->setItemChecked(p.actions[labels[i]], enums[i] == value);
p.menus["Time"]->setItemChecked(p.actions[labels[i]], enums[i] == value);
}
}
}
Expand Down
33 changes: 16 additions & 17 deletions lib/tlPlayApp/FileMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ namespace tl
std::shared_ptr<ui::RecentFilesModel> recentFilesModel;

std::map<std::string, std::shared_ptr<ui::Action> > actions;
std::shared_ptr<Menu> recentMenu;
std::shared_ptr<Menu> currentMenu;
std::vector<std::shared_ptr<ui::Action> > currentItems;
std::shared_ptr<Menu> layersMenu;
std::vector<std::shared_ptr<ui::Action> > layersItems;
std::map<std::string, std::shared_ptr<ui::Menu> > menus;

std::shared_ptr<observer::ListObserver<std::shared_ptr<play::FilesModelItem> > > filesObserver;
std::shared_ptr<observer::ValueObserver<std::shared_ptr<play::FilesModelItem> > > aObserver;
Expand Down Expand Up @@ -65,13 +63,13 @@ namespace tl
addItem(p.actions["Close"]);
addItem(p.actions["CloseAll"]);
addItem(p.actions["Reload"]);
p.recentMenu = addSubMenu("Recent");
p.menus["Recent"] = addSubMenu("Recent");
addDivider();
p.currentMenu = addSubMenu("Current");
p.menus["Current"] = addSubMenu("Current");
addItem(p.actions["Next"]);
addItem(p.actions["Prev"]);
addDivider();
p.layersMenu = addSubMenu("Layers");
p.menus["Layers"] = addSubMenu("Layers");
addItem(p.actions["NextLayer"]);
addItem(p.actions["PrevLayer"]);
addDivider();
Expand Down Expand Up @@ -138,9 +136,10 @@ namespace tl
{
Menu::close();
TLRENDER_P();
p.recentMenu->close();
p.currentMenu->close();
p.layersMenu->close();
for (const auto& menu : p.menus)
{
menu.second->close();
}
}

void FileMenu::_filesUpdate(
Expand All @@ -154,7 +153,7 @@ namespace tl
setItemEnabled(p.actions["Next"], value.size() > 1);
setItemEnabled(p.actions["Prev"], value.size() > 1);

p.currentMenu->clear();
p.menus["Current"]->clear();
p.currentItems.clear();
for (size_t i = 0; i < value.size(); ++i)
{
Expand All @@ -168,7 +167,7 @@ namespace tl
app->getFilesModel()->setA(i);
}
});
p.currentMenu->addItem(item);
p.menus["Current"]->addItem(item);
p.currentItems.push_back(item);
}
}
Expand All @@ -177,7 +176,7 @@ namespace tl
{
TLRENDER_P();

p.layersMenu->clear();
p.menus["Layers"]->clear();
p.layersItems.clear();
if (value)
{
Expand All @@ -194,7 +193,7 @@ namespace tl
}
});
item->checked = i == value->videoLayer;
p.layersMenu->addItem(item);
p.menus["Layers"]->addItem(item);
p.layersItems.push_back(item);
}
}
Expand All @@ -208,7 +207,7 @@ namespace tl
TLRENDER_P();
for (int i = 0; i < p.currentItems.size(); ++i)
{
p.currentMenu->setItemChecked(p.currentItems[i], i == value);
p.menus["Current"]->setItemChecked(p.currentItems[i], i == value);
}
}

Expand All @@ -220,15 +219,15 @@ namespace tl
auto a = app->getFilesModel()->getA();
for (size_t i = 0; i < p.layersItems.size(); ++i)
{
p.layersMenu->setItemChecked(p.layersItems[i], i == a->videoLayer);
p.menus["Layers"]->setItemChecked(p.layersItems[i], i == a->videoLayer);
}
}
}

void FileMenu::_recentUpdate(const std::vector<file::Path>& value)
{
TLRENDER_P();
p.recentMenu->clear();
p.menus["Recent"]->clear();
if (!value.empty())
{
for (auto i = value.rbegin(); i != value.rend(); ++i)
Expand Down Expand Up @@ -256,7 +255,7 @@ namespace tl
}
close();
});
p.recentMenu->addItem(item);
p.menus["Recent"]->addItem(item);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/tlPlayApp/RenderMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace tl
{
std::map<std::string, std::shared_ptr<ui::Action> > actions;
std::map<std::string, std::shared_ptr<Menu> > menus;

std::shared_ptr<observer::ValueObserver<timeline::ImageOptions> > imageOptionsObserver;
std::shared_ptr<observer::ValueObserver<image::PixelType> > offscreenColorTypeObserver;
};
Expand Down
17 changes: 10 additions & 7 deletions lib/tlPlayApp/TimelineMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace tl
std::weak_ptr<MainWindow> mainWindow;

std::map<std::string, std::shared_ptr<ui::Action> > actions;
std::shared_ptr<Menu> thumbnailsSizeMenu;
std::map<int, std::shared_ptr<ui::Action> > thumbnailsSizeItems;
std::map<std::string, std::shared_ptr<ui::Menu> > menus;

std::shared_ptr<observer::ValueObserver<bool> > editableObserver;
std::shared_ptr<observer::ValueObserver<bool> > frameViewObserver;
Expand Down Expand Up @@ -55,10 +55,10 @@ namespace tl
addItem(p.actions["TrackInfo"]);
addItem(p.actions["ClipInfo"]);
addItem(p.actions["Thumbnails"]);
p.thumbnailsSizeMenu = addSubMenu("Thumbnails Size");
p.thumbnailsSizeMenu->addItem(p.actions["Thumbnails100"]);
p.thumbnailsSizeMenu->addItem(p.actions["Thumbnails200"]);
p.thumbnailsSizeMenu->addItem(p.actions["Thumbnails300"]);
p.menus["ThumbnailSize"] = addSubMenu("Thumbnails Size");
p.menus["ThumbnailSize"]->addItem(p.actions["Thumbnails100"]);
p.menus["ThumbnailSize"]->addItem(p.actions["Thumbnails200"]);
p.menus["ThumbnailSize"]->addItem(p.actions["Thumbnails300"]);
addItem(p.actions["Transitions"]);
addItem(p.actions["Markers"]);

Expand Down Expand Up @@ -141,7 +141,10 @@ namespace tl
{
Menu::close();
TLRENDER_P();
p.thumbnailsSizeMenu->close();
for (const auto& menu : p.menus)
{
menu.second->close();
}
}

void TimelineMenu::_thumbnailsSizeUpdate()
Expand All @@ -158,7 +161,7 @@ namespace tl
for (auto item : p.thumbnailsSizeItems)
{
const bool checked = item == *i;
p.thumbnailsSizeMenu->setItemChecked(item.second, checked);
p.menus["ThumbnailSize"]->setItemChecked(item.second, checked);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/tlPlayApp/ViewMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace tl
{
std::map<std::string, std::shared_ptr<ui::Action> > actions;
std::map<std::string, std::shared_ptr<Menu> > menus;

std::shared_ptr<observer::ValueObserver<bool> > frameViewObserver;
std::shared_ptr<observer::ValueObserver<timeline::DisplayOptions> > displayOptionsObserver;
};
Expand Down
13 changes: 8 additions & 5 deletions lib/tlPlayApp/WindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace tl
struct WindowMenu::Private
{
std::map<std::string, std::shared_ptr<ui::Action> > actions;
std::shared_ptr<Menu> resizeMenu;
std::map<std::string, std::shared_ptr<ui::Menu> > menus;

std::shared_ptr<observer::ValueObserver<bool> > fullScreenObserver;
std::shared_ptr<observer::ValueObserver<bool> > floatOnTopObserver;
Expand All @@ -34,7 +34,7 @@ namespace tl

p.actions = actions;

p.resizeMenu = addSubMenu("Resize");
p.menus["Resize"] = addSubMenu("Resize");
auto mainWindowWeak = std::weak_ptr<MainWindow>(mainWindow);
auto action = std::make_shared<ui::Action>(
"1280x720",
Expand All @@ -45,7 +45,7 @@ namespace tl
mainWindow->setWindowSize(math::Size2i(1280, 720));
}
});
p.resizeMenu->addItem(action);
p.menus["Resize"]->addItem(action);
action = std::make_shared<ui::Action>(
"1920x1080",
[mainWindowWeak]
Expand All @@ -55,7 +55,7 @@ namespace tl
mainWindow->setWindowSize(math::Size2i(1920, 1080));
}
});
p.resizeMenu->addItem(action);
p.menus["Resize"]->addItem(action);

addDivider();
addItem(p.actions["FullScreen"]);
Expand Down Expand Up @@ -131,7 +131,10 @@ namespace tl
{
Menu::close();
TLRENDER_P();
p.resizeMenu->close();
for (const auto menu : p.menus)
{
menu.second->close();
}
}
}
}

0 comments on commit 9c05f15

Please sign in to comment.