=== modified file 'src/color.cpp' --- src/color.cpp 2012-10-04 01:45:44 +0000 +++ src/color.cpp 2012-12-09 14:19:45 +0000 @@ -52,6 +52,12 @@ set( value ); } +SPColor::SPColor( const Glib::ustring& rrggbbString ) : + icc(0) +{ + set( rrggbbString ); +} + SPColor::~SPColor() { delete icc; @@ -158,6 +164,28 @@ } /** + * Converts a RRGGBB string to RGB floats and sets color. + */ +void SPColor::set( const Glib::ustring& rrggbbString ) +{ + gchar* str = g_strdup(rrggbbString.c_str()); + gchar* end = 0; + guint64 rgb = g_ascii_strtoull( str, &end, 16 ); + + if ( end != str ) + { + ptrdiff_t len = end - str; + if ( len < 8 ) { + rgb = rgb << ( 4 * ( 8 - len ) ); + } + + this->set( rgb ); + } + + g_free(str); +} + +/** * Convert SPColor with integer alpha value to 32bit RGBA value. * \pre alpha < 256 */ === modified file 'src/color.h' --- src/color.h 2011-10-25 07:45:35 +0000 +++ src/color.h 2012-12-09 14:21:29 +0000 @@ -13,6 +13,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include #include @@ -41,6 +42,7 @@ SPColor( SPColor const& other ); SPColor( float r, float g, float b ); SPColor( guint32 value ); + SPColor( const Glib::ustring& rrggbbString ); virtual ~SPColor(); SPColor& operator= (SPColor const& other); @@ -50,6 +52,7 @@ void set( float r, float g, float b ); void set( guint32 value ); + void set( const Glib::ustring& rrggbbString ); guint32 toRGBA32( gint alpha ) const; guint32 toRGBA32( gdouble alpha ) const; === modified file 'src/ui/widget/Makefile_insert' --- src/ui/widget/Makefile_insert 2012-09-22 01:43:42 +0000 +++ src/ui/widget/Makefile_insert 2012-12-08 22:08:11 +0000 @@ -4,6 +4,8 @@ ui/widget/attr-widget.h \ ui/widget/button.h \ ui/widget/button.cpp \ + ui/widget/color-entry.cpp \ + ui/widget/color-entry.h \ ui/widget/color-picker.cpp \ ui/widget/color-picker.h \ ui/widget/color-preview.cpp \ === added file 'src/ui/widget/color-entry.cpp' --- src/ui/widget/color-entry.cpp 1970-01-01 00:00:00 +0000 +++ src/ui/widget/color-entry.cpp 2012-12-09 18:49:02 +0000 @@ -0,0 +1,70 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "color-entry.h" + +#include "../../widgets/sp-color-selector.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + +ColorEntry::ColorEntry( ColorSelector* csel ): + _nbLocked(0), + csel(csel) +{ + this->set_max_length (8); + this->set_width_chars (8); + this->set_tooltip_text (_("Hexadecimal RGBA value of the color")); + + _changedHandler = this->signal_changed().connect(sigc::mem_fun(*this, &ColorEntry::_changedHook)); +} + +void ColorEntry::_changedHook() +{ + if(_nbLocked == 0) + _changedHandler.block(); + _nbLocked++; + + csel->setColor(this->get_text()); + + _nbLocked--; + if(_nbLocked == 0) + _changedHandler.unblock(); +} + +gboolean ColorEntry::is_locked() +{ + return _changedHandler.blocked(); +} + +void ColorEntry::set_text(const Glib::ustring& text) +{ + if(_nbLocked == 0) + _changedHandler.block(); + _nbLocked++; + + Gtk::Entry::set_text( text ); + + _nbLocked--; + if(_nbLocked == 0) + _changedHandler.unblock(); +} + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : === added file 'src/ui/widget/color-entry.h' --- src/ui/widget/color-entry.h 1970-01-01 00:00:00 +0000 +++ src/ui/widget/color-entry.h 2012-12-09 18:51:26 +0000 @@ -0,0 +1,44 @@ +#ifndef INKSCAPE_UI_WIDGET_COLOR_ENTRY_H +#define INKSCAPE_UI_WIDGET_COLOR_ENTRY_H + +#include + +class ColorSelector; + +namespace Inkscape { +namespace UI { +namespace Widget { + +class ColorEntry : public Gtk::Entry +{ +protected: + sigc::connection _changedHandler; + unsigned int _nbLocked; + ColorSelector* csel; + + void _changedHook( ); + +public: + ColorEntry( ColorSelector* csel ); + + gboolean is_locked(); + virtual void set_text(const Glib::ustring& text); +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_COLOR_ENTRY_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : + === modified file 'src/widgets/sp-color-notebook.cpp' --- src/widgets/sp-color-notebook.cpp 2012-12-02 23:23:08 +0000 +++ src/widgets/sp-color-notebook.cpp 2012-12-09 17:28:36 +0000 @@ -40,6 +40,7 @@ #include "widgets/icon.h" #include "tools-switch.h" #include "event-context.h" +#include "../ui/widget/color-entry.h" using Inkscape::CMSSystem; @@ -212,9 +213,7 @@ wheel. */ // SP_TYPE_COLOR_GTKSELECTOR; - - _updating = FALSE; - _updatingrgba = FALSE; + _btn = 0; _popup = 0; _trackerList = g_ptr_array_new (); @@ -419,13 +418,10 @@ gtk_misc_set_alignment (GTK_MISC (_rgbal), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(rgbabox), _rgbal, TRUE, TRUE, 2); - _rgbae = gtk_entry_new (); - sp_dialog_defocus_on_enter (_rgbae); - gtk_entry_set_max_length (GTK_ENTRY (_rgbae), 8); - gtk_entry_set_width_chars (GTK_ENTRY (_rgbae), 8); - gtk_widget_set_tooltip_text (_rgbae, _("Hexadecimal RGBA value of the color")); - gtk_box_pack_start(GTK_BOX(rgbabox), _rgbae, FALSE, FALSE, 0); - gtk_label_set_mnemonic_widget (GTK_LABEL(_rgbal), _rgbae); + _rgbae = new Inkscape::UI::Widget::ColorEntry( this ); + sp_dialog_defocus_on_enter (GTK_WIDGET(_rgbae->gobj())); + gtk_box_pack_start(GTK_BOX(rgbabox), GTK_WIDGET(_rgbae->gobj()), FALSE, FALSE, 0); + gtk_label_set_mnemonic_widget (GTK_LABEL(_rgbal), GTK_WIDGET(_rgbae->gobj())); sp_set_font_size_smaller (rgbabox); gtk_widget_show_all (rgbabox); @@ -454,7 +450,7 @@ _switchId = g_signal_connect(G_OBJECT (_book), "switch-page", G_CALLBACK (sp_color_notebook_switch_page), SP_COLOR_NOTEBOOK(_csel)); - _entryId = g_signal_connect (G_OBJECT (_rgbae), "changed", G_CALLBACK (ColorNotebook::_rgbaEntryChangedHook), _csel); + //_entryId = g_signal_connect (G_OBJECT (_rgbae->gobj()), "changed", G_CALLBACK (ColorNotebook::_rgbaEntryChangedHook), _csel); } static void sp_color_notebook_dispose(GObject *object) @@ -547,51 +543,26 @@ sp_toggle_dropper(SP_ACTIVE_DESKTOP); } -void ColorNotebook::_rgbaEntryChangedHook(GtkEntry *entry, SPColorNotebook *colorbook) -{ - (dynamic_cast(SP_COLOR_SELECTOR(colorbook)->base))->_rgbaEntryChanged( entry ); -} - -void ColorNotebook::_rgbaEntryChanged(GtkEntry* entry) -{ - if (_updating) return; - if (_updatingrgba) return; - - const gchar *t = gtk_entry_get_text( entry ); - - if (t) { - Glib::ustring text = t; - bool changed = false; - if (!text.empty() && text[0] == '#') { - changed = true; - text.erase(0,1); - if (text.size() == 6) { - // it was a standard RGB hex - unsigned int alph = SP_COLOR_F_TO_U(_alpha); - gchar* tmp = g_strdup_printf("%02x", alph); - text += tmp; - g_free(tmp); - } - } - gchar* str = g_strdup(text.c_str()); - gchar* end = 0; - guint64 rgba = g_ascii_strtoull( str, &end, 16 ); - if ( end != str ) { - ptrdiff_t len = end - str; - if ( len < 8 ) { - rgba = rgba << ( 4 * ( 8 - len ) ); - } - _updatingrgba = TRUE; - if ( changed ) { - gtk_entry_set_text( entry, str ); - } - SPColor color( rgba ); - setColorAlpha( color, SP_RGBA32_A_F(rgba), true ); - _updatingrgba = FALSE; - } - g_free(str); +/*void ColorNotebook::_rgbaEntryChangedHook() +{ + gchar* str = g_strdup(_rgbae->get_text().c_str()); + gchar* end = 0; + guint64 rgba = g_ascii_strtoull( str, &end, 16 ); + + if ( end != str ) + { + ptrdiff_t len = end - str; + if ( len < 8 ) { + rgba = rgba << ( 4 * ( 8 - len ) ); + } + + if ( changed ) { + this->set_text( str ); + } + SPColor color( rgba ); + setColorAlpha( color, SP_RGBA32_A_F(rgba), true ); } -} +}*/ // TODO pass in param so as to avoid the need for SP_ACTIVE_DOCUMENT void ColorNotebook::_updateRgbaEntry( const SPColor& color, gfloat alpha ) @@ -632,7 +603,7 @@ } #endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if ( !_updatingrgba ) + if ( !_rgbae->is_locked() ) { gchar s[32]; guint32 rgba; @@ -641,12 +612,10 @@ rgba = color.toRGBA32( alpha ); g_snprintf (s, 32, "%08x", rgba); - const gchar* oldText = gtk_entry_get_text( GTK_ENTRY( _rgbae ) ); - if ( strcmp( oldText, s ) != 0 ) + Glib::ustring oldText = _rgbae->get_text(); + if ( oldText != s ) { - g_signal_handler_block( _rgbae, _entryId ); - gtk_entry_set_text( GTK_ENTRY(_rgbae), s ); - g_signal_handler_unblock( _rgbae, _entryId ); + _rgbae->set_text( s ); } } } === modified file 'src/widgets/sp-color-notebook.h' --- src/widgets/sp-color-notebook.h 2012-09-01 09:39:11 +0000 +++ src/widgets/sp-color-notebook.h 2012-12-09 17:28:42 +0000 @@ -18,7 +18,15 @@ #include - +namespace Inkscape { +namespace UI { +namespace Widget { + +class ColorEntry; + +} +} +} struct SPColorNotebook; @@ -40,7 +48,6 @@ gint menuHandler( GdkEvent* event ); protected: - static void _rgbaEntryChangedHook( GtkEntry* entry, SPColorNotebook *colorbook ); static void _entryGrabbed( SPColorSelector *csel, SPColorNotebook *colorbook ); static void _entryDragged( SPColorSelector *csel, SPColorNotebook *colorbook ); static void _entryReleased( SPColorSelector *csel, SPColorNotebook *colorbook ); @@ -51,19 +58,16 @@ virtual void _colorChanged(); - void _rgbaEntryChanged( GtkEntry* entry ); void _updateRgbaEntry( const SPColor& color, gfloat alpha ); void _setCurrentPage(int i); - gboolean _updating : 1; - gboolean _updatingrgba : 1; gboolean _dragging : 1; gulong _switchId; - gulong _entryId; GtkWidget *_book; GtkWidget *_buttonbox; GtkWidget **_buttons; - GtkWidget *_rgbal, *_rgbae; /* RGBA entry */ + GtkWidget *_rgbal; + Inkscape::UI::Widget::ColorEntry *_rgbae; /* RGBA entry */ #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) GtkWidget *_box_outofgamut, *_box_colormanaged, *_box_toomuchink; #endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) === modified file 'src/widgets/sp-color-selector.cpp' --- src/widgets/sp-color-selector.cpp 2012-05-18 18:08:32 +0000 +++ src/widgets/sp-color-selector.cpp 2012-12-09 18:35:19 +0000 @@ -178,9 +178,44 @@ _csel->base = new ColorSelector( _csel ); } -void ColorSelector::setColor( const SPColor& color ) -{ - setColorAlpha( color, _alpha ); +void ColorSelector::setColor( Glib::ustring colorString ) +{ + // If the color begin with a # : we remove it + if (colorString[0] == '#') + { + colorString.erase(0,1); + } + + // If it's a RRGGBB hex, we keep the previous alpha and update only the color + if (colorString.size() == 6) + { + SPColor rgb(colorString); + + this->setColor( rgb, true ); + } + // If it's a RRGGBBAA hex + else if (colorString.size() == 8) + { + gchar* str = g_strdup(colorString.c_str()); + gchar* end = 0; + guint64 rgba = g_ascii_strtoull( str, &end, 16 ); + + if ( end != str ) + { + ptrdiff_t len = end - str; + if ( len < 8 ) { + rgba = rgba << ( 4 * ( 8 - len ) ); + } + + SPColor color( rgba ); + this->setColorAlpha( color, SP_RGBA32_A_F(rgba), true ); + } + } +} + +void ColorSelector::setColor( const SPColor& color, bool emit ) +{ + setColorAlpha( color, _alpha, emit ); } SPColor ColorSelector::getColor() const === modified file 'src/widgets/sp-color-selector.h' --- src/widgets/sp-color-selector.h 2012-02-12 13:43:17 +0000 +++ src/widgets/sp-color-selector.h 2012-12-09 18:35:11 +0000 @@ -16,7 +16,8 @@ virtual void init(); - void setColor( const SPColor& color ); + void setColor( Glib::ustring color ); + void setColor( const SPColor& color, bool emit = false ); SPColor getColor() const; void setAlpha( gfloat alpha );