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