Code

Removed boolean "remove" from swatch, used new type enum in ColorDef.
authorjoncruz <joncruz@users.sourceforge.net>
Wed, 4 Mar 2009 09:11:28 +0000 (09:11 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Wed, 4 Mar 2009 09:11:28 +0000 (09:11 +0000)
src/ui/dialog/swatches.cpp
src/ui/dialog/swatches.h
src/widgets/eek-color-def.cpp
src/widgets/eek-color-def.h

index b294a140024f5ef767a5639fd5f9cfa1c80c8793..1a5ef85210a085192d3020346f4b833275261ad5 100644 (file)
@@ -41,10 +41,19 @@ namespace Inkscape {
 namespace UI {
 namespace Dialogs {
 
-ColorItem::ColorItem() : _isRemove(true){};
+// create a None color swatch
+ColorItem::ColorItem() :
+    def(),
+    _isLive(false),
+    _linkIsTone(false),
+    _linkPercent(0),
+    _linkGray(0),
+    _linkSrc(0)
+{
+}
+
 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),
@@ -251,7 +260,7 @@ static void dragBegin( GtkWidget */*widget*/, GdkDragContext* dc, gpointer data
     ColorItem* item = reinterpret_cast<ColorItem*>(data);
     if ( item )
     {
-        if (item->isRemove()){
+        if (item->def.getType() != eek::ColorDef::RGB){
             GError *error = NULL;
             gchar *filepath = (gchar *) g_strdup_printf("%s/remove-color.png", INKSCAPE_PIXMAPDIR);
             gsize bytesRead = 0;
@@ -588,7 +597,7 @@ void ColorItem::_colorDefChanged(void* data)
                         str = 0;
 
                         if ( bruteForce( document, rroot, paletteName, item->def.getR(), item->def.getG(), item->def.getB() ) ) {
-                            sp_document_done( document , SP_VERB_DIALOG_SWATCHES, 
+                            sp_document_done( document , SP_VERB_DIALOG_SWATCHES,
                                               _("Change color definition"));
                         }
                     }
@@ -617,7 +626,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());
-        if ( _isRemove ) {
+        if ( def.getType() != eek::ColorDef::RGB ) {
             GError *error = NULL;
             gchar *filepath = (gchar *) g_strdup_printf("%s/remove-color.png", INKSCAPE_PIXMAPDIR);
             gsize bytesRead = 0;
@@ -686,8 +695,10 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS
 
         gtk_drag_source_set( GTK_WIDGET(newBlot->gobj()),
                              GDK_BUTTON1_MASK,
-                             isRemove() ? sourceNoColorEntries : sourceColorEntries,
-                             isRemove() ? G_N_ELEMENTS(sourceNoColorEntries) : G_N_ELEMENTS(sourceColorEntries),
+                             (def.getType() != eek::ColorDef::RGB) ? sourceNoColorEntries :
+                             sourceColorEntries,
+                             (def.getType() != eek::ColorDef::RGB) ? G_N_ELEMENTS(sourceNoColorEntries) :
+                             G_N_ELEMENTS(sourceColorEntries),
                              GdkDragAction(GDK_ACTION_MOVE | GDK_ACTION_COPY) );
 
         g_signal_connect( G_OBJECT(newBlot->gobj()),
@@ -747,26 +758,37 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS
 void ColorItem::buttonClicked(bool secondary)
 {
     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
-    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;
-        sp_svg_write_color(c, sizeof(c), rgba);
-    }
-
-    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);
+    if (desktop) {
+        char const * attrName = secondary ? "stroke" : "fill";
+
+        SPCSSAttr *css = sp_repr_css_attr_new();
+        Glib::ustring descr;
+        switch (def.getType()) {
+            case eek::ColorDef::CLEAR: {
+                // TODO actually make this clear
+                sp_repr_css_set_property( css, attrName, "none" );
+                descr = secondary? _("Remove stroke color") : _("Remove fill color");
+                break;
+            }
+            case eek::ColorDef::NONE: {
+                sp_repr_css_set_property( css, attrName, "none" );
+                descr = secondary? _("Set stroke color to none") : _("Set fill color to none");
+                break;
+            }
+            case eek::ColorDef::RGB: {
+                gchar c[64];
+                guint32 rgba = (def.getR() << 24) | (def.getG() << 16) | (def.getB() << 8) | 0xff;
+                sp_svg_write_color(c, sizeof(c), rgba);
+
+                sp_repr_css_set_property( css, attrName, c );
+                descr = secondary? _("Set stroke color from swatch") : _("Set fill color from swatch");
+                break;
+            }
+        }
+        sp_desktop_set_style(desktop, css);
+        sp_repr_css_attr_unref(css);
 
-    if (_isRemove){
-        sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_SWATCHES, 
-                      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"));
+        sp_document_done( sp_desktop_document(desktop), SP_VERB_DIALOG_SWATCHES, descr.c_str() );
     }
 }
 
index 8428919e0b764e6ecf0f6cb239b295715e18e2ce..17081733d8912fd391c3a5d3760d2d50c6f336b0 100644 (file)
@@ -42,7 +42,6 @@ public:
                                     ::PreviewSize size,
                                     guint ratio);
     void buttonClicked(bool secondary = false);
-    bool isRemove(){ return _isRemove; }
     eek::ColorDef def;
 
 private:
@@ -70,7 +69,6 @@ private:
     Gtk::Tooltips tips;
     std::vector<Gtk::Widget*> _previews;
 
-    bool _isRemove;
     bool _isLive;
     bool _linkIsTone;
     int _linkPercent;
index 85b00b251a0708fbf8b679296505f92d0546856b..d7cb41b38970ae3b7f15f08bfa9444406b272988 100644 (file)
@@ -54,20 +54,20 @@ namespace eek
 
 ColorDef::ColorDef() :
     descr(_("none")),
+    type(NONE),
     r(0),
     g(0),
     b(0),
-    none(true),
     editable(false)
 {
 }
 
 ColorDef::ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description ) :
     descr(description),
+    type(RGB),
     r(r),
     g(g),
     b(b),
-    none(false),
     editable(false)
 {
 }
@@ -87,11 +87,11 @@ ColorDef& ColorDef::operator=( ColorDef const &other )
 {
     if ( this != & other )
     {
+        type = other.type;
         r = other.r;
         g = other.g;
         b = other.b;
         descr = other.descr;
-        none = other.none;
         editable = other.editable;
     }
     return *this;
index 63cd096be981d11649d09c16d5aa4c32ecd28c5e..764a28b12a105c70344ba5fed91c7eecadcfaefc 100644 (file)
@@ -52,6 +52,8 @@ typedef void (*ColorCallback)( void* data );
 class ColorDef
 {
 public:
+    enum ColorType{CLEAR, NONE, RGB};
+
     ColorDef();
     ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description );
     virtual ~ColorDef();
@@ -59,6 +61,8 @@ public:
     ColorDef( ColorDef const &other );
     virtual ColorDef& operator=( ColorDef const &other );
 
+    ColorType getType() const { return type; }
+
     void setRGB( unsigned int r, unsigned int g, unsigned int b );
     unsigned int getR() const { return r; }
     unsigned int getG() const { return g; }
@@ -73,10 +77,10 @@ public:
     std::string descr;
 
 protected:
+    ColorType type;
     unsigned int r;
     unsigned int g;
     unsigned int b;
-    bool none;
     bool editable;
 
 private: