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>
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 KeyframeTree::KeyframeTree()
56 const KeyframeTreeStore::Model model;
59 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time")) );
61 cell_renderer_time = Gtk::manage( new CellRenderer_Time() );
62 column->pack_start(*cell_renderer_time,true);
63 column->add_attribute(cell_renderer_time->property_time(), model.time);
65 cell_renderer_time->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_time));
67 column->set_reorderable();
68 column->set_resizable();
69 column->set_clickable();
70 //column->set_sort_column_id(COLUMNID_TIME);
71 column->set_sort_column_id(model.time);
73 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);
83 cell_renderer_time_delta->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_time_delta));
85 column->set_reorderable();
86 column->set_resizable();
88 column->set_sort_column_id(model.time_delta);
90 column->set_clickable(false);
92 append_column(*column);
96 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
98 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
99 column->pack_start(*cell_renderer_jump,true);
101 cell_renderer_jump->property_text()="(JMP)";
102 cell_renderer_jump->property_foreground()="#003a7f";
104 column->set_reorderable();
105 column->set_resizable();
107 column->set_sort_column_id(COLUMNID_JUMP);
109 column->set_clickable(false);
111 append_column(*column);
114 //append_column_editable(_("Description"),model.description);
116 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Description")) );
118 cell_renderer_description=Gtk::manage(new Gtk::CellRendererText());
119 column->pack_start(*cell_renderer_description,true);
120 column->add_attribute(cell_renderer_description->property_text(), model.description);
121 cell_renderer_description->signal_edited().connect(sigc::mem_fun(*this,&studio::KeyframeTree::on_edited_description));
123 column->set_reorderable();
124 column->set_resizable();
125 column->set_clickable();
126 //column->set_sort_column_id(COLUMNID_DESCRIPTION);
127 column->set_sort_column_id(model.description);
129 append_column(*column);
132 set_enable_search(true);
133 set_search_column(model.description);
135 // This makes things easier to read.
138 // Make us more sensitive to several events
139 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
142 KeyframeTree::~KeyframeTree()
144 synfig::info("KeyframeTree::~KeyframeTree(): deleted");
148 KeyframeTree::on_rend_desc_changed()
150 cell_renderer_time->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
155 KeyframeTree::set_model(Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store)
157 keyframe_tree_store_=keyframe_tree_store;
158 KeyframeTreeStore::Model model;
162 Glib::RefPtr<Gtk::TreeModelSort> sorted_store(Gtk::TreeModelSort::create(keyframe_tree_store_));
163 sorted_store->set_default_sort_func(sigc::ptr_fun(&studio::KeyframeTreeStore::time_sorter));
164 sorted_store->set_sort_func(model.time.index(),sigc::ptr_fun(&studio::KeyframeTreeStore::time_sorter));
165 sorted_store->set_sort_column_id(model.time.index(), Gtk::SORT_ASCENDING);
166 Gtk::TreeView::set_model(sorted_store);
169 Gtk::TreeView::set_model(keyframe_tree_store);
171 keyframe_tree_store_->canvas_interface()->signal_rend_desc_changed().connect(
174 &studio::KeyframeTree::on_rend_desc_changed
177 cell_renderer_time->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
178 cell_renderer_time_delta->property_fps().set_value(keyframe_tree_store_->canvas_interface()->get_canvas()->rend_desc().get_frame_rate());
182 KeyframeTree::set_editable(bool x)
188 cell_renderer_time->property_editable()=true;
189 cell_renderer_time_delta->property_editable()=true;
190 cell_renderer_description->property_editable()=true;
194 cell_renderer_time->property_editable()=false;
195 cell_renderer_time_delta->property_editable()=false;
196 cell_renderer_description->property_editable()=false;
201 KeyframeTree::on_edited_time(const Glib::ustring&path_string,synfig::Time time)
203 Gtk::TreePath path(path_string);
205 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
207 synfig::Keyframe keyframe(row[model.keyframe]);
208 if(time!=keyframe.get_time())
210 row[model.time]=time;
211 //keyframe.set_time(time);
212 //signal_edited_time()(keyframe,time);
213 //signal_edited()(keyframe);
218 KeyframeTree::on_edited_time_delta(const Glib::ustring&path_string,synfig::Time time)
220 Gtk::TreePath path(path_string);
222 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
224 if(row)row[model.time_delta]=time;
228 KeyframeTree::on_edited_description(const Glib::ustring&path_string,const Glib::ustring &desc)
230 Gtk::TreePath path(path_string);
232 const Gtk::TreeRow row = *(get_model()->get_iter(path));
234 const synfig::String description(desc);
235 synfig::Keyframe keyframe(row[model.keyframe]);
236 if(description!=keyframe.get_description())
238 row[model.description]=desc;
239 keyframe.set_description(description);
240 signal_edited_description()(keyframe,description);
241 signal_edited()(keyframe);
246 KeyframeTree::on_event(GdkEvent *event)
250 case GDK_BUTTON_PRESS:
252 Gtk::TreeModel::Path path;
253 Gtk::TreeViewColumn *column;
255 int wx(round_to_int(event->button.x)),wy(round_to_int(event->button.y));
256 //tree_to_widget_coords (,, wx, wy);
259 path, // TreeModel::Path&
260 column, //TreeViewColumn*&
261 cell_x,cell_y //int&cell_x,int&cell_y
264 const Gtk::TreeRow row = *(get_model()->get_iter(path));
266 signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
267 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
269 keyframe_tree_store_->canvas_interface()->set_time(row[model.time]);
273 case GDK_2BUTTON_PRESS:
275 Gtk::TreeModel::Path path;
276 Gtk::TreeViewColumn *column;
279 int(event->button.x),int(event->button.y), // x, y
280 path, // TreeModel::Path&
281 column, //TreeViewColumn*&
282 cell_x,cell_y //int&cell_x,int&cell_y
285 const Gtk::TreeRow row = *(get_model()->get_iter(path));
288 keyframe_tree_store_->canvas_interface()->set_time(row[model.time]);
294 case GDK_BUTTON_RELEASE: