Make jump-to-content-start on selection in the content list optional.
[dcpomatic.git] / src / wx / film_viewer.cc
index 42ce7cd1841fe27b5440e7324e4936b533c74c61..3c6138d465d39a65b2d33cc832a02ac75908d085 100644 (file)
  *  @brief A wx widget to view a preview of a Film.
  */
 
+#include "film_viewer.h"
+#include "playhead_to_timecode_dialog.h"
+#include "playhead_to_frame_dialog.h"
+#include "wx_util.h"
 #include "lib/film.h"
 #include "lib/ratio.h"
 #include "lib/util.h"
@@ -36,8 +40,7 @@
 #include "lib/video_decoder.h"
 #include "lib/timer.h"
 #include "lib/log.h"
-#include "film_viewer.h"
-#include "wx_util.h"
+#include "lib/config.h"
 extern "C" {
 #include <libavutil/pixfmt.h>
 }
@@ -67,6 +70,7 @@ FilmViewer::FilmViewer (wxWindow* p)
        , _outline_content (new wxCheckBox (this, wxID_ANY, _("Outline content")))
        , _left_eye (new wxRadioButton (this, wxID_ANY, _("Left eye"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP))
        , _right_eye (new wxRadioButton (this, wxID_ANY, _("Right eye")))
+       , _jump_to_selected (new wxCheckBox (this, wxID_ANY, _("Jump to selected content")))
        , _slider (new wxSlider (this, wxID_ANY, 0, 0, 4096))
        , _back_button (new wxButton (this, wxID_ANY, wxT("<")))
        , _forward_button (new wxButton (this, wxID_ANY, wxT(">")))
@@ -92,6 +96,7 @@ FilmViewer::FilmViewer (wxWindow* p)
        view_options->Add (_outline_content, 0, wxRIGHT, DCPOMATIC_SIZER_GAP);
        view_options->Add (_left_eye, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
        view_options->Add (_right_eye, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
+       view_options->Add (_jump_to_selected, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
        _v_sizer->Add (view_options, 0, wxALL, DCPOMATIC_SIZER_GAP);
 
        wxBoxSizer* h_sizer = new wxBoxSizer (wxHORIZONTAL);
@@ -112,18 +117,23 @@ FilmViewer::FilmViewer (wxWindow* p)
        _back_button->SetMinSize (wxSize (32, -1));
        _forward_button->SetMinSize (wxSize (32, -1));
 
-       _panel->Bind          (wxEVT_PAINT,                        boost::bind (&FilmViewer::paint_panel,     this));
-       _panel->Bind          (wxEVT_SIZE,                         boost::bind (&FilmViewer::panel_sized,     this, _1));
-       _outline_content->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED,     boost::bind (&FilmViewer::refresh_panel,   this));
-       _left_eye->Bind       (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&FilmViewer::refresh,         this));
-       _right_eye->Bind      (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&FilmViewer::refresh,         this));
-       _slider->Bind         (wxEVT_SCROLL_THUMBTRACK,            boost::bind (&FilmViewer::slider_moved,    this));
-       _slider->Bind         (wxEVT_SCROLL_PAGEUP,                boost::bind (&FilmViewer::slider_moved,    this));
-       _slider->Bind         (wxEVT_SCROLL_PAGEDOWN,              boost::bind (&FilmViewer::slider_moved,    this));
-       _play_button->Bind    (wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, boost::bind (&FilmViewer::play_clicked,    this));
-       _timer.Bind           (wxEVT_TIMER,                        boost::bind (&FilmViewer::timer,           this));
-       _back_button->Bind    (wxEVT_COMMAND_BUTTON_CLICKED,       boost::bind (&FilmViewer::back_clicked,    this));
-       _forward_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED,       boost::bind (&FilmViewer::forward_clicked, this));
+       _panel->Bind            (wxEVT_PAINT,             boost::bind (&FilmViewer::paint_panel,     this));
+       _panel->Bind            (wxEVT_SIZE,              boost::bind (&FilmViewer::panel_sized,     this, _1));
+       _outline_content->Bind  (wxEVT_CHECKBOX,          boost::bind (&FilmViewer::refresh_panel,   this));
+       _left_eye->Bind         (wxEVT_RADIOBUTTON,       boost::bind (&FilmViewer::refresh,         this));
+       _right_eye->Bind        (wxEVT_RADIOBUTTON,       boost::bind (&FilmViewer::refresh,         this));
+       _slider->Bind           (wxEVT_SCROLL_THUMBTRACK, boost::bind (&FilmViewer::slider_moved,    this));
+       _slider->Bind           (wxEVT_SCROLL_PAGEUP,     boost::bind (&FilmViewer::slider_moved,    this));
+       _slider->Bind           (wxEVT_SCROLL_PAGEDOWN,   boost::bind (&FilmViewer::slider_moved,    this));
+       _play_button->Bind      (wxEVT_TOGGLEBUTTON,      boost::bind (&FilmViewer::play_clicked,    this));
+       _timer.Bind             (wxEVT_TIMER,             boost::bind (&FilmViewer::timer,           this));
+       _back_button->Bind      (wxEVT_LEFT_DOWN,         boost::bind (&FilmViewer::back_clicked,    this, _1));
+       _forward_button->Bind   (wxEVT_LEFT_DOWN,         boost::bind (&FilmViewer::forward_clicked, this, _1));
+       _frame_number->Bind     (wxEVT_LEFT_DOWN,         boost::bind (&FilmViewer::frame_number_clicked, this));
+       _timecode->Bind         (wxEVT_LEFT_DOWN,         boost::bind (&FilmViewer::timecode_clicked, this));
+       _jump_to_selected->Bind (wxEVT_CHECKBOX,          boost::bind (&FilmViewer::jump_to_selected_clicked, this));
+
+       _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
 
        set_film (shared_ptr<Film> ());
 
@@ -448,32 +458,52 @@ FilmViewer::active_jobs_changed (optional<string> j)
        _play_button->Enable (a);
 }
 
-void
-FilmViewer::back_clicked ()
+DCPTime
+FilmViewer::nudge_amount (wxMouseEvent& ev)
 {
-       DCPTime p = _position - DCPTime::from_frames (1, _film->video_frame_rate ());
-       if (p < DCPTime ()) {
-               p = DCPTime ();
+       DCPTime amount = DCPTime::from_frames (1, _film->video_frame_rate ());
+
+       if (ev.ShiftDown() && !ev.ControlDown()) {
+               amount = DCPTime::from_seconds (1);
+       } else if (!ev.ShiftDown() && ev.ControlDown()) {
+               amount = DCPTime::from_seconds (10);
+       } else if (ev.ShiftDown() && ev.ControlDown()) {
+               amount = DCPTime::from_seconds (60);
        }
 
-       get (p, true);
-       update_position_label ();
-       update_position_slider ();
+       return amount;
 }
 
 void
-FilmViewer::forward_clicked ()
+FilmViewer::go_to (DCPTime t)
 {
-       DCPTime p = _position + DCPTime::from_frames (1, _film->video_frame_rate ());
-       if (p >= _film->length ()) {
-               p = _position;
+       if (t < DCPTime ()) {
+               t = DCPTime ();
+       }
+
+       if (t >= _film->length ()) {
+               t = _film->length ();
        }
 
-       get (p, true);
+       get (t, true);
        update_position_label ();
        update_position_slider ();
 }
 
+void
+FilmViewer::back_clicked (wxMouseEvent& ev)
+{
+       go_to (_position - nudge_amount (ev));
+       ev.Skip ();
+}
+
+void
+FilmViewer::forward_clicked (wxMouseEvent& ev)
+{
+       go_to (_position + nudge_amount (ev));
+       ev.Skip ();
+}
+
 void
 FilmViewer::player_changed (bool frequent)
 {
@@ -546,3 +576,29 @@ FilmViewer::set_coalesce_player_changes (bool c)
                }
        }
 }
+
+void
+FilmViewer::timecode_clicked ()
+{
+       PlayheadToTimecodeDialog* dialog = new PlayheadToTimecodeDialog (this, _film->video_frame_rate ());
+       if (dialog->ShowModal() == wxID_OK) {
+               go_to (dialog->get ());
+       }
+       dialog->Destroy ();
+}
+
+void
+FilmViewer::frame_number_clicked ()
+{
+       PlayheadToFrameDialog* dialog = new PlayheadToFrameDialog (this, _film->video_frame_rate ());
+       if (dialog->ShowModal() == wxID_OK) {
+               go_to (dialog->get ());
+       }
+       dialog->Destroy ();
+}
+
+void
+FilmViewer::jump_to_selected_clicked ()
+{
+       Config::instance()->set_jump_to_selected (_jump_to_selected->GetValue ());
+}