summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorTomasz Boczkowski <penginsbacon@gmail.com>2015-04-26 09:20:31 +0000
committerTomasz Boczkowski <penginsbacon@gmail.com>2015-04-26 09:20:31 +0000
commitae5c44bfac377f13a0031f3d4db3f7ea15fc939b (patch)
treefbd90c8e4ebb3eda625d88306b57f687766d9b10 /src/ui/widget
parentmerged SPSelected color implementation from svgpaints branch (diff)
parentadded ColorEntry class, refactored SPColorNotebook to use it (diff)
downloadinkscape-ae5c44bfac377f13a0031f3d4db3f7ea15fc939b.tar.gz
inkscape-ae5c44bfac377f13a0031f3d4db3f7ea15fc939b.zip
merged SPNotebook c++-sification from svgpaints branch
(bzr r14059.1.5)
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/Makefile_insert2
-rw-r--r--src/ui/widget/color-entry.cpp115
-rw-r--r--src/ui/widget/color-entry.h59
3 files changed, 176 insertions, 0 deletions
diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert
index 34438a3ac..b63d6b264 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 <penginsbacon@gmail.com>
+ *
+ * Copyright (C) 2014 Authors
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
+#include <iomanip>
+#include <glibmm/i18n.h>
+
+#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 <penginsbacon@gmail.com>
+ *
+ * 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 <config.h>
+#endif
+
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
+#include <gtkmm/entry.h>
+#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 :