Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Oct 18, 2024
1 parent 6645933 commit 633ecfb
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 128 deletions.
4 changes: 4 additions & 0 deletions bin/toucan-view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(HEADERS
DocumentTab.h
Document.h
DocumentsModel.h
Export.h
ExportTool.h
GapItem.h
GraphTool.h
IItem.h
Expand Down Expand Up @@ -33,6 +35,8 @@ set(SOURCE
DocumentTab.cpp
Document.cpp
DocumentsModel.cpp
Export.cpp
ExportTool.cpp
GapItem.cpp
GraphTool.cpp
IItem.cpp
Expand Down
45 changes: 3 additions & 42 deletions bin/toucan-view/DocumentTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include "DocumentTab.h"

#include "App.h"
#include "BottomBar.h"
#include "GraphTool.h"
#include "InspectorTool.h"
#include "TimelineWidget.h"
#include "Viewport.h"

namespace toucan
Expand All @@ -20,43 +16,8 @@ namespace toucan
const std::shared_ptr<IWidget>& parent)
{
dtk::IWidget::_init(context, "toucan::DocumentTab", parent);

_vSplitter = dtk::Splitter::create(context, dtk::Orientation::Vertical, shared_from_this());
_vSplitter->setSplit({ .7F, .3F });
_vSplitter->setStretch(dtk::Stretch::Expanding);
_hSplitter = dtk::Splitter::create(context, dtk::Orientation::Horizontal, _vSplitter);
_hSplitter->setSplit({ .75F, .25F });

_viewport = Viewport::create(context, document, _hSplitter);
_viewport = Viewport::create(context, document, shared_from_this());
_viewport->setStretch(dtk::Stretch::Expanding);

_toolWidget = dtk::TabWidget::create(context, _hSplitter);
_toolWidgets.push_back(InspectorTool::create(context, app, document));
_toolWidgets.push_back(GraphTool::create(context, app, document));
for (const auto& toolWidget : _toolWidgets)
{
_toolWidget->addTab(toolWidget->getText(), toolWidget);
}

_bottomLayout = dtk::VerticalLayout::create(context, _vSplitter);
_bottomLayout->setSpacingRole(dtk::SizeRole::None);
_bottomBar = BottomBar::create(context, app, _bottomLayout);
_timelineWidget = TimelineWidget::create(context, app, document, _bottomLayout);
_timelineWidget->setVStretch(dtk::Stretch::Expanding);

std::weak_ptr<App> appWeak(app);
_controlsObserver = dtk::MapObserver<WindowControl, bool>::create(
app->getWindowModel()->observeControls(),
[this](const std::map<WindowControl, bool>& value)
{
auto i = value.find(WindowControl::TimelineWidget);
_timelineWidget->setVisible(i->second);
auto j = value.find(WindowControl::BottomBar);
_bottomBar->setVisible(j->second);
_bottomLayout->setVisible(i->second || j->second);
i = value.find(WindowControl::Tools);
_toolWidget->setVisible(i->second);
});
}

DocumentTab::~DocumentTab()
Expand All @@ -76,12 +37,12 @@ namespace toucan
void DocumentTab::setGeometry(const dtk::Box2I& value)
{
dtk::IWidget::setGeometry(value);
_vSplitter->setGeometry(value);
_viewport->setGeometry(value);
}

void DocumentTab::sizeHintEvent(const dtk::SizeHintEvent& event)
{
dtk::IWidget::sizeHintEvent(event);
_setSizeHint(_vSplitter->getSizeHint());
_setSizeHint(_viewport->getSizeHint());
}
}
15 changes: 0 additions & 15 deletions bin/toucan-view/DocumentTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@

#include "WindowModel.h"

#include <dtk/ui/Divider.h>
#include <dtk/ui/RowLayout.h>
#include <dtk/ui/Splitter.h>
#include <dtk/ui/TabWidget.h>

namespace toucan
{
class App;
class BottomBar;
class Document;
class IToolWidget;
class TimelineWidget;
class Viewport;

class DocumentTab : public dtk::IWidget
Expand All @@ -42,16 +36,7 @@ namespace toucan
void sizeHintEvent(const dtk::SizeHintEvent&) override;

private:
std::shared_ptr<dtk::Splitter> _vSplitter;
std::shared_ptr<dtk::Splitter> _hSplitter;
std::shared_ptr<Viewport> _viewport;
std::shared_ptr<dtk::TabWidget> _toolWidget;
std::vector<std::shared_ptr<IToolWidget> > _toolWidgets;
std::shared_ptr<dtk::VerticalLayout> _bottomLayout;
std::shared_ptr<BottomBar> _bottomBar;
std::shared_ptr<TimelineWidget> _timelineWidget;

std::shared_ptr<dtk::MapObserver<WindowControl, bool> > _controlsObserver;
};
}

9 changes: 9 additions & 0 deletions bin/toucan-view/Export.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024 Darby Johnston
// All rights reserved.

#include "Export.h"

namespace toucan
{
}
10 changes: 10 additions & 0 deletions bin/toucan-view/Export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024 Darby Johnston
// All rights reserved.

#pragma once

namespace toucan
{
}

77 changes: 77 additions & 0 deletions bin/toucan-view/ExportTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024 Darby Johnston
// All rights reserved.

#include "ExportTool.h"

namespace toucan
{
void ExportWidget::_init(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<dtk::IWidget>& parent)
{
IWidget::_init(context, "toucan::ExportWidget", parent);

_layout = dtk::VerticalLayout::create(context, shared_from_this());
}

ExportWidget::~ExportWidget()
{}

std::shared_ptr<ExportWidget> ExportWidget::create(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<dtk::IWidget>& parent)
{
auto out = std::shared_ptr<ExportWidget>(new ExportWidget);
out->_init(context, parent);
return out;
}

void ExportWidget::setGeometry(const dtk::Box2I& value)
{
IWidget::setGeometry(value);
_layout->setGeometry(value);
}

void ExportWidget::sizeHintEvent(const dtk::SizeHintEvent& event)
{
IWidget::sizeHintEvent(event);
_setSizeHint(_layout->getSizeHint());
}

void ExportTool::_init(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<dtk::IWidget>& parent)
{
IToolWidget::_init(context, app, "toucan::ExportTool", "Export", parent);

_layout = dtk::VerticalLayout::create(context, shared_from_this());
_layout->setSpacingRole(dtk::SizeRole::None);
}

ExportTool::~ExportTool()
{}

std::shared_ptr<ExportTool> ExportTool::create(
const std::shared_ptr<dtk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<dtk::IWidget>& parent)
{
auto out = std::shared_ptr<ExportTool>(new ExportTool);
out->_init(context, app, parent);
return out;
}

void ExportTool::setGeometry(const dtk::Box2I& value)
{
IToolWidget::setGeometry(value);
_layout->setGeometry(value);
}

void ExportTool::sizeHintEvent(const dtk::SizeHintEvent& event)
{
IToolWidget::sizeHintEvent(event);
_setSizeHint(_layout->getSizeHint());
}
}
58 changes: 58 additions & 0 deletions bin/toucan-view/ExportTool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024 Darby Johnston
// All rights reserved.

#pragma once

#include "IToolWidget.h"

#include <dtk/ui/RowLayout.h>

namespace toucan
{
class ExportWidget : public dtk::IWidget
{
protected:
void _init(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<IWidget>& parent);

public:
virtual ~ExportWidget();

static std::shared_ptr<ExportWidget> create(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<IWidget>& parent = nullptr);

void setGeometry(const dtk::Box2I&) override;
void sizeHintEvent(const dtk::SizeHintEvent&) override;

private:
std::shared_ptr<dtk::VerticalLayout> _layout;
};

class ExportTool : public IToolWidget
{
protected:
void _init(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<App>&,
const std::shared_ptr<IWidget>& parent);

public:
virtual ~ExportTool();

static std::shared_ptr<ExportTool> create(
const std::shared_ptr<dtk::Context>&,
const std::shared_ptr<App>&,
const std::shared_ptr<IWidget>& parent = nullptr);

void setGeometry(const dtk::Box2I&) override;
void sizeHintEvent(const dtk::SizeHintEvent&) override;

private:
std::shared_ptr<dtk::VerticalLayout> _layout;
std::shared_ptr<ExportWidget> _widget;
};
}

Loading

0 comments on commit 633ecfb

Please sign in to comment.