2
* Copyright (C) 2005-2007 Authors:
3
* Ted Gould <ted@gould.cx>
4
* Johan Engelen <johan@shouraizou.nl> *
5
* Released under GNU GPL, read the file 'COPYING' for more information
12
#include <gtkmm/adjustment.h>
13
#include <gtkmm/box.h>
14
#include <gtkmm/spinbutton.h>
18
#include "extension.h"
19
#include "paramfloat.h"
25
/** \brief Use the superclass' allocator and set the \c _value */
26
ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
27
Parameter(name, guitext, desc, scope, ext), _value(0.0), _min(0.0), _max(10.0)
29
const char * defaultval = NULL;
30
if (sp_repr_children(xml) != NULL)
31
defaultval = sp_repr_children(xml)->content();
32
if (defaultval != NULL) {
33
_value = atof(defaultval);
36
const char * maxval = xml->attribute("max");
40
const char * minval = xml->attribute("min");
45
const char * precision = xml->attribute("precision");
46
if (precision != NULL)
47
_precision = atoi(precision);
49
/* We're handling this by just killing both values */
55
gchar * pref_name = this->pref_name();
56
_value = prefs_get_double_attribute(PREF_DIR, pref_name, _value);
59
// std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl;
61
if (_value > _max) _value = _max;
62
if (_value < _min) _value = _min;
67
/** \brief A function to set the \c _value
68
\param in The value to set to
69
\param doc A document that should be used to set the value.
70
\param node The node where the value may be placed
72
This function sets the internal value, but it also sets the value
73
in the preferences structure. To put it in the right place, \c PREF_DIR
74
and \c pref_name() are used.
77
ParamFloat::set (float in, SPDocument * doc, Inkscape::XML::Node * node)
80
if (_value > _max) _value = _max;
81
if (_value < _min) _value = _min;
83
gchar * prefname = this->pref_name();
84
prefs_set_double_attribute(PREF_DIR, prefname, _value);
90
/** \brief Return the value as a string */
92
ParamFloat::string (void)
94
char startstring[G_ASCII_DTOSTR_BUF_SIZE];
95
g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value);
96
Glib::ustring * mystring = new Glib::ustring(startstring);
100
/** \brief A class to make an adjustment that uses Extension params */
101
class ParamFloatAdjustment : public Gtk::Adjustment {
102
/** The parameter to adjust */
105
Inkscape::XML::Node * _node;
106
sigc::signal<void> * _changeSignal;
108
/** \brief Make the adjustment using an extension and the string
109
describing the parameter. */
110
ParamFloatAdjustment (ParamFloat * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) :
111
Gtk::Adjustment(0.0, param->min(), param->max(), 0.1), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) {
112
this->set_value(_pref->get(NULL, NULL) /* \todo fix */);
113
this->signal_value_changed().connect(sigc::mem_fun(this, &ParamFloatAdjustment::val_changed));
117
void val_changed (void);
118
}; /* class ParamFloatAdjustment */
120
/** \brief A function to respond to the value_changed signal from the
123
This function just grabs the value from the adjustment and writes
124
it to the parameter. Very simple, but yet beautiful.
127
ParamFloatAdjustment::val_changed (void)
129
//std::cout << "Value Changed to: " << this->get_value() << std::endl;
130
_pref->set(this->get_value(), _doc, _node);
131
if (_changeSignal != NULL) {
132
_changeSignal->emit();
138
\brief Creates a Float Adjustment for a float parameter
140
Builds a hbox with a label and a float adjustment in it.
143
ParamFloat::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal)
145
Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
147
Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
149
hbox->pack_start(*label, true, true);
151
ParamFloatAdjustment * fadjust = Gtk::manage(new ParamFloatAdjustment(this, doc, node, changeSignal));
152
Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 0.1, _precision));
154
hbox->pack_start(*spin, false, false);
158
return dynamic_cast<Gtk::Widget *>(hbox);
162
} /* namespace Extension */
163
} /* namespace Inkscape */