Code

add "remove color" ColorItem to the swatches dialog
authorJucaBlues <JucaBlues@users.sourceforge.net>
Sat, 24 Jan 2009 08:09:52 +0000 (08:09 +0000)
committerJucaBlues <JucaBlues@users.sourceforge.net>
Sat, 24 Jan 2009 08:09:52 +0000 (08:09 +0000)
share/icons/Makefile.am
share/icons/remove-color.png [new file with mode: 0644]
share/icons/remove-color.svg [new file with mode: 0644]
src/dialogs/eek-preview.cpp
src/dialogs/eek-preview.h
src/dialogs/swatches.cpp
src/dialogs/swatches.h

index 0c666d212c66e11663124599f5929c3e6df53393..e3bc8e05bed1cb2fd983c9e4dae3a82bd1a16e2e 100644 (file)
@@ -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 (file)
index 0000000..24ab982
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 (file)
index 0000000..10a2622
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="32"
+   height="32"
+   id="svg2"
+   sodipodi:version="0.32"
+   inkscape:version="0.46+devel r custom"
+   version="1.0"
+   sodipodi:docname="remove-color.svg"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape"
+   inkscape:export-filename="/home/felipe/devel/inkscape/share/icons/remove-color.png"
+   inkscape:export-xdpi="300"
+   inkscape:export-ydpi="300">
+  <defs
+     id="defs4">
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       id="perspective10" />
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="1"
+     inkscape:pageshadow="2"
+     inkscape:zoom="17.4375"
+     inkscape:cx="16"
+     inkscape:cy="16"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:window-width="1440"
+     inkscape:window-height="825"
+     inkscape:window-x="0"
+     inkscape:window-y="25" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Camada 1"
+     inkscape:groupmode="layer"
+     id="layer1">
+    <path
+       style="stroke-width:8;fill:none;stroke:#ff0000;stroke-opacity:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-linecap:round"
+       d="M 4,28 28,4"
+       id="path2842"
+       sodipodi:nodetypes="cc"
+       inkscape:export-filename="/home/felipe/Área de Trabalho/remove-color.png"
+       inkscape:export-xdpi="90"
+       inkscape:export-ydpi="90" />
+    <path
+       sodipodi:nodetypes="cc"
+       id="path3616"
+       d="M 28,28 4,4"
+       style="stroke-width:8;fill:none;stroke:#ff0000;stroke-opacity:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-linecap:round"
+       inkscape:export-filename="/home/felipe/Área de Trabalho/remove-color.png"
+       inkscape:export-xdpi="90"
+       inkscape:export-ydpi="90" />
+  </g>
+</svg>
index f9aadc561f8e9c4a98b3bdd869fca99a371c484a..a4e28b2fd82a8db92719567072e64785ca0c78f6 100644 (file)
  * 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;
index 40597eb486c84f908e7eb3925bd2ca04b724bbc2..e01472f1e79e7106ae12239b607a8649cf305f3f 100644 (file)
@@ -100,6 +100,7 @@ struct _EekPreview
     gboolean _hot;
     gboolean _within;
     gboolean _takesFocus;
+    gboolean _isRemove;
 
     PreviewStyle _prevstyle;
     ViewType _view;
index 2eb30f27cadca86a3906b3ce1931ff0f6f91a46f..13c65f7075b59979216a1759389aa224ad97774a 100644 (file)
@@ -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);
                 }
index fc3c772b869cdb7a1c8d2cd54aca840f09d68059..cc0cf89561681ed8591774c0942e5a029bf53e50 100644 (file)
@@ -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