2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2013-01-21 05:40:37 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/workspace.h"
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/ui/main_window.h"
|
2015-03-05 04:23:40 +08:00
|
|
|
#include "app/ui/skin/skin_theme.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/tabs.h"
|
|
|
|
#include "app/ui/workspace_view.h"
|
2015-03-05 04:23:40 +08:00
|
|
|
#include "base/remove_from_container.h"
|
2013-01-21 05:40:37 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
2013-03-28 09:13:25 +08:00
|
|
|
#include <queue>
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
using namespace app::skin;
|
|
|
|
using namespace ui;
|
2015-02-12 23:16:25 +08:00
|
|
|
|
2013-01-21 05:40:37 +08:00
|
|
|
Workspace::Workspace()
|
2015-03-05 04:23:40 +08:00
|
|
|
: Widget(kGenericWidget)
|
|
|
|
, m_activeView(nullptr)
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
2015-02-16 02:29:16 +08:00
|
|
|
setBgColor(theme->colors.workspace());
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Workspace::~Workspace()
|
|
|
|
{
|
2013-03-28 08:19:35 +08:00
|
|
|
// No views at this point.
|
|
|
|
ASSERT(m_views.empty());
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::addView(WorkspaceView* view)
|
|
|
|
{
|
|
|
|
m_views.push_back(view);
|
|
|
|
|
2013-03-28 08:19:35 +08:00
|
|
|
App::instance()->getMainWindow()->getTabsBar()->addTab(dynamic_cast<TabView*>(view));
|
2015-03-05 04:23:40 +08:00
|
|
|
setActiveView(view);
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::removeView(WorkspaceView* view)
|
|
|
|
{
|
2015-03-05 04:23:40 +08:00
|
|
|
base::remove_from_container(m_views, view);
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2015-03-05 04:23:40 +08:00
|
|
|
Widget* content = view->getContentWidget();
|
|
|
|
if (content->getParent())
|
|
|
|
content->getParent()->removeChild(content);
|
2014-01-26 22:22:23 +08:00
|
|
|
|
2015-03-05 04:23:40 +08:00
|
|
|
// Remove related tab
|
2015-03-03 20:33:59 +08:00
|
|
|
Tabs* tabs = App::instance()->getMainWindow()->getTabsBar();
|
|
|
|
tabs->removeTab(dynamic_cast<TabView*>(view));
|
2013-03-28 08:19:35 +08:00
|
|
|
|
2015-03-03 20:33:59 +08:00
|
|
|
TabView* tabView = tabs->getSelectedTab();
|
2015-03-05 04:23:40 +08:00
|
|
|
setActiveView(dynamic_cast<WorkspaceView*>(tabView));
|
2013-03-28 08:19:35 +08:00
|
|
|
}
|
|
|
|
|
2015-02-23 08:18:53 +08:00
|
|
|
bool Workspace::closeView(WorkspaceView* view)
|
|
|
|
{
|
|
|
|
return view->onCloseView(this);
|
|
|
|
}
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
WorkspaceView* Workspace::activeView()
|
2013-03-28 08:19:35 +08:00
|
|
|
{
|
2015-03-05 04:23:40 +08:00
|
|
|
return m_activeView;
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::setActiveView(WorkspaceView* view)
|
|
|
|
{
|
2015-03-05 04:23:40 +08:00
|
|
|
m_activeView = view;
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2015-03-05 04:23:40 +08:00
|
|
|
removeAllChildren();
|
|
|
|
if (view)
|
|
|
|
addChild(view->getContentWidget());
|
2013-03-28 08:19:35 +08:00
|
|
|
|
|
|
|
layout();
|
|
|
|
|
|
|
|
ActiveViewChanged(); // Fire ActiveViewChanged event
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
2015-03-05 04:23:40 +08:00
|
|
|
void Workspace::onPaint(PaintEvent& ev)
|
2014-01-26 22:22:23 +08:00
|
|
|
{
|
2015-03-05 04:23:40 +08:00
|
|
|
ev.getGraphics()->fillRect(getBgColor(), getClientBounds());
|
2014-01-26 22:22:23 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|