From: johanengelen Date: Sun, 20 Jul 2008 21:06:10 +0000 (+0000) Subject: extract ImageToggler from layers dialog X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5ad0193e0a4c9844c90cc1097684323d47d50313;p=inkscape.git extract ImageToggler from layers dialog --- diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index 6e5271ad1..c41d8ccb4 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -34,6 +34,7 @@ #include "sp-object.h" #include "sp-item.h" #include "widgets/icon.h" +#include "ui/widget/imagetoggler.h" #include #include "prefs-utils.h" #include "xml/repr.h" @@ -69,112 +70,6 @@ enum { BUTTON_SOLO }; -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; - int phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION); - - Glib::RefPtr pbmm = Gtk::IconTheme::get_default()->load_icon(_pixOnName, phys, (Gtk::IconLookupFlags)0); - if ( pbmm ) { - GdkPixbuf* pb = gdk_pixbuf_copy(pbmm->gobj()); - _property_pixbuf_on = Glib::wrap( pb ); - pbmm->unreference(); - } - - pbmm = Gtk::IconTheme::get_default()->load_icon(_pixOffName, phys, (Gtk::IconLookupFlags)0); - if ( pbmm ) { - GdkPixbuf* pb = gdk_pixbuf_copy(pbmm->gobj()); - _property_pixbuf_off = Glib::wrap( pb ); - pbmm->unreference(); - } - - property_pixbuf() = _property_pixbuf_off.get_value(); - } - - sigc::signal signal_toggled() - { - return _signal_toggled; - } - - sigc::signal signal_pre_toggle() - { - return _signal_pre_toggle; - } - - 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 get_size_vfunc( Gtk::Widget& widget, - const Gdk::Rectangle* cell_area, - int* x_offset, - int* y_offset, - int* width, - int* height ) const - { - Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height ); - - if ( width ) { - *width += (*width) >> 1; - } - if ( height ) { - *height += (*height) >> 1; - } - } - - - 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*/) - { - _signal_pre_toggle.emit(event); - _signal_toggled.emit(path); - - return false; - } - - -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; - sigc::signal _signal_pre_toggle; -}; - class LayersPanel::InternalUIBounce { public: @@ -694,7 +589,7 @@ LayersPanel::LayersPanel() : _tree.set_model( _store ); _tree.set_headers_visible(false); - ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") ); + Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler("visible", "hidden") ); int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1; eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) ); @@ -704,7 +599,7 @@ LayersPanel::LayersPanel() : col->add_attribute( eyeRenderer->property_active(), _model->_colVisible ); } - ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") ); + Inkscape::UI::Widget::ImageToggler * renderer = manage( new Inkscape::UI::Widget::ImageToggler("width_height_lock", "lock_unlocked") ); int lockedColNum = _tree.append_column("lock", *renderer) - 1; renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) ); diff --git a/src/ui/widget/CMakeLists.txt b/src/ui/widget/CMakeLists.txt index 9293e3be4..ffc94c299 100644 --- a/src/ui/widget/CMakeLists.txt +++ b/src/ui/widget/CMakeLists.txt @@ -11,6 +11,7 @@ filter-effect-chooser.cpp handlebox.cpp icon-widget.cpp imageicon.cpp +imagetoggler.cpp labelled.cpp licensor.cpp notebook-page.cpp diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index fbbc686ab..ef68f6114 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -32,6 +32,8 @@ ui_widget_libuiwidget_a_SOURCES = \ ui/widget/icon-widget.h \ ui/widget/imageicon.cpp \ ui/widget/imageicon.h \ + ui/widget/imagetoggler.cpp \ + ui/widget/imagetoggler.h \ ui/widget/labelled.cpp \ ui/widget/labelled.h \ ui/widget/licensor.cpp \ diff --git a/src/ui/widget/imagetoggler.cpp b/src/ui/widget/imagetoggler.cpp new file mode 100644 index 000000000..eafa1144a --- /dev/null +++ b/src/ui/widget/imagetoggler.cpp @@ -0,0 +1,121 @@ +/* + * Authors: + * Jon A. Cruz + * Johan B. C. Engelen + * + * Copyright (C) 2006-2008 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/imagetoggler.h" + +#include +#include + +#include + +#include "document.h" +#include "desktop.h" +#include "sp-object.h" +#include "sp-item.h" +#include "widgets/icon.h" +#include + +namespace Inkscape { +namespace UI { +namespace Widget { + +ImageToggler::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; + int phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION); + + Glib::RefPtr pbmm = Gtk::IconTheme::get_default()->load_icon(_pixOnName, phys, (Gtk::IconLookupFlags)0); + if ( pbmm ) { + GdkPixbuf* pb = gdk_pixbuf_copy(pbmm->gobj()); + _property_pixbuf_on = Glib::wrap( pb ); + pbmm->unreference(); + } + + pbmm = Gtk::IconTheme::get_default()->load_icon(_pixOffName, phys, (Gtk::IconLookupFlags)0); + if ( pbmm ) { + GdkPixbuf* pb = gdk_pixbuf_copy(pbmm->gobj()); + _property_pixbuf_off = Glib::wrap( pb ); + pbmm->unreference(); + } + + property_pixbuf() = _property_pixbuf_off.get_value(); +} + +void +ImageToggler::get_size_vfunc( Gtk::Widget& widget, + const Gdk::Rectangle* cell_area, + int* x_offset, + int* y_offset, + int* width, + int* height ) const +{ + Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height ); + + if ( width ) { + *width += (*width) >> 1; + } + if ( height ) { + *height += (*height) >> 1; + } +} + + +void +ImageToggler::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 ); +} + +bool +ImageToggler::activate_vfunc(GdkEvent* event, + Gtk::Widget& /*widget*/, + const Glib::ustring& path, + const Gdk::Rectangle& /*background_area*/, + const Gdk::Rectangle& /*cell_area*/, + Gtk::CellRendererState /*flags*/) +{ + _signal_pre_toggle.emit(event); + _signal_toggled.emit(path); + + return false; +} + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : + + diff --git a/src/ui/widget/imagetoggler.h b/src/ui/widget/imagetoggler.h new file mode 100644 index 000000000..29ff79180 --- /dev/null +++ b/src/ui/widget/imagetoggler.h @@ -0,0 +1,102 @@ +#ifndef __UI_DIALOG_IMAGETOGGLER_H__ +#define __UI_DIALOG_IMAGETOGGLER_H__ +/* + * Authors: + * Jon A. Cruz + * Johan B. C. Engelen + * + * Copyright (C) 2006-2008 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + //TODO: we don't need all these include files here! +#include +#include + +#include + +#include "inkscape.h" + +#include "layers-panel.h" + +#include "layer-manager.h" +#include "layer-fns.h" + +#include "verbs.h" +#include "helper/action.h" + +#include "widgets/icon.h" +#include + +namespace Inkscape { +namespace UI { +namespace Widget { + +class ImageToggler : public Gtk::CellRendererPixbuf { +public: + ImageToggler( char const *on, char const *off); + virtual ~ImageToggler() {}; + + sigc::signal signal_toggled() { return _signal_toggled;} + sigc::signal signal_pre_toggle() { return _signal_pre_toggle; } + + 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(); + +protected: + + virtual void get_size_vfunc( Gtk::Widget &widget, + Gdk::Rectangle const *cell_area, + int *x_offset, int *y_offset, int *width, int *height ) const; + + + 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 ); + + 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); + + +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; + sigc::signal _signal_pre_toggle; +}; + + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + + +#endif /* __UI_DIALOG_IMAGETOGGLER_H__ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :