TODO.
[dcpomatic.git] / src / wx / 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 "lib/film.h"
21 #include "dcp_range_dialog.h"
22 #include "wx_util.h"
23
24 DCPRangeDialog::DCPRangeDialog (wxWindow* p, Film* f)
25         : wxDialog (p, wxID_ANY, wxString (_("DCP Range")))
26         , _film (f)
27 {
28         wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
29
30         _whole = new wxRadioButton (this, wxID_ANY, _("Whole film"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
31         table->Add (_whole, 1);
32         table->AddSpacer (0);
33         
34         _first = new wxRadioButton (this, wxID_ANY, _("First"));
35         table->Add (_first);
36         {
37                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
38                 _n_frames = new wxSpinCtrl (this, wxID_ANY);
39                 s->Add (_n_frames);
40                 add_label_to_sizer (s, this, "frames");
41                 table->Add (s);
42         }
43
44         table->AddSpacer (0);
45         _cut = new wxRadioButton (this, wxID_ANY, _("Cut remainder"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
46         table->Add (_cut);
47
48         table->AddSpacer (0);
49         _black_out = new wxRadioButton (this, wxID_ANY, _("Black-out remainder"));
50         table->Add (_black_out);
51
52         _n_frames->SetRange (1, INT_MAX - 1);
53         if (_film->dcp_frames() > 0) {
54                 _whole->SetValue (false);
55                 _first->SetValue (true);
56                 _n_frames->SetValue (_film->dcp_frames ());
57         } else {
58                 _whole->SetValue (true);
59                 _first->SetValue (false);
60                 _n_frames->SetValue (24);
61         }
62
63         _black_out->Enable (_film->dcp_trim_action() == BLACK_OUT);
64         _cut->Enable (_film->dcp_trim_action() == CUT);
65
66         _whole->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::whole_toggled), 0, this);
67         _first->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::first_toggled), 0, this);
68         _cut->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::cut_toggled), 0, this);
69         _n_frames->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (DCPRangeDialog::n_frames_changed), 0, this);
70
71         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
72         overall_sizer->Add (table);
73         
74         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
75         if (buttons) {
76                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
77         }
78
79         SetSizer (overall_sizer);
80         overall_sizer->SetSizeHints (this);
81
82         set_sensitivity ();
83 }
84
85 void
86 DCPRangeDialog::whole_toggled (wxCommandEvent &)
87 {
88         set_sensitivity ();
89         emit_changed ();
90 }
91
92 void
93 DCPRangeDialog::first_toggled (wxCommandEvent &)
94 {
95         set_sensitivity ();
96         emit_changed ();
97 }
98
99 void
100 DCPRangeDialog::set_sensitivity ()
101 {
102         _n_frames->Enable (_first->GetValue ());
103         _black_out->Enable (_first->GetValue ());
104         _cut->Enable (_first->GetValue ());
105 }
106
107 void
108 DCPRangeDialog::cut_toggled (wxCommandEvent &)
109 {
110         set_sensitivity ();
111         emit_changed ();
112 }
113
114 void
115 DCPRangeDialog::n_frames_changed (wxCommandEvent &)
116 {
117         emit_changed ();
118 }
119
120 void
121 DCPRangeDialog::emit_changed ()
122 {
123         int frames = 0;
124         if (!_whole->GetValue ()) {
125                 frames = _n_frames->GetValue ();
126         }
127
128         TrimAction action = CUT;
129         if (_black_out->GetValue ()) {
130                 action = BLACK_OUT;
131         }
132
133         Changed (frames, action);
134 }