Extract common code out into kdm_for_screen()
[dcpomatic.git] / src / wx / kdm_advanced_dialog.cc
1 /*
2     Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "kdm_advanced_dialog.h"
22 #include "check_box.h"
23 #include "wx_util.h"
24 #include <wx/spinctrl.h>
25
26 using boost::optional;
27
28 KDMAdvancedDialog::KDMAdvancedDialog (wxWindow* parent, bool forensic_mark_video, bool forensic_mark_audio, optional<int> forensic_mark_audio_up_to)
29         : TableDialog (parent, _("Advanced KDM options"), 2, 1, false)
30 {
31         _forensic_mark_video = new CheckBox (this, _("Forensically mark video"));
32         _forensic_mark_video->SetValue (forensic_mark_video);
33         add (_forensic_mark_video);
34         add_spacer ();
35         _forensic_mark_audio = new CheckBox (this, _("Forensically mark audio"));
36         _forensic_mark_audio->SetValue (forensic_mark_audio);
37         add (_forensic_mark_audio);
38         add_spacer ();
39
40         _forensic_mark_all_audio = new wxRadioButton (this, wxID_ANY, _("Mark all audio channels"));
41         _table->Add (_forensic_mark_all_audio, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_GAP);
42         add_spacer ();
43         wxBoxSizer* hbox = new wxBoxSizer (wxHORIZONTAL);
44         _forensic_mark_some_audio = new wxRadioButton (this, wxID_ANY, _("Mark audio channels up to (and including)"));
45         hbox->Add (_forensic_mark_some_audio, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
46         _forensic_mark_audio_up_to = new wxSpinCtrl (this, wxID_ANY);
47         hbox->Add (_forensic_mark_audio_up_to, 0, wxRIGHT, DCPOMATIC_SIZER_X_GAP);
48         _table->Add (hbox, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
49         add_spacer ();
50
51         if (forensic_mark_audio_up_to) {
52                 _forensic_mark_audio_up_to->SetValue (*forensic_mark_audio_up_to);
53                 _forensic_mark_some_audio->SetValue (true);
54         }
55
56         layout ();
57         setup_sensitivity ();
58
59         _forensic_mark_audio_up_to->SetRange (1, 15);
60         _forensic_mark_audio->Bind (wxEVT_CHECKBOX, boost::bind(&KDMAdvancedDialog::setup_sensitivity, this));
61         _forensic_mark_all_audio->Bind (wxEVT_RADIOBUTTON, boost::bind(&KDMAdvancedDialog::setup_sensitivity, this));
62         _forensic_mark_some_audio->Bind (wxEVT_RADIOBUTTON, boost::bind(&KDMAdvancedDialog::setup_sensitivity, this));
63 }
64
65 bool
66 KDMAdvancedDialog::forensic_mark_video () const
67 {
68         return _forensic_mark_video->GetValue ();
69 }
70
71 bool
72 KDMAdvancedDialog::forensic_mark_audio () const
73 {
74         return _forensic_mark_audio->GetValue ();
75 }
76
77 optional<int>
78 KDMAdvancedDialog::forensic_mark_audio_up_to () const
79 {
80         if (!_forensic_mark_some_audio->GetValue()) {
81                 return optional<int>();
82         }
83
84         return _forensic_mark_audio_up_to->GetValue();
85 }
86
87 void
88 KDMAdvancedDialog::setup_sensitivity ()
89 {
90         _forensic_mark_all_audio->Enable (_forensic_mark_audio->GetValue());
91         _forensic_mark_some_audio->Enable (_forensic_mark_audio->GetValue());
92         _forensic_mark_audio_up_to->Enable (_forensic_mark_audio->GetValue() && _forensic_mark_some_audio->GetValue());
93 }