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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "keyframetree.h"
33 #include "cellrenderer_time.h"
34 #include <gtkmm/treemodelsort.h>
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
46 using namespace studio;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 KeyframeTree::KeyframeTree()
58 const KeyframeTreeStore::Model model;
61 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time")) );
63 cell_renderer_time = Gtk::manage( new CellRenderer_Time() );
64 column->pack_start(*cell_renderer_time,true);
65 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_id(COLUMNID_TIME);
73 column->set_sort_column_id(model.time);
75 append_column(*column);
79 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Length")) );
81 cell_renderer_time_delta = Gtk::manage( new CellRenderer_Time() );
82 column->pack_start(*cell_renderer_time_delta,true);
83 column->add_attribute(cell_renderer_time_delta->property_time(), model.time_delta);
85 cell_renderer_time_delta->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_time_delta));
87 column->set_reorderable();
88 column->set_resizable();
90 column->set_sort_column_id(model.time_delta);
92 column->set_clickable(false);
94 append_column(*column);
98 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
100 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
101 column->pack_start(*cell_renderer_jump,true);
103 cell_renderer_jump->property_text()=_("(JMP)");
104 cell_renderer_jump->property_foreground()="#003a7f";
106 column->set_reorderable();
107 column->set_resizable();
109 column->set_sort_column_id(COLUMNID_JUMP);
111 column->set_clickable(false);
113 append_column(*column);
116 //append_column_editable(_("Description"),model.description);
118 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Description")) );
120 cell_renderer_description=Gtk::manage(new Gtk::CellRendererText());
121 column->pack_start(*cell_renderer_description,true);
122 column->add_attribute(cell_renderer_description->property_text(), model.description);
123 cell_renderer_description->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_description));
125 column->set_reorderable();
126 column->set_resizable();
127 column->set_clickable();
128 //column->set_sort_column_id(COLUMNID_DESCRIPTION);
129 column->set_sort_column_id(model.description);
131 append_column(*column);
134 set_enable_search(true);
135 set_search_column(model.description);
137 // This makes things easier to read.
140 // Make us more sensitive to several events
141 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
144 KeyframeTree::~KeyframeTree()
146 synfig::info("KeyframeTree::~KeyframeTree(): deleted");
150 KeyframeTree::on_rend_desc_changed()
152 cell_renderer_time->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
157 KeyframeTree::set_model(Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store)
159 keyframe_tree_store_=keyframe_tree_store;
160 KeyframeTreeStore::Model model;
164 Glib::RefPtr<Gtk::TreeModelSort> sorted_store(Gtk::TreeModelSort::create(keyframe_tree_store_));
165 sorted_store->set_default_sort_func(sigc::ptr_fun(&studio::KeyframeTreeStore::time_sorter));
166 sorted_store->set_sort_func(model.time.index(),sigc::ptr_fun(&studio::KeyframeTreeStore::time_sorter));
167 sorted_store->set_sort_column_id(model.time.index(), Gtk::SORT_ASCENDING);
168 Gtk::TreeView::set_model(sorted_store);
171 Gtk::TreeView::set_model(keyframe_tree_store);
173 keyframe_tree_store_->canvas_interface()->signal_rend_desc_changed().connect(
176 &studio::KeyframeTree::on_rend_desc_changed
179 cell_renderer_time->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
180 cell_renderer_time_delta->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
184 KeyframeTree::set_editable(bool x)
190 cell_renderer_time->property_editable()=true;
191 cell_renderer_time_delta->property_editable()=true;
192 cell_renderer_description->property_editable()=true;
196 cell_renderer_time->property_editable()=false;
197 cell_renderer_time_delta->property_editable()=false;
198 cell_renderer_description->property_editable()=false;
203 KeyframeTree::on_edited_time(const Glib::ustring&path_string,synfig::Time time)
205 Gtk::TreePath path(path_string);
207 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
209 synfig::Keyframe keyframe(row[model.keyframe]);
210 if(time!=keyframe.get_time())
212 row[model.time]=time;
213 //keyframe.set_time(time);
214 //signal_edited_time()(keyframe,time);
215 //signal_edited()(keyframe);
220 KeyframeTree::on_edited_time_delta(const Glib::ustring&path_string,synfig::Time time)
222 Gtk::TreePath path(path_string);
224 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
226 if(row)row[model.time_delta]=time;
230 KeyframeTree::on_edited_description(const Glib::ustring&path_string,const Glib::ustring &desc)
232 Gtk::TreePath path(path_string);
234 const Gtk::TreeRow row = *(get_model()->get_iter(path));
236 const synfig::String description(desc);
237 synfig::Keyframe keyframe(row[model.keyframe]);
238 if(description!=keyframe.get_description())
240 row[model.description]=desc;
241 keyframe.set_description(description);
242 signal_edited_description()(keyframe,description);
243 signal_edited()(keyframe);
248 KeyframeTree::on_event(GdkEvent *event)
252 case GDK_BUTTON_PRESS:
254 Gtk::TreeModel::Path path;
255 Gtk::TreeViewColumn *column;
257 int wx(round_to_int(event->button.x)),wy(round_to_int(event->button.y));
258 //tree_to_widget_coords (,, wx, wy);
261 path, // TreeModel::Path&
262 column, //TreeViewColumn*&
263 cell_x,cell_y //int&cell_x,int&cell_y
266 const Gtk::TreeRow row = *(get_model()->get_iter(path));
268 signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
269 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
271 keyframe_tree_store_->canvas_interface()->set_time(row[model.time]);
275 case GDK_2BUTTON_PRESS:
277 Gtk::TreeModel::Path path;
278 Gtk::TreeViewColumn *column;
281 int(event->button.x),int(event->button.y), // x, y
282 path, // TreeModel::Path&
283 column, //TreeViewColumn*&
284 cell_x,cell_y //int&cell_x,int&cell_y
287 const Gtk::TreeRow row = *(get_model()->get_iter(path));
290 keyframe_tree_store_->canvas_interface()->set_time(row[model.time]);
296 case GDK_BUTTON_RELEASE: