From f54286b03b7b653147608dcfada81f794fc80448 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 15 Nov 2020 23:16:56 +0100 Subject: [PATCH] Add LanguageTagWidget and use it for the SMPTE metadata. --- src/wx/language_tag_widget.cc | 62 +++++++++++++++++++++++++++++++++ src/wx/language_tag_widget.h | 51 +++++++++++++++++++++++++++ src/wx/smpte_metadata_dialog.cc | 57 ++++++++++++------------------ src/wx/smpte_metadata_dialog.h | 9 ++--- src/wx/wscript | 1 + 5 files changed, 141 insertions(+), 39 deletions(-) create mode 100644 src/wx/language_tag_widget.cc create mode 100644 src/wx/language_tag_widget.h diff --git a/src/wx/language_tag_widget.cc b/src/wx/language_tag_widget.cc new file mode 100644 index 000000000..592741b4d --- /dev/null +++ b/src/wx/language_tag_widget.cc @@ -0,0 +1,62 @@ +/* + Copyright (C) 2020 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + + +#include "dcpomatic_button.h" +#include "language_tag_dialog.h" +#include "language_tag_widget.h" +#include "wx_util.h" +#include + + +LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxSizer* sizer, wxString label, wxString tooltip, dcp::LanguageTag tag) + : _parent (parent) +{ + add_label_to_sizer(sizer, parent, label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL); + wxSizer* s = new wxBoxSizer (wxHORIZONTAL); + _language = new wxStaticText (parent, wxID_ANY, wxT("")); + _language->SetToolTip (tooltip); + set (tag); + s->Add (_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP); + _edit = new Button (parent, _("Edit...")); + s->Add (_edit, 0, wxLEFT, DCPOMATIC_SIZER_GAP); + sizer->Add (s, 0, wxEXPAND); + + _edit->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagWidget::edit, this)); +} + + +void +LanguageTagWidget::edit () +{ + LanguageTagDialog* d = new LanguageTagDialog(_parent, _tag); + d->ShowModal (); + set (d->get()); + Changed (d->get()); + d->Destroy (); +} + + +void +LanguageTagWidget::set (dcp::LanguageTag tag) +{ + _tag = tag; + checked_set (_language, std_to_wx(tag.to_string())); +} diff --git a/src/wx/language_tag_widget.h b/src/wx/language_tag_widget.h new file mode 100644 index 000000000..eee72f6a0 --- /dev/null +++ b/src/wx/language_tag_widget.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2020 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + + +#include +#include +#include +#include + + +class wxButton; +class wxSizer; +class wxStaticText; +class wxWindow; + + +class LanguageTagWidget : public boost::noncopyable +{ +public: + LanguageTagWidget (wxWindow* parent, wxSizer* sizer, wxString label, wxString tooltip, dcp::LanguageTag tag); + + void set (dcp::LanguageTag tag); + + boost::signals2::signal Changed; + +private: + void edit (); + + wxStaticText* _language; + wxButton* _edit; + wxWindow* _parent; + dcp::LanguageTag _tag; +}; + diff --git a/src/wx/smpte_metadata_dialog.cc b/src/wx/smpte_metadata_dialog.cc index ba45329f2..faf63d6ca 100644 --- a/src/wx/smpte_metadata_dialog.cc +++ b/src/wx/smpte_metadata_dialog.cc @@ -21,6 +21,7 @@ #include "content_version_dialog.h" #include "editable_list.h" #include "language_tag_dialog.h" +#include "language_tag_widget.h" #include "smpte_metadata_dialog.h" #include "rating_dialog.h" #include "lib/film.h" @@ -66,29 +67,21 @@ SMPTEMetadataDialog::SMPTEMetadataDialog (wxWindow* parent, weak_ptr weak_ wxFlexGridSizer* sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); sizer->AddGrowableCol (1, 1); - wxButton* edit_name_language = 0; - add_label_to_sizer(sizer, this, _("Title language"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL); - { - wxSizer* s = new wxBoxSizer (wxHORIZONTAL); - _name_language = new wxStaticText (this, wxID_ANY, wxT("")); - _name_language->SetToolTip (wxString::Format(_("The language that the film's title (\"%s\") is in"), std_to_wx(film()->name()))); - s->Add (_name_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP); - edit_name_language = new Button (this, _("Edit...")); - s->Add (edit_name_language, 0, wxLEFT, DCPOMATIC_SIZER_GAP); - sizer->Add (s, 0, wxEXPAND); - } + _name_language = new LanguageTagWidget( + this, + sizer, + _("Title language"), + wxString::Format(_("The language that the film's title (\"%s\") is in"), std_to_wx(film()->name())), + film()->name_language() + ); - wxButton* edit_audio_language = 0; - add_label_to_sizer(sizer, this, _("Audio language"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL); - { - wxSizer* s = new wxBoxSizer (wxHORIZONTAL); - _audio_language = new wxStaticText (this, wxID_ANY, wxT("")); - _audio_language->SetToolTip (_("The main language that is spoken in the film's soundtrack")); - s->Add (_audio_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP); - edit_audio_language = new Button (this, _("Edit...")); - s->Add (edit_audio_language, 0, wxLEFT, DCPOMATIC_SIZER_GAP); - sizer->Add (s, 0, wxEXPAND); - } + _audio_language = new LanguageTagWidget( + this, + sizer, + _("Audio language"), + _("The main language that is spoken in the film's soundtrack"), + film()->audio_language() + ); Button* edit_release_territory = 0; add_label_to_sizer (sizer, this, _("Release territory"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL); @@ -195,8 +188,8 @@ SMPTEMetadataDialog::SMPTEMetadataDialog (wxWindow* parent, weak_ptr weak_ _luminance_unit->Append (_("candela per m²")); _luminance_unit->Append (_("foot lambert")); - edit_name_language->Bind (wxEVT_BUTTON, boost::bind(&SMPTEMetadataDialog::edit_name_language, this)); - edit_audio_language->Bind (wxEVT_BUTTON, boost::bind(&SMPTEMetadataDialog::edit_audio_language, this)); + _name_language->Changed.connect (boost::bind(&SMPTEMetadataDialog::name_language_changed, this, _1)); + _audio_language->Changed.connect (boost::bind(&SMPTEMetadataDialog::audio_language_changed, this, _1)); edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&SMPTEMetadataDialog::edit_release_territory, this)); _version_number->Bind (wxEVT_SPINCTRL, boost::bind(&SMPTEMetadataDialog::version_number_changed, this)); _status->Bind (wxEVT_CHOICE, boost::bind(&SMPTEMetadataDialog::status_changed, this)); @@ -230,7 +223,7 @@ SMPTEMetadataDialog::film_changed (ChangeType type, Film::Property property) } if (property == Film::NAME_LANGUAGE) { - checked_set (_name_language, std_to_wx(film()->name_language().to_string())); + _name_language->set (film()->name_language()); } else if (property == Film::RELEASE_TERRITORY) { checked_set (_release_territory, std_to_wx(*dcp::LanguageTag::get_subtag_description(dcp::LanguageTag::REGION, film()->release_territory().subtag()))); } else if (property == Film::VERSION_NUMBER) { @@ -296,22 +289,16 @@ SMPTEMetadataDialog::set_content_versions (vector cv) void -SMPTEMetadataDialog::edit_name_language () +SMPTEMetadataDialog::name_language_changed (dcp::LanguageTag tag) { - LanguageTagDialog* d = new LanguageTagDialog(this, film()->name_language()); - d->ShowModal (); - film()->set_name_language (d->get()); - d->Destroy (); + film()->set_name_language (tag); } void -SMPTEMetadataDialog::edit_audio_language () +SMPTEMetadataDialog::audio_language_changed (dcp::LanguageTag tag) { - LanguageTagDialog* d = new LanguageTagDialog(this, film()->audio_language()); - d->ShowModal (); - film()->set_audio_language (d->get()); - d->Destroy (); + film()->set_audio_language (tag); } diff --git a/src/wx/smpte_metadata_dialog.h b/src/wx/smpte_metadata_dialog.h index 4859002e1..e47ffe288 100644 --- a/src/wx/smpte_metadata_dialog.h +++ b/src/wx/smpte_metadata_dialog.h @@ -30,6 +30,7 @@ class Film; class RatingDialog; class ContentVersionDialog; +class LanguageTagWidget; class SMPTEMetadataDialog : public wxDialog @@ -42,8 +43,8 @@ private: void set_ratings (std::vector r); std::vector content_versions () const; void set_content_versions (std::vector v); - void edit_name_language (); - void edit_audio_language (); + void name_language_changed (dcp::LanguageTag tag); + void audio_language_changed (dcp::LanguageTag tag); void edit_release_territory (); void version_number_changed (); void status_changed (); @@ -55,8 +56,8 @@ private: boost::shared_ptr film () const; boost::weak_ptr _film; - wxStaticText* _name_language; - wxStaticText* _audio_language; + LanguageTagWidget* _name_language; + LanguageTagWidget* _audio_language; wxStaticText* _release_territory; wxSpinCtrl* _version_number; wxChoice* _status; diff --git a/src/wx/wscript b/src/wx/wscript index 3f0ca2b97..a5597a87b 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -94,6 +94,7 @@ sources = """ kdm_output_panel.cc kdm_timing_panel.cc language_tag_dialog.cc + language_tag_widget.cc make_chain_dialog.cc markers_dialog.cc message_dialog.cc -- 2.30.2