C++11 tidying.
[dcpomatic.git] / src / wx / timeline_dialog.cc
1 /*
2     Copyright (C) 2013-2021 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
22 #include "content_panel.h"
23 #include "film_editor.h"
24 #include "timeline_dialog.h"
25 #include "wx_util.h"
26 #include "lib/compose.hpp"
27 #include "lib/cross.h"
28 #include "lib/playlist.h"
29 #include <wx/graphics.h>
30 #include <iostream>
31 #include <list>
32
33
34 using std::list;
35 using std::cout;
36 using std::string;
37 using std::shared_ptr;
38 using std::weak_ptr;
39 #if BOOST_VERSION >= 106100
40 using namespace boost::placeholders;
41 #endif
42
43
44 TimelineDialog::TimelineDialog (ContentPanel* cp, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
45         : wxDialog (
46                 cp->window(),
47                 wxID_ANY,
48                 _("Timeline"),
49                 wxDefaultPosition,
50                 wxSize (640, 512),
51 #ifdef DCPOMATIC_OSX
52                 /* I can't get wxFRAME_FLOAT_ON_PARENT to work on OS X, and although wxSTAY_ON_TOP keeps
53                    the window above all others (and not just our own) it's better than nothing for now.
54                 */
55                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxSTAY_ON_TOP
56 #else
57                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxFRAME_FLOAT_ON_PARENT
58 #endif
59                 )
60         , _film (film)
61         , _timeline (this, cp, film, viewer)
62 {
63         auto sizer = new wxBoxSizer (wxVERTICAL);
64
65         wxBitmap select (bitmap_path("select"), wxBITMAP_TYPE_PNG);
66         wxBitmap zoom (bitmap_path("zoom"), wxBITMAP_TYPE_PNG);
67         wxBitmap zoom_all (bitmap_path("zoom_all"), wxBITMAP_TYPE_PNG);
68         wxBitmap snap (bitmap_path("snap"), wxBITMAP_TYPE_PNG);
69         wxBitmap sequence (bitmap_path("sequence"), wxBITMAP_TYPE_PNG);
70
71         _toolbar = new wxToolBar (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL);
72         _toolbar->SetMargins (4, 4);
73         _toolbar->SetToolBitmapSize (wxSize(32, 32));
74         _toolbar->AddRadioTool ((int) Timeline::SELECT, _("Select"), select, wxNullBitmap, _("Select and move content"));
75         _toolbar->AddRadioTool ((int) Timeline::ZOOM, _("Zoom"), zoom, wxNullBitmap, _("Zoom in / out"));
76         _toolbar->AddTool ((int) Timeline::ZOOM_ALL, _("Zoom all"), zoom_all, _("Zoom out to whole film"));
77         _toolbar->AddCheckTool ((int) Timeline::SNAP, _("Snap"), snap, wxNullBitmap, _("Snap"));
78         _toolbar->AddCheckTool ((int) Timeline::SEQUENCE, _("Sequence"), sequence, wxNullBitmap, _("Keep video and subtitles in sequence"));
79         _toolbar->Realize ();
80
81         _toolbar->Bind (wxEVT_TOOL, bind (&TimelineDialog::tool_clicked, this, _1));
82
83         sizer->Add (_toolbar, 0, wxALL, 12);
84         sizer->Add (&_timeline, 1, wxEXPAND | wxALL, 12);
85
86 #ifdef DCPOMATIC_LINUX
87         auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
88         if (buttons) {
89                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
90         }
91 #endif
92
93         SetSizer (sizer);
94         sizer->Layout ();
95         sizer->SetSizeHints (this);
96
97         _toolbar->ToggleTool ((int) Timeline::SNAP, _timeline.snap ());
98         film_change (ChangeType::DONE, Film::Property::SEQUENCE);
99
100         _film_changed_connection = film->Change.connect (bind (&TimelineDialog::film_change, this, _1, _2));
101 }
102
103
104 void
105 TimelineDialog::film_change (ChangeType type, Film::Property p)
106 {
107         if (type != ChangeType::DONE) {
108                 return;
109         }
110
111         auto film = _film.lock ();
112         if (!film) {
113                 return;
114         }
115
116         if (p == Film::Property::SEQUENCE) {
117                 _toolbar->ToggleTool ((int) Timeline::SEQUENCE, film->sequence ());
118         }
119 }
120
121
122 void
123 TimelineDialog::set_selection (ContentList selection)
124 {
125         _timeline.set_selection (selection);
126 }
127
128
129 void
130 TimelineDialog::tool_clicked (wxCommandEvent& ev)
131 {
132         Timeline::Tool t = static_cast<Timeline::Tool>(ev.GetId());
133         _timeline.tool_clicked (t);
134         if (t == Timeline::SNAP) {
135                 _timeline.set_snap (_toolbar->GetToolState(static_cast<int>(t)));
136         } else if (t == Timeline::SEQUENCE) {
137                 auto film = _film.lock ();
138                 if (film) {
139                         film->set_sequence (_toolbar->GetToolState(static_cast<int>(t)));
140                 }
141         }
142 }