From c01d6dbd0b62952713ee0754e2df05dcb3989a25 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 27 Dec 2010 07:16:02 +0100 Subject: [PATCH] Move Track enabled/locked state to GUI model. --- src/gui/model/track.cpp | 42 +++++- src/gui/model/track.hpp | 136 ++++++++++++++------ src/gui/widgets/timeline/timeline-track.cpp | 119 ++++++++++------- src/gui/widgets/timeline/timeline-track.hpp | 74 +++++++---- 4 files changed, 262 insertions(+), 109 deletions(-) diff --git a/src/gui/model/track.cpp b/src/gui/model/track.cpp index 6d5cf2a65..b8588ed49 100644 --- a/src/gui/model/track.cpp +++ b/src/gui/model/track.cpp @@ -33,6 +33,8 @@ namespace model { const list< shared_ptr > Track::NoChildren; Track::Track() + : enabled(true), + locked(false) { } @@ -43,12 +45,38 @@ Track::get_child_tracks() const return Track::NoChildren; } +bool +Track::getEnabled() const +{ + return enabled; +} + +bool +Track::getLocked() const +{ + return locked; +} + const string Track::get_name() const { return name; } +void +Track::setEnabled(bool enabled) +{ + this->enabled = enabled; + enabledChangedSignal.emit(enabled); +} + +void +Track::setLocked(bool locked) +{ + this->locked = locked; + lockedChangedSignal.emit(locked); +} + void Track::set_name(const string &name) { @@ -75,8 +103,20 @@ Track::find_descendant_track_parent( return shared_ptr(); } +sigc::signal +Track::signalEnabledChanged() const +{ + return enabledChangedSignal; +} + +sigc::signal +Track::signalLockedChanged() const +{ + return lockedChangedSignal; +} + sigc::signal -Track::signal_name_changed() const +Track::signalNameChanged() const { return nameChangedSignal; } diff --git a/src/gui/model/track.hpp b/src/gui/model/track.hpp index 7517219a7..4aebc95ee 100644 --- a/src/gui/model/track.hpp +++ b/src/gui/model/track.hpp @@ -48,27 +48,56 @@ protected: public: + /** + * Returns true if this track can own any child tracks. + **/ + virtual bool + can_host_children () const; + /** * Gets the list of child tracks. **/ virtual const std::list< boost::shared_ptr >& - get_child_tracks() const; + get_child_tracks () const; + /** + * Gets the enabled status of this track, i.e. if the track is to be rendered. + **/ + bool + getEnabled () const; + + /** + * Gets the locked status of this track, i.e. if the track can be edited. + **/ + bool + getLocked () const; + /** * Gets the name of this track. **/ - const std::string get_name() const; - + const std::string + get_name () const; + + /** + * Sets the enabled status of this track, i.e. if the track is to be rendered. + * @param[in] name The new enabled status. + **/ + void + setEnabled (bool enabled); + + /** + * Gets the locked status of this track, i.e. if the track can be edited. + * @param[in] name The new locked status. + **/ + void + setLocked (bool locked); + /** * Sets the name of this track. * @param[in] name The new name to set this track to. **/ - void set_name(const std::string &name); - - /** - * Returns true if this track can own any child tracks. - **/ - virtual bool can_host_children() const; + void + set_name (const std::string &name); /** * A utility function that attempts to find the parent of a track by @@ -78,59 +107,94 @@ public: * shared_ptr if none was found. **/ virtual boost::shared_ptr - find_descendant_track_parent(boost::shared_ptr child); + find_descendant_track_parent (boost::shared_ptr child); -public: + /** + * A signal which fires when the enabled status changes. + * @return Returns the signal. The signal sends the new name for the + * track. + **/ + sigc::signal + signalEnabledChanged () const; + + /** + * A signal which fires when the locked status changes changes. + * @return Returns the signal. The signal sends the new name for the + * track. + **/ + sigc::signal + signalLockedChanged () const; /** * A signal which fires when the name changes. * @return Returns the signal. The signal sends the new name for the * track. **/ - sigc::signal signal_name_changed() const; + sigc::signal + signalNameChanged () const; -public: /** * A debugging helper function that prints this track, and all it's * child tracks in a human-readable form. * @return Returns the human readable string. **/ - std::string print_branch(); + std::string + print_branch (); /** * A pure-virtual function which is the base of functions that print * this track in human readable form. * @return Returns the human readable string. **/ - virtual std::string print_track() = 0; + virtual std::string + print_track () = 0; -protected: - /** - * The internal implementation of print_branch. - * @param indentation The level of recursion into the tree. This value - * is used to specify the width of indentation to print with. - * @return Returns the human readable string. - **/ - std::string print_branch_recursive(const unsigned int indentation); - -private: - //----- Data -----// - /** - * The name of this track. - **/ - std::string name; - - /** - * A signal which fires when the name changes. - **/ - sigc::signal nameChangedSignal; - protected: /** * An object used internally as a return value for when there's no * children. **/ static const std::list< boost::shared_ptr > NoChildren; + + /** + * The internal implementation of print_branch. + * @param indentation The level of recursion into the tree. This value + * is used to specify the width of indentation to print with. + * @return Returns the human readable string. + **/ + std::string + print_branch_recursive (const unsigned int indentation); + +private: + /** + * The name of this track. + **/ + std::string name; + + /** + * True if this track is enabled, i.e. will not be rendered. + */ + bool enabled; + + /** + * True if this track is locked, i.e. cannot be edited. + */ + bool locked; + + /** + * A signal which fires when the enabled status changes. + **/ + sigc::signal enabledChangedSignal; + + /** + * A signal which fires when the locked status changes. + **/ + sigc::signal lockedChangedSignal; + + /** + * A signal which fires when the name changes. + **/ + sigc::signal nameChangedSignal; }; } // namespace model diff --git a/src/gui/widgets/timeline/timeline-track.cpp b/src/gui/widgets/timeline/timeline-track.cpp index ea76eb1ea..af33ce725 100644 --- a/src/gui/widgets/timeline/timeline-track.cpp +++ b/src/gui/widgets/timeline/timeline-track.cpp @@ -40,10 +40,8 @@ Track::Track(TimelineWidget &timeline_widget, shared_ptr track) : timelineWidget(timeline_widget), model_track(track), - enabled(true), expanded(true), expandDirection(None), - locked(false), headerWidget(*this), enableButton(Gtk::StockID("track_enabled"), WindowManager::MenuIconSize), lockButton(Gtk::StockID("track_unlocked"), WindowManager::MenuIconSize) @@ -53,8 +51,8 @@ Track::Track(TimelineWidget &timeline_widget, titleMenuButton.set_relief(RELIEF_HALF); titleMenuButton.unset_flags(CAN_FOCUS); - buttonBar.append(enableButton, mem_fun(this, &Track::on_enable)); - buttonBar.append(lockButton, mem_fun(this, &Track::on_lock)); + buttonBar.append(enableButton, mem_fun(this, &Track::onToggleEnabled)); + buttonBar.append(lockButton, mem_fun(this, &Track::onToggleLocked)); headerWidget.set_child_widget(headerBox); @@ -71,11 +69,11 @@ Track::Track(TimelineWidget &timeline_widget, title_list.push_back( Menu_Helpers::MenuElem(_("_Remove"), mem_fun(this, &Track::on_remove_track) ) ); - update_name(); - - // Setup tooltips - enableButton.set_tooltip_text(_("Disable track")); - lockButton.set_tooltip_text(_("Lock track")); + updateEnableButton(); + + updateLockButton(); + + updateName(); // Setup the context menu Menu::MenuList& context_list = contextMenu.items(); @@ -85,9 +83,12 @@ Track::Track(TimelineWidget &timeline_widget, mem_fun(this, &Track::on_remove_track) ) ); // Connect to the model - model_track->signal_name_changed().connect(sigc::mem_fun(this, - &Track::on_name_changed)); - + model_track->signalEnabledChanged().connect(sigc::mem_fun(this, + &Track::onEnabledChanged)); + model_track->signalLockedChanged().connect(sigc::mem_fun(this, + &Track::onLockedChanged)); + model_track->signalNameChanged().connect(sigc::mem_fun(this, + &Track::onNameChanged)); } Track::~Track() @@ -226,42 +227,15 @@ Track::show_header_context_menu(guint button, guint32 time) } void -Track::update_name() +Track::onEnabledChanged(bool) { - REQUIRE(model_track); - titleMenuButton.set_label(model_track->get_name()); + updateEnableButton(); } void -Track::on_enable() +Track::onLockedChanged(bool) { - enabled = !enabled; - if (enabled) - { - enableButton.set_stock_id(Gtk::StockID("track_enabled"), WindowManager::MenuIconSize); - enableButton.set_tooltip_text(_("Disable track")); - } - else - { - enableButton.set_stock_id(Gtk::StockID("track_disabled"), WindowManager::MenuIconSize); - enableButton.set_tooltip_text(_("Enable track")); - } -} - -void -Track::on_lock() -{ - locked = !locked; - if (locked) - { - lockButton.set_stock_id(Gtk::StockID("track_locked"), WindowManager::MenuIconSize); - lockButton.set_tooltip_text(_("Unlock track")); - } - else - { - lockButton.set_stock_id(Gtk::StockID("track_unlocked"), WindowManager::MenuIconSize); - lockButton.set_tooltip_text(_("Lock track")); - } + updateLockButton(); } void @@ -281,9 +255,9 @@ Track::on_set_name() } void -Track::on_name_changed(std::string) +Track::onNameChanged(std::string) { - update_name(); + updateName(); } void @@ -296,6 +270,61 @@ Track::on_remove_track() state->get_sequence()->remove_descendant_track(model_track); } +void +Track::onToggleEnabled() +{ + bool status = model_track->getEnabled(); + model_track->setEnabled(!status); +} + +void +Track::onToggleLocked() +{ + bool status = model_track->getLocked(); + model_track->setLocked(!status); +} + +void +Track::updateEnableButton() +{ + REQUIRE (model_track); + + if (model_track->getEnabled()) + { + enableButton.set_stock_id(Gtk::StockID("track_enabled"), WindowManager::MenuIconSize); + enableButton.set_tooltip_text(_("Disable track")); + } + else + { + enableButton.set_stock_id(Gtk::StockID("track_disabled"), WindowManager::MenuIconSize); + enableButton.set_tooltip_text(_("Enable track")); + } +} + +void +Track::updateLockButton() +{ + REQUIRE (model_track); + + if (model_track->getLocked()) + { + lockButton.set_stock_id(Gtk::StockID("track_locked"), WindowManager::MenuIconSize); + lockButton.set_tooltip_text(_("Unlock track")); + } + else + { + lockButton.set_stock_id(Gtk::StockID("track_unlocked"), WindowManager::MenuIconSize); + lockButton.set_tooltip_text(_("Lock track")); + } +} + +void +Track::updateName() +{ + REQUIRE(model_track); + titleMenuButton.set_label(model_track->get_name()); +} + } // namespace timeline } // namespace widgets } // namespace gui diff --git a/src/gui/widgets/timeline/timeline-track.hpp b/src/gui/widgets/timeline/timeline-track.hpp index 474b74e41..3d9a14ab8 100644 --- a/src/gui/widgets/timeline/timeline-track.hpp +++ b/src/gui/widgets/timeline/timeline-track.hpp @@ -62,6 +62,9 @@ public: }; public: + /** + * Constructor + */ Track(TimelineWidget &timeline_widget, boost::shared_ptr track); @@ -74,6 +77,10 @@ public: boost::shared_ptr get_model_track() const; + /** + * Return the visual height of the track in pixels. + * @return The visual height of the track in pixels. + */ int get_height() const; /** @@ -125,45 +132,63 @@ public: virtual void draw_track(Cairo::RefPtr cairo, TimelineViewWindow* const window) const = 0; - -public: - //----- Constants -----// - + +private: + /** * Specifies the period of the expand animation in seconds. **/ static const float ExpandAnimationPeriod; -private: - //----- Internals -----// - void update_name(); - private: - //----- Event Handlers -----// - void on_enable(); - void on_lock(); + /** + * Event handler for when the enabled status changes. + **/ + void onEnabledChanged(bool); + + /** + * Event handler for when the track name changes. + **/ + void onNameChanged(std::string); + + /** + * Event handler for when the user requested to remove the track. + **/ + void on_remove_track(); + + /** + * Event handler for when the locked status changes. + **/ + void onLockedChanged(bool); + + /** + * Event handler for when the user requested a name change. + **/ void on_set_name(); /** - * Event handler for when the track name changes - **/ - void on_name_changed(std::string); + * Event handler for when the user pressed the Enable button. + */ + void onToggleEnabled(); + + /** + * Event handler for when the user pressed the Lock button. + */ + void onToggleLocked(); + + void updateEnableButton(); + + void updateLockButton(); + + void updateName(); - void on_remove_track(); - protected: TimelineWidget &timelineWidget; boost::shared_ptr model_track; private: - - /** - * True if this track is enabled. - */ - bool enabled; - /** * This bool is true if this branch is expanded. false if it is * collapsed. @@ -194,11 +219,6 @@ private: **/ boost::scoped_ptr expand_timer; - /** - * True if this track is locked. - */ - bool locked; - //----- Header Widgets ------// timeline::TimelineHeaderWidget headerWidget;