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