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