diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-11-28 22:10:44 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-11-29 00:15:02 +0100 |
| commit | 716f05c1301bc5cd811df687875cafaf0d37ffd2 (patch) | |
| tree | b9a21346e85bbce22175e2af1cd69153085c1613 /src | |
| parent | 62b44b2f0690fdd8150d12f8f49cb196ac0e8097 (diff) | |
Extract RegionSubtagWidget.
Diffstat (limited to 'src')
| -rw-r--r-- | src/wx/metadata_dialog.cc | 33 | ||||
| -rw-r--r-- | src/wx/metadata_dialog.h | 8 | ||||
| -rw-r--r-- | src/wx/region_subtag_widget.cc | 97 | ||||
| -rw-r--r-- | src/wx/region_subtag_widget.h | 69 | ||||
| -rw-r--r-- | src/wx/wscript | 1 | ||||
| -rw-r--r-- | src/wx/wx_util.cc | 10 | ||||
| -rw-r--r-- | src/wx/wx_util.h | 2 |
7 files changed, 194 insertions, 26 deletions
diff --git a/src/wx/metadata_dialog.cc b/src/wx/metadata_dialog.cc index 2b9c967f9..ae5db5ec4 100644 --- a/src/wx/metadata_dialog.cc +++ b/src/wx/metadata_dialog.cc @@ -27,7 +27,7 @@ #include "language_tag_widget.h" #include "metadata_dialog.h" #include "rating_dialog.h" -#include "region_subtag_dialog.h" +#include "region_subtag_widget.h" #include "wx_util.h" #include "lib/film.h" #include <dcp/warnings.h> @@ -42,6 +42,7 @@ LIBDCP_ENABLE_WARNINGS using std::weak_ptr; using std::vector; +using boost::optional; MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film) @@ -86,8 +87,8 @@ MetadataDialog::setup () overall_sizer->SetSizeHints (this); _sign_language_video_language->Changed.connect (boost::bind(&MetadataDialog::sign_language_video_language_changed, this)); - _edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&MetadataDialog::edit_release_territory, this)); _enable_release_territory->bind(&MetadataDialog::enable_release_territory_changed, this); + _release_territory->Changed.connect(boost::bind(&MetadataDialog::release_territory_changed, this, _1)); _enable_facility->bind(&MetadataDialog::enable_facility_changed, this); _facility->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::facility_changed, this)); _enable_studio->bind(&MetadataDialog::enable_studio_changed, this); @@ -132,8 +133,8 @@ MetadataDialog::film_changed (ChangeType type, Film::Property property) auto rt = film()->release_territory(); checked_set (_enable_release_territory, static_cast<bool>(rt)); if (rt) { - _release_territory = *rt; - checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory))); + _release_territory_copy = *rt; + checked_set(_release_territory, *_release_territory_copy); } } else if (property == Film::Property::FACILITY) { checked_set (_enable_facility, static_cast<bool>(film()->facility())); @@ -183,14 +184,8 @@ MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer) { _enable_release_territory = new CheckBox(panel, _("Release territory")); sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP); - { - auto s = new wxBoxSizer (wxHORIZONTAL); - _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT("")); - s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP); - _edit_release_territory = new Button (panel, _("Edit...")); - s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP); - sizer->Add (s, 0, wxEXPAND); - } + _release_territory = new RegionSubtagWidget(panel, _("Release territory for this DCP"), film()->release_territory()); + sizer->Add(_release_territory->sizer(), 0, wxEXPAND); vector<EditableListColumn> columns; columns.push_back(EditableListColumn("Agency", 200, true)); @@ -218,17 +213,12 @@ MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer) void -MetadataDialog::edit_release_territory () +MetadataDialog::release_territory_changed(optional<dcp::LanguageTag::RegionSubtag> tag) { - DCPOMATIC_ASSERT (film()->release_territory()); - auto d = new RegionSubtagDialog(this, *film()->release_territory()); - d->ShowModal (); - auto tag = d->get(); if (tag) { - _release_territory = *tag; + _release_territory_copy = *tag; film()->set_release_territory(*tag); } - d->Destroy (); } @@ -237,8 +227,7 @@ MetadataDialog::setup_sensitivity () { _sign_language_video_language->enable (film()->has_sign_language_video_channel()); auto const enabled = _enable_release_territory->GetValue(); - _release_territory_text->Enable (enabled); - _edit_release_territory->Enable (enabled); + _release_territory->enable(enabled); _facility->Enable (_enable_facility->GetValue()); _chain->Enable (_enable_chain->GetValue()); _studio->Enable (_enable_studio->GetValue()); @@ -252,7 +241,7 @@ MetadataDialog::enable_release_territory_changed () { setup_sensitivity (); if (_enable_release_territory->GetValue()) { - film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US"))); + film()->set_release_territory (_release_territory->get().get_value_or(dcp::LanguageTag::RegionSubtag("US"))); } else { film()->set_release_territory (); } diff --git a/src/wx/metadata_dialog.h b/src/wx/metadata_dialog.h index cda8d2ace..b77b14a99 100644 --- a/src/wx/metadata_dialog.h +++ b/src/wx/metadata_dialog.h @@ -39,6 +39,7 @@ class CheckBox; class Choice; class LanguageTagWidget; class RatingDialog; +class RegionSubtagWidget; class wxSpinCtrlDouble; @@ -60,7 +61,7 @@ protected: private: void sign_language_video_language_changed (); - void edit_release_territory (); + void release_territory_changed(boost::optional<dcp::LanguageTag::RegionSubtag> tag); void enable_release_territory_changed (); void facility_changed (); void enable_facility_changed (); @@ -82,9 +83,8 @@ private: * the string in _release_territory_text to a RegionSubtag we just store the RegionSubtag * alongside. */ - boost::optional<dcp::LanguageTag::RegionSubtag> _release_territory; - wxStaticText* _release_territory_text; - Button* _edit_release_territory; + boost::optional<dcp::LanguageTag::RegionSubtag> _release_territory_copy; + RegionSubtagWidget* _release_territory; LanguageTagWidget* _sign_language_video_language = nullptr; CheckBox* _enable_facility; wxTextCtrl* _facility; diff --git a/src/wx/region_subtag_widget.cc b/src/wx/region_subtag_widget.cc new file mode 100644 index 000000000..3b0457f13 --- /dev/null +++ b/src/wx/region_subtag_widget.cc @@ -0,0 +1,97 @@ +/* + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> + + 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 <http://www.gnu.org/licenses/>. + +*/ + + +#include "dcpomatic_button.h" +#include "full_language_tag_dialog.h" +#include "region_subtag_dialog.h" +#include "region_subtag_widget.h" +#include "wx_util.h" +#include "lib/scope_guard.h" +#include <dcp/warnings.h> +LIBDCP_DISABLE_WARNINGS +#include <wx/wx.h> +LIBDCP_ENABLE_WARNINGS + + +using boost::optional; + + +RegionSubtagWidget::RegionSubtagWidget(wxWindow* parent, wxString tooltip, optional<dcp::LanguageTag::RegionSubtag> tag, optional<wxString> size_to_fit) + : _parent(parent) + , _sizer(new wxBoxSizer(wxHORIZONTAL)) +{ + _region = new wxStaticText(parent, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END); + _region->SetToolTip(tooltip); + set(tag); + + if (size_to_fit) { + int w; + int h; + _region->GetTextExtent(*size_to_fit, &w, &h); + _region->SetMinSize(wxSize(w, -1)); + } + + _sizer->Add(_region, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP); + _edit = new Button(parent, _("Edit...")); + _sizer->Add(_edit, 0, wxLEFT, DCPOMATIC_SIZER_GAP); + + _edit->Bind(wxEVT_BUTTON, boost::bind(&RegionSubtagWidget::edit, this)); +} + + +RegionSubtagWidget::~RegionSubtagWidget() +{ + _region->Destroy(); + _edit->Destroy(); +} + + +void +RegionSubtagWidget::edit() +{ + auto d = new RegionSubtagDialog(_parent, _tag.get_value_or(dcp::LanguageTag::RegionSubtag("US"))); + ScopeGuard sg = [d]() { d->Destroy(); }; + + if (d->ShowModal() == wxID_OK) { + set(d->get()); + Changed(d->get()); + } +} + + +void +RegionSubtagWidget::set(optional<dcp::LanguageTag::RegionSubtag> tag) +{ + _tag = tag; + if (tag) { + checked_set(_region, std_to_wx(tag->subtag())); + } else { + checked_set(_region, wxT("")); + } +} + + +void +RegionSubtagWidget::enable(bool e) +{ + _region->Enable(e); + _edit->Enable(e); +} diff --git a/src/wx/region_subtag_widget.h b/src/wx/region_subtag_widget.h new file mode 100644 index 000000000..1fa5efe4e --- /dev/null +++ b/src/wx/region_subtag_widget.h @@ -0,0 +1,69 @@ +/* + Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + + 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 <http://www.gnu.org/licenses/>. + +*/ + + +#include <dcp/language_tag.h> +#include <dcp/warnings.h> +LIBDCP_DISABLE_WARNINGS +#include <wx/wx.h> +LIBDCP_ENABLE_WARNINGS +#include <boost/signals2.hpp> + + +class wxButton; +class wxSizer; +class wxStaticText; +class wxWindow; + + +/** A widget which displays and allows the user to edit a RegionSubtag i.e. a representation of a region of the world, + * perhaps a "territory" where a DCP will be released. + */ +class RegionSubtagWidget +{ +public: + RegionSubtagWidget(wxWindow* parent, wxString tooltip, boost::optional<dcp::LanguageTag::RegionSubtag> tag, boost::optional<wxString> size_to_fit = boost::none); + ~RegionSubtagWidget(); + + RegionSubtagWidget(RegionSubtagWidget const&) = delete; + RegionSubtagWidget& operator=(RegionSubtagWidget const&) = delete; + + wxSizer* sizer() const { + return _sizer; + } + + boost::optional<dcp::LanguageTag::RegionSubtag> get() const { + return _tag; + } + void set(boost::optional<dcp::LanguageTag::RegionSubtag> tag); + void enable(bool e); + + boost::signals2::signal<void (boost::optional<dcp::LanguageTag::RegionSubtag>)> Changed; + +private: + void edit (); + + wxStaticText* _region; + wxButton* _edit; + wxWindow* _parent; + boost::optional<dcp::LanguageTag::RegionSubtag> _tag; + wxSizer* _sizer; +}; + diff --git a/src/wx/wscript b/src/wx/wscript index 5677a9cda..a91ec6189 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -127,6 +127,7 @@ sources = """ recipient_dialog.cc recreate_chain_dialog.cc region_subtag_dialog.cc + region_subtag_widget.cc repeat_dialog.cc report_problem_dialog.cc rename_template_dialog.cc diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index ee6663101..933d303d1 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -27,6 +27,7 @@ #include "file_picker_ctrl.h" #include "language_tag_widget.h" #include "password_entry.h" +#include "region_subtag_widget.h" #include "static_text.h" #include "wx_util.h" #include "lib/config.h" @@ -403,6 +404,15 @@ checked_set(LanguageTagWidget* widget, optional<dcp::LanguageTag> value) void +checked_set(RegionSubtagWidget* widget, optional<dcp::LanguageTag::RegionSubtag> value) +{ + if (widget->get() != value) { + widget->set(value); + } +} + + +void dcpomatic_setup_i18n () { int language = wxLANGUAGE_DEFAULT; diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h index fd87e04d9..5ef221b15 100644 --- a/src/wx/wx_util.h +++ b/src/wx/wx_util.h @@ -41,6 +41,7 @@ LIBDCP_ENABLE_WARNINGS class FilePickerCtrl; class LanguageTagWidget; +class RegionSubtagWidget; class wxDirPickerCtrl; class wxSpinCtrl; class wxSpinCtrlDouble; @@ -159,6 +160,7 @@ extern void checked_set (wxStaticText* widget, std::string value); extern void checked_set (wxStaticText* widget, wxString value); extern void checked_set(LanguageTagWidget* widget, dcp::LanguageTag value); extern void checked_set(LanguageTagWidget* widget, boost::optional<dcp::LanguageTag> value); +extern void checked_set(RegionSubtagWidget* widget, boost::optional<dcp::LanguageTag::RegionSubtag> value); extern int wx_get (wxChoice* widget); extern int wx_get (wxSpinCtrl* widget); |
