From: joncruz Date: Wed, 4 Mar 2009 09:11:28 +0000 (+0000) Subject: Removed boolean "remove" from swatch, used new type enum in ColorDef. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5699e1b0751ddeaee06797406efde1a11c5f64bb;p=inkscape.git Removed boolean "remove" from swatch, used new type enum in ColorDef. --- diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index b294a1400..1a5ef8521 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -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(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() ); } } diff --git a/src/ui/dialog/swatches.h b/src/ui/dialog/swatches.h index 8428919e0..17081733d 100644 --- a/src/ui/dialog/swatches.h +++ b/src/ui/dialog/swatches.h @@ -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 _previews; - bool _isRemove; bool _isLive; bool _linkIsTone; int _linkPercent; diff --git a/src/widgets/eek-color-def.cpp b/src/widgets/eek-color-def.cpp index 85b00b251..d7cb41b38 100644 --- a/src/widgets/eek-color-def.cpp +++ b/src/widgets/eek-color-def.cpp @@ -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; diff --git a/src/widgets/eek-color-def.h b/src/widgets/eek-color-def.h index 63cd096be..764a28b12 100644 --- a/src/widgets/eek-color-def.h +++ b/src/widgets/eek-color-def.h @@ -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: