2 Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "kdm_timing_panel.h"
22 #include <wx/datectrl.h>
23 #include <wx/timectrl.h>
24 #include <wx/dateevt.h>
28 KDMTimingPanel::KDMTimingPanel (wxWindow* parent)
29 : wxPanel (parent, wxID_ANY)
31 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
33 wxFlexGridSizer* table = new wxFlexGridSizer (6, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
34 add_label_to_sizer (table, this, _("From"), true);
37 _from_date = new wxDatePickerCtrl (this, wxID_ANY, from);
38 table->Add (_from_date, 1, wxEXPAND);
39 _from_time = new wxTimePickerCtrl (this, wxID_ANY, from);
40 table->Add (_from_time, 1, wxEXPAND);
42 add_label_to_sizer (table, this, _("until"), true);
45 to.Add (wxDateSpan (0, 0, 1, 0));
46 _until_date = new wxDatePickerCtrl (this, wxID_ANY, to);
47 table->Add (_until_date, 1, wxEXPAND);
48 _until_time = new wxTimePickerCtrl (this, wxID_ANY, to);
49 table->Add (_until_time, 1, wxEXPAND);
51 overall_sizer->Add (table);
53 _warning = new wxStaticText (this, wxID_ANY, wxT (""));
54 overall_sizer->Add (_warning, 0, wxTOP, DCPOMATIC_SIZER_GAP);
55 wxFont font = _warning->GetFont();
56 font.SetStyle(wxFONTSTYLE_ITALIC);
57 font.SetPointSize(font.GetPointSize() - 1);
58 _warning->SetForegroundColour (wxColour (255, 0, 0));
59 _warning->SetFont(font);
61 _from_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this));
62 _until_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this));
63 _from_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this));
64 _until_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this));
66 SetSizer (overall_sizer);
69 boost::posix_time::ptime
70 KDMTimingPanel::from () const
72 return posix_time (_from_date, _from_time);
75 boost::posix_time::ptime
76 KDMTimingPanel::posix_time (wxDatePickerCtrl* date_picker, wxTimePickerCtrl* time_picker)
78 wxDateTime const date = date_picker->GetValue ();
79 wxDateTime const time = time_picker->GetValue ();
80 return boost::posix_time::ptime (
81 boost::gregorian::date (date.GetYear(), date.GetMonth() + 1, date.GetDay()),
82 boost::posix_time::time_duration (time.GetHour(), time.GetMinute(), time.GetSecond())
86 boost::posix_time::ptime
87 KDMTimingPanel::until () const
89 return posix_time (_until_date, _until_time);
93 KDMTimingPanel::valid () const
95 return until() > from();
99 KDMTimingPanel::changed () const
102 _warning->SetLabel (wxT (""));
104 _warning->SetLabel (_("The 'until' time must be after the 'from' time."));