diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-07-20 21:06:10 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-07-20 21:06:10 +0000 |
| commit | 585505da2573e4d4f60dfc90ba45e3e89e3211a9 (patch) | |
| tree | 702911ba021bd49b382a9d911a90cafe5b596ebc /src/ui | |
| parent | noop: rename function name and whitespace (diff) | |
| download | inkscape-585505da2573e4d4f60dfc90ba45e3e89e3211a9.tar.gz inkscape-585505da2573e4d4f60dfc90ba45e3e89e3211a9.zip | |
extract ImageToggler from layers dialog
(bzr r6377)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/widget/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/ui/widget/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/ui/widget/imagetoggler.cpp | 121 | ||||
| -rw-r--r-- | src/ui/widget/imagetoggler.h | 102 |
4 files changed, 226 insertions, 0 deletions
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 <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 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 <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 : |
