From 17055d029cc8732d1b2636b9e98338c8e7056558 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Fri, 30 May 2014 15:55:34 +0200 Subject: SPColorNotebok c++-sification - available pages list (bzr r13341.6.28) --- src/ui/selected-color.cpp | 5 +++-- src/ui/selected-color.h | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/selected-color.cpp b/src/ui/selected-color.cpp index 927c421b8..f61c3b7f8 100644 --- a/src/ui/selected-color.cpp +++ b/src/ui/selected-color.cpp @@ -10,11 +10,12 @@ * Copyright (C) 2014 Authors * Released under GNU GPL, read the file 'COPYING' for more information */ -#include -#include #include "selected-color.h" +#include +#include + namespace Inkscape { namespace UI { diff --git a/src/ui/selected-color.h b/src/ui/selected-color.h index db2f2f68c..a56ee6afb 100644 --- a/src/ui/selected-color.h +++ b/src/ui/selected-color.h @@ -13,6 +13,14 @@ #ifndef SEEN_SELECTED_COLOR #define SEEN_SELECTED_COLOR +#ifdef HAVE_CONFIG_H +# include +#endif + +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H +#include +#endif + #include #include #include "color.h" -- cgit v1.2.3 From 7a205911659013dea26f1554158cc050fdff20bc Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Fri, 30 May 2014 18:47:23 +0200 Subject: changed coding style of SelectedColor (bzr r13341.6.30) --- src/ui/selected-color.cpp | 32 +++++++++++++++++++++----------- src/ui/selected-color.h | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 30 deletions(-) (limited to 'src/ui') diff --git a/src/ui/selected-color.cpp b/src/ui/selected-color.cpp index f61c3b7f8..296b15796 100644 --- a/src/ui/selected-color.cpp +++ b/src/ui/selected-color.cpp @@ -19,7 +19,7 @@ namespace Inkscape { namespace UI { -double SelectedColor::_epsilon = 1e-4; +double const SelectedColor::_EPSILON = 1e-4; SelectedColor::SelectedColor() : _color(0) @@ -33,28 +33,28 @@ SelectedColor::~SelectedColor() { } -void SelectedColor::set_color(const SPColor& color) +void SelectedColor::setColor(SPColor const &color) { - set_color_alpha( color, _alpha ); + setColorAlpha( color, _alpha ); } -SPColor SelectedColor::get_color() const +SPColor SelectedColor::color() const { return _color; } -void SelectedColor::set_alpha(gfloat alpha) +void SelectedColor::setAlpha(gfloat alpha) { g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); - set_color_alpha( _color, alpha ); + setColorAlpha( _color, alpha ); } -gfloat SelectedColor::get_alpha() const +gfloat SelectedColor::alpha() const { return _alpha; } -void SelectedColor::set_color_alpha(const SPColor& color, gfloat alpha, bool emit) +void SelectedColor::setColorAlpha(SPColor const &color, gfloat alpha, bool emit) { #ifdef DUMP_CHANGE_INFO g_message("SelectedColor::setColorAlpha( this=%p, %f, %f, %f, %s, %f, %s) in %s", this, color.v.c[0], color.v.c[1], color.v.c[2], (color.icc?color.icc->colorProfile.c_str():""), alpha, (emit?"YES":"no"), FOO_NAME(_csel)); @@ -70,8 +70,8 @@ void SelectedColor::set_color_alpha(const SPColor& color, gfloat alpha, bool emi ); #endif - if ( _virgin || !color.isClose( _color, _epsilon ) || - (fabs((_alpha) - (alpha)) >= _epsilon )) { + if ( _virgin || !color.isClose( _color, _EPSILON ) || + (fabs((_alpha) - (alpha)) >= _EPSILON )) { _virgin = false; @@ -89,7 +89,7 @@ void SelectedColor::set_color_alpha(const SPColor& color, gfloat alpha, bool emi } } -void SelectedColor::get_color_alpha(SPColor &color, gfloat &alpha) const { +void SelectedColor::colorAlpha(SPColor &color, gfloat &alpha) const { color = _color; alpha = _alpha; } @@ -97,3 +97,13 @@ void SelectedColor::get_color_alpha(SPColor &color, gfloat &alpha) const { } } +/* + 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 : diff --git a/src/ui/selected-color.h b/src/ui/selected-color.h index a56ee6afb..08b84b66c 100644 --- a/src/ui/selected-color.h +++ b/src/ui/selected-color.h @@ -33,47 +33,55 @@ public: SelectedColor(); virtual ~SelectedColor(); - void set_color( const SPColor& color ); - SPColor get_color() const; + void setColor(SPColor const &color); + SPColor color() const; - void set_alpha( gfloat alpha ); - gfloat get_alpha() const; + void setAlpha(gfloat alpha); + gfloat alpha() const; - void set_color_alpha( const SPColor& color, gfloat alpha, bool emit = false ); - void get_color_alpha( SPColor &color, gfloat &alpha ) const; + void setColorAlpha(SPColor const &color, gfloat alpha, bool emit = false); + void colorAlpha(SPColor &color, gfloat &alpha) const; sigc::signal signal_changed; private: // By default, disallow copy constructor and assignment operator - SelectedColor( const SelectedColor& obj ); - SelectedColor& operator=( const SelectedColor& obj ); + SelectedColor(SelectedColor const &obj); + SelectedColor& operator=(SelectedColor const &obj); - SPColor _color; - /** - * Color alpha value guaranteed to be in [0, 1]. - */ - gfloat _alpha; + SPColor _color; + /** + * Color alpha value guaranteed to be in [0, 1]. + */ + gfloat _alpha; /** * This flag is true if no color is set yet */ bool _virgin; - static double _epsilon; + static double const _EPSILON; }; - class ColorSelectorFactory { public: - virtual ~ColorSelectorFactory() {} + virtual ~ColorSelectorFactory() { + } - virtual Gtk::Widget* createWidget(SelectedColor& color) const = 0; + virtual Gtk::Widget* createWidget(SelectedColor &color) const = 0; virtual Glib::ustring modeName() const = 0; }; - } } #endif - +/* + 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 : -- cgit v1.2.3 From b0e9181bacdad19055532a2620f5390815b91727 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Fri, 30 May 2014 22:53:40 +0200 Subject: added ColorEntry class, refactored SPColorNotebook to use it (bzr r13341.6.31) --- src/ui/widget/Makefile_insert | 2 + src/ui/widget/color-entry.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++ src/ui/widget/color-entry.h | 59 ++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 src/ui/widget/color-entry.cpp create mode 100644 src/ui/widget/color-entry.h (limited to 'src/ui') diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index 6deaf6671..bad3342b1 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -6,6 +6,8 @@ ink_common_sources += \ 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 \ diff --git a/src/ui/widget/color-entry.cpp b/src/ui/widget/color-entry.cpp new file mode 100644 index 000000000..223c86fd3 --- /dev/null +++ b/src/ui/widget/color-entry.cpp @@ -0,0 +1,115 @@ +/** @file + * Entry widget for typing color value in css form + *//* + * Authors: + * Tomasz Boczkowski + * + * Copyright (C) 2014 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H +#include +#endif + +#include +#include + +#include "color-entry.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + +ColorEntry::ColorEntry(SelectedColor &color) + : _color(color) + , _updating(false) +{ + _color_changed_connection = color.signal_changed.connect(sigc::mem_fun(this, &ColorEntry::_onColorChanged)); + _onColorChanged(); + + set_max_length(8); + set_width_chars(8); + set_tooltip_text(_("Hexadecimal RGBA value of the color")); +} + +ColorEntry::~ColorEntry() { + _color_changed_connection.disconnect(); +} + +void ColorEntry::on_changed() { + if (_updating) { + return; + } + + Glib::ustring text = get_text(); + bool changed = false; + + //Coerce the value format to eight hex digits + 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(_color.alpha()); + Glib::ustring tmp = Glib::ustring::format(std::hex, std::setw(2), std::setfill(L'0'), alph); + text += 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)); + } + _updating = true; + if (changed) { + set_text(str); + } + SPColor color(rgba); + _color.setColorAlpha(color, SP_RGBA32_A_F(rgba), true); + _updating = false; + } + g_free(str); +} + + +void ColorEntry::_onColorChanged() { + if (_updating) { + return; + } + + SPColor color = _color.color(); + gdouble alpha = _color.alpha(); + + guint32 rgba = color.toRGBA32( alpha ); + Glib::ustring text = Glib::ustring::format(std::hex, std::setw(8), std::setfill(L'0'), rgba); + + Glib::ustring old_text = get_text(); + if (old_text != text) { + _updating = true; + set_text(text); + _updating = false; + } +} + +} +} +} +/* + 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 : diff --git a/src/ui/widget/color-entry.h b/src/ui/widget/color-entry.h new file mode 100644 index 000000000..742324337 --- /dev/null +++ b/src/ui/widget/color-entry.h @@ -0,0 +1,59 @@ +/** @file + * Entry widget for typing color value in css form + *//* + * Authors: + * Tomasz Boczkowski + * + * Copyright (C) 2014 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_COLOR_ENTRY_H +#define SEEN_COLOR_ENTRY_H_ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H +#include +#endif + +#include +#include "ui/selected-color.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + +class ColorEntry: public Gtk::Entry { +public: + ColorEntry(SelectedColor &color); + virtual ~ColorEntry(); + +protected: + void on_changed(); + +private: + void _onColorChanged(); + + SelectedColor &_color; + sigc::connection _color_changed_connection; + bool _updating; +}; + +} +} +} + +#endif +/* + 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 : -- cgit v1.2.3