Added SelectionListener handling selection changing events

This commit is contained in:
Michael R. Fisher 2011-10-22 21:53:23 -05:00
parent 8ff36fc209
commit 3811183546
3 changed files with 75 additions and 4 deletions

View file

@ -49,7 +49,8 @@ IBeamTool::IBeamTool(TimelineBody &timeline_body) :
scrollSlideRate(0) scrollSlideRate(0)
{ {
// Connect the timlinebody selection to the selectionControl // 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() IBeamTool::~IBeamTool()

View file

@ -24,6 +24,7 @@
#include "gui/widgets/timeline/timeline-state.hpp" #include "gui/widgets/timeline/timeline-state.hpp"
#include "lib/time/timevalue.hpp" #include "lib/time/timevalue.hpp"
#include "lib/time/mutation.hpp" #include "lib/time/mutation.hpp"
#include "lib/time/control.hpp"
using namespace Gtk; using namespace Gtk;
using namespace sigc; using namespace sigc;
@ -36,14 +37,15 @@ using lib::time::FSecs;
using lib::time::Offset; using lib::time::Offset;
using lib::time::Duration; using lib::time::Duration;
using lib::time::Mutation; using lib::time::Mutation;
using lib::time::Control;
using std::tr1::shared_ptr; using std::tr1::shared_ptr;
TimelineState::TimelineState (shared_ptr<model::Sequence> source_sequence) TimelineState::TimelineState (shared_ptr<model::Sequence> source_sequence)
: sequence(source_sequence) : sequence(source_sequence)
, viewWindow(Offset(Time::ZERO), 1) , viewWindow(Offset(Time::ZERO), 1)
, selection_(Time::ZERO, Duration::NIL) , selection_(Time::ZERO, Duration::NIL)
, selectionListener()
, playbackPeriod_(Time::ZERO, Duration::NIL) , playbackPeriod_(Time::ZERO, Duration::NIL)
, playbackPoint_(Time::ZERO) , playbackPoint_(Time::ZERO)
, isPlayback_(false) , isPlayback_(false)
@ -55,6 +57,9 @@ TimelineState::TimelineState (shared_ptr<model::Sequence> source_sequence)
viewWindow.set_time_scale(DEFAULT_TIMELINE_SCALE); viewWindow.set_time_scale(DEFAULT_TIMELINE_SCALE);
selectionListener.connect(
mem_fun(*this, &TimelineState::on_selection_changed));
setSelection (Mutation::changeTime (Time(FSecs(2)))); setSelection (Mutation::changeTime (Time(FSecs(2))));
setSelection (Mutation::changeDuration(Duration(FSecs(2)))); setSelection (Mutation::changeDuration(Duration(FSecs(2))));
//////////////////////////////////////////////////////TICKET #797 : this is cheesy. Should provide a single Mutation to change all //////////////////////////////////////////////////////TICKET #797 : this is cheesy. Should provide a single Mutation to change all
@ -97,6 +102,14 @@ TimelineState::setPlaybackPoint (Time newPosition)
playbackChangedSignal.emit(); playbackChangedSignal.emit();
} }
void
TimelineState::set_selection_control (SelectionControl &control)
{
control.disconnect();
selection_.accept (control);
control.connectChangeNotification (selectionListener);
}
sigc::signal<void> sigc::signal<void>
TimelineState::selection_changed_signal() const TimelineState::selection_changed_signal() const
{ {
@ -109,6 +122,12 @@ TimelineState::playback_changed_signal() const
return playbackChangedSignal; return playbackChangedSignal;
} }
void
TimelineState::on_selection_changed()
{
selectionChangedSignal.emit();
}
} // namespace timeline } // namespace timeline
} // namespace widgets } // namespace widgets
} // namespace gui } // namespace gui

View file

@ -28,6 +28,7 @@
#include "gui/widgets/timeline/timeline-view-window.hpp" #include "gui/widgets/timeline/timeline-view-window.hpp"
#include "lib/time/mutation.hpp" #include "lib/time/mutation.hpp"
#include "lib/time/control.hpp"
namespace gui { namespace gui {
@ -39,8 +40,41 @@ class Sequence;
namespace widgets { namespace widgets {
namespace timeline { namespace timeline {
using lib::time::Control;
using lib::time::Mutation; using lib::time::Mutation;
typedef Control<TimeSpan> SelectionControl;
/**
* SelectionListener is a template class which emits a signal when
* the value is changed by it's associated time::Control object.
*/
template<class TI>
class SelectionListener
: boost::noncopyable
{
sigc::signal<void> valueChangedSignal;
public:
SelectionListener()
{
}
void
operator() (TI const& changeValue) const
{
valueChangedSignal.emit();
}
void connect (const sigc::slot<void> &connection)
{
valueChangedSignal.connect (connection);
}
};
/** /**
* TimelineState is a container for the state data for TimelineWidget. * TimelineState is a container for the state data for TimelineWidget.
* @remarks TimelineState s can be swapped out so that TimelineWidget * @remarks TimelineState s can be swapped out so that TimelineWidget
@ -70,7 +104,11 @@ public:
*/ */
timeline::TimelineViewWindow& get_view_window(); timeline::TimelineViewWindow& get_view_window();
TimeSpan get_selection() const { return selection_; } TimeSpan& get_selection() { return selection_; }
SelectionListener<TimeSpan>&
get_selection_listener() { return selectionListener; }
Time getSelectionStart() const { return selection_.start();} Time getSelectionStart() const { return selection_.start();}
Time getSelectionEnd() const { return selection_.end(); } Time getSelectionEnd() const { return selection_.end(); }
Time getPlaybackPeriodStart() const { return selection_.start();} Time getPlaybackPeriodStart() const { return selection_.start();}
@ -83,6 +121,7 @@ public:
* Otherwise the #getPlaybackPoint is meaningless */ * Otherwise the #getPlaybackPoint is meaningless */
bool isPlaying() const { return isPlayback_; } bool isPlaying() const { return isPlayback_; }
void set_selection_control (SelectionControl &control);
/** /**
* Sets the period of the selection. * Sets the period of the selection.
@ -114,6 +153,15 @@ public:
*/ */
sigc::signal<void> playback_changed_signal() const; sigc::signal<void> playback_changed_signal() const;
private:
/* ========= Event Handlers ========== */
/**
* Event handler for when the selection is changed
*/
void on_selection_changed();
private: private:
/** /**
@ -134,6 +182,9 @@ private:
/** currently selected time period. */ /** currently selected time period. */
TimeSpan selection_; TimeSpan selection_;
/** listens for a selection change */
SelectionListener<TimeSpan> selectionListener;
/** current playback period. */ /** current playback period. */
TimeSpan playbackPeriod_; TimeSpan playbackPeriod_;