Implemented initial PanelManager implementation

This commit is contained in:
Joel Holdsworth 2009-04-04 16:57:06 +01:00
parent 775ef6d809
commit 6151415029
13 changed files with 389 additions and 79 deletions

View file

@ -61,6 +61,8 @@ gtk_gui_la_SOURCES = \
$(lumigui_srcdir)/window-manager.hpp \
$(lumigui_srcdir)/workspace/actions.cpp \
$(lumigui_srcdir)/workspace/actions.hpp \
$(lumigui_srcdir)/workspace/panel-manager.cpp \
$(lumigui_srcdir)/workspace/panel-manager.hpp \
$(lumigui_srcdir)/workspace/workspace-window.cpp \
$(lumigui_srcdir)/workspace/workspace-window.hpp \
$(lumigui_srcdir)/dialogs/dialog.hpp \

View file

@ -69,12 +69,12 @@ protected:
const gchar *name, const gchar *long_name, const gchar *stock_id,
GdlDockItemBehavior behavior = GDL_DOCK_ITEM_BEH_NORMAL);
public:
/**
* Destructor
**/
~Panel();
public:
/**
* Returns a pointer to the underlying GdlDockItem structure
*/

View file

@ -27,7 +27,7 @@ namespace gui {
namespace panels {
ResourcesPanel::ResourcesPanel(workspace::WorkspaceWindow &workspace_window) :
Panel(workspace_window, "resources", _("Resources"), "panel_resources")
Panel(workspace_window, "resources", get_title(), "panel_resources")
{
notebook.append_page(media, _("Media"));
@ -38,5 +38,11 @@ ResourcesPanel::ResourcesPanel(workspace::WorkspaceWindow &workspace_window) :
pack_start(notebook);
}
const char*
ResourcesPanel::get_title()
{
return _("Resources");
}
} // namespace panels
} // namespace gui

View file

@ -40,6 +40,12 @@ public:
* @param workspace_window The window that owns this panel.
**/
ResourcesPanel(workspace::WorkspaceWindow &workspace_window);
/**
* Get the title of the panel.
* @return Returns a pointer to the string title of the panel.
**/
static const char* get_title();
protected:
Gtk::Notebook notebook;

View file

@ -48,7 +48,7 @@ const int TimelinePanel::ZoomToolSteps = 2; // 2 seems comfortable
TimelinePanel::TimelinePanel(workspace::WorkspaceWindow
&workspace_window) :
Panel(workspace_window, "timeline", _("Timeline"), "panel_timeline"),
Panel(workspace_window, "timeline", get_title(), "panel_timeline"),
timeIndicator(),
timeIndicatorButton(),
previousButton(Stock::MEDIA_PREVIOUS),
@ -130,6 +130,12 @@ TimelinePanel::~TimelinePanel()
}
const char*
TimelinePanel::get_title()
{
return _("Timeline");
}
void
TimelinePanel::on_play_pause()
{

View file

@ -56,6 +56,12 @@ public:
* Destructor
**/
~TimelinePanel();
/**
* Get the title of the panel.
* @return Returns a pointer to the string title of the panel.
**/
static const char* get_title();
private:
//----- Event Handlers -----//

View file

@ -37,7 +37,7 @@ namespace gui {
namespace panels {
ViewerPanel::ViewerPanel(workspace::WorkspaceWindow &workspace_window) :
Panel(workspace_window, "viewer", _("Viewer"), "panel_viewer")
Panel(workspace_window, "viewer", get_title(), "panel_viewer")
{
//----- Pack in the Widgets -----//
pack_start(display, PACK_EXPAND_WIDGET);
@ -49,6 +49,12 @@ ViewerPanel::ViewerPanel(workspace::WorkspaceWindow &workspace_window) :
playback.use_display (DisplayService::setUp (outputDestination));
}
const char*
ViewerPanel::get_title()
{
return _("Viewer");
}
void
ViewerPanel::on_frame(void *buffer)
{

View file

@ -46,6 +46,12 @@ public:
**/
ViewerPanel(workspace::WorkspaceWindow &owner_window);
/**
* Get the title of the panel.
* @return Returns a pointer to the string title of the panel.
**/
static const char* get_title();
protected:
void on_frame(void *buffer);

View file

@ -115,7 +115,7 @@ Actions::Actions(WorkspaceWindow &workspace_window) :
void
Actions::update_action_state()
{
REQUIRE(workspaceWindow.resourcesPanel != NULL);
/*REQUIRE(workspaceWindow.resourcesPanel != NULL);
REQUIRE(workspaceWindow.timelinePanel != NULL);
REQUIRE(workspaceWindow.viewerPanel != NULL);
@ -126,7 +126,7 @@ Actions::update_action_state()
workspaceWindow.timelinePanel->is_shown());
viewerPanelAction->set_active(
workspaceWindow.viewerPanel->is_shown());
is_updating_action_state = false;
is_updating_action_state = false;*/
}
/* ===== File Menu Event Handlers ===== */
@ -172,23 +172,23 @@ Actions::on_menu_edit_preferences()
void
Actions::on_menu_view_resources()
{
if(!is_updating_action_state)
workspaceWindow.resourcesPanel->show(
assetsPanelAction->get_active());
//if(!is_updating_action_state)
// workspaceWindow.resourcesPanel->show(
// assetsPanelAction->get_active());
}
void
Actions::on_menu_view_timeline()
{
if(!is_updating_action_state)
workspaceWindow.timelinePanel->show(timelinePanelAction->get_active());
//if(!is_updating_action_state)
// workspaceWindow.timelinePanel->show(timelinePanelAction->get_active());
}
void
Actions::on_menu_view_viewer()
{
if(!is_updating_action_state)
workspaceWindow.viewerPanel->show(viewerPanelAction->get_active());
//if(!is_updating_action_state)
// workspaceWindow.viewerPanel->show(viewerPanelAction->get_active());
}
/* ===== Sequence Menu Event Handlers ===== */

View file

@ -0,0 +1,163 @@
/*
panel-manager.cpp - Definition of the panel manager object
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include "panel-manager.hpp"
#include "../panels/resources-panel.hpp"
#include "../panels/viewer-panel.hpp"
#include "../panels/timeline-panel.hpp"
#include "include/logging.h"
using namespace boost;
using namespace std;
namespace gui {
namespace workspace {
const PanelManager::PanelDescription
PanelManager::panelDescriptionList[] = {
PanelManager::Panel<TimelinePanel>(),
PanelManager::Panel<ViewerPanel>(),
PanelManager::Panel<ResourcesPanel>()
};
PanelManager::PanelManager(WorkspaceWindow &workspace_window) :
workspaceWindow(workspace_window),
dock(NULL),
dockBar(NULL),
dockLayout(NULL)
{
memset(&dockPlaceholders, 0, sizeof(dockPlaceholders));
}
PanelManager::~PanelManager()
{
if(dock)
g_object_unref(dock);
if(dockBar)
g_object_unref(dockBar);
if(dockLayout)
g_object_unref(dockLayout);
for(int i = 0; i < 4; i++)
if(dockPlaceholders[i])
g_object_unref(dockPlaceholders[i]);
}
void
PanelManager::setup_dock()
{
REQUIRE(dock == NULL);
dock = GDL_DOCK(gdl_dock_new());
ENSURE(dock);
REQUIRE(dockBar == NULL);
dockBar = GDL_DOCK_BAR(gdl_dock_bar_new(dock));
ENSURE(dockBar);
REQUIRE(dockLayout == NULL);
dockLayout = GDL_DOCK_LAYOUT(gdl_dock_layout_new(dock));
ENSURE(dockLayout);
REQUIRE(dockPlaceholders[0] == NULL && dockPlaceholders[1] == NULL &&
dockPlaceholders[2] == NULL && dockPlaceholders[3] == NULL);
dockPlaceholders[0] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
"ph1", GDL_DOCK_OBJECT(dock), GDL_DOCK_TOP, FALSE));
dockPlaceholders[1] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
"ph2", GDL_DOCK_OBJECT(dock), GDL_DOCK_BOTTOM, FALSE));
dockPlaceholders[2] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
"ph3", GDL_DOCK_OBJECT(dock), GDL_DOCK_LEFT, FALSE));
dockPlaceholders[3] = GDL_DOCK_PLACEHOLDER(gdl_dock_placeholder_new(
"ph4", GDL_DOCK_OBJECT(dock), GDL_DOCK_RIGHT, FALSE));
ENSURE(dockPlaceholders[0] && dockPlaceholders[1] &&
dockPlaceholders[2] && dockPlaceholders[3]);
create_panels();
}
GdlDock*
PanelManager::get_dock() const
{
ENSURE(dock);
return dock;
}
GdlDockBar*
PanelManager::get_dock_bar() const
{
ENSURE(dockBar);
return dockBar;
}
void
PanelManager::create_panels()
{
shared_ptr<panels::Panel> resourcesPanel(
(panels::Panel*)new ResourcesPanel(workspaceWindow));
shared_ptr<panels::Panel> viewerPanel(
(panels::Panel*)new ViewerPanel(workspaceWindow));
shared_ptr<panels::Panel> timelinePanel(
(panels::Panel*)new TimelinePanel(workspaceWindow));
gdl_dock_add_item(dock,
resourcesPanel->get_dock_item(), GDL_DOCK_LEFT);
gdl_dock_add_item(dock,
timelinePanel->get_dock_item(), GDL_DOCK_BOTTOM);
gdl_dock_add_item(dock,
viewerPanel->get_dock_item(), GDL_DOCK_RIGHT);
panels.push_back(timelinePanel);
panels.push_back(viewerPanel);
panels.push_back(resourcesPanel);
const int panelDescriptionCount =
sizeof(panelDescriptionList) /
sizeof(PanelDescription);
for(int i = 0; i < panelDescriptionCount; i++)
{
g_message("%s", panelDescriptionList[i].get_title());
}
}
shared_ptr<panels::Panel>
PanelManager::create_panel_by_name(const char* class_name)
{
const int panelDescriptionCount =
sizeof(panelDescriptionList) /
sizeof(PanelDescription);
for(int i = 0; i < panelDescriptionCount; i++)
{
if(strstr(panelDescriptionList[i].get_class_name(), class_name))
return shared_ptr<panels::Panel>(panelDescriptionList[i].create(
workspaceWindow));
}
ERROR(gui, "Unable to create a panel with class name %s", class_name);
return shared_ptr<panels::Panel>();
}
} // namespace workspace
} // namespace gui

View file

@ -0,0 +1,165 @@
/*
panel-manager.hpp - Definition of the panel manager object
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file panel-manager.hpp
** This file contains the definition of the panel manager object.
**
** @see actions.hpp
*/
#ifndef PANEL_MANAGER_HPP
#define PANEL_MANAGER_HPP
#include <libgdl-1.0/gdl/gdl.h>
#include "../panels/panel.hpp"
using namespace gui::panels;
namespace gui {
namespace workspace {
/**
* A class to managers DockItem objects for WorkspaceWindow.
**/
class PanelManager
{
public:
/**
* Constructor
* @param workspace_window A reference to the owner WorkspaceWindow
* object.
**/
PanelManager(WorkspaceWindow &workspace_window);
/**
* Destructor.
**/
~PanelManager();
/**
* Initializes this dock manager and creates the dock and all it's
* widgets.
* @remarks This function must be called only once as the first call
* after construction.
**/
void setup_dock();
/**
* Gets a pointer to the dock object.
* @remarks Note that this must not be called before setup_dock.
**/
GdlDock* get_dock() const;
GdlDockBar* get_dock_bar() const;
private:
void create_panels();
boost::shared_ptr<panels::Panel> create_panel_by_name(
const char* class_name);
private:
WorkspaceWindow &workspaceWindow;
GdlDock *dock;
GdlDockBar *dockBar;
GdlDockLayout *dockLayout;
GdlDockPlaceholder *dockPlaceholders[4];
std::list< boost::shared_ptr<panels::Panel> > panels;
private:
/**
* A class to describe and instantiate Panel types.
**/
class PanelDescription
{
protected:
PanelDescription(const char* class_name, const char *title,
boost::shared_ptr<panels::Panel> (*const create_panel_proc)(
WorkspaceWindow&)) :
className(class_name),
titleName(title),
createPanelProc(create_panel_proc)
{
REQUIRE(className);
REQUIRE(titleName);
}
public:
const char* get_class_name() const
{
ENSURE(className);
return className;
}
const char* get_title() const
{
ENSURE(titleName);
return titleName;
}
boost::shared_ptr<panels::Panel> create(
WorkspaceWindow& owner_window) const
{
REQUIRE(createPanelProc);
return createPanelProc(owner_window);
}
private:
const char* className;
const char* titleName;
boost::shared_ptr<panels::Panel> (*const createPanelProc)(
WorkspaceWindow&);
};
template<class P> class Panel : public PanelDescription
{
public:
Panel() :
PanelDescription(typeid(P).name(), P::get_title(),
Panel::create_panel)
{}
private:
static boost::shared_ptr<panels::Panel> create_panel(
WorkspaceWindow &workspace_window)
{
return boost::shared_ptr<panels::Panel>(
new P(workspace_window));
}
};
static const PanelDescription panelDescriptionList[];
};
} // namespace workspace
} // namespace gui
#endif // PANEL_MANAGER_HPP

View file

@ -47,27 +47,14 @@ WorkspaceWindow::WorkspaceWindow(Project &source_project,
gui::controller::Controller &source_controller) :
project(source_project),
controller(source_controller),
panelManager(*this),
actions(*this)
{
layout = NULL;
resourcesPanel = NULL;
viewerPanel = NULL;
timelinePanel = NULL;
create_ui();
}
WorkspaceWindow::~WorkspaceWindow()
{
REQUIRE(layout != NULL);
g_object_unref(layout);
REQUIRE(resourcesPanel != NULL);
resourcesPanel->unreference();
REQUIRE(viewerPanel != NULL);
viewerPanel->unreference();
REQUIRE(timelinePanel != NULL);
timelinePanel->unreference();
}
Project&
@ -162,50 +149,16 @@ WorkspaceWindow::create_ui()
toolbar->set_toolbar_style(TOOLBAR_ICONS);
baseContainer.pack_start(*toolbar, Gtk::PACK_SHRINK);
//----- Create the Panels -----//
resourcesPanel = new ResourcesPanel(*this);
ENSURE(resourcesPanel != NULL);
viewerPanel = new ViewerPanel(*this);
ENSURE(viewerPanel != NULL);
timelinePanel = new TimelinePanel(*this);
ENSURE(timelinePanel != NULL);
//----- Create the Dock -----//
dock = Glib::wrap(gdl_dock_new());
//----- Create the Docks -----//
panelManager.setup_dock();
layout = gdl_dock_layout_new((GdlDock*)dock->gobj());
GdlDock const *dock = panelManager.get_dock();
dockbar = Glib::wrap(gdl_dock_bar_new ((GdlDock*)dock->gobj()));
dockContainer.pack_start(*dockbar, PACK_SHRINK);
dockContainer.pack_end(*dock, PACK_EXPAND_WIDGET);
gtk_box_pack_start(GTK_BOX(dockContainer.gobj()),
GTK_WIDGET(panelManager.get_dock_bar()), FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(dockContainer.gobj()),
GTK_WIDGET(dock), TRUE, TRUE, 0);
baseContainer.pack_start(dockContainer, PACK_EXPAND_WIDGET);
gdl_dock_add_item ((GdlDock*)dock->gobj(),
resourcesPanel->get_dock_item(), GDL_DOCK_LEFT);
gdl_dock_add_item ((GdlDock*)dock->gobj(),
viewerPanel->get_dock_item(), GDL_DOCK_RIGHT);
gdl_dock_add_item ((GdlDock*)dock->gobj(),
timelinePanel->get_dock_item(), GDL_DOCK_BOTTOM);
// Manually dock and move around some of the items
gdl_dock_item_dock_to (timelinePanel->get_dock_item(),
resourcesPanel->get_dock_item(), GDL_DOCK_BOTTOM, -1);
gdl_dock_item_dock_to (viewerPanel->get_dock_item(),
resourcesPanel->get_dock_item(), GDL_DOCK_RIGHT, -1);
gchar ph1[] = "ph1";
gdl_dock_placeholder_new (ph1, (GdlDockObject*)dock->gobj(),
GDL_DOCK_TOP, FALSE);
gchar ph2[] = "ph2";
gdl_dock_placeholder_new (ph2, (GdlDockObject*)dock->gobj(),
GDL_DOCK_BOTTOM, FALSE);
gchar ph3[] = "ph3";
gdl_dock_placeholder_new (ph3, (GdlDockObject*)dock->gobj(),
GDL_DOCK_LEFT, FALSE);
gchar ph4[] = "ph4";
gdl_dock_placeholder_new (ph4, (GdlDockObject*)dock->gobj(),
GDL_DOCK_RIGHT, FALSE);
//----- Create the status bar -----//
statusBar.set_has_resize_grip();

View file

@ -30,9 +30,9 @@
#define WORKSPACE_WINDOW_HPP
#include <gtkmm.h>
#include <libgdl-1.0/gdl/gdl-dock-layout.h>
#include "actions.hpp"
#include "panel-manager.hpp"
#include "../panels/resources-panel.hpp"
#include "../panels/viewer-panel.hpp"
@ -84,19 +84,10 @@ private:
Gtk::VBox baseContainer;
Gtk::HBox dockContainer;
//----- Dock Frame -----//
Gtk::Widget *dock;
Gtk::Widget *dockbar;
GdlDockLayout *layout;
PanelManager panelManager;
//----- Status Bar -----//
Gtk::Statusbar statusBar;
/* ===== Panels ===== */
private:
ResourcesPanel *resourcesPanel;
ViewerPanel *viewerPanel;
TimelinePanel *timelinePanel;
/* ===== Helpers ===== */
private: