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