Tinker with layout.
[dcpomatic.git] / src / wx / kdm_dialog.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "kdm_dialog.h"
22 #include "wx_util.h"
23 #include "screens_panel.h"
24 #include "kdm_timing_panel.h"
25 #include "kdm_output_panel.h"
26 #include "kdm_cpl_panel.h"
27 #include "lib/film.h"
28 #include "lib/screen.h"
29 #include <libcxml/cxml.h>
30 #include <wx/treectrl.h>
31 #include <wx/listctrl.h>
32 #include <iostream>
33
34 using std::string;
35 using std::map;
36 using std::list;
37 using std::pair;
38 using std::cout;
39 using std::vector;
40 using std::make_pair;
41 using boost::shared_ptr;
42
43 KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
44         : wxDialog (parent, wxID_ANY, _("Make KDMs"))
45 {
46         /* Main sizer */
47         wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
48
49         /* Font for sub-headings */
50         wxFont subheading_font (*wxNORMAL_FONT);
51         subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
52
53         /* Sub-heading: Screens */
54         wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
55         h->SetFont (subheading_font);
56         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL);
57         _screens = new ScreensPanel (this);
58         /* Hack to stop KDM dialogs that are taller than my laptop screen; this
59            really isn't the right way to fix it...
60         */
61         _screens->SetMaxSize (wxSize (-1, 280));
62         vertical->Add (_screens, 1, wxEXPAND);
63
64         /* Sub-heading: Timing */
65         /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
66         h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
67         h->SetFont (subheading_font);
68         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
69         _timing = new KDMTimingPanel (this);
70         vertical->Add (_timing);
71
72         /* Sub-heading: CPL */
73         h = new wxStaticText (this, wxID_ANY, _("CPL"));
74         h->SetFont (subheading_font);
75         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
76         _cpl = new KDMCPLPanel (this, film->cpls ());
77         vertical->Add (_cpl, 0, wxEXPAND);
78
79         /* Sub-heading: Output */
80         h = new wxStaticText (this, wxID_ANY, _("Output"));
81         h->SetFont (subheading_font);
82         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
83         _output = new KDMOutputPanel (this, film->interop ());
84         vertical->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
85
86
87         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
88         if (buttons) {
89                 vertical->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
90         }
91
92         /* Make an overall sizer to get a nice border, and put some buttons in */
93
94         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
95         overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
96
97         /* Bind */
98
99         _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
100         _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
101
102         setup_sensitivity ();
103
104         SetSizer (overall_sizer);
105         overall_sizer->Layout ();
106         overall_sizer->SetSizeHints (this);
107 }
108
109 void
110 KDMDialog::setup_sensitivity ()
111 {
112         _screens->setup_sensitivity ();
113         _output->setup_sensitivity ();
114
115         bool const sd = _cpl->has_selected ();
116
117         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
118         if (ok) {
119                 ok->Enable (!_screens->screens().empty() && _timing->valid() && sd);
120         }
121 }
122
123 boost::filesystem::path
124 KDMDialog::cpl () const
125 {
126         return _cpl->cpl ();
127 }
128
129 list<shared_ptr<Screen> >
130 KDMDialog::screens () const
131 {
132         return _screens->screens ();
133 }
134
135 boost::posix_time::ptime
136 KDMDialog::from () const
137 {
138         return _timing->from ();
139 }
140
141 boost::posix_time::ptime
142 KDMDialog::until () const
143 {
144         return _timing->until ();
145 }
146
147 boost::filesystem::path
148 KDMDialog::directory () const
149 {
150         return _output->directory ();
151 }
152
153 bool
154 KDMDialog::write_to () const
155 {
156         return _output->write_to ();
157 }
158
159 dcp::Formulation
160 KDMDialog::formulation () const
161 {
162         return _output->formulation ();
163 }