Merge master.
[dcpomatic.git] / src / wx / imagemagick_content_dialog.cc
1 /*
2     Copyright (C) 2013 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 <wx/spinctrl.h>
21 #include "lib/imagemagick_content.h"
22 #include "imagemagick_content_dialog.h"
23 #include "wx_util.h"
24
25 using boost::shared_ptr;
26 using boost::dynamic_pointer_cast;
27
28 ImageMagickContentDialog::ImageMagickContentDialog (wxWindow* parent, shared_ptr<ImageMagickContent> content)
29         : wxDialog (parent, wxID_ANY, _("Image"))
30         , _content (content)
31 {
32         wxFlexGridSizer* grid = new wxFlexGridSizer (3, 6, 6);
33         grid->AddGrowableCol (1, 1);
34
35         {
36                 add_label_to_sizer (grid, this, _("Duration"), true);
37                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
38                 _video_length = new wxSpinCtrl (this);
39                 s->Add (_video_length);
40                 /// TRANSLATORS: this is an abbreviation for seconds, the unit of time
41                 add_label_to_sizer (s, this, _("s"), false);
42                 grid->Add (s);
43         }
44
45         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
46         overall_sizer->Add (grid, 1, wxEXPAND | wxALL, 6);
47
48         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
49         if (buttons) {
50                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
51         }
52
53         SetSizer (overall_sizer);
54         overall_sizer->Layout ();
55         overall_sizer->SetSizeHints (this);
56
57         checked_set (_video_length, content->video_length () / 24);
58         _video_length->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ImageMagickContentDialog::video_length_changed), 0, this);
59 }
60
61 void
62 ImageMagickContentDialog::video_length_changed (wxCommandEvent &)
63 {
64         shared_ptr<ImageMagickContent> c = _content.lock ();
65         if (!c) {
66                 return;
67         }
68         
69         c->set_video_length (_video_length->GetValue() * 24);
70 }