From 1415214ff18e05e5b609aab8c4efb89e5b9e0cc0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 11 Nov 2013 18:04:16 +0000 Subject: [PATCH] Try to neaten things up; first wxChoice. --- src/wx/audio_panel.cc | 6 ++- src/wx/audio_panel.h | 4 +- src/wx/content_widget.h | 81 +++++++++++++++++++++++++++++------------ src/wx/video_panel.cc | 36 ++++++++---------- src/wx/video_panel.h | 11 +++--- 5 files changed, 84 insertions(+), 54 deletions(-) diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index b9aa9d6df..56fcf5c32 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -50,13 +50,14 @@ AudioPanel::AudioPanel (FilmEditor* e) ++r; add_label_to_grid_bag_sizer (grid, this, _("Audio Gain"), true, wxGBPosition (r, 0)); - _gain = new ContentWidget ( + _gain = new ContentSpinCtrl ( this, new wxSpinCtrl (this), AudioContentProperty::AUDIO_GAIN, boost::mem_fn (&AudioContent::audio_gain), boost::mem_fn (&AudioContent::set_audio_gain) ); + _gain->add (grid, wxGBPosition (r, 1)); add_label_to_grid_bag_sizer (grid, this, _("dB"), false, wxGBPosition (r, 2)); _gain_calculate_button = new wxButton (this, wxID_ANY, _("Calculate...")); @@ -64,13 +65,14 @@ AudioPanel::AudioPanel (FilmEditor* e) ++r; add_label_to_grid_bag_sizer (grid, this, _("Audio Delay"), false, wxGBPosition (r, 0)); - _delay = new ContentWidget ( + _delay = new ContentSpinCtrl ( this, new wxSpinCtrl (this), AudioContentProperty::AUDIO_DELAY, boost::mem_fn (&AudioContent::audio_delay), boost::mem_fn (&AudioContent::set_audio_delay) ); + _delay->add (grid, wxGBPosition (r,1 )); /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time add_label_to_grid_bag_sizer (grid, this, _("ms"), false, wxGBPosition (r, 2)); diff --git a/src/wx/audio_panel.h b/src/wx/audio_panel.h index 110dc4efa..f1b932e7c 100644 --- a/src/wx/audio_panel.h +++ b/src/wx/audio_panel.h @@ -44,10 +44,10 @@ private: void mapping_changed (AudioMapping); void setup_stream_description (); - ContentWidget* _gain; + ContentSpinCtrl* _gain; wxButton* _gain_calculate_button; wxButton* _show; - ContentWidget* _delay; + ContentSpinCtrl* _delay; wxChoice* _stream; wxStaticText* _description; AudioMappingView* _mapping; diff --git a/src/wx/content_widget.h b/src/wx/content_widget.h index eb264eae9..07abc7cbd 100644 --- a/src/wx/content_widget.h +++ b/src/wx/content_widget.h @@ -31,30 +31,39 @@ * * @param S Type containing the content being represented (e.g. VideoContent) * @param T Type of the widget (e.g. wxSpinCtrl) + * @param U Data type of state as used by the model. + * @param V Data type of state as used by the view. */ -template +template class ContentWidget { public: /** @param parent Parent window. * @param wrapped Control widget that we are wrapping. * @param property ContentProperty that the widget is handling. - * @param getter Function on the Content to get the value. - * @param setter Function on the Content to set the value. + * @param model_getter Function on the Content to get the value. + * @param model_setter Function on the Content to set the value. */ - ContentWidget (wxWindow* parent, T* wrapped, int property, boost::function getter, boost::function setter) + ContentWidget ( + wxWindow* parent, + T* wrapped, + int property, + boost::function model_getter, + boost::function model_setter, + boost::function view_getter + ) : _wrapped (wrapped) , _sizer (0) , _button (new wxButton (parent, wxID_ANY, _("Multiple values"))) , _property (property) - , _getter (getter) - , _setter (setter) + , _model_getter (model_getter) + , _model_setter (model_setter) + , _view_getter (view_getter) , _ignore_model_changes (false) { _button->SetToolTip (_("Click the button to set all selected content to the same value.")); _button->Hide (); _button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ContentWidget::button_clicked, this)); - _wrapped->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&ContentWidget::view_changed, this)); } T* wrapped () const { @@ -68,6 +77,8 @@ public: for (typename std::list::iterator i = _connections.begin(); i != _connections.end(); ++i) { i->disconnect (); } + + _connections.clear (); _content = content; @@ -87,7 +98,6 @@ public: _sizer->Add (_wrapped, _position); } - void update_from_model () { if (_content.empty ()) { @@ -96,8 +106,8 @@ public: } typename List::iterator i = _content.begin (); - int const v = boost::bind (_getter, _content.front().get())(); - while (i != _content.end() && boost::bind (_getter, i->get())() == v) { + U const v = boost::bind (_model_getter, _content.front().get())(); + while (i != _content.end() && boost::bind (_model_getter, i->get())() == v) { ++i; } @@ -109,6 +119,15 @@ public: } } + void view_changed () + { + for (size_t i = 0; i < _content.size(); ++i) { + /* Only update our view on the last time round this loop */ + _ignore_model_changes = i < (_content.size() - 1); + boost::bind (_model_setter, _content[i].get(), static_cast (boost::bind (_view_getter, _wrapped)()))(); + } + } + private: void set_single () @@ -139,18 +158,9 @@ private: void button_clicked () { - int const v = boost::bind (_getter, _content.front().get())(); + U const v = boost::bind (_model_getter, _content.front().get())(); for (typename List::iterator i = _content.begin (); i != _content.end(); ++i) { - boost::bind (_setter, i->get(), v) (); - } - } - - void view_changed () - { - for (size_t i = 0; i < _content.size(); ++i) { - /* Only update our view on the last time round this loop */ - _ignore_model_changes = i < (_content.size() - 1); - boost::bind (_setter, _content[i].get(), _wrapped->GetValue ()) (); + boost::bind (_model_setter, i->get(), v) (); } } @@ -167,10 +177,35 @@ private: wxButton* _button; List _content; int _property; - boost::function _getter; - boost::function _setter; + boost::function _model_getter; + boost::function _model_setter; + boost::function _view_getter; std::list _connections; bool _ignore_model_changes; }; +template +class ContentSpinCtrl : public ContentWidget +{ +public: + ContentSpinCtrl (wxWindow* parent, wxSpinCtrl* wrapped, int property, boost::function getter, boost::function setter) + : ContentWidget (parent, wrapped, property, getter, setter, boost::mem_fn (&wxSpinCtrl::GetValue)) + { + wrapped->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&ContentWidget::view_changed, this)); + } + +}; + +template +class ContentChoice : public ContentWidget +{ +public: + ContentChoice (wxWindow* parent, wxChoice* wrapped, int property, boost::function getter, boost::function setter) + : ContentWidget (parent, wrapped, property, getter, setter, boost::mem_fn (&wxChoice::GetSelection)) + { + wrapped->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&ContentWidget::view_changed, this)); + } + +}; + #endif diff --git a/src/wx/video_panel.cc b/src/wx/video_panel.cc index ca1fd1ce8..9adc64641 100644 --- a/src/wx/video_panel.cc +++ b/src/wx/video_panel.cc @@ -50,12 +50,18 @@ VideoPanel::VideoPanel (FilmEditor* e) int r = 0; add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0)); - _frame_type = new wxChoice (this, wxID_ANY); - grid->Add (_frame_type, wxGBPosition (r, 1)); + _frame_type = new ContentChoice ( + this, + new wxChoice (this, wxID_ANY), + VideoContentProperty::VIDEO_FRAME_TYPE, + boost::mem_fn (&VideoContent::video_frame_type), + boost::mem_fn (&VideoContent::set_video_frame_type) + ); + _frame_type->add (grid, wxGBPosition (r, 1)); ++r; add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0)); - _left_crop = new ContentWidget ( + _left_crop = new ContentSpinCtrl ( this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)), VideoContentProperty::VIDEO_CROP, @@ -66,7 +72,7 @@ VideoPanel::VideoPanel (FilmEditor* e) ++r; add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0)); - _right_crop = new ContentWidget ( + _right_crop = new ContentSpinCtrl ( this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)), VideoContentProperty::VIDEO_CROP, @@ -77,7 +83,7 @@ VideoPanel::VideoPanel (FilmEditor* e) ++r; add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0)); - _top_crop = new ContentWidget ( + _top_crop = new ContentSpinCtrl ( this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)), VideoContentProperty::VIDEO_CROP, @@ -88,7 +94,7 @@ VideoPanel::VideoPanel (FilmEditor* e) ++r; add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0)); - _bottom_crop = new ContentWidget ( + _bottom_crop = new ContentSpinCtrl ( this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)), VideoContentProperty::VIDEO_CROP, @@ -156,10 +162,9 @@ VideoPanel::VideoPanel (FilmEditor* e) } _ratio->Append (_("No stretch")); - _frame_type->Append (_("2D")); - _frame_type->Append (_("3D left/right")); + _frame_type->wrapped()->Append (_("2D")); + _frame_type->wrapped()->Append (_("3D left/right")); - _frame_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::frame_type_changed, this)); _ratio->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::ratio_changed, this)); _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this)); _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this)); @@ -190,7 +195,6 @@ VideoPanel::film_content_changed (int property) } if (property == VideoContentProperty::VIDEO_FRAME_TYPE) { - checked_set (_frame_type, vcs ? vcs->video_frame_type () : VIDEO_FRAME_TYPE_2D); setup_description (); } else if (property == VideoContentProperty::VIDEO_CROP) { setup_description (); @@ -347,15 +351,6 @@ VideoPanel::ratio_changed () } } -void -VideoPanel::frame_type_changed () -{ - VideoContentList vc = _editor->selected_video_content (); - if (vc.size() == 1) { - vc.front()->set_video_frame_type (static_cast (_frame_type->GetSelection ())); - } -} - void VideoPanel::edit_colour_conversion_clicked () { @@ -383,14 +378,13 @@ VideoPanel::content_selection_changed () _right_crop->set_content (sel); _top_crop->set_content (sel); _bottom_crop->set_content (sel); + _frame_type->set_content (sel); /* Things that are only allowed with single selections */ - _frame_type->Enable (single); _ratio->Enable (single); _filters_button->Enable (single); _colour_conversion_button->Enable (single); - film_content_changed (VideoContentProperty::VIDEO_FRAME_TYPE); film_content_changed (VideoContentProperty::VIDEO_CROP); film_content_changed (VideoContentProperty::VIDEO_RATIO); film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE); diff --git a/src/wx/video_panel.h b/src/wx/video_panel.h index b4e0eb71b..577bbf0e7 100644 --- a/src/wx/video_panel.h +++ b/src/wx/video_panel.h @@ -38,16 +38,15 @@ public: private: void edit_filters_clicked (); void ratio_changed (); - void frame_type_changed (); void edit_colour_conversion_clicked (); void setup_description (); - wxChoice* _frame_type; - ContentWidget* _left_crop; - ContentWidget* _right_crop; - ContentWidget* _top_crop; - ContentWidget* _bottom_crop; + ContentChoice* _frame_type; + ContentSpinCtrl* _left_crop; + ContentSpinCtrl* _right_crop; + ContentSpinCtrl* _top_crop; + ContentSpinCtrl* _bottom_crop; wxChoice* _ratio; wxStaticText* _ratio_description; wxStaticText* _description; -- 2.30.2