2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "check_box.h"
23 #include "colour_conversion_editor.h"
24 #include "content_colour_conversion_dialog.h"
26 #include "lib/colour_conversion.h"
27 #include "lib/config.h"
29 #include "lib/warnings.h"
30 DCPOMATIC_DISABLE_WARNINGS
31 #include <wx/statline.h>
32 DCPOMATIC_ENABLE_WARNINGS
39 using boost::optional;
42 ContentColourConversionDialog::ContentColourConversionDialog (wxWindow* parent, bool yuv)
43 : wxDialog (parent, wxID_ANY, _("Colour conversion"))
44 , _editor (new ColourConversionEditor(this, yuv))
47 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
48 SetSizer (overall_sizer);
50 auto table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_Y_GAP - 2, DCPOMATIC_SIZER_X_GAP);
51 _preset_check = new CheckBox (this, _("Use preset"));
52 table->Add (_preset_check, 0, wxALIGN_CENTER_VERTICAL);
53 _preset_choice = new wxChoice (this, wxID_ANY);
54 table->Add (_preset_choice);
56 overall_sizer->Add (table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
57 overall_sizer->Add (new wxStaticLine (this, wxID_ANY), 0, wxEXPAND);
58 overall_sizer->Add (_editor);
60 auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
62 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
65 overall_sizer->Layout ();
66 overall_sizer->SetSizeHints (this);
68 _preset_check->Bind (wxEVT_CHECKBOX, boost::bind (&ContentColourConversionDialog::preset_check_clicked, this));
69 _preset_choice->Bind (wxEVT_CHOICE, boost::bind (&ContentColourConversionDialog::preset_choice_changed, this));
71 _editor_connection = _editor->Changed.connect (boost::bind (&ContentColourConversionDialog::check_for_preset, this));
73 for (auto const& i: PresetColourConversion::all ()) {
74 _preset_choice->Append (std_to_wx (i.name));
80 ContentColourConversionDialog::get () const
82 return _editor->get ();
87 ContentColourConversionDialog::set (ColourConversion c)
98 ContentColourConversionDialog::check_for_preset ()
104 auto preset = _editor->get().preset ();
106 _preset_check->SetValue (static_cast<bool>(preset));
107 _preset_choice->Enable (static_cast<bool>(preset));
109 _preset_choice->SetSelection (preset.get ());
111 _preset_choice->SetSelection (-1);
117 ContentColourConversionDialog::preset_check_clicked ()
119 if (_preset_check->GetValue ()) {
120 _preset_choice->SetSelection (0);
121 preset_choice_changed ();
123 _preset_choice->SetSelection (-1);
124 _preset_choice->Enable (false);
130 ContentColourConversionDialog::preset_choice_changed ()
132 auto presets = PresetColourConversion::all ();
133 int const s = _preset_choice->GetCurrentSelection();
135 set (presets[s].conversion);