diff --git a/src/gui/widgets/timeline/timeline-ibeam-tool.cpp b/src/gui/widgets/timeline/timeline-ibeam-tool.cpp index 02d6cbd74..cd397bf3f 100644 --- a/src/gui/widgets/timeline/timeline-ibeam-tool.cpp +++ b/src/gui/widgets/timeline/timeline-ibeam-tool.cpp @@ -49,7 +49,8 @@ IBeamTool::IBeamTool(TimelineBody &timeline_body) : scrollSlideRate(0) { // Connect the timlinebody selection to the selectionControl - this->get_state()->setSelection (selectionControl, false); + // TODO: Create a virtual initialize function in the base class + get_state()->set_selection_control(selectionControl); } IBeamTool::~IBeamTool() diff --git a/src/gui/widgets/timeline/timeline-state.cpp b/src/gui/widgets/timeline/timeline-state.cpp index 74042ef39..70a8521cc 100644 --- a/src/gui/widgets/timeline/timeline-state.cpp +++ b/src/gui/widgets/timeline/timeline-state.cpp @@ -24,6 +24,7 @@ #include "gui/widgets/timeline/timeline-state.hpp" #include "lib/time/timevalue.hpp" #include "lib/time/mutation.hpp" +#include "lib/time/control.hpp" using namespace Gtk; using namespace sigc; @@ -36,14 +37,15 @@ using lib::time::FSecs; using lib::time::Offset; using lib::time::Duration; using lib::time::Mutation; +using lib::time::Control; using std::tr1::shared_ptr; - TimelineState::TimelineState (shared_ptr source_sequence) : sequence(source_sequence) , viewWindow(Offset(Time::ZERO), 1) , selection_(Time::ZERO, Duration::NIL) + , selectionListener() , playbackPeriod_(Time::ZERO, Duration::NIL) , playbackPoint_(Time::ZERO) , isPlayback_(false) @@ -55,6 +57,9 @@ TimelineState::TimelineState (shared_ptr source_sequence) viewWindow.set_time_scale(DEFAULT_TIMELINE_SCALE); + selectionListener.connect( + mem_fun(*this, &TimelineState::on_selection_changed)); + setSelection (Mutation::changeTime (Time(FSecs(2)))); setSelection (Mutation::changeDuration(Duration(FSecs(2)))); //////////////////////////////////////////////////////TICKET #797 : this is cheesy. Should provide a single Mutation to change all @@ -97,6 +102,14 @@ TimelineState::setPlaybackPoint (Time newPosition) playbackChangedSignal.emit(); } +void +TimelineState::set_selection_control (SelectionControl &control) +{ + control.disconnect(); + selection_.accept (control); + control.connectChangeNotification (selectionListener); +} + sigc::signal TimelineState::selection_changed_signal() const { @@ -109,6 +122,12 @@ TimelineState::playback_changed_signal() const return playbackChangedSignal; } +void +TimelineState::on_selection_changed() +{ + selectionChangedSignal.emit(); +} + } // namespace timeline } // namespace widgets } // namespace gui diff --git a/src/gui/widgets/timeline/timeline-state.hpp b/src/gui/widgets/timeline/timeline-state.hpp index 0d0b02a32..2033665db 100644 --- a/src/gui/widgets/timeline/timeline-state.hpp +++ b/src/gui/widgets/timeline/timeline-state.hpp @@ -28,6 +28,7 @@ #include "gui/widgets/timeline/timeline-view-window.hpp" #include "lib/time/mutation.hpp" +#include "lib/time/control.hpp" namespace gui { @@ -38,9 +39,42 @@ class Sequence; namespace widgets { namespace timeline { - + +using lib::time::Control; using lib::time::Mutation; +typedef Control SelectionControl; + +/** + * SelectionListener is a template class which emits a signal when + * the value is changed by it's associated time::Control object. + */ +template +class SelectionListener + : boost::noncopyable + { + sigc::signal valueChangedSignal; + public: + SelectionListener() + { + + } + + + void + operator() (TI const& changeValue) const + { + valueChangedSignal.emit(); + } + + + void connect (const sigc::slot &connection) + { + valueChangedSignal.connect (connection); + } + + }; + /** * TimelineState is a container for the state data for TimelineWidget. * @remarks TimelineState s can be swapped out so that TimelineWidget @@ -70,7 +104,11 @@ public: */ timeline::TimelineViewWindow& get_view_window(); - TimeSpan get_selection() const { return selection_; } + TimeSpan& get_selection() { return selection_; } + + SelectionListener& + get_selection_listener() { return selectionListener; } + Time getSelectionStart() const { return selection_.start();} Time getSelectionEnd() const { return selection_.end(); } Time getPlaybackPeriodStart() const { return selection_.start();} @@ -83,6 +121,7 @@ public: * Otherwise the #getPlaybackPoint is meaningless */ bool isPlaying() const { return isPlayback_; } + void set_selection_control (SelectionControl &control); /** * Sets the period of the selection. @@ -113,6 +152,15 @@ public: * changed. */ sigc::signal playback_changed_signal() const; + +private: + + /* ========= Event Handlers ========== */ + + /** + * Event handler for when the selection is changed + */ + void on_selection_changed(); private: @@ -134,6 +182,9 @@ private: /** currently selected time period. */ TimeSpan selection_; + /** listens for a selection change */ + SelectionListener selectionListener; + /** current playback period. */ TimeSpan playbackPeriod_;