From 8031edf0ce27b75727438e504128448b0884b426 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 22 Apr 2016 12:28:19 +0100 Subject: Disallow KDM until times being before from times (#821). --- src/wx/kdm_timing_panel.cc | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/wx/kdm_timing_panel.cc') 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 + Copyright (C) 2015-2016 Carl Hetherington 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 #include +#include + +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 (); +} -- cgit v1.2.3