From 7b09d7d251ce2fb203fb6856646a80bacc4b8f91 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Fri, 8 Apr 2005 11:02:11 +0000 Subject: [PATCH] added first zebra stripes to ZebraTreeView --- .../LiveSupport/Widgets/ZebraTreeView.h | 11 ++++---- .../modules/widgets/src/ZebraTreeView.cxx | 27 ++++++++++--------- .../products/gLiveSupport/src/DjBagWindow.cxx | 26 +++++++++++++++--- .../products/gLiveSupport/src/DjBagWindow.h | 20 +++++++++++--- 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h index a5935c55d..ff7b5568d 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.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h,v $ ------------------------------------------------------------------------------*/ @@ -72,7 +72,7 @@ using namespace LiveSupport::Core; * A list of items, in rows colored alternately grey and light blue. * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class ZebraTreeView : public Gtk::TreeView { @@ -102,10 +102,11 @@ class ZebraTreeView : public Gtk::TreeView ~ZebraTreeView(void) throw (); /** - * Color the columns blue. + * Set the callback function for every column. */ - void - colorBlue(void) throw (); + void + setCellDataFunction(const Column::SlotCellData& callback) + throw (); }; diff --git a/livesupport/modules/widgets/src/ZebraTreeView.cxx b/livesupport/modules/widgets/src/ZebraTreeView.cxx index 70cc7291b..4af11dc9c 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.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ZebraTreeView.cxx,v $ ------------------------------------------------------------------------------*/ @@ -35,7 +35,8 @@ #include -#include "LiveSupport/Widgets/WidgetFactory.h" +#include "LiveSupport/Widgets/WidgetFactory.h" Gdk::Color blueColor = Colors::getColor(Colors::LightBlue); + #include "LiveSupport/Widgets/ZebraTreeView.h" @@ -57,7 +58,7 @@ using namespace LiveSupport::Widgets; * Constructor. *----------------------------------------------------------------------------*/ ZebraTreeView :: ZebraTreeView(Glib::RefPtr treeModel) - throw () + throw () : Gtk::TreeView(treeModel) { } @@ -66,22 +67,24 @@ ZebraTreeView :: ZebraTreeView(Glib::RefPtr treeModel) /*------------------------------------------------------------------------------ * Destructor. *----------------------------------------------------------------------------*/ -ZebraTreeView :: ~ZebraTreeView(void) throw () +ZebraTreeView :: ~ZebraTreeView(void) throw () { } /*------------------------------------------------------------------------------ - * Color the table blue. + * Set the callback function for every column. *----------------------------------------------------------------------------*/ void -ZebraTreeView :: colorBlue(void) throw () +ZebraTreeView :: setCellDataFunction(const Column::SlotCellData& callback) throw () { - Gdk::Color bgColor = Colors::getColor(Colors::LightBlue); - - for (int i = 0; i < get_columns().size(); i++) { - Gtk::CellRenderer* renderer = get_column_cell_renderer(i); - renderer->property_cell_background_gdk() = bgColor; -// renderer->property_cell_background_set() = false; + std::list columnList = get_columns(); + std::list::iterator it; + + for (it = columnList.begin(); it != columnList.end(); ++it) { + (*it)->set_cell_data_func(*(*it)->get_first_cell_renderer(), callback); } + +// set_rules_hint(); // suggest coloring with alternate colors } + diff --git a/livesupport/products/gLiveSupport/src/DjBagWindow.cxx b/livesupport/products/gLiveSupport/src/DjBagWindow.cxx index 4e48bcea8..e09454818 100644 --- a/livesupport/products/gLiveSupport/src/DjBagWindow.cxx +++ b/livesupport/products/gLiveSupport/src/DjBagWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.12 $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/DjBagWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -126,7 +126,8 @@ DjBagWindow :: DjBagWindow (Ptr::Ref gLiveSupport, } // color the columns blue - treeView->colorBlue(); + treeView->setCellDataFunction( + sigc::mem_fun(*this, &DjBagWindow::cellDataFunction)); // register the signal handler for treeview entries being clicked treeView->signal_button_press_event().connect_notify(sigc::mem_fun(*this, @@ -246,6 +247,8 @@ DjBagWindow :: showContents(void) throw () it = djBagContents->begin(); end = djBagContents->end(); treeModel->clear(); + int rowNumber = 0; + while (it != end) { playable = *it; row = *(treeModel->append()); @@ -264,8 +267,11 @@ DjBagWindow :: showContents(void) throw () break; } row[modelColumns.titleColumn] = *playable->getTitle(); + row[modelColumns.colorColumn] = rowNumber % 2 ? Colors::Gray + : Colors::LightBlue; - it++; + ++it; + ++rowNumber; } } @@ -639,3 +645,17 @@ DjBagWindow :: onStopButtonClicked(void) throw () } } + +/*------------------------------------------------------------------------------ + * The callback function. + *----------------------------------------------------------------------------*/ +void +DjBagWindow :: cellDataFunction(Gtk::CellRenderer* cell, + const Gtk::TreeModel::iterator& iter) + throw () +{ + Gdk::Color color = Colors::getColor((*iter)[modelColumns.colorColumn]); + cell->property_cell_background_gdk() = color; +} + + diff --git a/livesupport/products/gLiveSupport/src/DjBagWindow.h b/livesupport/products/gLiveSupport/src/DjBagWindow.h index e4c320916..b84d93ca7 100644 --- a/livesupport/products/gLiveSupport/src/DjBagWindow.h +++ b/livesupport/products/gLiveSupport/src/DjBagWindow.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/Attic/DjBagWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -71,10 +71,18 @@ using namespace LiveSupport::Widgets; * playlists. * * @author $Author: fgerlits $ - * @version $Revision: 1.10 $ + * @version $Revision: 1.11 $ */ class DjBagWindow : public WhiteWindow, public LocalizedObject { + private: + /** + * The callback function to set the colors of the rows. + */ + void + cellDataFunction(Gtk::CellRenderer* cell, + const Gtk::TreeModel::iterator& iter) + throw (); protected: @@ -83,7 +91,7 @@ class DjBagWindow : public WhiteWindow, public LocalizedObject * Lists one clip per row. * * @author $Author: fgerlits $ - * @version $Revision: 1.10 $ + * @version $Revision: 1.11 $ */ class ModelColumns : public Gtk::TreeModel::ColumnRecord { @@ -103,6 +111,11 @@ class DjBagWindow : public WhiteWindow, public LocalizedObject */ Gtk::TreeModelColumn titleColumn; + /** + * The column for the color of the row. + */ + Gtk::TreeModelColumn colorColumn; + /** * Constructor. */ @@ -111,6 +124,7 @@ class DjBagWindow : public WhiteWindow, public LocalizedObject add(playableColumn); add(typeColumn); add(titleColumn); + add(colorColumn); } };