diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h index 4138ac7e1..83e35f54c 100644 --- a/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h +++ b/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.14 $ + Version : $Revision: 1.15 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h,v $ ------------------------------------------------------------------------------*/ @@ -92,7 +92,7 @@ using namespace LiveSupport::Core; * 3) connected with a TreeModelColumn using set_renderer(). * * @author $Author: fgerlits $ - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ */ class ZebraTreeView : public Gtk::TreeView { @@ -130,7 +130,30 @@ class ZebraTreeView : public Gtk::TreeView const Gtk::TreeModel::iterator& iter, int offset) throw (); + + /** + * Emit the "cell has been edited" signal. + */ + void + emitSignalCellEdited(const Glib::ustring & path, + const Glib::ustring & newText, + int columnId) + throw () + { + signalCellEdited().emit(path, columnId, newText); + } + + protected: + + /** + * A signal object to notify people that a cell has been edited. + */ + sigc::signal signalCellEditedObject; + public: /** @@ -226,6 +249,31 @@ class ZebraTreeView : public Gtk::TreeView int minimumWidth = 0) throw (); + /** + * Add an editable text column to the TreeView. + * + * The signal_edited() signal of the cell renderer gets connected + * to the signalEdited() signal of the ZebraTreeView object; the + * columnId argument will get passed to the signal handler. + * + * This is used to display fade info (time durations), so the text is + * right aligned in the column. + * + * @param title the title of the column + * @param modelColumn the model column this view will display + * @param columnId the column ID passed to the signal handler + * @param minimumWidth the minimum width of the column, in pixels + * (optional) + * @return the number of columns after adding this one + */ + int + appendEditableColumn( + const Glib::ustring& title, + const Gtk::TreeModelColumn& modelColumn, + int columnId, + int minimumWidth = 0) + throw (); + /** * Signal handler for the "up" menu option selected from * the context menu. @@ -254,6 +302,17 @@ class ZebraTreeView : public Gtk::TreeView */ void removeItem(const Gtk::TreeModel::iterator & iter) throw (); + + /** + * The signal raised when a cell has been edited. + * + * @return the signal object (a protected member of this class) + */ + sigc::signal + signalCellEdited(void) throw () + { + return signalCellEditedObject; + } }; diff --git a/livesupport/modules/widgets/src/ZebraTreeView.cxx b/livesupport/modules/widgets/src/ZebraTreeView.cxx index 362a24218..cbb869c26 100644 --- a/livesupport/modules/widgets/src/ZebraTreeView.cxx +++ b/livesupport/modules/widgets/src/ZebraTreeView.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.17 $ + Version : $Revision: 1.18 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ZebraTreeView.cxx,v $ ------------------------------------------------------------------------------*/ @@ -303,6 +303,50 @@ ZebraTreeView :: lineNumberCellDataFunction( } +/*------------------------------------------------------------------------------ + * Add a centered text column to the TreeView. + *----------------------------------------------------------------------------*/ +int +ZebraTreeView :: appendEditableColumn( + const Glib::ustring& title, + const Gtk::TreeModelColumn& modelColumn, + int columnId, + int minimumWidth) + throw () +{ + // a standard cell renderer; can be replaced with a ZebraCellRenderer + Gtk::CellRendererText* renderer = Gtk::manage(new Gtk::CellRendererText); + + // right align the text in the column + renderer->property_xalign() = 1; + + // set the cells to be editable, and connect the signal to our own + renderer->property_editable() = true; + renderer->signal_edited().connect(sigc::bind( + sigc::mem_fun(*this, &ZebraTreeView::emitSignalCellEdited), + columnId )); + + // the constructor packs the renderer into the TreeViewColumn + Gtk::TreeViewColumn* viewColumn = Gtk::manage( + new Gtk::TreeViewColumn(title, *renderer) ); + + // and then we associate this renderer with the model column + viewColumn->add_attribute(renderer->property_markup(), modelColumn); + + // this cell data function will do the blue-gray zebra stripes + viewColumn->set_cell_data_func( + *renderer, + sigc::mem_fun(*this, &ZebraTreeView::cellDataFunction) ); + + // set the minimum width of the column + if (minimumWidth) { + viewColumn->set_min_width(minimumWidth); + } + + return append_column(*viewColumn); +} + + /*------------------------------------------------------------------------------ * Event handler for the Up menu item selected from the entry conext menu *----------------------------------------------------------------------------*/ diff --git a/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx b/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx index 71503f01e..5c8e0c605 100644 --- a/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx +++ b/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.18 $ + Version : $Revision: 1.19 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -100,15 +100,24 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow ( // Add the TreeView's view columns: try { entriesView->appendColumn(*getResourceUstring("startColumnLabel"), - modelColumns.startColumn, 80); + modelColumns.startColumn, + 60); entriesView->appendColumn(*getResourceUstring("titleColumnLabel"), - modelColumns.titleColumn, 200); - entriesView->appendColumn(*getResourceUstring("fadeInColumnLabel"), - modelColumns.fadeInColumn, 80); + modelColumns.titleColumn, + 200); + entriesView->appendEditableColumn( + *getResourceUstring("fadeInColumnLabel"), + modelColumns.fadeInColumn, + fadeInColumnId, + 60); entriesView->appendColumn(*getResourceUstring("lengthColumnLabel"), - modelColumns.lengthColumn, 80); - entriesView->appendColumn(*getResourceUstring("fadeOutColumnLabel"), - modelColumns.fadeOutColumn, 80); + modelColumns.lengthColumn, + 60); + entriesView->appendEditableColumn( + *getResourceUstring("fadeOutColumnLabel"), + modelColumns.fadeOutColumn, + fadeOutColumnId, + 60); statusBar = Gtk::manage(new Gtk::Label("")); } catch (std::invalid_argument &e) { @@ -116,6 +125,9 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow ( std::exit(1); } + entriesView->signalCellEdited().connect(sigc::mem_fun( + *this, &SimplePlaylistManagementWindow::onFadeInfoEdited )); + // set up the layout Gtk::VBox * mainBox = Gtk::manage(new Gtk::VBox); @@ -152,7 +164,7 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow ( // show set_name("simplePlaylistManagementWindow"); - set_default_size(450, 300); + set_default_size(470, 300); set_modal(false); property_window_position().set_value(Gtk::WIN_POS_NONE); @@ -312,12 +324,104 @@ SimplePlaylistManagementWindow :: showContents(void) throw () row[modelColumns.fadeInColumn] = (fadeIn && fadeIn->total_microseconds() != 0) ? *TimeConversion::timeDurationToHhMmSsString(fadeIn) - : "-"; + : "- "; row[modelColumns.fadeOutColumn] = (fadeOut && fadeOut->total_microseconds() != 0) ? *TimeConversion::timeDurationToHhMmSsString(fadeOut) - : "-"; + : "- "; } } } + +/*------------------------------------------------------------------------------ + * Signal handler for the fade info being edited. + *----------------------------------------------------------------------------*/ +void +SimplePlaylistManagementWindow :: onFadeInfoEdited( + const Glib::ustring & pathString, + int columnId, + const Glib::ustring & newText) + throw() +{ + Gtk::TreeModel::Path path(pathString); + std::vector rowNumberVector = path.get_indices(); + int rowNumber = rowNumberVector.at(0); + + Ptr::Ref newTime(new time_duration( + duration_from_string(newText) )); + + Ptr::Ref playlist = gLiveSupport->getEditedPlaylist(); + Playlist::const_iterator iter = playlist->begin(); + for (int i=0; i::Ref playlistElement = iter->second; + + switch (columnId) { + case fadeInColumnId : + setFadeIn(playlistElement, newTime); + if (iter != playlist->begin()) { + --iter; + Ptr::Ref prevPlaylistElement = iter->second; + setFadeOut(prevPlaylistElement, newTime); + } + break; + case fadeOutColumnId : + setFadeOut(playlistElement, newTime); + ++iter; + if (iter != playlist->end()) { + Ptr::Ref nextPlaylistElement = iter->second; + setFadeIn(nextPlaylistElement, newTime); + } + break; + default : + return; // should never happen + } + + showContents(); +} + + +/*------------------------------------------------------------------------------ + * Auxilliary function: set the fade in of a playlist element. + *----------------------------------------------------------------------------*/ +void +GLiveSupport :: setFadeIn(Ptr::Ref playlistElement, + Ptr::Ref newFadeIn) + throw() +{ + Ptr::Ref oldFadeInfo = playlistElement->getFadeInfo(); + Ptr::Ref oldFadeOut; + if (oldFadeInfo) { + oldFadeOut = oldFadeInfo->getFadeOut(); + } else { + oldFadeOut.reset(new time_duration(0,0,0,0)); + } + Ptr::Ref newFadeInfo(new FadeInfo( + newFadeIn, oldFadeOut )); + playlistElement->setFadeInfo(newFadeInfo); +} + + +/*------------------------------------------------------------------------------ + * Auxilliary function: set the fade out of a playlist element. + *----------------------------------------------------------------------------*/ +void +GLiveSupport :: setFadeOut(Ptr::Ref playlistElement, + Ptr::Ref newFadeOut) + throw() +{ + Ptr::Ref oldFadeInfo = playlistElement->getFadeInfo(); + Ptr::Ref oldFadeIn; + if (oldFadeInfo) { + oldFadeIn = oldFadeInfo->getFadeIn(); + } else { + oldFadeIn.reset(new time_duration(0,0,0,0)); + } + Ptr::Ref newFadeInfo(new FadeInfo( + oldFadeIn, newFadeOut )); + playlistElement->setFadeInfo(newFadeInfo); +} + diff --git a/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h b/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h index faf792d35..30ca7187a 100644 --- a/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h +++ b/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.8 $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -87,11 +87,27 @@ using namespace LiveSupport::Widgets; * * * @author $Author: fgerlits $ - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ */ class SimplePlaylistManagementWindow : public WhiteWindow, public LocalizedObject { + private: + + /** + * Constants for identifying the two fade info columns. + */ + enum { fadeInColumnId, + fadeOutColumnId }; + + /** + * Signal handler for the fade info being edited. + */ + void + onFadeInfoEdited(const Glib::ustring & path, + int columnId, + const Glib::ustring & newText) throw(); + protected: @@ -100,7 +116,7 @@ class SimplePlaylistManagementWindow : public WhiteWindow, * Lists one playlist entry per row. * * @author $Author: fgerlits $ - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ */ class ModelColumns : public ZebraTreeModelColumnRecord { @@ -257,6 +273,19 @@ class SimplePlaylistManagementWindow : public WhiteWindow, /* ====================================================== function prototypes */ + /** + * Auxilliary function: set the fade in of a playlist element. + */ + void + setFadeIn(Ptr::Ref playlistElement, + Ptr::Ref newFadeIn) throw(); + + /** + * Auxilliary function: set the fade out of a playlist element. + */ + void + setFadeOut(Ptr::Ref playlistElement, + Ptr::Ref newFadeOut) throw(); } // namespace GLiveSupport } // namespace LiveSupport