Remove seconds from KDM time period specification (#819).
authorCarl Hetherington <cth@carlh.net>
Wed, 15 Jun 2016 23:46:26 +0000 (00:46 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 15 Jun 2016 23:46:26 +0000 (00:46 +0100)
ChangeLog
src/wx/kdm_timing_panel.cc
src/wx/kdm_timing_panel.h
src/wx/time_picker.cc [new file with mode: 0644]
src/wx/time_picker.h [new file with mode: 0644]
src/wx/wscript

index 648f868142ff7bc681c09e71e737670fba2f429c..71e89e72460322aba1d8c92d1f2206ee147a9cea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-06-16  Carl Hetherington  <cth@carlh.net>
+
+       * Remove seconds from KDM time period specification (#819).
+
 2016-06-14  c.hetherington  <cth@carlh.net>
 
        * Basic guessing of audio channels from filenames (#393).
index dfd9d6b6ebd23f6581d48472195e4db4f164e6bc..a07929b99ea7836ca1ece174670425877b8b6058 100644 (file)
 
 #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)
                );
 }
 
index e23a235f4f20b6e83707a734bd7caaa21e20ab97..368b451463e949f0bfaf898d5caed4dc83ba07a5 100644 (file)
@@ -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 (file)
index 0000000..2528d73
--- /dev/null
@@ -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 (file)
index 0000000..8088830
--- /dev/null
@@ -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;
+};
index b5df3aca1010599728a8b81400058d5c0632bf56..57de1b0c3890cd5dddd885ea692afa1df2274099 100644 (file)
@@ -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