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