diff options
| author | Felipe Corr??a da Silva Sanches <juca@members.fsf.org> | 2009-01-24 08:09:52 +0000 |
|---|---|---|
| committer | JucaBlues <JucaBlues@users.sourceforge.net> | 2009-01-24 08:09:52 +0000 |
| commit | 25fb1bfdc2612c448daa368022f86ae42ff8935d (patch) | |
| tree | 346bf68a26e2e40eb7bfb62e76bd852df7de673e /src | |
| parent | sort combo enumerations (diff) | |
| download | inkscape-25fb1bfdc2612c448daa368022f86ae42ff8935d.tar.gz inkscape-25fb1bfdc2612c448daa368022f86ae42ff8935d.zip | |
add "remove color" ColorItem to the swatches dialog
(bzr r7164)
Diffstat (limited to 'src')
| -rw-r--r-- | src/dialogs/eek-preview.cpp | 42 | ||||
| -rw-r--r-- | src/dialogs/eek-preview.h | 1 | ||||
| -rw-r--r-- | src/dialogs/swatches.cpp | 40 | ||||
| -rw-r--r-- | src/dialogs/swatches.h | 6 |
4 files changed, 63 insertions, 26 deletions
diff --git a/src/dialogs/eek-preview.cpp b/src/dialogs/eek-preview.cpp index f9aadc561..a4e28b2fd 100644 --- a/src/dialogs/eek-preview.cpp +++ b/src/dialogs/eek-preview.cpp @@ -36,9 +36,13 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include <gtk/gtk.h> #include "eek-preview.h" +#include "path-prefix.h" #define PRIME_BUTTON_MAGIC_NUMBER 1 @@ -57,15 +61,11 @@ static GtkWidgetClass* parent_class = 0; void eek_preview_set_color( EekPreview* preview, int r, int g, int b ) { - if ( (preview->_r = r) - || (preview->_g = g) - || (preview->_b = b) ) { - preview->_r = r; - preview->_g = g; - preview->_b = b; - - gtk_widget_queue_draw(GTK_WIDGET(preview)); - } + preview->_r = r; + preview->_g = g; + preview->_b = b; + + gtk_widget_queue_draw(GTK_WIDGET(preview)); } @@ -222,6 +222,7 @@ gboolean eek_preview_expose_event( GtkWidget* widget, GdkEventExpose* event ) GdkGC *gc = gdk_gc_new( widget->window ); EekPreview* preview = EEK_PREVIEW(widget); GdkColor fg = {0, preview->_r, preview->_g, preview->_b}; + gdk_colormap_alloc_color( gdk_colormap_get_system(), &fg, FALSE, TRUE ); gdk_gc_set_foreground( gc, &fg ); @@ -306,6 +307,28 @@ gboolean eek_preview_expose_event( GtkWidget* widget, GdkEventExpose* event ) } } + if (preview->_isRemove){ + GtkDrawingArea* da = &(preview->drawing); + GdkDrawable* drawable = (GdkDrawable*) (((GtkWidget*)da)->window); + gint w,h; + gdk_drawable_get_size(drawable, &w, &h); + GError *error = NULL; + gchar *filepath = (gchar *) g_strdup_printf("%s/remove-color.png", INKSCAPE_PIXMAPDIR); + g_warning("filepath: %s", filepath); + gsize bytesRead = 0; + gsize bytesWritten = 0; + gchar *localFilename = g_filename_from_utf8( filepath, + -1, + &bytesRead, + &bytesWritten, + &error); + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(localFilename, w, h, &error); + gdk_draw_pixbuf(drawable, 0, pixbuf, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0); + g_free(localFilename); + g_free(filepath); + } + + if ( GTK_WIDGET_HAS_FOCUS(widget) ) { gtk_paint_focus( style, widget->window, @@ -633,6 +656,7 @@ static void eek_preview_init( EekPreview *preview ) preview->_hot = FALSE; preview->_within = FALSE; preview->_takesFocus = FALSE; + preview->_isRemove = FALSE; preview->_prevstyle = PREVIEW_STYLE_ICON; preview->_view = VIEW_TYPE_LIST; diff --git a/src/dialogs/eek-preview.h b/src/dialogs/eek-preview.h index 40597eb48..e01472f1e 100644 --- a/src/dialogs/eek-preview.h +++ b/src/dialogs/eek-preview.h @@ -100,6 +100,7 @@ struct _EekPreview gboolean _hot; gboolean _within; gboolean _takesFocus; + gboolean _isRemove; PreviewStyle _prevstyle; ViewType _view; diff --git a/src/dialogs/swatches.cpp b/src/dialogs/swatches.cpp index 2eb30f27c..13c65f707 100644 --- a/src/dialogs/swatches.cpp +++ b/src/dialogs/swatches.cpp @@ -42,9 +42,10 @@ namespace Inkscape { namespace UI { namespace Dialogs { - +ColorItem::ColorItem() : _isRemove(true){}; ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ) : def( r, g, b, name ), + _isRemove(false), _isLive(false), _linkIsTone(false), _linkPercent(0), @@ -532,7 +533,7 @@ void ColorItem::_colorDefChanged(void* data) Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewSize size, guint ratio) { Gtk::Widget* widget = 0; - if ( style == PREVIEW_STYLE_BLURB ) { + if ( style == PREVIEW_STYLE_BLURB) { Gtk::Label *lbl = new Gtk::Label(def.descr); lbl->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); widget = lbl; @@ -547,6 +548,7 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS Gtk::Widget* newBlot = Glib::wrap(eekWidget); eek_preview_set_color( preview, (def.getR() << 8) | def.getR(), (def.getG() << 8) | def.getG(), (def.getB() << 8) | def.getB()); + preview->_isRemove = _isRemove; eek_preview_set_details( preview, (::PreviewStyle)style, (::ViewType)view, (::PreviewSize)size, ratio ); eek_preview_set_linked( preview, (LinkType)((_linkSrc ? PREVIEW_LINK_IN:0) @@ -658,25 +660,29 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS void ColorItem::buttonClicked(bool secondary) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) { - char const * attrName = secondary ? "stroke" : "fill"; + if (!desktop) return; + char const * attrName = secondary ? "stroke" : "fill"; + + gchar c[64]; + if (!_isRemove){ guint32 rgba = (def.getR() << 24) | (def.getG() << 16) | (def.getB() << 8) | 0xff; - gchar c[64]; sp_svg_write_color(c, sizeof(c), rgba); + } - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property( css, attrName, c ); - sp_desktop_set_style(desktop, css); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property( css, attrName, _isRemove ? "none" : c ); + sp_desktop_set_style(desktop, css); + sp_repr_css_attr_unref(css); - sp_repr_css_attr_unref(css); + if (_isRemove){ sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_SWATCHES, - secondary? _("Set stroke color from swatch") : _("Set fill color from swatch")); + secondary? _("Remove stroke color") : _("Remove fill color")); + } else { + sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_SWATCHES, + secondary? _("Set stroke color from swatch") : _("Set fill color from swatch")); } } - - - static char* trim( char* str ) { char* ret = str; while ( *str && (*str == ' ' || *str == '\t') ) { @@ -1039,8 +1045,8 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : { Gtk::RadioMenuItem* hotItem = 0; _holder = new PreviewHolder(); + _remove = new ColorItem(); loadEmUp(); - if ( !possible.empty() ) { JustForNow* first = 0; Glib::ustring targetName; @@ -1065,12 +1071,14 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : _holder->setColumnPref( first->_prefWidth ); } _holder->freezeUpdates(); + _holder->addPreview(_remove); for ( std::vector<ColorItem*>::iterator it = first->_colors.begin(); it != first->_colors.end(); it++ ) { _holder->addPreview(*it); } _holder->thawUpdates(); Gtk::RadioMenuItem::Group groupOne; + int i = 0; for ( std::vector<JustForNow*>::iterator it = possible.begin(); it != possible.end(); it++ ) { JustForNow* curr = *it; @@ -1081,7 +1089,6 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : _regItem( single, 3, i ); i++; } - } @@ -1098,6 +1105,8 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : SwatchesPanel::~SwatchesPanel() { + if (_remove) delete _remove; + if (_holder) delete _holder; } void SwatchesPanel::setOrientation( Gtk::AnchorType how ) @@ -1129,6 +1138,7 @@ void SwatchesPanel::_handleAction( int setId, int itemId ) _holder->setColumnPref( curr->_prefWidth ); } _holder->freezeUpdates(); + _holder->addPreview(_remove); for ( std::vector<ColorItem*>::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) { _holder->addPreview(*it); } diff --git a/src/dialogs/swatches.h b/src/dialogs/swatches.h index fc3c772b8..cc0cf8956 100644 --- a/src/dialogs/swatches.h +++ b/src/dialogs/swatches.h @@ -26,7 +26,6 @@ namespace Dialogs { void _loadPaletteFile( gchar const *filename ); - /** * The color swatch you see on screen as a clickable box. */ @@ -34,6 +33,7 @@ class ColorItem : public Inkscape::UI::Previewable { friend void _loadPaletteFile( gchar const *filename ); public: + ColorItem(); ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ); virtual ~ColorItem(); @@ -72,6 +72,7 @@ private: Gtk::Tooltips tips; std::vector<Gtk::Widget*> _previews; + bool _isRemove; bool _isLive; bool _linkIsTone; int _linkPercent; @@ -79,8 +80,8 @@ private: ColorItem* _linkSrc; std::vector<ColorItem*> _listeners; }; - +class RemoveColorItem; /** * A panel that displays color swatches. @@ -104,6 +105,7 @@ private: static SwatchesPanel* instance; PreviewHolder* _holder; + ColorItem* _remove; }; } //namespace Dialogs |
