C++11 tidying.
[dcpomatic.git] / src / wx / filter_dialog.cc
index ac3e354045718516f97109a6b55a1c4c408511bf..3dbb482364bcd6e221e82b88fe99be6c6585f7f5 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 /** @file  src/filter_dialog.cc
  *  @brief A dialog to select FFmpeg filters.
  */
 
-#include "lib/film.h"
+
+#include "check_box.h"
 #include "filter_dialog.h"
-#include "filter_editor.h"
+#include "static_text.h"
+#include "wx_util.h"
+#include "lib/film.h"
+#include "lib/filter.h"
+
 
 using namespace std;
 using boost::bind;
 
-FilterDialog::FilterDialog (wxWindow* parent, vector<Filter const *> const & f)
-       : wxDialog (parent, wxID_ANY, wxString (_("Filters")))
-       , _filters (new FilterEditor (this, f))
+
+FilterDialog::FilterDialog (wxWindow* parent, vector<Filter const *> const & active)
+       : wxDialog (parent, wxID_ANY, wxString(_("Filters")))
 {
-       wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
-       sizer->Add (_filters, 1, wxEXPAND | wxALL, 6);
+       auto panel = new wxPanel (this);
+       auto sizer = new wxBoxSizer (wxVERTICAL);
+
+       auto filters = Filter::all ();
+
+       map<string, list<Filter const *>> categories;
+
+       for (auto i: filters) {
+               auto j = categories.find (i->category());
+               if (j == categories.end ()) {
+                       categories[i->category()] = { i };
+               } else {
+                       j->second.push_back (i);
+               }
+       }
+
+       for (auto const& i: categories) {
+               auto c = new StaticText (panel, std_to_wx(i.first));
+               auto font = c->GetFont();
+               font.SetWeight(wxFONTWEIGHT_BOLD);
+               c->SetFont(font);
+               sizer->Add (c, 1, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
 
-       _filters->ActiveChanged.connect (bind (&FilterDialog::active_changed, this));
+               for (auto j: i.second) {
+                       auto b = new CheckBox(panel, std_to_wx(j->name()));
+                       bool const a = find (active.begin(), active.end(), j) != active.end();
+                       b->SetValue (a);
+                       _filters[j] = b;
+                       b->Bind (wxEVT_CHECKBOX, boost::bind(&FilterDialog::filter_toggled, this));
+                       sizer->Add (b);
+               }
 
-       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
+               sizer->AddSpacer (6);
+       }
+
+       auto buttons = CreateSeparatedButtonSizer (wxOK);
        if (buttons) {
                sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
        }
 
-       SetSizer (sizer);
-       sizer->Layout ();
-       sizer->SetSizeHints (this);
+       panel->SetSizer (sizer);
+
+       auto overall_sizer = new wxBoxSizer (wxVERTICAL);
+       overall_sizer->Add (panel, 1, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
+       SetSizerAndFit (overall_sizer);
 }
 
 
 void
-FilterDialog::active_changed ()
+FilterDialog::filter_toggled ()
+{
+       ActiveChanged (active());
+}
+
+
+vector<Filter const*>
+FilterDialog::active () const
 {
-       ActiveChanged (_filters->active ());
+       vector<Filter const *> active;
+       for (auto const& i: _filters) {
+               if (i.second->IsChecked()) {
+                       active.push_back(i.first);
+               }
+       }
+
+       return active;
 }
+