2 Copyright (C) 2012 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/>.
21 /** @file src/filter_dialog.cc
22 * @brief A dialog to select FFmpeg filters.
25 #include "check_box.h"
26 #include "filter_dialog.h"
27 #include "static_text.h"
30 #include "lib/filter.h"
31 #include <boost/foreach.hpp>
38 FilterDialog::FilterDialog (wxWindow* parent, vector<Filter const *> const & active)
39 : wxDialog (parent, wxID_ANY, wxString(_("Filters")))
41 wxPanel* panel = new wxPanel (this);
42 wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
44 vector<Filter const *> filters = Filter::all ();
46 typedef map<string, list<Filter const *> > CategoryMap;
47 CategoryMap categories;
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;
54 categories[i->category()] = c;
56 j->second.push_back (i);
60 for (CategoryMap::iterator i = categories.begin(); i != categories.end(); ++i) {
62 wxStaticText* c = new StaticText (panel, std_to_wx(i->first));
63 wxFont font = c->GetFont();
64 font.SetWeight(wxFONTWEIGHT_BOLD);
66 sizer->Add (c, 1, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
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();
73 b->Bind (wxEVT_CHECKBOX, boost::bind(&FilterDialog::filter_toggled, this));
80 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
82 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
85 panel->SetSizer (sizer);
87 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
88 overall_sizer->Add (panel, 1, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
89 SetSizerAndFit (overall_sizer);
94 FilterDialog::filter_toggled ()
96 ActiveChanged (active());
100 vector<Filter const*>
101 FilterDialog::active () const
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);