From: joncruz Date: Sat, 20 May 2006 06:34:27 +0000 (+0000) Subject: Changled dialog from checkboxes to icons for visible and locked. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4721d344da8766410df7b783d2b86a996ba00104;p=inkscape.git Changled dialog from checkboxes to icons for visible and locked. --- diff --git a/ChangeLog b/ChangeLog index b1fad2013..80f9c71d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,19 @@ +2006-05-20 Jon A. Cruz + + * 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 * 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 + * 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 * src/layer-manager.cpp, src/dialogs/layers-panel.h, src/dialogs/layers-panel.cpp: diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index 186aad70b..0ee6ac7e7 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -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(0)), + _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr(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 signal_toggled() + { + return _signal_toggled; + } + + Glib::PropertyProxy property_active() { return _property_active.get_proxy(); } + Glib::PropertyProxy property_activatable() { return _property_activatable.get_proxy(); } + Glib::PropertyProxy< Glib::RefPtr > property_pixbuf_on(); + Glib::PropertyProxy< Glib::RefPtr > property_pixbuf_off(); +// virtual Glib::PropertyProxy_Base _property_renderable(); //override + +protected: + virtual void render_vfunc( const Glib::RefPtr& 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 _property_active; + Glib::Property _property_activatable; + Glib::Property< Glib::RefPtr > _property_pixbuf_on; + Glib::Property< Glib::RefPtr > _property_pixbuf_off; + + sigc::signal _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(_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(_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) ); diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index cab03fa50..0aa01a37e 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -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 ) { diff --git a/src/widgets/icon.h b/src/widgets/icon.h index de643a131..55112c0ae 100644 --- a/src/widgets/icon.h +++ b/src/widgets/icon.h @@ -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