1 /* === S Y N F I G ========================================================= */
2 /*! \file dialog_keyframe.cpp
3 ** \brief Keyframe properties dialog implementation
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 ** \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 # include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31
32 #include <synfig/general.h>
33
34 #include "dialogs/dialog_keyframe.h"
35 #include <gtkmm/scrolledwindow.h>
36 #include <gtkmm/button.h>
37 #include "widgets/widget_waypointmodel.h"
38 #include <synfigapp/action.h>
39 #include <synfigapp/instance.h>
40
41 #include <gui/localization.h>
42
43 #endif
44
45 /* === U S I N G =========================================================== */
46
47 using namespace std;
48 using namespace etl;
49 using namespace synfig;
50 using namespace studio;
51
52 /* === M A C R O S ========================================================= */
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
Dialog_Keyframe(Gtk::Window & parent,etl::handle<synfigapp::CanvasInterface> canvas_interface)60 Dialog_Keyframe::Dialog_Keyframe(Gtk::Window& parent, etl::handle<synfigapp::CanvasInterface> canvas_interface):
61 Gtk::Dialog(_("Keyframe Dialog"),parent),
62 canvas_interface(canvas_interface)
63 {
64 // Set up the buttons
65 {
66 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
67 ok_button->show();
68 add_action_widget(*ok_button,2);
69 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Keyframe::on_ok_pressed));
70
71 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
72 apply_button->show();
73 add_action_widget(*apply_button,1);
74 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Keyframe::on_apply_pressed));
75
76 Gtk::Button *delete_button(manage(new class Gtk::Button(Gtk::StockID("gtk-delete"))));
77 delete_button->show();
78 add_action_widget(*delete_button,3);
79 delete_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Keyframe::on_delete_pressed));
80
81 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
82 cancel_button->show();
83 add_action_widget(*cancel_button,0);
84 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Keyframe::hide));
85 }
86
87 Gtk::Grid *grid=manage(new Gtk::Grid());
88 grid->set_row_spacing(6);
89 grid->set_column_spacing(12);
90
91 get_content_area()->add(*grid);
92
93 // Allow setting descriptions for keyframes
94 entry_description.set_text("");
95 grid->attach(*manage(new Gtk::Label(_("Description :"))), 0, 0, 1, 1);
96 grid->attach(entry_description, 1, 0, 3, 1);
97 entry_description.set_hexpand(true);
98
99 // Allow toggling active status for keyframes
100 grid->attach(*manage(new Gtk::Label(_("Active :"))), 4, 0, 1, 1);
101 grid->attach(entry_toogle, 5, 0, 1, 1);
102
103 widget_waypoint_model=Gtk::manage(new Widget_WaypointModel());
104 widget_waypoint_model->show();
105 grid->attach(*widget_waypoint_model, 0, 1, 6, 2);
106
107 grid->show_all();
108 }
109
~Dialog_Keyframe()110 Dialog_Keyframe::~Dialog_Keyframe()
111 {
112 }
113
114 const synfig::Keyframe&
get_keyframe() const115 Dialog_Keyframe::get_keyframe()const
116 {
117 return keyframe_;
118 }
119
120 void
set_keyframe(const synfig::Keyframe & x)121 Dialog_Keyframe::set_keyframe(const synfig::Keyframe& x)
122 {
123 keyframe_=x;
124 entry_description.set_text(keyframe_.get_description());
125 entry_toogle.set_active(keyframe_.active());
126
127 widget_waypoint_model->reset_waypoint_model();
128
129 if (keyframe_.has_model())
130 {
131 // TODO operator = for wp::model ?
132 widget_waypoint_model->set_waypoint_model(keyframe_.get_waypoint_model());
133 }
134 }
135
136 void
on_ok_pressed()137 Dialog_Keyframe::on_ok_pressed()
138 {
139 on_apply_pressed();
140 hide();
141 }
142
143
144 void
on_delete_pressed()145 Dialog_Keyframe::on_delete_pressed()
146 {
147 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeRemove"));
148
149 assert(action);
150
151 action->set_param("canvas",canvas_interface->get_canvas());
152 action->set_param("canvas_interface",canvas_interface);
153 action->set_param("keyframe",keyframe_);
154 action->set_param("model",widget_waypoint_model->get_waypoint_model());
155
156 if(canvas_interface->get_instance()->perform_action(action))
157 {
158 hide();
159 }
160 }
161
162
163 void
on_apply_pressed()164 Dialog_Keyframe::on_apply_pressed()
165 {
166 //! Set the new description if needed
167 if(entry_description.get_text() != keyframe_.get_description())
168 {
169 keyframe_.set_description(entry_description.get_text());
170
171 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeSet"));
172 assert(action);
173
174 action->set_param("canvas",canvas_interface->get_canvas());
175 action->set_param("canvas_interface",canvas_interface);
176 action->set_param("keyframe",keyframe_);
177
178 if(!canvas_interface->get_instance()->perform_action(action))
179 {
180 }
181 }
182
183 //! Update the active status if needed
184 if(entry_toogle.get_active() != keyframe_.active())
185 {
186 keyframe_.set_active(entry_toogle.get_active());
187
188 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeToggl"));
189 assert(action);
190
191 action->set_param("canvas",canvas_interface->get_canvas());
192 action->set_param("canvas_interface",canvas_interface);
193 action->set_param("keyframe",keyframe_);
194 action->set_param("new_status",keyframe_.active ());
195
196 if(!canvas_interface->get_instance()->perform_action(action))
197 {
198 }
199 }
200
201 if(widget_waypoint_model->get_waypoint_model().is_trivial())
202 return;
203
204 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeWaypointSet"));
205
206 assert(action);
207
208 action->set_param("canvas",canvas_interface->get_canvas());
209 action->set_param("canvas_interface",canvas_interface);
210 action->set_param("keyframe",keyframe_);
211 action->set_param("model",widget_waypoint_model->get_waypoint_model());
212
213 if(!canvas_interface->get_instance()->perform_action(action))
214 {
215 }
216 }
217