Attempt to tidy up layout of KDM window.
authorCarl Hetherington <cth@carlh.net>
Fri, 28 Oct 2016 21:56:23 +0000 (22:56 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 28 Oct 2016 21:56:23 +0000 (22:56 +0100)
src/wx/kdm_timing_panel.cc
src/wx/time_picker.cc
src/wx/time_picker.h

index a07929b99ea7836ca1ece174670425877b8b6058..613b62cbf19e29b6b0e2154394e872e3b8a52a00 100644 (file)
@@ -32,23 +32,23 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent)
 {
        wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
 
-       wxFlexGridSizer* table = new wxFlexGridSizer (6, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+       wxSizer* table = new wxBoxSizer (wxHORIZONTAL);
        add_label_to_sizer (table, this, _("From"), true);
        wxDateTime from;
        from.SetToCurrent ();
        _from_date = new wxDatePickerCtrl (this, wxID_ANY, from);
-       table->Add (_from_date, 1, wxEXPAND);
+       table->Add (_from_date);
        _from_time = new TimePicker (this, from);
-       table->Add (_from_time, 0);
+       table->Add (_from_time);
 
        add_label_to_sizer (table, this, _("until"), true);
        wxDateTime to = from;
        /* 1 week from now */
        to.Add (wxDateSpan (0, 0, 1, 0));
        _until_date = new wxDatePickerCtrl (this, wxID_ANY, to);
-       table->Add (_until_date, 1, wxEXPAND);
+       table->Add (_until_date);
        _until_time = new TimePicker (this, to);
-       table->Add (_until_time, 0);
+       table->Add (_until_time);
 
        overall_sizer->Add (table);
 
index 309e5c713b564cea157d8f772270786284e5b292..ee591023bdbda95af34436528e738098ba4e8a78 100644 (file)
@@ -36,82 +36,45 @@ using dcp::locale_convert;
 
 TimePicker::TimePicker (wxWindow* parent, wxDateTime time)
        : wxPanel (parent)
-       , _block_update (false)
 {
        wxClientDC dc (parent);
-       wxSize size = dc.GetTextExtent (wxT ("9999"));
+       wxSize size = dc.GetTextExtent (wxT ("9999999"));
        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);
+       _hours = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
+       sizer->Add (_hours, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_GAP);
        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);
+       _minutes = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
+       sizer->Add (_minutes, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
 
        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);
+       _hours->SetValue (time.GetHour ());
+       _hours->SetRange (0, 23);
+       _minutes->SetValue (time.GetMinute ());
+       _minutes->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::Format ("%d", _hours_spin->GetValue ()));
-       _minutes->SetValue (wxString::Format ("%02d", _minutes_spin->GetValue ()));
-
-       _block_update = false;
-
-       Changed ();
+       _hours->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, (bind (&TimePicker::spin_changed, this)));
+       _minutes->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, (bind (&TimePicker::spin_changed, this)));
 }
 
 void
-TimePicker::update_spin ()
+TimePicker::spin_changed ()
 {
-       if (_block_update) {
-               return;
-       }
-
-       _block_update = true;
-       _hours_spin->SetValue (locale_convert<int> (wx_to_std (_hours->GetValue())));
-       _minutes_spin->SetValue (locale_convert<int> (wx_to_std (_minutes->GetValue())));
-       _block_update = false;
-
        Changed ();
 }
 
 int
 TimePicker::hours () const
 {
-       return _hours_spin->GetValue();
+       return _hours->GetValue();
 }
 
 int
 TimePicker::minutes () const
 {
-       return _minutes_spin->GetValue();
+       return _minutes->GetValue();
 }
index 80888301031f18f2599bf5fddc8654cf319aae1d..53e31a06a8d21e15c26cfe90f3d29b8b1a161de3 100644 (file)
@@ -21,8 +21,7 @@
 #include <wx/wx.h>
 #include <boost/signals2.hpp>
 
-class wxTextCtrl;
-class wxSpinButton;
+class wxSpinCtrl;
 
 class TimePicker : public wxPanel
 {
@@ -35,13 +34,8 @@ public:
        boost::signals2::signal<void ()> Changed;
 
 private:
-       void update_spin ();
-       void update_text ();
+       void spin_changed ();
 
-       wxTextCtrl* _hours;
-       wxSpinButton* _hours_spin;
-       wxTextCtrl* _minutes;
-       wxSpinButton* _minutes_spin;
-
-       bool _block_update;
+       wxSpinCtrl* _hours;
+       wxSpinCtrl* _minutes;
 };