Move _state_timer into VideoView.
[dcpomatic.git] / src / wx / content_colour_conversion_dialog.cc
1 /*
2     Copyright (C) 2013-2018 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 "wx_util.h"
22 #include "check_box.h"
23 #include "content_colour_conversion_dialog.h"
24 #include "colour_conversion_editor.h"
25 #include "lib/colour_conversion.h"
26 #include "lib/config.h"
27 #include "lib/util.h"
28 #include <wx/statline.h>
29 #include <boost/foreach.hpp>
30 #include <iostream>
31
32 using std::string;
33 using std::vector;
34 using std::cout;
35 using boost::optional;
36
37 ContentColourConversionDialog::ContentColourConversionDialog (wxWindow* parent, bool yuv)
38         : wxDialog (parent, wxID_ANY, _("Colour conversion"))
39         , _editor (new ColourConversionEditor (this, yuv))
40         , _setting (false)
41 {
42         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
43         SetSizer (overall_sizer);
44
45         wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_Y_GAP - 2, DCPOMATIC_SIZER_X_GAP);
46         _preset_check = new CheckBox (this, _("Use preset"));
47         table->Add (_preset_check, 0, wxALIGN_CENTER_VERTICAL);
48         _preset_choice = new wxChoice (this, wxID_ANY);
49         table->Add (_preset_choice);
50
51         overall_sizer->Add (table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
52         overall_sizer->Add (new wxStaticLine (this, wxID_ANY), 0, wxEXPAND);
53         overall_sizer->Add (_editor);
54
55         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
56         if (buttons) {
57                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
58         }
59
60         overall_sizer->Layout ();
61         overall_sizer->SetSizeHints (this);
62
63         _preset_check->Bind (wxEVT_CHECKBOX, boost::bind (&ContentColourConversionDialog::preset_check_clicked, this));
64         _preset_choice->Bind (wxEVT_CHOICE, boost::bind (&ContentColourConversionDialog::preset_choice_changed, this));
65
66         _editor_connection = _editor->Changed.connect (boost::bind (&ContentColourConversionDialog::check_for_preset, this));
67
68         BOOST_FOREACH (PresetColourConversion const &i, PresetColourConversion::all ()) {
69                 _preset_choice->Append (std_to_wx (i.name));
70         }
71 }
72
73 ColourConversion
74 ContentColourConversionDialog::get () const
75 {
76         return _editor->get ();
77 }
78
79 void
80 ContentColourConversionDialog::set (ColourConversion c)
81 {
82         _setting = true;
83         _editor->set (c);
84         _setting = false;
85
86         check_for_preset ();
87 }
88
89 void
90 ContentColourConversionDialog::check_for_preset ()
91 {
92         if (_setting) {
93                 return;
94         }
95
96         optional<size_t> preset = _editor->get().preset ();
97
98         _preset_check->SetValue (static_cast<bool>(preset));
99         _preset_choice->Enable (static_cast<bool>(preset));
100         if (preset) {
101                 _preset_choice->SetSelection (preset.get ());
102         } else {
103                 _preset_choice->SetSelection (-1);
104         }
105 }
106
107 void
108 ContentColourConversionDialog::preset_check_clicked ()
109 {
110         if (_preset_check->GetValue ()) {
111                 _preset_choice->SetSelection (0);
112                 preset_choice_changed ();
113         } else {
114                 _preset_choice->SetSelection (-1);
115                 _preset_choice->Enable (false);
116         }
117 }
118
119 void
120 ContentColourConversionDialog::preset_choice_changed ()
121 {
122         vector<PresetColourConversion> presets = PresetColourConversion::all ();
123         int const s = _preset_choice->GetCurrentSelection();
124         if (s != -1) {
125                 set (presets[s].conversion);
126         }
127 }