diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-06-16 00:46:26 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-06-16 00:46:26 +0100 |
| commit | 5b7c8b06f7d9ea910020b4620c234cf0dce95a66 (patch) | |
| tree | 82591e59c6f48d1bae95a45e01d54e4e706dfbd0 /src | |
| parent | faeda64d4829a3717762778f48607f1cb750f4d5 (diff) | |
Remove seconds from KDM time period specification (#819).
Diffstat (limited to 'src')
| -rw-r--r-- | src/wx/kdm_timing_panel.cc | 20 | ||||
| -rw-r--r-- | src/wx/kdm_timing_panel.h | 8 | ||||
| -rw-r--r-- | src/wx/time_picker.cc | 118 | ||||
| -rw-r--r-- | src/wx/time_picker.h | 47 | ||||
| -rw-r--r-- | src/wx/wscript | 1 |
5 files changed, 180 insertions, 14 deletions
diff --git a/src/wx/kdm_timing_panel.cc b/src/wx/kdm_timing_panel.cc index dfd9d6b6e..a07929b99 100644 --- a/src/wx/kdm_timing_panel.cc +++ b/src/wx/kdm_timing_panel.cc @@ -20,10 +20,11 @@ #include "kdm_timing_panel.h" #include "wx_util.h" +#include "time_picker.h" #include <wx/datectrl.h> -#include <wx/timectrl.h> #include <wx/dateevt.h> +using std::cout; using boost::bind; KDMTimingPanel::KDMTimingPanel (wxWindow* parent) @@ -37,8 +38,8 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent) from.SetToCurrent (); _from_date = new wxDatePickerCtrl (this, wxID_ANY, from); table->Add (_from_date, 1, wxEXPAND); - _from_time = new wxTimePickerCtrl (this, wxID_ANY, from); - table->Add (_from_time, 1, wxEXPAND); + _from_time = new TimePicker (this, from); + table->Add (_from_time, 0); add_label_to_sizer (table, this, _("until"), true); wxDateTime to = from; @@ -46,8 +47,8 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent) to.Add (wxDateSpan (0, 0, 1, 0)); _until_date = new wxDatePickerCtrl (this, wxID_ANY, to); table->Add (_until_date, 1, wxEXPAND); - _until_time = new wxTimePickerCtrl (this, wxID_ANY, to); - table->Add (_until_time, 1, wxEXPAND); + _until_time = new TimePicker (this, to); + table->Add (_until_time, 0); overall_sizer->Add (table); @@ -61,8 +62,8 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent) _from_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this)); _until_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this)); - _from_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this)); - _until_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this)); + _from_time->Changed.connect (bind (&KDMTimingPanel::changed, this)); + _until_time->Changed.connect (bind (&KDMTimingPanel::changed, this)); SetSizer (overall_sizer); } @@ -74,13 +75,12 @@ KDMTimingPanel::from () const } boost::posix_time::ptime -KDMTimingPanel::posix_time (wxDatePickerCtrl* date_picker, wxTimePickerCtrl* time_picker) +KDMTimingPanel::posix_time (wxDatePickerCtrl* date_picker, TimePicker* time_picker) { wxDateTime const date = date_picker->GetValue (); - wxDateTime const time = time_picker->GetValue (); return boost::posix_time::ptime ( boost::gregorian::date (date.GetYear(), date.GetMonth() + 1, date.GetDay()), - boost::posix_time::time_duration (time.GetHour(), time.GetMinute(), time.GetSecond()) + boost::posix_time::time_duration (time_picker->hours(), time_picker->minutes(), 0) ); } diff --git a/src/wx/kdm_timing_panel.h b/src/wx/kdm_timing_panel.h index e23a235f4..368b45146 100644 --- a/src/wx/kdm_timing_panel.h +++ b/src/wx/kdm_timing_panel.h @@ -23,7 +23,7 @@ #include <boost/signals2.hpp> class wxDatePickerCtrl; -class wxTimePickerCtrl; +class TimePicker; class KDMTimingPanel : public wxPanel { @@ -41,11 +41,11 @@ public: private: void changed () const; - static boost::posix_time::ptime posix_time (wxDatePickerCtrl *, wxTimePickerCtrl *); + static boost::posix_time::ptime posix_time (wxDatePickerCtrl *, TimePicker *); wxDatePickerCtrl* _from_date; wxDatePickerCtrl* _until_date; - wxTimePickerCtrl* _from_time; - wxTimePickerCtrl* _until_time; + TimePicker* _from_time; + TimePicker* _until_time; wxStaticText* _warning; }; diff --git a/src/wx/time_picker.cc b/src/wx/time_picker.cc new file mode 100644 index 000000000..2528d737e --- /dev/null +++ b/src/wx/time_picker.cc @@ -0,0 +1,118 @@ +/* + Copyright (C) 2016 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 "time_picker.h" +#include "lib/raw_convert.h" +#include <wx/spinctrl.h> +#include <boost/bind.hpp> +#include <iomanip> + +using std::setfill; +using std::setw; +using std::min; +using std::max; +using std::string; +using std::cout; +using boost::bind; + +TimePicker::TimePicker (wxWindow* parent, wxDateTime time) + : wxPanel (parent) + , _block_update (false) +{ + wxClientDC dc (parent); + wxSize size = dc.GetTextExtent (wxT ("9999")); + size.SetHeight (-1); + + wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); + _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size); + _hours->SetMaxLength (2); + sizer->Add (_hours, 0); + _hours_spin = new wxSpinButton (this, wxID_ANY); + sizer->Add (_hours_spin, 0, wxLEFT | wxRIGHT, 2); + sizer->Add (new wxStaticText (this, wxID_ANY, wxT (":")), 0, wxALIGN_CENTER_VERTICAL); + _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size); + _minutes->SetMaxLength (2); + sizer->Add (_minutes, 0); + _minutes_spin = new wxSpinButton (this, wxID_ANY); + sizer->Add (_minutes_spin, 0, wxLEFT | wxRIGHT, 2); + + SetSizerAndFit (sizer); + + _minutes->MoveAfterInTabOrder (_hours); + + _hours_spin->SetValue (time.GetHour ()); + _hours_spin->SetRange (0, 23); + _minutes_spin->SetValue (time.GetMinute ()); + _minutes_spin->SetRange (0, 59); + + update_text (); + + _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this))); + _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this))); + _hours_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this)); + _minutes_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this)); +} + +void +TimePicker::update_text () +{ + if (_block_update) { + return; + } + + _block_update = true; + + _hours->SetValue (wxString (raw_convert<string> (_hours_spin->GetValue ()))); + + SafeStringStream m; + m << setfill('0') << setw(2) << _minutes_spin->GetValue(); + _minutes->SetValue (wxString (m.str())); + + _block_update = false; + + Changed (); +} + +void +TimePicker::update_spin () +{ + if (_block_update) { + return; + } + + _block_update = true; + _hours_spin->SetValue (raw_convert<int> (_hours->GetValue().ToStdString())); + _minutes_spin->SetValue (raw_convert<int> (_minutes->GetValue().ToStdString())); + _block_update = false; + + Changed (); +} + +int +TimePicker::hours () const +{ + return _hours_spin->GetValue(); +} + +int +TimePicker::minutes () const +{ + return _minutes_spin->GetValue(); +} diff --git a/src/wx/time_picker.h b/src/wx/time_picker.h new file mode 100644 index 000000000..808883010 --- /dev/null +++ b/src/wx/time_picker.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2016 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 <wx/wx.h> +#include <boost/signals2.hpp> + +class wxTextCtrl; +class wxSpinButton; + +class TimePicker : public wxPanel +{ +public: + TimePicker (wxWindow* parent, wxDateTime time); + + int hours () const; + int minutes () const; + + boost::signals2::signal<void ()> Changed; + +private: + void update_spin (); + void update_text (); + + wxTextCtrl* _hours; + wxSpinButton* _hours_spin; + wxTextCtrl* _minutes; + wxSpinButton* _minutes_spin; + + bool _block_update; +}; diff --git a/src/wx/wscript b/src/wx/wscript index b5df3aca1..57de1b0c3 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -82,6 +82,7 @@ sources = """ system_font_dialog.cc table_dialog.cc text_subtitle_appearance_dialog.cc + time_picker.cc timecode.cc timeline.cc timeline_atmos_content_view.cc |
