1 /* === S Y N F I G ========================================================= */
2 /*! \file canvasoptions.cpp
3 ** \brief Template File
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 "canvasoptions.h"
35 #include <gtkmm/frame.h>
36 #include <gtkmm/table.h>
37 #include <gtkmm/label.h>
38 #include <gtkmm/notebook.h>
39 #include <gtkmm/alignment.h>
40 #include "canvasview.h"
41 #include "workarea.h"
42
43 #include <gui/localization.h>
44
45 #endif
46
47 /* === U S I N G =========================================================== */
48
49 using namespace std;
50 using namespace etl;
51 using namespace synfig;
52 using namespace studio;
53
54 /* === M A C R O S ========================================================= */
55
56 /* === G L O B A L S ======================================================= */
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
CanvasOptions(Gtk::Window & window,etl::loose_handle<CanvasView> canvas_view)62 CanvasOptions::CanvasOptions(Gtk::Window &window,etl::loose_handle<CanvasView> canvas_view):
63 Gtk::Dialog(_("Canvas Options"),window),
64 canvas_view_(canvas_view),
65 toggle_grid_snap(_("_Snap to grid"), true),
66 toggle_grid_show(_("S_how grid"), true),
67 toggle_time_snap(_("Snap to _frame"), true)
68 {
69 vector_grid_size.set_canvas(canvas_view->get_canvas());
70
71 Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
72 dialogPadding->set_padding(12, 12, 12, 12);
73
74 Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
75 dialogPadding->add(*notebook);
76
77 toggle_grid_snap.signal_toggled().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_grid_snap_toggle));
78 toggle_grid_show.signal_toggled().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_grid_show_toggle));
79
80 Gtk::Alignment *gridPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
81 gridPadding->set_padding(12, 12, 12, 12);
82 notebook->append_page(*gridPadding, _("Grid"));
83
84 Gtk::VBox *gridBox = manage(new Gtk::VBox(false, 12));
85 gridPadding->add(*gridBox);
86
87 Gtk::Table *gridTable = manage(new Gtk::Table(3, 2, false));
88 gridTable->set_row_spacings(6);
89 gridTable->set_col_spacings(12);
90 gridBox->pack_start(*gridTable, false, false, 0);
91
92 Gtk::Label *gridSizeLabel = manage(new Gtk::Label(_("_Grid size"), true));
93 gridSizeLabel->set_alignment(0, 0.5);
94 gridSizeLabel->set_mnemonic_widget(vector_grid_size);
95
96 toggle_grid_show.set_alignment(0, 0.5);
97 toggle_grid_snap.set_alignment(0, 0.5);
98
99 gridTable->attach(*gridSizeLabel, 0, 1, 0, 1, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
100 gridTable->attach(vector_grid_size, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
101 gridTable->attach(toggle_grid_show, 0, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
102 gridTable->attach(toggle_grid_snap, 0, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
103
104 Gtk::Alignment *timePadding = manage(new Gtk::Alignment(0, 0, 1, 1));
105 timePadding->set_padding(12, 12, 12, 12);
106 notebook->append_page(*timePadding, _("Time"));
107
108 Gtk::VBox *timeBox = manage(new Gtk::VBox(false, 12));
109 timePadding->add(*timeBox);
110
111 timeBox->pack_start(toggle_time_snap, false, false, 0);
112
113 Gtk::Alignment *unitPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
114 unitPadding->set_padding(12, 12, 12, 12);
115 notebook->append_page(*unitPadding, _("Units"));
116 unitPadding->add(*manage(new Gtk::Label(_("Not yet implemented!"))));
117
118 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
119 ok_button->show();
120 add_action_widget(*ok_button,2);
121 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_ok_pressed));
122
123 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
124 apply_button->show();
125 add_action_widget(*apply_button,1);
126 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_apply_pressed));
127
128 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
129 cancel_button->show();
130 add_action_widget(*cancel_button,0);
131 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_cancel_pressed));
132
133 //set_default_response(1);
134
135
136 get_vbox()->pack_start(*dialogPadding);
137 get_vbox()->show_all();
138
139 signal_show().connect(sigc::mem_fun(*this, &studio::CanvasOptions::refresh));
140
141 vector_grid_size.set_digits(5);
142
143 update_title();
144 }
145
~CanvasOptions()146 CanvasOptions::~CanvasOptions()
147 {
148 }
149
150 void
update_title()151 CanvasOptions::update_title()
152 {
153 set_title(_("Options")+String(" - ")+canvas_view_->get_canvas()->get_name());
154 }
155
156 void
refresh()157 CanvasOptions::refresh()
158 {
159 if(canvas_view_->get_work_area()->grid_status())
160 toggle_grid_show.set_active(true);
161 else
162 toggle_grid_show.set_active(false);
163
164 if(canvas_view_->get_work_area()->get_grid_snap())
165 toggle_grid_snap.set_active(true);
166 else
167 toggle_grid_snap.set_active(false);
168
169 vector_grid_size.set_value(canvas_view_->get_work_area()->get_grid_size());
170
171 toggle_time_snap.set_tooltip_text(_("Not yet implemented"));
172 toggle_time_snap.set_sensitive(false);
173
174 update_title();
175 }
176
177 void
on_grid_snap_toggle()178 CanvasOptions::on_grid_snap_toggle()
179 {
180 }
181
182 void
on_grid_show_toggle()183 CanvasOptions::on_grid_show_toggle()
184 {
185 }
186
187 void
on_apply_pressed()188 CanvasOptions::on_apply_pressed()
189 {
190 canvas_view_->set_grid_snap_toggle(toggle_grid_snap.get_active());
191 if(toggle_grid_snap.get_active())
192 canvas_view_->get_work_area()->enable_grid_snap();
193 else
194 canvas_view_->get_work_area()->disable_grid_snap();
195
196 canvas_view_->set_grid_show_toggle(toggle_grid_show.get_active());
197 if(toggle_grid_show.get_active())
198 canvas_view_->get_work_area()->enable_grid();
199 else
200 canvas_view_->get_work_area()->disable_grid();
201
202 canvas_view_->get_work_area()->set_grid_size(vector_grid_size.get_value());
203 }
204
205 void
on_ok_pressed()206 CanvasOptions::on_ok_pressed()
207 {
208 on_apply_pressed();
209 hide();
210 }
211
212 void
on_cancel_pressed()213 CanvasOptions::on_cancel_pressed()
214 {
215 refresh();
216 hide();
217 }
218