added fade in/out editing to SimplePlaylistManagementWindow

This commit is contained in:
fgerlits 2005-07-14 15:56:59 +00:00
parent bb9553f329
commit 6efcdee4ca
4 changed files with 253 additions and 17 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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(). * 3) connected with a TreeModelColumn using set_renderer().
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.14 $ * @version $Revision: 1.15 $
*/ */
class ZebraTreeView : public Gtk::TreeView class ZebraTreeView : public Gtk::TreeView
{ {
@ -130,7 +130,30 @@ class ZebraTreeView : public Gtk::TreeView
const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::iterator& iter,
int offset) int offset)
throw (); 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: protected:
/**
* A signal object to notify people that a cell has been edited.
*/
sigc::signal<void,
const Glib::ustring &,
int,
const Glib::ustring &> signalCellEditedObject;
public: public:
/** /**
@ -226,6 +249,31 @@ class ZebraTreeView : public Gtk::TreeView
int minimumWidth = 0) int minimumWidth = 0)
throw (); 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<Glib::ustring>& modelColumn,
int columnId,
int minimumWidth = 0)
throw ();
/** /**
* Signal handler for the "up" menu option selected from * Signal handler for the "up" menu option selected from
* the context menu. * the context menu.
@ -254,6 +302,17 @@ class ZebraTreeView : public Gtk::TreeView
*/ */
void void
removeItem(const Gtk::TreeModel::iterator & iter) throw (); 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<void, const Glib::ustring &, int, const Glib::ustring &>
signalCellEdited(void) throw ()
{
return signalCellEditedObject;
}
}; };

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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<Glib::ustring>& 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<int>(
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 * Event handler for the Up menu item selected from the entry conext menu
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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: // Add the TreeView's view columns:
try { try {
entriesView->appendColumn(*getResourceUstring("startColumnLabel"), entriesView->appendColumn(*getResourceUstring("startColumnLabel"),
modelColumns.startColumn, 80); modelColumns.startColumn,
60);
entriesView->appendColumn(*getResourceUstring("titleColumnLabel"), entriesView->appendColumn(*getResourceUstring("titleColumnLabel"),
modelColumns.titleColumn, 200); modelColumns.titleColumn,
entriesView->appendColumn(*getResourceUstring("fadeInColumnLabel"), 200);
modelColumns.fadeInColumn, 80); entriesView->appendEditableColumn(
*getResourceUstring("fadeInColumnLabel"),
modelColumns.fadeInColumn,
fadeInColumnId,
60);
entriesView->appendColumn(*getResourceUstring("lengthColumnLabel"), entriesView->appendColumn(*getResourceUstring("lengthColumnLabel"),
modelColumns.lengthColumn, 80); modelColumns.lengthColumn,
entriesView->appendColumn(*getResourceUstring("fadeOutColumnLabel"), 60);
modelColumns.fadeOutColumn, 80); entriesView->appendEditableColumn(
*getResourceUstring("fadeOutColumnLabel"),
modelColumns.fadeOutColumn,
fadeOutColumnId,
60);
statusBar = Gtk::manage(new Gtk::Label("")); statusBar = Gtk::manage(new Gtk::Label(""));
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
@ -116,6 +125,9 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
std::exit(1); std::exit(1);
} }
entriesView->signalCellEdited().connect(sigc::mem_fun(
*this, &SimplePlaylistManagementWindow::onFadeInfoEdited ));
// set up the layout // set up the layout
Gtk::VBox * mainBox = Gtk::manage(new Gtk::VBox); Gtk::VBox * mainBox = Gtk::manage(new Gtk::VBox);
@ -152,7 +164,7 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
// show // show
set_name("simplePlaylistManagementWindow"); set_name("simplePlaylistManagementWindow");
set_default_size(450, 300); set_default_size(470, 300);
set_modal(false); set_modal(false);
property_window_position().set_value(Gtk::WIN_POS_NONE); property_window_position().set_value(Gtk::WIN_POS_NONE);
@ -312,12 +324,104 @@ SimplePlaylistManagementWindow :: showContents(void) throw ()
row[modelColumns.fadeInColumn] row[modelColumns.fadeInColumn]
= (fadeIn && fadeIn->total_microseconds() != 0) = (fadeIn && fadeIn->total_microseconds() != 0)
? *TimeConversion::timeDurationToHhMmSsString(fadeIn) ? *TimeConversion::timeDurationToHhMmSsString(fadeIn)
: "-"; : "- ";
row[modelColumns.fadeOutColumn] row[modelColumns.fadeOutColumn]
= (fadeOut && fadeOut->total_microseconds() != 0) = (fadeOut && fadeOut->total_microseconds() != 0)
? *TimeConversion::timeDurationToHhMmSsString(fadeOut) ? *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<int> rowNumberVector = path.get_indices();
int rowNumber = rowNumberVector.at(0);
Ptr<time_duration>::Ref newTime(new time_duration(
duration_from_string(newText) ));
Ptr<Playlist>::Ref playlist = gLiveSupport->getEditedPlaylist();
Playlist::const_iterator iter = playlist->begin();
for (int i=0; i<rowNumber; ++i) {
++iter;
}
// TODO: add an at(n) access function to Playlist
Ptr<PlaylistElement>::Ref playlistElement = iter->second;
switch (columnId) {
case fadeInColumnId :
setFadeIn(playlistElement, newTime);
if (iter != playlist->begin()) {
--iter;
Ptr<PlaylistElement>::Ref prevPlaylistElement = iter->second;
setFadeOut(prevPlaylistElement, newTime);
}
break;
case fadeOutColumnId :
setFadeOut(playlistElement, newTime);
++iter;
if (iter != playlist->end()) {
Ptr<PlaylistElement>::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<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeIn)
throw()
{
Ptr<FadeInfo>::Ref oldFadeInfo = playlistElement->getFadeInfo();
Ptr<time_duration>::Ref oldFadeOut;
if (oldFadeInfo) {
oldFadeOut = oldFadeInfo->getFadeOut();
} else {
oldFadeOut.reset(new time_duration(0,0,0,0));
}
Ptr<FadeInfo>::Ref newFadeInfo(new FadeInfo(
newFadeIn, oldFadeOut ));
playlistElement->setFadeInfo(newFadeInfo);
}
/*------------------------------------------------------------------------------
* Auxilliary function: set the fade out of a playlist element.
*----------------------------------------------------------------------------*/
void
GLiveSupport :: setFadeOut(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeOut)
throw()
{
Ptr<FadeInfo>::Ref oldFadeInfo = playlistElement->getFadeInfo();
Ptr<time_duration>::Ref oldFadeIn;
if (oldFadeInfo) {
oldFadeIn = oldFadeInfo->getFadeIn();
} else {
oldFadeIn.reset(new time_duration(0,0,0,0));
}
Ptr<FadeInfo>::Ref newFadeInfo(new FadeInfo(
oldFadeIn, newFadeOut ));
playlistElement->setFadeInfo(newFadeInfo);
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -87,11 +87,27 @@ using namespace LiveSupport::Widgets;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.8 $ * @version $Revision: 1.9 $
*/ */
class SimplePlaylistManagementWindow : public WhiteWindow, class SimplePlaylistManagementWindow : public WhiteWindow,
public LocalizedObject 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: protected:
@ -100,7 +116,7 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
* Lists one playlist entry per row. * Lists one playlist entry per row.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.8 $ * @version $Revision: 1.9 $
*/ */
class ModelColumns : public ZebraTreeModelColumnRecord class ModelColumns : public ZebraTreeModelColumnRecord
{ {
@ -257,6 +273,19 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
/* ====================================================== function prototypes */ /* ====================================================== function prototypes */
/**
* Auxilliary function: set the fade in of a playlist element.
*/
void
setFadeIn(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeIn) throw();
/**
* Auxilliary function: set the fade out of a playlist element.
*/
void
setFadeOut(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeOut) throw();
} // namespace GLiveSupport } // namespace GLiveSupport
} // namespace LiveSupport } // namespace LiveSupport