Code

extract ImageToggler from layers dialog
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 20 Jul 2008 21:06:10 +0000 (21:06 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 20 Jul 2008 21:06:10 +0000 (21:06 +0000)
src/dialogs/layers-panel.cpp
src/ui/widget/CMakeLists.txt
src/ui/widget/Makefile_insert
src/ui/widget/imagetoggler.cpp [new file with mode: 0644]
src/ui/widget/imagetoggler.h [new file with mode: 0644]

index 6e5271ad156c65282d03ebb7e1d3bbc2b45a143a..c41d8ccb48615e50481d740bfd3c48812892ead7 100644 (file)
@@ -34,6 +34,7 @@
 #include "sp-object.h"
 #include "sp-item.h"
 #include "widgets/icon.h"
+#include "ui/widget/imagetoggler.h"
 #include <gtkmm/widget.h>
 #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<Gdk::Pixbuf>(0)),
-        _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
-    {
-        property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
-        int phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION);
-
-        Glib::RefPtr<Gdk::Pixbuf> 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<void, const Glib::ustring&> signal_toggled()
-    {
-        return _signal_toggled;
-    }
-
-    sigc::signal<void, GdkEvent const *> signal_pre_toggle()
-    {
-        return _signal_pre_toggle;
-    }
-
-    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 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<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*/)
-    {
-        _signal_pre_toggle.emit(event);
-        _signal_toggled.emit(path);
-
-        return false;
-    }
-
-
-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;
-    sigc::signal<void, GdkEvent const *> _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) );
index 9293e3be452601166100854b4c2f6981fc898ed0..ffc94c299765709057120b2456f6f852fe195214 100644 (file)
@@ -11,6 +11,7 @@ filter-effect-chooser.cpp
 handlebox.cpp
 icon-widget.cpp
 imageicon.cpp
+imagetoggler.cpp
 labelled.cpp
 licensor.cpp
 notebook-page.cpp
index fbbc686ab3dfbc19b38c4b080f1bc91969a430e9..ef68f61149565c58cfd573b054382d772f3c4915 100644 (file)
@@ -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 (file)
index 0000000..eafa114
--- /dev/null
@@ -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 <gtk/gtkstock.h>
+#include <gtk/gtkmain.h>
+
+#include <gtkmm/icontheme.h>
+
+#include "document.h"
+#include "desktop.h"
+#include "sp-object.h"
+#include "sp-item.h"
+#include "widgets/icon.h"
+#include <gtkmm/widget.h>
+
+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<Gdk::Pixbuf>(0)),
+    _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
+{
+    property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
+    int phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION);
+
+    Glib::RefPtr<Gdk::Pixbuf> 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<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 );
+}
+
+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 (file)
index 0000000..29ff791
--- /dev/null
@@ -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 <gtk/gtkstock.h>
+#include <gtk/gtkmain.h>
+
+#include <gtkmm/icontheme.h>
+
+#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 <gtkmm/widget.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class ImageToggler : public Gtk::CellRendererPixbuf {
+public:
+    ImageToggler( char const *on, char const *off);
+    virtual ~ImageToggler() {};
+
+    sigc::signal<void, const Glib::ustring&> signal_toggled() { return _signal_toggled;}
+    sigc::signal<void, GdkEvent const *> signal_pre_toggle()  { return _signal_pre_toggle; }
+
+    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();
+
+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<Gdk::Drawable>& 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<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;
+    sigc::signal<void, GdkEvent const *> _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 :