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