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