From: JucaBlues Date: Sat, 24 Jan 2009 08:09:52 +0000 (+0000) Subject: add "remove color" ColorItem to the swatches dialog X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=101151f48224596a666f5c4bcd1f66025101bd32;p=inkscape.git add "remove color" ColorItem to the swatches dialog --- diff --git a/share/icons/Makefile.am b/share/icons/Makefile.am index 0c666d212..e3bc8e05b 100644 --- a/share/icons/Makefile.am +++ b/share/icons/Makefile.am @@ -2,6 +2,8 @@ iconsdir = $(datadir)/inkscape/icons pixmaps = \ + remove-color.png \ + remove-color.svg \ ticotico.jpg \ feBlend-icon.png \ feBlend-icon.svg \ diff --git a/share/icons/remove-color.png b/share/icons/remove-color.png new file mode 100644 index 000000000..24ab98277 Binary files /dev/null and b/share/icons/remove-color.png differ diff --git a/share/icons/remove-color.svg b/share/icons/remove-color.svg new file mode 100644 index 000000000..10a2622cf --- /dev/null +++ b/share/icons/remove-color.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + 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 #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::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::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::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 _previews; + bool _isRemove; bool _isLive; bool _linkIsTone; int _linkPercent; @@ -79,8 +80,8 @@ private: ColorItem* _linkSrc; std::vector _listeners; }; - +class RemoveColorItem; /** * A panel that displays color swatches. @@ -104,6 +105,7 @@ private: static SwatchesPanel* instance; PreviewHolder* _holder; + ColorItem* _remove; }; } //namespace Dialogs