diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-04-22 12:28:19 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-04-22 12:28:19 +0100 |
| commit | 8031edf0ce27b75727438e504128448b0884b426 (patch) | |
| tree | c1de0021c11575bd0da5829d24c2cc6701c57da9 /src | |
| parent | 450063921e66534da362ac5dab08ff9d67e2bdbe (diff) | |
Disallow KDM until times being before from times (#821).
Diffstat (limited to 'src')
| -rw-r--r-- | src/wx/kdm_dialog.cc | 3 | ||||
| -rw-r--r-- | src/wx/kdm_timing_panel.cc | 42 | ||||
| -rw-r--r-- | src/wx/kdm_timing_panel.h | 9 |
3 files changed, 50 insertions, 4 deletions
diff --git a/src/wx/kdm_dialog.cc b/src/wx/kdm_dialog.cc index 5874dea54..856808f11 100644 --- a/src/wx/kdm_dialog.cc +++ b/src/wx/kdm_dialog.cc @@ -95,6 +95,7 @@ KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film) /* Bind */ _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this)); + _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this)); setup_sensitivity (); @@ -113,7 +114,7 @@ KDMDialog::setup_sensitivity () wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this)); if (ok) { - ok->Enable (!_screens->screens().empty() && sd); + ok->Enable (!_screens->screens().empty() && _timing->valid() && sd); } } diff --git a/src/wx/kdm_timing_panel.cc b/src/wx/kdm_timing_panel.cc index c0d0c27e8..6c5bd7e3b 100644 --- a/src/wx/kdm_timing_panel.cc +++ b/src/wx/kdm_timing_panel.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,10 +21,15 @@ #include "wx_util.h" #include <wx/datectrl.h> #include <wx/timectrl.h> +#include <wx/dateevt.h> + +using boost::bind; KDMTimingPanel::KDMTimingPanel (wxWindow* parent) : wxPanel (parent, wxID_ANY) { + wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); + wxFlexGridSizer* table = new wxFlexGridSizer (6, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); add_label_to_sizer (table, this, _("From"), true); wxDateTime from; @@ -43,7 +48,22 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent) _until_time = new wxTimePickerCtrl (this, wxID_ANY, to); table->Add (_until_time, 1, wxEXPAND); - SetSizer (table); + overall_sizer->Add (table); + + _warning = new wxStaticText (this, wxID_ANY, wxT ("")); + overall_sizer->Add (_warning, 0, wxTOP, DCPOMATIC_SIZER_GAP); + wxFont font = _warning->GetFont(); + font.SetStyle(wxFONTSTYLE_ITALIC); + font.SetPointSize(font.GetPointSize() - 1); + _warning->SetForegroundColour (wxColour (255, 0, 0)); + _warning->SetFont(font); + + _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)); + + SetSizer (overall_sizer); } boost::posix_time::ptime @@ -68,3 +88,21 @@ KDMTimingPanel::until () const { return posix_time (_until_date, _until_time); } + +bool +KDMTimingPanel::valid () const +{ + return until() > from(); +} + +void +KDMTimingPanel::changed () const +{ + if (valid ()) { + _warning->SetLabel (wxT ("")); + } else { + _warning->SetLabel (_("The 'until' time must be after the 'from' time.")); + } + + TimingChanged (); +} diff --git a/src/wx/kdm_timing_panel.h b/src/wx/kdm_timing_panel.h index 7e607296f..d71e2d292 100644 --- a/src/wx/kdm_timing_panel.h +++ b/src/wx/kdm_timing_panel.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ #include <wx/wx.h> #include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/signals2.hpp> class wxDatePickerCtrl; class wxTimePickerCtrl; @@ -33,11 +34,17 @@ public: /** @return KDM until time in local time */ boost::posix_time::ptime until () const; + bool valid () const; + + boost::signals2::signal<void ()> TimingChanged; + private: + void changed () const; static boost::posix_time::ptime posix_time (wxDatePickerCtrl *, wxTimePickerCtrl *); wxDatePickerCtrl* _from_date; wxDatePickerCtrl* _until_date; wxTimePickerCtrl* _from_time; wxTimePickerCtrl* _until_time; + wxStaticText* _warning; }; |
