added functionality to output play button in the Live Mode window;

added new appendLineNumberColumn() function in ZebraTreeView;
fixed bug #972
This commit is contained in:
fgerlits 2005-05-18 16:28:54 +00:00
parent 89ae010689
commit 6af5fe6bd5
6 changed files with 197 additions and 45 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
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.11 $ * @version $Revision: 1.12 $
*/ */
class ZebraTreeView : public Gtk::TreeView class ZebraTreeView : public Gtk::TreeView
{ {
@ -106,12 +106,30 @@ class ZebraTreeView : public Gtk::TreeView
/** /**
* The callback function to set the colors of the rows. * The callback function to set the colors of the rows.
*
* @param cell the cell renderer of the column.
* @param iter points to the current row in the model.
*/ */
void void
cellDataFunction(Gtk::CellRenderer* cell, cellDataFunction(Gtk::CellRenderer* cell,
const Gtk::TreeModel::iterator& iter) const Gtk::TreeModel::iterator& iter)
throw (); throw ();
/**
* The callback function for the line number columns.
* It reads the line number from the rowNumberColumn of the model.
*
* @param cell the cell renderer of the column.
* @param iter points to the current row in the model.
* @param offset the line number of the first row, set by the
* call to appendLineNumberColumn()
*/
void
lineNumberCellDataFunction(
Gtk::CellRenderer* cell,
const Gtk::TreeModel::iterator& iter,
int offset)
throw ();
protected: protected:
public: public:
@ -175,6 +193,22 @@ class ZebraTreeView : public Gtk::TreeView
int minimumWidth = 0) int minimumWidth = 0)
throw (); throw ();
/**
* Add a centered line number column to the TreeView.
*
* @param title the title of the column
* @param offset the line number of the first row
* @param minimumWidth the minimum width of the column, in pixels
* (optional)
* @return the number of columns after adding this one
*/
int
appendLineNumberColumn(
const Glib::ustring& title,
int offset = 0,
int minimumWidth = 0)
throw ();
}; };

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.12 $ Version : $Revision: 1.13 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -34,6 +34,7 @@
#endif #endif
#include <iostream> #include <iostream>
#include <sstream>
#include "LiveSupport/Widgets/ZebraTreeModelColumnRecord.h" #include "LiveSupport/Widgets/ZebraTreeModelColumnRecord.h"
@ -198,3 +199,71 @@ ZebraTreeView :: appendCenteredColumn(
return append_column(*viewColumn); return append_column(*viewColumn);
} }
/*------------------------------------------------------------------------------
* Add a centered line number column to the TreeView.
*----------------------------------------------------------------------------*/
int
ZebraTreeView :: appendLineNumberColumn(
const Glib::ustring& title,
int offset,
int minimumWidth)
throw ()
{
// a standard cell renderer; can be replaced with a ZebraCellRenderer
Gtk::CellRendererText* renderer = Gtk::manage(new Gtk::CellRendererText);
// center the text in the column
renderer->property_xalign() = 0.5;
// the constructor packs the renderer into the TreeViewColumn
Gtk::TreeViewColumn* viewColumn = Gtk::manage(new
Gtk::TreeViewColumn(title, *renderer) );
// this cell data function will do the blue-gray zebra stripes
// and fill in the line number from the model.rowNumberColumn
viewColumn->set_cell_data_func(
*renderer,
sigc::bind<int>(
sigc::mem_fun(*this, &ZebraTreeView::lineNumberCellDataFunction),
offset ));
// set the minimum width of the column
if (minimumWidth) {
viewColumn->set_min_width(minimumWidth);
}
return append_column(*viewColumn);
}
/*------------------------------------------------------------------------------
* The callback function for the line number column(s).
*----------------------------------------------------------------------------*/
void
ZebraTreeView :: lineNumberCellDataFunction(
Gtk::CellRenderer* cell,
const Gtk::TreeModel::iterator& iter,
int offset)
throw ()
{
ZebraTreeModelColumnRecord model;
int rowNumber = (*iter)[model.rowNumberColumn];
Colors::ColorName colorName = rowNumber % 2 ? Colors::Gray
: Colors::LightBlue;
cell->property_cell_background_gdk() = Colors::getColor(colorName);
cell->property_cell_background_gdk() = Colors::getColor(colorName);
Glib::ustring numberString;
numberString.append("<span size=\"larger\" weight=\"ultrabold\">");
std::stringstream numberStr;
numberStr << (rowNumber + offset);
numberString.append(numberStr.str());
numberString.append("</span>");
Gtk::CellRendererText * textCell
= dynamic_cast<Gtk::CellRendererText*>(cell);
textCell->property_markup() = numberString;
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.41 $ Version : $Revision: 1.42 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -593,7 +593,7 @@ GLiveSupport :: addToLiveMode(Ptr<Playable>::Ref playable)
masterPanel->updateLiveModeWindow(playable); masterPanel->updateLiveModeWindow(playable);
} else { } else {
playOutputAudio(playable); playOutputAudio(playable);
masterPanel->setNowPlaying(playable); setNowPlaying(playable);
} }
} }
@ -606,19 +606,31 @@ LiveSupport :: GLiveSupport ::
GLiveSupport :: onStop(void) throw () GLiveSupport :: onStop(void) throw ()
{ {
Ptr<Playable>::Ref playable; Ptr<Playable>::Ref playable;
masterPanel->setNowPlaying(playable); // reset to empty setNowPlaying(playable); // reset to empty
playable = masterPanel->getNextItemToPlay(); playable = masterPanel->getNextItemToPlay();
if (playable) { if (playable) {
playOutputAudio(playable); playOutputAudio(playable);
masterPanel->setNowPlaying(playable); setNowPlaying(playable);
} else { } else {
stopOutputAudio(); stopOutputAudio();
} }
} }
/*------------------------------------------------------------------------------
* Display the playable item on the master panel as "now playing".
*----------------------------------------------------------------------------*/
inline void
LiveSupport :: GLiveSupport ::
GLiveSupport :: setNowPlaying(Ptr<Playable>::Ref playable)
throw ()
{
masterPanel->setNowPlaying(playable);
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Open a playlist for editing. * Open a playlist for editing.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.33 $ Version : $Revision: 1.34 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -101,7 +101,7 @@ class MasterPanelWindow;
* respective documentation. * respective documentation.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.33 $ * @version $Revision: 1.34 $
* @see LocalizedObject#getBundle(const xmlpp::Element &) * @see LocalizedObject#getBundle(const xmlpp::Element &)
* @see AuthenticationClientFactory * @see AuthenticationClientFactory
* @see StorageClientFactory * @see StorageClientFactory
@ -691,6 +691,13 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
virtual void virtual void
onStop(void) throw (); onStop(void) throw ();
/**
* Display the playable item on the master panel as "now playing".
*/
void
setNowPlaying(Ptr<Playable>::Ref playable)
throw ();
}; };
/* ================================================= external data structures */ /* ================================================= external data structures */

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/LiveModeWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/LiveModeWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -86,7 +86,7 @@ LiveModeWindow :: LiveModeWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
// Add the TreeView's view columns: // Add the TreeView's view columns:
try { try {
treeView->appendCenteredColumn("", modelColumns.numberColumn, 50); treeView->appendLineNumberColumn("", 2 /* offset */, 50);
// treeView->appendColumn("", WidgetFactory::hugePlayButton, 82); // treeView->appendColumn("", WidgetFactory::hugePlayButton, 82);
treeView->appendColumn("", modelColumns.infoColumn, 200); treeView->appendColumn("", modelColumns.infoColumn, 200);
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
@ -133,6 +133,10 @@ LiveModeWindow :: LiveModeWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
vBox.pack_start(scrolledWindow, Gtk::PACK_EXPAND_WIDGET, 5); vBox.pack_start(scrolledWindow, Gtk::PACK_EXPAND_WIDGET, 5);
add(vBox); add(vBox);
// connect the signal handler for the output play button
outputPlayButton->signal_clicked().connect(sigc::mem_fun(*this,
&LiveModeWindow::onOutputPlayButtonClicked ));
// create the right-click entry context menu for audio clips // create the right-click entry context menu for audio clips
contextMenu = Gtk::manage(new Gtk::Menu()); contextMenu = Gtk::manage(new Gtk::Menu());
Gtk::Menu::MenuList& contextMenuList = contextMenu->items(); Gtk::Menu::MenuList& contextMenuList = contextMenu->items();
@ -180,18 +184,9 @@ LiveModeWindow :: addItem(Ptr<Playable>::Ref playable) throw ()
int rowNumber = treeModel->children().size(); int rowNumber = treeModel->children().size();
Gtk::TreeModel::Row row = *(treeModel->append()); Gtk::TreeModel::Row row = *(treeModel->append());
row[modelColumns.rowNumberColumn] = rowNumber;
row[modelColumns.playableColumn] = playable; row[modelColumns.playableColumn] = playable;
Ptr<Glib::ustring>::Ref numberString(new Glib::ustring);
numberString->append("<span size=\"larger\" weight=\"ultrabold\">");
std::stringstream numberStr;
numberStr << (rowNumber + 2);
numberString->append(numberStr.str());
numberString->append("</span>");
row[modelColumns.numberColumn] = *numberString;
Ptr<Glib::ustring>::Ref infoString(new Glib::ustring); Ptr<Glib::ustring>::Ref infoString(new Glib::ustring);
infoString->append("<span size=\"larger\" weight=\"bold\">"); infoString->append("<span size=\"larger\" weight=\"bold\">");
@ -220,8 +215,6 @@ LiveModeWindow :: addItem(Ptr<Playable>::Ref playable) throw ()
infoString->append(to_simple_string(*playable->getPlaylength())); infoString->append(to_simple_string(*playable->getPlaylength()));
row[modelColumns.infoColumn] = *infoString; row[modelColumns.infoColumn] = *infoString;
row[modelColumns.rowNumberColumn] = rowNumber;
} }
@ -244,6 +237,25 @@ LiveModeWindow :: popTop(void) throw ()
} }
/*------------------------------------------------------------------------------
* Signal handler for the output play button clicked.
*----------------------------------------------------------------------------*/
void
LiveModeWindow :: onOutputPlayButtonClicked(void) throw ()
{
Glib::RefPtr<Gtk::TreeView::Selection> refSelection =
treeView->get_selection();
Gtk::TreeModel::iterator iter = refSelection->get_selected();
if (iter) {
Ptr<Playable>::Ref playable = (*iter)[modelColumns.playableColumn];
gLiveSupport->playOutputAudio(playable);
gLiveSupport->setNowPlaying(playable);
removeItem(iter);
}
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Event handler for an entry being clicked in the list * Event handler for an entry being clicked in the list
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -270,8 +282,6 @@ LiveModeWindow :: onEntryClicked (GdkEventButton * event) throw ()
} }
if (iter) { if (iter) {
Ptr<Playable>::Ref playable =
(*iter)[modelColumns.playableColumn];
contextMenu->popup(event->button, event->time); contextMenu->popup(event->button, event->time);
} }
} }
@ -337,7 +347,20 @@ LiveModeWindow :: onRemoveMenuOption(void) throw ()
Gtk::TreeModel::iterator iter = refSelection->get_selected(); Gtk::TreeModel::iterator iter = refSelection->get_selected();
if (iter) { if (iter) {
removeItem(iter);
}
}
/*------------------------------------------------------------------------------
* Remove an item from the window.
*----------------------------------------------------------------------------*/
void
LiveModeWindow :: removeItem(const Gtk::TreeModel::iterator & iter)
throw ()
{
Gtk::TreeModel::iterator later = iter; Gtk::TreeModel::iterator later = iter;
int rowNumber = (*iter)[modelColumns.rowNumberColumn]; int rowNumber = (*iter)[modelColumns.rowNumberColumn];
for (++later; later != treeModel->children().end(); ++later) { for (++later; later != treeModel->children().end(); ++later) {
(*later)[modelColumns.rowNumberColumn] = rowNumber++; (*later)[modelColumns.rowNumberColumn] = rowNumber++;
@ -345,5 +368,4 @@ LiveModeWindow :: onRemoveMenuOption(void) throw ()
treeModel->erase(iter); treeModel->erase(iter);
} }
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.10 $ Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/LiveModeWindow.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/LiveModeWindow.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -74,7 +74,7 @@ using namespace LiveSupport::Widgets;
* playlists. * playlists.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.10 $ * @version $Revision: 1.11 $
*/ */
class LiveModeWindow : public WhiteWindow, public LocalizedObject class LiveModeWindow : public WhiteWindow, public LocalizedObject
{ {
@ -87,16 +87,11 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject
* Lists one clip per row. * Lists one clip per row.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.10 $ * @version $Revision: 1.11 $
*/ */
class ModelColumns : public PlayableTreeModelColumnRecord class ModelColumns : public PlayableTreeModelColumnRecord
{ {
public: public:
/**
* The column for the big row number display.
*/
Gtk::TreeModelColumn<Glib::ustring> numberColumn;
/** /**
* The column for the play button. * The column for the play button.
*/ */
@ -113,7 +108,6 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject
*/ */
ModelColumns(void) throw () ModelColumns(void) throw ()
{ {
add(numberColumn);
// add(playButtonColumn); // add(playButtonColumn);
add(infoColumn); add(infoColumn);
} }
@ -156,26 +150,32 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject
*/ */
Gtk::Menu * contextMenu; Gtk::Menu * contextMenu;
/**
* Signal handler for the output play button clicked.
*/
void
onOutputPlayButtonClicked(void) throw ();
/** /**
* Signal handler for the mouse clicked on one of the entries. * Signal handler for the mouse clicked on one of the entries.
* *
* @param event the button event recieved * @param event the button event recieved
*/ */
virtual void void
onEntryClicked(GdkEventButton * event) throw (); onEntryClicked(GdkEventButton * event) 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.
*/ */
virtual void void
onUpMenuOption(void) throw (); onUpMenuOption(void) throw ();
/** /**
* Signal handler for the "down" menu option selected from * Signal handler for the "down" menu option selected from
* the context menu. * the context menu.
*/ */
virtual void void
onDownMenuOption(void) throw (); onDownMenuOption(void) throw ();
/** /**
@ -185,6 +185,14 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject
virtual void virtual void
onRemoveMenuOption(void) throw (); onRemoveMenuOption(void) throw ();
/**
* Remove an item from the window.
*
* @param iter points to the row to be removed
*/
void
removeItem(const Gtk::TreeModel::iterator & iter) throw ();
/** /**
* Signal handler for the "rows reordered" event. * Signal handler for the "rows reordered" event.
*/ */