Shrink height of KDM creator a bit.
[dcpomatic.git] / src / wx / kdm_timing_panel.cc
1 /*
2     Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "kdm_timing_panel.h"
21 #include "wx_util.h"
22 #include <wx/datectrl.h>
23 #include <wx/timectrl.h>
24
25 KDMTimingPanel::KDMTimingPanel (wxWindow* parent)
26         : wxPanel (parent, wxID_ANY)
27 {
28         wxFlexGridSizer* table = new wxFlexGridSizer (6, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
29         add_label_to_sizer (table, this, _("From"), true);
30         wxDateTime from;
31         from.SetToCurrent ();
32         _from_date = new wxDatePickerCtrl (this, wxID_ANY, from);
33         table->Add (_from_date, 1, wxEXPAND);
34         _from_time = new wxTimePickerCtrl (this, wxID_ANY, from);
35         table->Add (_from_time, 1, wxEXPAND);
36
37         add_label_to_sizer (table, this, _("until"), true);
38         wxDateTime to = from;
39         /* 1 week from now */
40         to.Add (wxDateSpan (0, 0, 1, 0));
41         _until_date = new wxDatePickerCtrl (this, wxID_ANY, to);
42         table->Add (_until_date, 1, wxEXPAND);
43         _until_time = new wxTimePickerCtrl (this, wxID_ANY, to);
44         table->Add (_until_time, 1, wxEXPAND);
45
46         SetSizer (table);
47 }
48
49 boost::posix_time::ptime
50 KDMTimingPanel::from () const
51 {
52         return posix_time (_from_date, _from_time);
53 }
54
55 boost::posix_time::ptime
56 KDMTimingPanel::posix_time (wxDatePickerCtrl* date_picker, wxTimePickerCtrl* time_picker)
57 {
58         wxDateTime const date = date_picker->GetValue ();
59         wxDateTime const time = time_picker->GetValue ();
60         return boost::posix_time::ptime (
61                 boost::gregorian::date (date.GetYear(), date.GetMonth() + 1, date.GetDay()),
62                 boost::posix_time::time_duration (time.GetHour(), time.GetMinute(), time.GetSecond())
63                 );
64 }
65
66 boost::posix_time::ptime
67 KDMTimingPanel::until () const
68 {
69         return posix_time (_until_date, _until_time);
70 }