Move things round a bit.
[dcpomatic.git] / src / gtk / dcp_range_dialog.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "dcp_range_dialog.h"
21 #include "lib/film.h"
22
23 DCPRangeDialog::DCPRangeDialog (Film* f)
24         : _film (f)
25         , _whole ("Whole film")
26         , _first ("First")
27         , _cut ("Cut remainder")
28         , _black_out ("Black-out remainder")
29 {
30         set_title ("DCP range");
31
32         Gtk::Table* table = Gtk::manage (new Gtk::Table ());
33         table->set_border_width (6);
34         table->set_row_spacings (6);
35         table->set_col_spacings (6);
36         table->attach (_whole, 0, 4, 0, 1);
37         table->attach (_first, 0, 1, 1, 2);
38         table->attach (_n_frames, 1, 2, 1, 2);
39         table->attach (*manage (new Gtk::Label ("frames")), 2, 3, 1, 2);
40         table->attach (_cut, 1, 2, 2, 3);
41         table->attach (_black_out, 1, 2, 3, 4);
42
43         Gtk::RadioButtonGroup g = _whole.get_group ();
44         _first.set_group (g);
45
46         g = _black_out.get_group ();
47         _cut.set_group (g);
48
49         _n_frames.set_range (1, INT_MAX - 1);
50         _n_frames.set_increments (24, 24 * 60);
51         if (_film->dcp_frames() > 0) {
52                 _whole.set_active (false);
53                 _first.set_active (true);
54                 _n_frames.set_value (_film->dcp_frames ());
55         } else {
56                 _whole.set_active (true);
57                 _first.set_active (false);
58                 _n_frames.set_value (24);
59         }
60
61         _black_out.set_active (_film->dcp_trim_action() == BLACK_OUT);
62         _cut.set_active (_film->dcp_trim_action() == CUT);
63
64         _whole.signal_toggled().connect (sigc::mem_fun (*this, &DCPRangeDialog::whole_toggled));
65         _cut.signal_toggled().connect (sigc::mem_fun (*this, &DCPRangeDialog::cut_toggled));
66         _n_frames.signal_value_changed().connect (sigc::mem_fun (*this, &DCPRangeDialog::n_frames_changed));
67
68         get_vbox()->pack_start (*table);
69
70         add_button ("Close", Gtk::RESPONSE_CLOSE);
71         show_all_children ();
72
73         set_sensitivity ();
74 }
75
76 void
77 DCPRangeDialog::whole_toggled ()
78 {
79         set_sensitivity ();
80         emit_changed ();
81 }
82
83 void
84 DCPRangeDialog::set_sensitivity ()
85 {
86         _n_frames.set_sensitive (_first.get_active ());
87         _black_out.set_sensitive (_first.get_active ());
88         _cut.set_sensitive (_first.get_active ());
89 }
90
91 void
92 DCPRangeDialog::cut_toggled ()
93 {
94         emit_changed ();
95 }
96
97 void
98 DCPRangeDialog::n_frames_changed ()
99 {
100         emit_changed ();
101 }
102
103 void
104 DCPRangeDialog::emit_changed ()
105 {
106         int frames = 0;
107         if (!_whole.get_active ()) {
108                 frames = _n_frames.get_value_as_int ();
109         }
110
111         TrimAction action = CUT;
112         if (_black_out.get_active ()) {
113                 action = BLACK_OUT;
114         }
115
116         Changed (frames, action);
117 }