Fix 1675309: CanvasView::close() was previously just hiding the canvas, not closing it.
[synfig.git] / synfig-studio / trunk / src / gtkmm / dialog_preview.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dialog_preview.cpp
3 **      \brief Preview dialog File
4 **
5 **      $Id: dialog_preview.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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 "dialog_preview.h"
33 #include "preview.h"
34 #include <gtkmm/spinbutton.h>
35 #include <gtkmm/alignment.h>
36 #include <gtkmm/frame.h>
37 #include <gtkmm/box.h>
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45 using namespace studio;
46 using namespace Gtk;
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 /* === P R O C E D U R E S ================================================= */
53
54 /* === M E T H O D S ======================================================= */
55
56 /* === E N T R Y P O I N T ================================================= */
57
58 //dialog_preview stuff...
59 Dialog_Preview::Dialog_Preview()
60 :Dialog(_("Preview Window"),false,true),
61 settings(this,"preview")
62 {
63         get_vbox()->pack_start(preview);
64 }
65
66 Dialog_Preview::~Dialog_Preview()
67 {
68 }
69
70 void Dialog_Preview::set_preview(handle<Preview>        prev)
71 {
72         get_window().clear();
73         preview.set_preview(prev);
74         //preview.update();
75 }
76
77 void Dialog_Preview::on_hide()
78 {
79         Dialog::on_hide();
80         preview.stop();
81         preview.stoprender();
82 }
83
84 //dialog_previewoptions stuff
85 Dialog_PreviewOptions::Dialog_PreviewOptions()
86 :Dialog(_("Preview Options"),false,true),
87 adj_zoom(0.5,0.1,5.0,0.1,0.2),
88 adj_fps(15,1,120,1,5),
89 check_overbegin(_("_Begin Time"),false),
90 check_overend(_("_End Time"),false),
91 settings(this,"prevoptions")
92 {
93         //framerate = 15.0f;
94         //zoom = 0.2f;
95         
96         //set the fps of the time widgets       
97         Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
98         dialogPadding->set_padding(12, 12, 12, 12);
99         get_vbox()->add(*dialogPadding);
100
101         Gtk::VBox *dialogBox = manage(new Gtk::VBox(false, 12));
102         dialogPadding->add(*dialogBox);
103
104         Gtk::Frame *generalFrame = manage(new Gtk::Frame(_("General Settings")));
105         generalFrame->set_shadow_type(Gtk::SHADOW_NONE);
106         ((Gtk::Label *) generalFrame->get_label_widget())->set_markup(_("<b>General Settings</b>"));
107         dialogBox->pack_start(*generalFrame, false, false, 0);
108
109         Gtk::Alignment *generalPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
110         generalPadding->set_padding(6, 0, 24, 0);
111         generalFrame->add(*generalPadding);
112         
113         Gtk::Table *generalTable = manage(new Gtk::Table(2, 2, false));
114         generalTable->set_row_spacings(6);
115         generalTable->set_col_spacings(12);
116         generalPadding->add(*generalTable);
117
118         Gtk::Label *zoomLabel = manage(new Gtk::Label(_("_Zoom")));
119         zoomLabel->set_alignment(0, 0.5);
120         zoomLabel->set_use_underline(TRUE);
121         Gtk::SpinButton *zoomSpinner = manage(new Gtk::SpinButton(adj_zoom, 0.1, 2));
122         zoomLabel->set_mnemonic_widget(*zoomSpinner);
123         zoomSpinner->set_alignment(1);
124         generalTable->attach(*zoomLabel, 0, 1, 0, 1, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
125         generalTable->attach(*zoomSpinner, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
126
127         Gtk::Label *fpsLabel = manage(new Gtk::Label(_("_Frames per second")));
128         fpsLabel->set_alignment(0, 0.5);
129         fpsLabel->set_use_underline(TRUE);
130         Gtk::SpinButton *fpsSpinner = manage(new Gtk::SpinButton(adj_fps, 1, 1));
131         fpsLabel->set_mnemonic_widget(*fpsSpinner);
132         fpsSpinner->set_alignment(1);
133         generalTable->attach(*fpsLabel, 0, 1, 1, 2, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
134         generalTable->attach(*fpsSpinner, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
135         
136         Gtk::Frame *timeFrame = manage(new Gtk::Frame(_("Time Settings")));
137         timeFrame->set_shadow_type(Gtk::SHADOW_NONE);
138         ((Gtk::Label *) timeFrame->get_label_widget())->set_markup(_("<b>Time Settings</b>"));
139         dialogBox->pack_start(*timeFrame, false, false, 0);
140
141         Gtk::Alignment *timePadding = manage(new Gtk::Alignment(0, 0, 1, 1));
142         timePadding->set_padding(6, 0, 24, 0);
143         timeFrame->add(*timePadding);
144
145         Gtk::Table *timeTable = manage(new Gtk::Table(2, 2, false));
146         timeTable->set_row_spacings(6);
147         timeTable->set_col_spacings(12);
148         timePadding->add(*timeTable);
149         
150         check_overbegin.set_alignment(0, 0.5);
151         check_overbegin.set_use_underline(TRUE);
152         check_overend.set_alignment(0, 0.5);
153         check_overend.set_use_underline(TRUE);
154         time_begin.set_alignment(1);
155         time_end.set_alignment(1);
156         timeTable->attach(check_overbegin, 0, 1, 0, 1, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
157         timeTable->attach(time_begin, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
158         timeTable->attach(check_overend, 0, 1, 1, 2, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
159         timeTable->attach(time_end, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
160         
161         check_overbegin.signal_toggled().connect(sigc::mem_fun(*this,&Dialog_PreviewOptions::on_overbegin_toggle));
162         check_overend.signal_toggled().connect(sigc::mem_fun(*this,&Dialog_PreviewOptions::on_overend_toggle));
163                 
164         Gtk::Button *cancelButton = manage(new Gtk::Button(Gtk::StockID("gtk-cancel")));
165         cancelButton->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_PreviewOptions::on_cancel_pressed));
166         add_action_widget(*cancelButton, 1);
167
168         Gtk::Button *okbutton = manage(new Gtk::Button(Gtk::StockID("gtk-go-forward")));
169         okbutton->set_label(_("Preview"));
170         okbutton->signal_clicked().connect(sigc::mem_fun(*this,&Dialog_PreviewOptions::on_ok_pressed));
171         add_action_widget(*okbutton, 0);
172         
173         time_begin.set_sensitive(false);
174         time_end.set_sensitive(false);
175         show_all();
176 }
177
178 Dialog_PreviewOptions::~Dialog_PreviewOptions()
179 {
180 }
181
182 void Dialog_PreviewOptions::on_ok_pressed()
183 {
184         PreviewInfo     i;
185         i.zoom = get_zoom();
186         i.fps = get_fps();
187         i.overbegin = get_begin_override();
188         i.overend = get_end_override();
189         if(i.overbegin) i.begintime = (float)get_begintime();
190         if(i.overend)   i.endtime = (float)get_endtime();
191         
192         hide();
193         signal_finish_(i);
194         signal_finish_.clear();
195 }
196
197 void
198 Dialog_PreviewOptions::on_cancel_pressed()
199 {
200         hide();
201 }
202
203 void Dialog_PreviewOptions::on_overbegin_toggle()
204 {
205         time_begin.set_sensitive(get_begin_override());
206 }
207
208 void Dialog_PreviewOptions::on_overend_toggle()
209 {
210         time_end.set_sensitive(get_end_override());
211 }
212
213 void studio::Dialog_PreviewOptions::set_global_fps(float f) 
214
215         globalfps = f; 
216         time_begin.set_fps(f); 
217         time_end.set_fps(f);
218 }