diff options
Diffstat (limited to 'src/wx/timeline.cc')
| -rw-r--r-- | src/wx/timeline.cc | 139 |
1 files changed, 119 insertions, 20 deletions
diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index 3747a3dac..f9205fc5d 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -25,6 +25,7 @@ #include "film_editor.h" #include "timeline.h" #include "wx_util.h" +#include "repeat_dialog.h" using std::list; using std::cout; @@ -314,6 +315,10 @@ private: int _y; }; +enum { + ID_repeat +}; + Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film) : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE) , _film_editor (ed) @@ -324,26 +329,25 @@ Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film) , _left_down (false) , _down_view_start (0) , _first_move (false) + , _menu (0) { #ifndef __WXOSX__ SetDoubleBuffered (true); #endif - setup_pixels_per_time_unit (); - Connect (wxID_ANY, wxEVT_PAINT, wxPaintEventHandler (Timeline::paint), 0, this); Connect (wxID_ANY, wxEVT_LEFT_DOWN, wxMouseEventHandler (Timeline::left_down), 0, this); Connect (wxID_ANY, wxEVT_LEFT_UP, wxMouseEventHandler (Timeline::left_up), 0, this); + Connect (wxID_ANY, wxEVT_RIGHT_DOWN, wxMouseEventHandler (Timeline::right_down), 0, this); Connect (wxID_ANY, wxEVT_MOTION, wxMouseEventHandler (Timeline::mouse_moved), 0, this); Connect (wxID_ANY, wxEVT_SIZE, wxSizeEventHandler (Timeline::resized), 0, this); + Connect (ID_repeat, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Timeline::repeat), 0, this); playlist_changed (); SetMinSize (wxSize (640, tracks() * track_height() + 96)); _playlist_connection = film->playlist()->Changed.connect (bind (&Timeline::playlist_changed, this)); - - _views.push_back (_time_axis_view); } void @@ -374,8 +378,9 @@ Timeline::playlist_changed () } _views.clear (); + _views.push_back (_time_axis_view); - Playlist::ContentList content = fl->playlist()->content_with_loop (); + Playlist::ContentList content = fl->playlist()->content (); for (Playlist::ContentList::iterator i = content.begin(); i != content.end(); ++i) { if (dynamic_pointer_cast<VideoContent> (*i)) { @@ -387,6 +392,7 @@ Timeline::playlist_changed () } assign_tracks (); + setup_pixels_per_time_unit (); Refresh (); } @@ -460,11 +466,11 @@ Timeline::setup_pixels_per_time_unit () return; } - _pixels_per_time_unit = static_cast<double>(width() - x_offset() * 2) / film->length_with_loop(); + _pixels_per_time_unit = static_cast<double>(width() - x_offset() * 2) / film->length (); } -void -Timeline::left_down (wxMouseEvent& ev) +shared_ptr<View> +Timeline::event_to_view (wxMouseEvent& ev) { list<shared_ptr<View> >::iterator i = _views.begin(); Position<int> const p (ev.GetX(), ev.GetY()); @@ -472,24 +478,43 @@ Timeline::left_down (wxMouseEvent& ev) ++i; } + if (i == _views.end ()) { + return shared_ptr<View> (); + } + + return *i; +} + +void +Timeline::left_down (wxMouseEvent& ev) +{ + shared_ptr<View> view = event_to_view (ev); + shared_ptr<ContentView> content_view = dynamic_pointer_cast<ContentView> (view); + _down_view.reset (); - if (i != _views.end ()) { + if (content_view) { + _down_view = content_view; + _down_view_start = content_view->content()->start (); + } + + for (list<shared_ptr<View> >::iterator i = _views.begin(); i != _views.end(); ++i) { shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i); - if (cv) { - _down_view = cv; - _down_view_start = cv->content()->start (); + if (!cv) { + continue; + } + + if (!ev.ShiftDown ()) { + cv->set_selected (view == *i); + } + + if (view == *i) { + _film_editor->set_selection (cv->content ()); } } - for (list<shared_ptr<View> >::iterator j = _views.begin(); j != _views.end(); ++j) { - shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*j); - if (cv) { - cv->set_selected (i == j); - if (i == j) { - _film_editor->set_selection (cv->content ()); - } - } + if (content_view && ev.ShiftDown ()) { + content_view->set_selected (!content_view->selected ()); } _left_down = true; @@ -524,6 +549,28 @@ Timeline::mouse_moved (wxMouseEvent& ev) } void +Timeline::right_down (wxMouseEvent& ev) +{ + shared_ptr<View> view = event_to_view (ev); + shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (view); + if (!cv) { + return; + } + + if (!cv->selected ()) { + clear_selection (); + cv->set_selected (true); + } + + if (!_menu) { + _menu = new wxMenu; + _menu->Append (ID_repeat, _("Repeat...")); + } + + PopupMenu (_menu, ev.GetPosition ()); +} + +void Timeline::set_start_from_event (wxMouseEvent& ev) { wxPoint const p = ev.GetPosition(); @@ -563,3 +610,55 @@ Timeline::resized (wxSizeEvent &) { setup_pixels_per_time_unit (); } + +void +Timeline::clear_selection () +{ + for (list<shared_ptr<View> >::iterator i = _views.begin(); i != _views.end(); ++i) { + shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i); + if (cv) { + cv->set_selected (false); + } + } +} + +void +Timeline::repeat (wxCommandEvent &) +{ + list<shared_ptr<ContentView> > sel = selected (); + if (sel.empty ()) { + return; + } + + RepeatDialog d (this); + d.ShowModal (); + + shared_ptr<const Film> film = _film.lock (); + if (!film) { + return; + } + + list<shared_ptr<Content> > content; + for (list<shared_ptr<ContentView> >::iterator i = sel.begin(); i != sel.end(); ++i) { + content.push_back ((*i)->content ()); + } + + film->playlist()->repeat (content, d.number ()); + d.Destroy (); +} + +list<shared_ptr<ContentView> > +Timeline::selected () const +{ + list<shared_ptr<ContentView> > sel; + + for (list<shared_ptr<View> >::const_iterator i = _views.begin(); i != _views.end(); ++i) { + shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i); + if (cv && cv->selected()) { + sel.push_back (cv); + } + } + + return sel; +} + |
