Code

Changled dialog from checkboxes to icons for visible and locked.
authorjoncruz <joncruz@users.sourceforge.net>
Sat, 20 May 2006 06:34:27 +0000 (06:34 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Sat, 20 May 2006 06:34:27 +0000 (06:34 +0000)
ChangeLog
src/dialogs/layers-panel.cpp
src/widgets/icon.cpp
src/widgets/icon.h

index b1fad2013549b70cc0c5a2a10f3a8a58eb2d1673..80f9c71d292651b225f0ca4c60754dab22b55238 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,19 @@
+2006-05-20  Jon A. Cruz  <jon@joncruz.org>
+
+       * src/widgets/icon.h, src/widgets/icon.cpp, src/dialogs/layers-panel.cpp:
+         Changled dialog from checkboxes to icons for visible and locked.
+
 2006-05-20  Michael Wybrow  <mjwybrow@users.sourceforge.net>
 
        * src/libnrtype/FontInstance.cpp: patch from David Turner of the
          FreeType Project.  Fixes a compilation problem and a possible
          segmentation fault.
 
+2006-05-19  Jon A. Cruz  <jon@joncruz.org>
+       * src/preferences-skeleton.h, src/dialogs/layers-panel.h,
+         src/dialogs/layers-panel.cpp:
+         Selection and event handling cleanup. Added deeper display.
+
 2006-05-18  Jon A. Cruz  <jon@joncruz.org>
        * src/layer-manager.cpp, src/dialogs/layers-panel.h,
          src/dialogs/layers-panel.cpp:
index 186aad70b2e7e81fec1bed86eafeab199d097e10..0ee6ac7e7191ef8a2f84cd4d6d30038e722ed20e 100644 (file)
@@ -65,6 +65,88 @@ enum {
     BUTTON_DELETE
 };
 
+class ImageToggler : public Gtk::CellRendererPixbuf {
+public:
+    ImageToggler( char const* on, char const* off) :
+        Glib::ObjectBase(typeid(ImageToggler)),
+        Gtk::CellRendererPixbuf(),
+        _pixOnName(on),
+        _pixOffName(off),
+        _property_active(*this, "active", false),
+        _property_activatable(*this, "activatable", true),
+        _property_pixbuf_on(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)),
+        _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
+    {
+        property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
+
+        Gtk::Widget* thingie = sp_icon_get_icon(_pixOnName.c_str(), Inkscape::ICON_SIZE_DECORATION);
+        if ( thingie ) {
+            if ( SP_IS_ICON(thingie->gobj()) ) {
+                SPIcon* icon = SP_ICON(thingie->gobj());
+                sp_icon_fetch_pixbuf( icon );
+                _property_pixbuf_on = Glib::wrap( icon->pb, true );
+            }
+            delete thingie;
+        }
+        thingie = sp_icon_get_icon(_pixOffName.c_str(), Inkscape::ICON_SIZE_DECORATION);
+        if ( thingie ) {
+            if ( SP_IS_ICON(thingie->gobj()) ) {
+                SPIcon* icon = SP_ICON(thingie->gobj());
+                sp_icon_fetch_pixbuf( icon );
+                _property_pixbuf_off = Glib::wrap( icon->pb, true );
+            }
+            delete thingie;
+        }
+        property_pixbuf() = _property_pixbuf_off.get_value();
+    }
+
+    sigc::signal<void, const Glib::ustring&> signal_toggled()
+    {
+        return _signal_toggled;
+    }
+
+    Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); }
+    Glib::PropertyProxy<bool> property_activatable() { return _property_activatable.get_proxy(); }
+    Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_on();
+    Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_off();
+//  virtual Glib::PropertyProxy_Base _property_renderable(); //override
+
+protected:
+    virtual void render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window,
+                               Gtk::Widget& widget,
+                               const Gdk::Rectangle& background_area,
+                               const Gdk::Rectangle& cell_area,
+                               const Gdk::Rectangle& expose_area,
+                               Gtk::CellRendererState flags )
+    {
+        property_pixbuf() = _property_active.get_value() ? _property_pixbuf_on : _property_pixbuf_off;
+        Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags );
+    }
+
+    virtual bool activate_vfunc(GdkEvent* event,
+                                Gtk::Widget& widget,
+                                const Glib::ustring& path,
+                                const Gdk::Rectangle& background_area,
+                                const Gdk::Rectangle& cell_area,
+                                Gtk::CellRendererState flags) {
+        bool val = false;
+        _signal_toggled.emit(path);
+        return val;
+    }
+
+
+private:
+    Glib::ustring _pixOnName;
+    Glib::ustring _pixOffName;
+
+    Glib::Property<bool> _property_active;
+    Glib::Property<bool> _property_activatable;
+    Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_on;
+    Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_off;
+
+    sigc::signal<void, const Glib::ustring&> _signal_toggled;
+};
+
 class LayersPanel::InternalUIBounce
 {
 public:
@@ -492,26 +574,32 @@ LayersPanel::LayersPanel() :
 
     _store = Gtk::TreeStore::create( *zoop );
 
-    Gtk::CellRendererToggle* cell = 0;
     _tree.set_model( _store );
-    int visibleColNum = _tree.append_column("vis", _model->_colVisible) - 1;
-    int lockedColNum = _tree.append_column("lock", _model->_colLocked) - 1;
-    int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
+    _tree.set_headers_visible(false);
 
-    _tree.set_expander_column( *_tree.get_column(nameColNum) );
-
-    cell = dynamic_cast<Gtk::CellRendererToggle*>(_tree.get_column_cell_renderer(visibleColNum));
-    if ( cell ) {
-        cell->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
-        cell->property_activatable() = true;
+    ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") );
+    int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
+    eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
+    eyeRenderer->property_activatable() = true;
+    Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
+    if ( col ) {
+        col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
     }
 
-    cell = dynamic_cast<Gtk::CellRendererToggle*>(_tree.get_column_cell_renderer(lockedColNum));
-    if ( cell ) {
-        cell->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
-        cell->property_activatable() = true;
+    ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") );
+    int lockedColNum = _tree.append_column("lock", *renderer) - 1;
+    renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
+    renderer->property_activatable() = true;
+    col = _tree.get_column(lockedColNum);
+    if ( col ) {
+        col->add_attribute( renderer->property_active(), _model->_colLocked );
     }
 
+    int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
+
+    _tree.set_expander_column( *_tree.get_column(nameColNum) );
+
+
     _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
 
     _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
index cab03fa503890783235b81d0a94d76c724bef1b8..0aa01a37e36daaea75d0a9d91f7ba9ed2ba58f59 100644 (file)
@@ -188,6 +188,19 @@ static int sp_icon_expose(GtkWidget *widget, GdkEventExpose *event)
 {
     if ( GTK_WIDGET_DRAWABLE(widget) ) {
         SPIcon *icon = SP_ICON(widget);
+        if ( !icon->pb ) {
+            sp_icon_fetch_pixbuf( icon );
+        }
+
+        sp_icon_paint(SP_ICON(widget), &event->area);
+    }
+
+    return TRUE;
+}
+
+void sp_icon_fetch_pixbuf( SPIcon *icon )
+{
+    if ( icon ) {
         if ( !icon->pb ) {
             guchar *pixels = 0;
 
@@ -220,14 +233,9 @@ static int sp_icon_expose(GtkWidget *widget, GdkEventExpose *event)
                 g_warning ("failed to load icon '%s'", icon->name);
             }
         }
-
-        sp_icon_paint(SP_ICON(widget), &event->area);
     }
-
-    return TRUE;
 }
 
-
 static void sp_icon_screen_changed( GtkWidget *widget, GdkScreen *previous_screen )
 {
     if ( GTK_WIDGET_CLASS( parent_class )->screen_changed ) {
index de643a131973a1d9ed9580966723a4bb0bc8dad8..55112c0aeeadb7338b0d8d69c541441b69823d38 100644 (file)
@@ -47,5 +47,6 @@ GtkWidget *sp_icon_new( Inkscape::IconSize size, const gchar *name );
 // Might return a wrapped SPIcon, or Gtk::Image
 Gtk::Widget *sp_icon_get_icon( const Glib::ustring &oid, Inkscape::IconSize size = Inkscape::ICON_SIZE_BUTTON );
 
+void sp_icon_fetch_pixbuf( SPIcon *icon );
 
 #endif // SEEN_SP_ICON_H