C++11 tidying.
[dcpomatic.git] / src / wx / filter_dialog.cc
1 /*
2     Copyright (C) 2012-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 /** @file  src/filter_dialog.cc
23  *  @brief A dialog to select FFmpeg filters.
24  */
25
26
27 #include "check_box.h"
28 #include "filter_dialog.h"
29 #include "static_text.h"
30 #include "wx_util.h"
31 #include "lib/film.h"
32 #include "lib/filter.h"
33
34
35 using namespace std;
36 using boost::bind;
37
38
39 FilterDialog::FilterDialog (wxWindow* parent, vector<Filter const *> const & active)
40         : wxDialog (parent, wxID_ANY, wxString(_("Filters")))
41 {
42         auto panel = new wxPanel (this);
43         auto sizer = new wxBoxSizer (wxVERTICAL);
44
45         auto filters = Filter::all ();
46
47         map<string, list<Filter const *>> categories;
48
49         for (auto i: filters) {
50                 auto j = categories.find (i->category());
51                 if (j == categories.end ()) {
52                         categories[i->category()] = { i };
53                 } else {
54                         j->second.push_back (i);
55                 }
56         }
57
58         for (auto const& i: categories) {
59                 auto c = new StaticText (panel, std_to_wx(i.first));
60                 auto font = c->GetFont();
61                 font.SetWeight(wxFONTWEIGHT_BOLD);
62                 c->SetFont(font);
63                 sizer->Add (c, 1, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
64
65                 for (auto j: i.second) {
66                         auto b = new CheckBox(panel, std_to_wx(j->name()));
67                         bool const a = find (active.begin(), active.end(), j) != active.end();
68                         b->SetValue (a);
69                         _filters[j] = b;
70                         b->Bind (wxEVT_CHECKBOX, boost::bind(&FilterDialog::filter_toggled, this));
71                         sizer->Add (b);
72                 }
73
74                 sizer->AddSpacer (6);
75         }
76
77         auto buttons = CreateSeparatedButtonSizer (wxOK);
78         if (buttons) {
79                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
80         }
81
82         panel->SetSizer (sizer);
83
84         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
85         overall_sizer->Add (panel, 1, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
86         SetSizerAndFit (overall_sizer);
87 }
88
89
90 void
91 FilterDialog::filter_toggled ()
92 {
93         ActiveChanged (active());
94 }
95
96
97 vector<Filter const*>
98 FilterDialog::active () const
99 {
100         vector<Filter const *> active;
101         for (auto const& i: _filters) {
102                 if (i.second->IsChecked()) {
103                         active.push_back(i.first);
104                 }
105         }
106
107         return active;
108 }
109