1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframetree.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "keyframetree.h"
34 #include "cellrenderer_time.h"
35 #include <gtkmm/treemodelsort.h>
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
47 using namespace studio;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 KeyframeTree::KeyframeTree()
59 const KeyframeTreeStore::Model model;
62 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time")) );
64 cell_renderer_time = Gtk::manage( new CellRenderer_Time() );
65 column->pack_start(*cell_renderer_time,true);
66 column->add_attribute(cell_renderer_time->property_time(), model.time);
67 cell_renderer_time->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_time));
69 column->set_reorderable();
70 column->set_resizable();
71 column->set_clickable();
72 column->set_sort_column(model.time);
74 append_column(*column);
77 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Length")) );
79 cell_renderer_time_delta = Gtk::manage( new CellRenderer_Time() );
80 column->pack_start(*cell_renderer_time_delta,true);
81 column->add_attribute(cell_renderer_time_delta->property_time(), model.time_delta);
82 cell_renderer_time_delta->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_time_delta));
84 column->set_reorderable();
85 column->set_resizable();
86 column->set_clickable(false);
87 // column->set_sort_column(model.time_delta);
89 append_column(*column);
92 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
94 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
95 column->pack_start(*cell_renderer_jump,true);
96 cell_renderer_jump->property_text()=_("(JMP)");
97 cell_renderer_jump->property_foreground()="#003a7f";
99 column->set_reorderable();
100 column->set_resizable();
101 column->set_clickable(false);
102 column->set_sort_column(COLUMNID_JUMP); // without this, (JMP) needs a double click?!
104 append_column(*column);
106 // append_column_editable(_("Description"),model.description);
108 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Description")) );
110 cell_renderer_description=Gtk::manage(new Gtk::CellRendererText());
111 column->pack_start(*cell_renderer_description,true);
112 column->add_attribute(cell_renderer_description->property_text(), model.description);
113 cell_renderer_description->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_description));
115 column->set_reorderable();
116 column->set_resizable();
117 column->set_clickable();
118 column->set_sort_column(model.description);
120 append_column(*column);
123 set_enable_search(true);
124 set_search_column(model.description);
126 // This makes things easier to read.
129 // Make us more sensitive to several events
130 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
133 KeyframeTree::~KeyframeTree()
135 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
136 synfig::info("KeyframeTree::~KeyframeTree(): Deleted");
140 KeyframeTree::on_rend_desc_changed()
142 cell_renderer_time->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
147 KeyframeTree::set_model(Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store)
149 keyframe_tree_store_=keyframe_tree_store;
150 KeyframeTreeStore::Model model;
154 Glib::RefPtr<Gtk::TreeModelSort> sorted_store(Gtk::TreeModelSort::create(keyframe_tree_store_));
155 sorted_store->set_default_sort_func(sigc::ptr_fun(&studio::KeyframeTreeStore::time_sorter));
156 sorted_store->set_sort_func(model.time, sigc::ptr_fun(&studio::KeyframeTreeStore::time_sorter));
157 sorted_store->set_sort_func(model.description, sigc::ptr_fun(&studio::KeyframeTreeStore::description_sorter));
158 Gtk::TreeView::set_model(sorted_store);
161 Gtk::TreeView::set_model(keyframe_tree_store);
163 keyframe_tree_store_->canvas_interface()->signal_rend_desc_changed().connect(
166 &studio::KeyframeTree::on_rend_desc_changed
169 cell_renderer_time->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
170 cell_renderer_time_delta->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
174 KeyframeTree::set_editable(bool x)
180 cell_renderer_time->property_editable()=true;
181 cell_renderer_time_delta->property_editable()=true;
182 cell_renderer_description->property_editable()=true;
186 cell_renderer_time->property_editable()=false;
187 cell_renderer_time_delta->property_editable()=false;
188 cell_renderer_description->property_editable()=false;
193 KeyframeTree::on_edited_time(const Glib::ustring&path_string,synfig::Time time)
195 Gtk::TreePath path(path_string);
197 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
199 synfig::Keyframe keyframe(row[model.keyframe]);
200 if(time!=keyframe.get_time())
202 row[model.time]=time;
203 //keyframe.set_time(time);
204 //signal_edited_time()(keyframe,time);
205 //signal_edited()(keyframe);
210 KeyframeTree::on_edited_time_delta(const Glib::ustring&path_string,synfig::Time time)
212 Gtk::TreePath path(path_string);
214 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
216 if(row)row[model.time_delta]=time;
220 KeyframeTree::on_edited_description(const Glib::ustring&path_string,const Glib::ustring &desc)
222 Gtk::TreePath path(path_string);
224 const Gtk::TreeRow row = *(get_model()->get_iter(path));
226 const synfig::String description(desc);
227 synfig::Keyframe keyframe(row[model.keyframe]);
228 if(description!=keyframe.get_description())
230 row[model.description]=desc;
231 keyframe.set_description(description);
232 signal_edited_description()(keyframe,description);
233 signal_edited()(keyframe);
238 KeyframeTree::on_event(GdkEvent *event)
242 case GDK_BUTTON_PRESS:
244 Gtk::TreeModel::Path path;
245 Gtk::TreeViewColumn *column;
247 int wx(round_to_int(event->button.x)),wy(round_to_int(event->button.y));
248 //tree_to_widget_coords (,, wx, wy);
251 path, // TreeModel::Path&
252 column, //TreeViewColumn*&
253 cell_x,cell_y //int&cell_x,int&cell_y
256 const Gtk::TreeRow row = *(get_model()->get_iter(path));
258 signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
259 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
261 keyframe_tree_store_->canvas_interface()->set_time(row[model.time]);
265 case GDK_2BUTTON_PRESS:
267 Gtk::TreeModel::Path path;
268 Gtk::TreeViewColumn *column;
271 int(event->button.x),int(event->button.y), // x, y
272 path, // TreeModel::Path&
273 column, //TreeViewColumn*&
274 cell_x,cell_y //int&cell_x,int&cell_y
277 const Gtk::TreeRow row = *(get_model()->get_iter(path));
280 keyframe_tree_store_->canvas_interface()->set_time(row[model.time]);
286 case GDK_BUTTON_RELEASE: