[niepce] Implement a star rating widget. Use the star rating widget in the metadata widget Use star rating me



commit ea4255ac26320add71a2cca0408095e63f6bb32d
Author: Hubert Figuiere <hub figuiere net>
Date:   Sat Oct 29 00:07:14 2011 -0700

    Implement a star rating widget.
    Use the star rating widget in the metadata widget
    Use star rating menu item (needs fixage)

 src/fwk/toolkit/Makefile.am                |    4 +
 src/fwk/toolkit/metadatawidget.cpp         |   44 ++++++--
 src/fwk/toolkit/widgets/ratingaction.cpp   |   39 ++++++
 src/fwk/toolkit/widgets/ratingaction.hpp   |   48 +++++++
 src/fwk/toolkit/widgets/ratinglabel.cpp    |  184 ++++++++++++++++++++++++++++
 src/fwk/toolkit/widgets/ratinglabel.hpp    |   70 +++++++++++
 src/fwk/toolkit/widgets/ratingmenuitem.hpp |   48 +++++++
 src/niepce/ui/librarycellrenderer.cpp      |   44 ++------
 src/niepce/ui/librarycellrenderer.hpp      |    3 -
 src/niepce/ui/moduleshell.cpp              |   21 ++--
 10 files changed, 449 insertions(+), 56 deletions(-)
---
diff --git a/src/fwk/toolkit/Makefile.am b/src/fwk/toolkit/Makefile.am
index 2dbc6a9..6976c18 100644
--- a/src/fwk/toolkit/Makefile.am
+++ b/src/fwk/toolkit/Makefile.am
@@ -3,6 +3,7 @@
 
 
 INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/ext \
+	-DDATADIR=\"$(datadir)\" \
 	@LIBGLIBMM_CFLAGS@ \
 	@LIBGTKMM_CFLAGS@ \
 	@GCONF_CFLAGS@  @EXEMPI_CFLAGS@ \
@@ -27,6 +28,9 @@ libniepceframework_a_SOURCES = configuration.hpp configuration.cpp \
 	gdkutils.hpp gdkutils.cpp \
 	gtkutils.hpp gtkutils.cpp \
 	widgets/addinstreemodel.hpp widgets/addinstreemodel.cpp \
+	widgets/ratingaction.hpp widgets/ratingaction.cpp \
+	widgets/ratinglabel.hpp widgets/ratinglabel.cpp \
+	widgets/ratingmenuitem.hpp \
 	widgets/toolboxitemwidget.hpp widgets/toolboxitemwidget.cpp \
 	widgets/editablehscale.hpp widgets/editablehscale.cpp \
 	widgets/dock.cpp widgets/dock.hpp \
diff --git a/src/fwk/toolkit/metadatawidget.cpp b/src/fwk/toolkit/metadatawidget.cpp
index 8efc10d..27b61c8 100644
--- a/src/fwk/toolkit/metadatawidget.cpp
+++ b/src/fwk/toolkit/metadatawidget.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/toolkit/metadatawidget.cpp
  *
- * Copyright (C) 2008-2009 Hubert Figuiere
+ * Copyright (C) 2008-2011 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@
 #include "fwk/base/fractions.hpp"
 #include "fwk/utils/exempi.hpp"
 #include "fwk/utils/stringutils.hpp"
+#include "fwk/toolkit/widgets/ratinglabel.hpp"
 
 #include "metadatawidget.hpp"
 
@@ -56,6 +57,12 @@ void clear_widget(std::pair<const std::string, Gtk::Widget *> & p)
     Gtk::Label * l = dynamic_cast<Gtk::Label*>(p.second);
     if(l) {
         l->set_text("");
+        return;
+    }
+    fwk::RatingLabel * rl = dynamic_cast<fwk::RatingLabel*>(p.second);
+    if(rl) {
+        rl->set_rating(0);
+        return;
     }
 }
 }
@@ -116,7 +123,7 @@ void MetaDataWidget::add_data(const std::string & id,
                               const char * value,
                               xmp::MetaDataType type)
 {
-    Gtk::Label *w = NULL;
+    Gtk::Widget *w = NULL;
     int n_row;
     std::map<std::string, Gtk::Widget *>::iterator iter 
         = m_data_map.end();
@@ -134,8 +141,13 @@ void MetaDataWidget::add_data(const std::string & id,
         labelw->set_alignment(0, 0.5);
         labelw->set_use_markup(true);
 
-        w = Gtk::manage(new Gtk::Label());
-        w->set_alignment(0, 0.5);
+        if(type == xmp::META_DT_STAR_RATING) {
+            w = Gtk::manage(new fwk::RatingLabel());
+        }
+        else {
+            w = Gtk::manage(new Gtk::Label());
+            static_cast<Gtk::Label*>(w)->set_alignment(0, 0.5);
+        }
 
         m_table.resize(n_row + 1, 2);
         m_table.attach(*labelw, 0, 1, n_row, n_row+1, 
@@ -150,13 +162,29 @@ void MetaDataWidget::add_data(const std::string & id,
     switch(type) {
     case xmp::META_DT_FRAC:
     {
-        double decimal = fwk::fraction_to_decimal(value);
-        std::string frac = boost::lexical_cast<std::string>(decimal);
-        w->set_text(frac);
+        try {
+            double decimal = fwk::fraction_to_decimal(value);
+            std::string frac = boost::lexical_cast<std::string>(decimal);
+            static_cast<Gtk::Label*>(w)->set_text(frac);
+        }
+        catch(...) {
+            DBG_OUT("conversion of '%s' to frac failed", value);
+        }
+        break;
+    }
+    case xmp::META_DT_STAR_RATING:
+    {
+        try {
+            int rating = boost::lexical_cast<int>(value);
+            static_cast<fwk::RatingLabel*>(w)->set_rating(rating);
+        }
+        catch(...) {
+            DBG_OUT("conversion of '%s' to int failed", value);
+        }
         break;
     }
     default:
-        w->set_text(value);
+        static_cast<Gtk::Label*>(w)->set_text(value);
         break;
     }
     m_table.show_all();
diff --git a/src/fwk/toolkit/widgets/ratingaction.cpp b/src/fwk/toolkit/widgets/ratingaction.cpp
new file mode 100644
index 0000000..8b65fa0
--- /dev/null
+++ b/src/fwk/toolkit/widgets/ratingaction.cpp
@@ -0,0 +1,39 @@
+/*
+ * niepce - fwk/toolkit/widgets/ratingaction.cpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fwk/base/debug.hpp"
+
+#include "ratingaction.hpp"
+#include "ratingmenuitem.hpp"
+
+namespace fwk  {
+
+  Glib::RefPtr<RatingAction> RatingAction::create (const Glib::ustring& name, 
+						   int rating)
+  {
+    return Glib::RefPtr<RatingAction>(new RatingAction(name, rating));
+  }
+
+  Gtk::Widget* RatingAction::create_menu_item_vfunc()
+  {
+    DBG_OUT("created menu item");
+    return new RatingMenuItem(m_rating);
+  }
+
+}
diff --git a/src/fwk/toolkit/widgets/ratingaction.hpp b/src/fwk/toolkit/widgets/ratingaction.hpp
new file mode 100644
index 0000000..2f90185
--- /dev/null
+++ b/src/fwk/toolkit/widgets/ratingaction.hpp
@@ -0,0 +1,48 @@
+/*
+ * niepce - fwk/toolkit/widgets/ratingaction.hpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _FWK_TOOLKIT_RATINGACTION_HPP_
+#define _FWK_TOOLKIT_RATINGACTION_HPP_
+
+#include <gtkmm/action.h>
+
+namespace fwk {
+
+class RatingAction
+  : public Gtk::Action
+{
+public:
+
+  static Glib::RefPtr<RatingAction> create (const Glib::ustring& name, 
+					    int rating);
+protected:
+  RatingAction(const Glib::ustring& name, int rating)
+    : Gtk::Action(name)
+    , m_rating(rating)
+  {
+  }
+
+  virtual Gtk::Widget* create_menu_item_vfunc();
+private:
+  int m_rating;
+};
+
+}
+
+#endif
diff --git a/src/fwk/toolkit/widgets/ratinglabel.cpp b/src/fwk/toolkit/widgets/ratinglabel.cpp
new file mode 100644
index 0000000..a42c965
--- /dev/null
+++ b/src/fwk/toolkit/widgets/ratinglabel.cpp
@@ -0,0 +1,184 @@
+/*
+ * niepce - fwk/toolkit/widgets/ratinglabel.cpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "fwk/base/debug.hpp"
+#include "ratinglabel.hpp"
+
+
+namespace fwk {
+
+#ifndef DATADIR
+#error DATADIR is not defined
+#endif
+
+
+
+const Cairo::RefPtr<Cairo::ImageSurface> & RatingLabel::get_star()
+{
+  static Cairo::RefPtr<Cairo::ImageSurface>  s_star;
+  if(!s_star) {
+    s_star = Cairo::ImageSurface::create_from_png(
+		   std::string(DATADIR"/niepce/pixmaps/niepce-set-star.png"));
+  }
+  return s_star;
+}
+
+const Cairo::RefPtr<Cairo::ImageSurface> & RatingLabel::get_unstar()
+{
+  static Cairo::RefPtr<Cairo::ImageSurface> s_unstar;
+  if(!s_unstar) {
+    s_unstar = Cairo::ImageSurface::create_from_png(
+            std::string(DATADIR"/niepce/pixmaps/niepce-unset-star.png"));
+  }
+  return s_unstar;
+}
+
+
+void RatingLabel::draw_rating(const Cairo::RefPtr<Cairo::Context> & cr, 
+			      int32_t rating,
+			      const Cairo::RefPtr<Cairo::ImageSurface> & star,
+			      const Cairo::RefPtr<Cairo::ImageSurface> & unstar,
+			      double x, double y)
+{
+    if(!star || !unstar) {
+        return;
+    }
+    if(rating == -1) {
+        rating = 0;
+    }
+    int w = star->get_width();
+    int h = star->get_height();
+    y -= h;
+    for(int32_t i = 1; i <= 5; i++) {
+        if(i <= rating) {
+            cr->set_source(star, x, y);
+        }
+        else {
+            cr->set_source(unstar, x, y);
+        }
+        cr->paint();
+        x += w;
+    }
+}
+
+int RatingLabel::rating_value_from_hit_x(const Cairo::RefPtr<Cairo::ImageSurface> & star, double x)
+{
+    int width = star->get_width();
+    return (x / width) + 1;
+}
+
+RatingLabel::RatingLabel(int rating)
+  : Gtk::DrawingArea()
+  , m_rating(rating)
+  , m_is_editable(false)
+{
+  DBG_OUT("ctor");
+}
+
+RatingLabel::~RatingLabel()
+{
+  DBG_OUT("dtor");
+}
+
+void RatingLabel::set_editable(bool editable)
+{
+  m_is_editable = editable;
+  // TODO change the GdkEventMask if the widget is realized.
+}
+
+void RatingLabel::set_rating(int rating)
+{
+  if(rating != m_rating) {
+    m_rating = rating;
+    queue_draw();
+  }
+}
+
+
+void RatingLabel::on_realize()
+{
+  Gtk::Widget::on_realize();
+  if(m_is_editable) {
+    Glib::RefPtr<Gdk::Window> win = get_window();
+    Gdk::EventMask mask = win->get_events();
+    mask |= Gdk::BUTTON_PRESS_MASK;
+    //    | Gdk::BUTTON_RELEASE_MASK 
+    //    | Gdk::BUTTON1_MOTION_MASK;
+    win->set_events(mask);
+  }
+}
+
+bool RatingLabel::on_button_press_event (GdkEventButton* e)
+{
+  if(e->button == 1) {
+    int new_rating =  rating_value_from_hit_x(get_star(), e->x);
+    DBG_OUT("new rating = %d", new_rating);
+
+    if(new_rating != m_rating) {
+      set_rating(new_rating);
+      signal_changed.emit(new_rating);
+    }
+  }
+  return true;
+}
+
+
+bool RatingLabel::on_button_release_event (GdkEventButton* e)
+{
+  return true;
+}
+
+
+bool RatingLabel::on_motion_notify_event (GdkEventMotion* e)
+{
+  return true;
+}
+
+
+
+void RatingLabel::on_size_request(Gtk::Requisition* requisition)
+{
+  *requisition = Gtk::Requisition();
+  const Cairo::RefPtr<Cairo::ImageSurface> & star = get_star();
+  requisition->width = star->get_width() * 5;
+  requisition->height = star->get_height();
+  //  DBG_OUT("size request is %d %d", requisition->width, requisition->height);
+}
+
+bool RatingLabel::on_expose_event(GdkEventExpose *evt)
+{
+  if (is_drawable()) {
+    const Gtk::Allocation& allocation = get_allocation();
+    double x, y;
+    x = 0;
+    y = allocation.get_height();
+    Cairo::RefPtr< Cairo::Context >  cr = get_window()->create_cairo_context();
+    draw_rating(cr , m_rating, get_star(), get_unstar(), x, y);
+  }
+  return true;
+}
+
+void RatingLabel::on_state_changed (Gtk::StateType previous_state)
+{
+  Gtk::Widget::on_state_changed(previous_state);
+}
+
+
+}
diff --git a/src/fwk/toolkit/widgets/ratinglabel.hpp b/src/fwk/toolkit/widgets/ratinglabel.hpp
new file mode 100644
index 0000000..813964d
--- /dev/null
+++ b/src/fwk/toolkit/widgets/ratinglabel.hpp
@@ -0,0 +1,70 @@
+/*
+ * niepce - fwk/toolkit/widgets/ratinglabel.hpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __FWK_TOOLKIT_RATINGLABEL_HPP__
+#define __FWK_TOOLKIT_RATINGLABEL_HPP__
+
+#include <gtkmm/drawingarea.h>
+#include <cairomm/surface.h>
+
+namespace fwk {
+
+class RatingLabel
+  : public Gtk::DrawingArea
+{
+public:
+  RatingLabel(int rating = 0);
+  virtual ~RatingLabel();
+
+  bool is_editable() const
+  { return m_is_editable; }
+  void set_editable(bool);
+
+  void set_rating(int rating);
+  static const Cairo::RefPtr<Cairo::ImageSurface> & get_star();
+  static const Cairo::RefPtr<Cairo::ImageSurface> & get_unstar();
+
+  // draw the rating at x and y in the context.
+  // this can be called by anybody who wants to print these
+  static void draw_rating(const Cairo::RefPtr<Cairo::Context> & cr, 
+			  int32_t rating,
+			  const Cairo::RefPtr<Cairo::ImageSurface> & star,
+			  const Cairo::RefPtr<Cairo::ImageSurface> & unstar,
+			  double x, double y);
+  static int rating_value_from_hit_x(const Cairo::RefPtr<Cairo::ImageSurface> & star, double x);
+
+  // signal emitted when the rating is changed in the UI
+  sigc::signal<void, int> signal_changed;
+protected:
+  virtual void  on_realize();
+  virtual bool 	on_button_press_event (GdkEventButton* event);
+  virtual bool 	on_button_release_event (GdkEventButton* event);
+  virtual bool 	on_motion_notify_event (GdkEventMotion* event);
+
+  virtual void 	on_size_request (Gtk::Requisition* requisition);
+  virtual bool  on_expose_event (GdkEventExpose *event);
+  virtual void 	on_state_changed (Gtk::StateType previous_state);
+private:
+  int m_rating;
+  bool m_is_editable;
+};
+
+}
+
+#endif
diff --git a/src/fwk/toolkit/widgets/ratingmenuitem.hpp b/src/fwk/toolkit/widgets/ratingmenuitem.hpp
new file mode 100644
index 0000000..f2750d8
--- /dev/null
+++ b/src/fwk/toolkit/widgets/ratingmenuitem.hpp
@@ -0,0 +1,48 @@
+/*
+ * niepce - fwk/toolkit/widgets/ratingmenuitem.hpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __FWK_TOOLKIT_RATINGMENUITEM__
+#define __FWK_TOOLKIT_RATINGMENUITEM__
+
+#include <gtkmm/menuitem.h>
+#include "fwk/base/debug.hpp"
+#include "fwk/toolkit/widgets/ratinglabel.hpp"
+
+namespace fwk {
+
+class RatingMenuItem
+  : public Gtk::MenuItem
+{
+public:
+  RatingMenuItem(int rating)
+    : Gtk::MenuItem()
+    , m_label(rating)
+  {
+    DBG_OUT("ctor");
+    m_label.show();
+    add(m_label);
+  }
+
+private:
+  RatingLabel m_label;
+};
+
+}
+
+#endif
diff --git a/src/niepce/ui/librarycellrenderer.cpp b/src/niepce/ui/librarycellrenderer.cpp
index 653d30e..7ad2ca5 100644
--- a/src/niepce/ui/librarycellrenderer.cpp
+++ b/src/niepce/ui/librarycellrenderer.cpp
@@ -19,6 +19,7 @@
 
 
 #include "fwk/base/debug.hpp"
+#include "fwk/toolkit/widgets/ratinglabel.hpp"
 #include "librarycellrenderer.hpp"
 
 #include <gdkmm/general.h>
@@ -56,10 +57,6 @@ LibraryCellRenderer::LibraryCellRenderer()
             = Cairo::ImageSurface::create_from_png(
                 std::string(DATADIR"/niepce/pixmaps/niepce-unknown-fmt.png"));
         
-        m_star = Cairo::ImageSurface::create_from_png(
-            std::string(DATADIR"/niepce/pixmaps/niepce-set-star.png"));
-        m_unstar = Cairo::ImageSurface::create_from_png(
-            std::string(DATADIR"/niepce/pixmaps/niepce-unset-star.png"));
 	}
 	catch(const std::exception & e)
 	{
@@ -126,34 +123,6 @@ void drawFormatEmblem(const Cairo::RefPtr<Cairo::Context> & cr,
     }
 }
 
-void drawRating(const Cairo::RefPtr<Cairo::Context> & cr, 
-                int32_t rating,
-                const Cairo::RefPtr<Cairo::ImageSurface> & star,
-                const Cairo::RefPtr<Cairo::ImageSurface> & unstar,
-                const GdkRectangle & r)
-{
-    if(!star || !unstar) {
-        return;
-    }
-    if(rating == -1) {
-        rating = 0;
-    }
-    int w = star->get_width();
-    int h = star->get_height();
-    double x, y;
-    x = r.x + 4;
-    y = r.y + r.height - 4 - h;
-    for(int32_t i = 1; i <= 5; i++) {
-        if(i <= rating) {
-            cr->set_source(star, x, y);
-        }
-        else {
-            cr->set_source(unstar, x, y);
-        }
-        cr->paint();
-        x += w;
-    }
-}
 
 }
 
@@ -221,10 +190,15 @@ LibraryCellRenderer::render_vfunc (const Glib::RefPtr<Gdk::Drawable>& window,
       cr->stroke();
   }
 
-	Glib::RefPtr<Gdk::Pixbuf> pixbuf = property_pixbuf();
-	_drawThumbnail(cr, pixbuf, r);
+  Glib::RefPtr<Gdk::Pixbuf> pixbuf = property_pixbuf();
+  _drawThumbnail(cr, pixbuf, r);
   if(m_drawrating) {
-      drawRating(cr, file->rating(), m_star, m_unstar, r);
+      double x, y;
+      x = r.x + 4;
+      y = r.y + r.height - 4;
+      fwk::RatingLabel::draw_rating(cr, file->rating(), 
+                                    fwk::RatingLabel::get_star(), 
+                                    fwk::RatingLabel::get_unstar(), x, y);
   }
 
   if(m_drawemblem) {
diff --git a/src/niepce/ui/librarycellrenderer.hpp b/src/niepce/ui/librarycellrenderer.hpp
index 78723d0..6f1e414 100644
--- a/src/niepce/ui/librarycellrenderer.hpp
+++ b/src/niepce/ui/librarycellrenderer.hpp
@@ -84,9 +84,6 @@ private:
 	Cairo::RefPtr<Cairo::ImageSurface>  m_img_format_emblem;
 	Cairo::RefPtr<Cairo::ImageSurface>  m_video_format_emblem;
 	Cairo::RefPtr<Cairo::ImageSurface>  m_unknown_format_emblem;
-
-	Cairo::RefPtr<Cairo::ImageSurface>  m_star;
-	Cairo::RefPtr<Cairo::ImageSurface>  m_unstar;
 };
 
 
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index 8585a25..90c19fc 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -31,6 +31,7 @@
 #include "engine/db/library.hpp"
 #include "engine/db/libfile.hpp"
 #include "fwk/toolkit/application.hpp"
+#include "fwk/toolkit/widgets/ratingaction.hpp"
 #include "moduleshell.hpp"
 #include "niepcewindow.hpp"
 #include "metadatapanecontroller.hpp"
@@ -98,36 +99,36 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
                               4));
     
     m_actionGroup->add(Gtk::Action::create("SetRating", _("Set _Rating")));
-    m_actionGroup->add(Gtk::Action::create("SetRating0", _("_No Rating")),
+    m_actionGroup->add(fwk::RatingAction::create("SetRating0", 0),
                           Gtk::AccelKey("0"), sigc::bind(
                               sigc::mem_fun(*m_selection_controller,
                                             &SelectionController::set_rating),
                               0));
-    m_actionGroup->add(Gtk::Action::create("SetRating1", _("_1 Star")),
+    m_actionGroup->add(fwk::RatingAction::create("SetRating1", 1),
                           Gtk::AccelKey("1"), sigc::bind(
                               sigc::mem_fun(*m_selection_controller,
                                             &SelectionController::set_rating),
                               1));
-    m_actionGroup->add(Gtk::Action::create("SetRating2", _("_2 Stars")),
+    m_actionGroup->add(fwk::RatingAction::create("SetRating2", 2),
                           Gtk::AccelKey("2"), sigc::bind(
                               sigc::mem_fun(*m_selection_controller,
                                             &SelectionController::set_rating),
                               2));
-    m_actionGroup->add(Gtk::Action::create("SetRating3", _("_3 Stars")),
+    m_actionGroup->add(fwk::RatingAction::create("SetRating3", 3),
                           Gtk::AccelKey("3"), sigc::bind(
                               sigc::mem_fun(*m_selection_controller,
                                             &SelectionController::set_rating),
                               3));
-    m_actionGroup->add(Gtk::Action::create("SetRating4", _("_4 Stars")),
+    m_actionGroup->add(fwk::RatingAction::create("SetRating4", 4),
                           Gtk::AccelKey("4"), sigc::bind(
                               sigc::mem_fun(*m_selection_controller,
                                             &SelectionController::set_rating),
                               4));
-    m_actionGroup->add(Gtk::Action::create("SetRating5", _("_5 Stars")),
-                          Gtk::AccelKey("5"), sigc::bind(
-                              sigc::mem_fun(*m_selection_controller,
-                                            &SelectionController::set_rating),
-                              5));
+    m_actionGroup->add(fwk::RatingAction::create("SetRating5", 5),
+                       Gtk::AccelKey("5"), sigc::bind(
+                           sigc::mem_fun(*m_selection_controller,
+                                         &SelectionController::set_rating),
+                           5));
     m_actionGroup->add(Gtk::Action::create("DeleteImage", Gtk::Stock::DELETE));
 
     manager->insert_action_group(m_actionGroup);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]