diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h index 0f5560925..acba2528e 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.11 $ + Version : $Revision: 1.12 $ 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.11 $ + * @version $Revision: 1.12 $ */ class ZebraTreeView : public Gtk::TreeView { @@ -106,12 +106,30 @@ class ZebraTreeView : public Gtk::TreeView /** * 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 cellDataFunction(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter) 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: public: @@ -175,6 +193,22 @@ class ZebraTreeView : public Gtk::TreeView int minimumWidth = 0) 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 (); + }; diff --git a/livesupport/modules/widgets/src/ZebraTreeView.cxx b/livesupport/modules/widgets/src/ZebraTreeView.cxx index f3fa38c71..d8ad64bf2 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.12 $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ZebraTreeView.cxx,v $ ------------------------------------------------------------------------------*/ @@ -34,6 +34,7 @@ #endif #include +#include #include "LiveSupport/Widgets/ZebraTreeModelColumnRecord.h" @@ -198,3 +199,71 @@ ZebraTreeView :: appendCenteredColumn( 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( + 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(""); + std::stringstream numberStr; + numberStr << (rowNumber + offset); + numberString.append(numberStr.str()); + numberString.append(""); + Gtk::CellRendererText * textCell + = dynamic_cast(cell); + textCell->property_markup() = numberString; +} + + diff --git a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx index 57ea0e158..3d77e062b 100644 --- a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx +++ b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -593,7 +593,7 @@ GLiveSupport :: addToLiveMode(Ptr::Ref playable) masterPanel->updateLiveModeWindow(playable); } else { playOutputAudio(playable); - masterPanel->setNowPlaying(playable); + setNowPlaying(playable); } } @@ -603,22 +603,34 @@ GLiveSupport :: addToLiveMode(Ptr::Ref playable) *----------------------------------------------------------------------------*/ void LiveSupport :: GLiveSupport :: -GLiveSupport :: onStop(void) throw () +GLiveSupport :: onStop(void) throw () { Ptr::Ref playable; - masterPanel->setNowPlaying(playable); // reset to empty + setNowPlaying(playable); // reset to empty playable = masterPanel->getNextItemToPlay(); if (playable) { playOutputAudio(playable); - masterPanel->setNowPlaying(playable); + setNowPlaying(playable); } else { stopOutputAudio(); } } +/*------------------------------------------------------------------------------ + * Display the playable item on the master panel as "now playing". + *----------------------------------------------------------------------------*/ +inline void +LiveSupport :: GLiveSupport :: +GLiveSupport :: setNowPlaying(Ptr::Ref playable) + throw () +{ + masterPanel->setNowPlaying(playable); +} + + /*------------------------------------------------------------------------------ * Open a playlist for editing. *----------------------------------------------------------------------------*/ diff --git a/livesupport/products/gLiveSupport/src/GLiveSupport.h b/livesupport/products/gLiveSupport/src/GLiveSupport.h index 17b62fde9..a7c58836e 100644 --- a/livesupport/products/gLiveSupport/src/GLiveSupport.h +++ b/livesupport/products/gLiveSupport/src/GLiveSupport.h @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -101,7 +101,7 @@ class MasterPanelWindow; * respective documentation. * * @author $Author: fgerlits $ - * @version $Revision: 1.33 $ + * @version $Revision: 1.34 $ * @see LocalizedObject#getBundle(const xmlpp::Element &) * @see AuthenticationClientFactory * @see StorageClientFactory @@ -691,6 +691,13 @@ class GLiveSupport : public LocalizedConfigurable, */ virtual void onStop(void) throw (); + + /** + * Display the playable item on the master panel as "now playing". + */ + void + setNowPlaying(Ptr::Ref playable) + throw (); }; /* ================================================= external data structures */ diff --git a/livesupport/products/gLiveSupport/src/LiveModeWindow.cxx b/livesupport/products/gLiveSupport/src/LiveModeWindow.cxx index 0af711388..2b64f2b1a 100644 --- a/livesupport/products/gLiveSupport/src/LiveModeWindow.cxx +++ b/livesupport/products/gLiveSupport/src/LiveModeWindow.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -86,7 +86,7 @@ LiveModeWindow :: LiveModeWindow (Ptr::Ref gLiveSupport, // Add the TreeView's view columns: try { - treeView->appendCenteredColumn("", modelColumns.numberColumn, 50); + treeView->appendLineNumberColumn("", 2 /* offset */, 50); // treeView->appendColumn("", WidgetFactory::hugePlayButton, 82); treeView->appendColumn("", modelColumns.infoColumn, 200); } catch (std::invalid_argument &e) { @@ -133,6 +133,10 @@ LiveModeWindow :: LiveModeWindow (Ptr::Ref gLiveSupport, vBox.pack_start(scrolledWindow, Gtk::PACK_EXPAND_WIDGET, 5); 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 contextMenu = Gtk::manage(new Gtk::Menu()); Gtk::Menu::MenuList& contextMenuList = contextMenu->items(); @@ -180,18 +184,9 @@ LiveModeWindow :: addItem(Ptr::Ref playable) throw () int rowNumber = treeModel->children().size(); Gtk::TreeModel::Row row = *(treeModel->append()); + row[modelColumns.rowNumberColumn] = rowNumber; row[modelColumns.playableColumn] = playable; - Ptr::Ref numberString(new Glib::ustring); - - numberString->append(""); - std::stringstream numberStr; - numberStr << (rowNumber + 2); - numberString->append(numberStr.str()); - numberString->append(""); - - row[modelColumns.numberColumn] = *numberString; - Ptr::Ref infoString(new Glib::ustring); infoString->append(""); @@ -220,8 +215,6 @@ LiveModeWindow :: addItem(Ptr::Ref playable) throw () infoString->append(to_simple_string(*playable->getPlaylength())); 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 refSelection = + treeView->get_selection(); + Gtk::TreeModel::iterator iter = refSelection->get_selected(); + + if (iter) { + Ptr::Ref playable = (*iter)[modelColumns.playableColumn]; + gLiveSupport->playOutputAudio(playable); + gLiveSupport->setNowPlaying(playable); + removeItem(iter); + } +} + + /*------------------------------------------------------------------------------ * Event handler for an entry being clicked in the list *----------------------------------------------------------------------------*/ @@ -270,8 +282,6 @@ LiveModeWindow :: onEntryClicked (GdkEventButton * event) throw () } if (iter) { - Ptr::Ref playable = - (*iter)[modelColumns.playableColumn]; contextMenu->popup(event->button, event->time); } } @@ -337,13 +347,25 @@ LiveModeWindow :: onRemoveMenuOption(void) throw () Gtk::TreeModel::iterator iter = refSelection->get_selected(); if (iter) { - Gtk::TreeModel::iterator later = iter; - int rowNumber = (*iter)[modelColumns.rowNumberColumn]; - for (++later; later != treeModel->children().end(); ++later) { - (*later)[modelColumns.rowNumberColumn] = rowNumber++; - } - - treeModel->erase(iter); + removeItem(iter); } } + +/*------------------------------------------------------------------------------ + * Remove an item from the window. + *----------------------------------------------------------------------------*/ +void +LiveModeWindow :: removeItem(const Gtk::TreeModel::iterator & iter) + throw () +{ + Gtk::TreeModel::iterator later = iter; + + int rowNumber = (*iter)[modelColumns.rowNumberColumn]; + for (++later; later != treeModel->children().end(); ++later) { + (*later)[modelColumns.rowNumberColumn] = rowNumber++; + } + + treeModel->erase(iter); +} + diff --git a/livesupport/products/gLiveSupport/src/LiveModeWindow.h b/livesupport/products/gLiveSupport/src/LiveModeWindow.h index c16798492..a4f139ac0 100644 --- a/livesupport/products/gLiveSupport/src/LiveModeWindow.h +++ b/livesupport/products/gLiveSupport/src/LiveModeWindow.h @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -74,7 +74,7 @@ using namespace LiveSupport::Widgets; * playlists. * * @author $Author: fgerlits $ - * @version $Revision: 1.10 $ + * @version $Revision: 1.11 $ */ class LiveModeWindow : public WhiteWindow, public LocalizedObject { @@ -87,16 +87,11 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject * Lists one clip per row. * * @author $Author: fgerlits $ - * @version $Revision: 1.10 $ + * @version $Revision: 1.11 $ */ class ModelColumns : public PlayableTreeModelColumnRecord { public: - /** - * The column for the big row number display. - */ - Gtk::TreeModelColumn numberColumn; - /** * The column for the play button. */ @@ -113,7 +108,6 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject */ ModelColumns(void) throw () { - add(numberColumn); // add(playButtonColumn); add(infoColumn); } @@ -156,26 +150,32 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject */ 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. * * @param event the button event recieved */ - virtual void + void onEntryClicked(GdkEventButton * event) throw (); /** * Signal handler for the "up" menu option selected from * the context menu. */ - virtual void + void onUpMenuOption(void) throw (); /** * Signal handler for the "down" menu option selected from * the context menu. */ - virtual void + void onDownMenuOption(void) throw (); /** @@ -185,6 +185,14 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject virtual void 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. */