2
* Copyright (C) 2005-2007 Authors:
3
* Ted Gould <ted@gould.cx>
4
* Johan Engelen <johan@shouraizou.nl>
5
* Christopher Brown <audiere@gmail.com>
6
* Released under GNU GPL, read the file 'COPYING' for more information
16
#include <gtkmm/adjustment.h>
17
#include <gtkmm/box.h>
18
#include <gtkmm/spinbutton.h>
22
#include "../extension.h"
26
#include "widgets/sp-color-selector.h"
27
#include "widgets/sp-color-notebook.h"
28
#include "preferences.h"
34
void sp_color_param_changed(SPColorSelector *csel, GObject *cp);
37
/** \brief Free the allocated data. */
38
ParamColor::~ParamColor(void)
44
ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ )
48
gchar * prefname = this->pref_name();
52
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
53
prefs->setString(extension_pref_root + prefname, value);
59
/** \brief Initialize the object, to do that, copy the data. */
60
ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
61
Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext)
63
const char * defaulthex = NULL;
64
if (sp_repr_children(xml) != NULL)
65
defaulthex = sp_repr_children(xml)->content();
67
gchar * pref_name = this->pref_name();
68
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
69
Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name);
72
if (!paramval.empty())
73
defaulthex = paramval.data();
75
_value = atoi(defaulthex);
81
ParamColor::string (std::string &string)
84
sprintf(str, "%i", _value);
90
ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal )
92
if (_gui_hidden) return NULL;
94
_changeSignal = new sigc::signal<void>(*changeSignal);
95
Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
96
SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK);
98
ColorSelector* colorSelector = spColorSelector->base;
102
SPColor *color = new SPColor( _value );
103
float alpha = (_value & 0xff) / 255.0F;
104
colorSelector->setColorAlpha(*color, alpha);
106
hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0);
107
g_signal_connect(G_OBJECT(spColorSelector), "changed", G_CALLBACK(sp_color_param_changed), (void*)this);
109
gtk_widget_show(GTK_WIDGET(spColorSelector));
112
return dynamic_cast<Gtk::Widget *>(hbox);
116
sp_color_param_changed(SPColorSelector *csel, GObject *obj)
118
const SPColor color = csel->base->getColor();
119
float alpha = csel->base->getAlpha();
121
ParamColor* ptr = (ParamColor*)obj;
122
ptr->set(color.toRGBA32( alpha ), NULL, NULL);
124
ptr->_changeSignal->emit();
127
}; /* namespace Extension */
128
}; /* namespace Inkscape */