~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/extension/paramfloat.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Kees Cook, Ted Gould
  • Date: 2008-02-10 14:20:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080210142016-vcnb2zqyhszu0xvb
Tags: 0.46~pre1-0ubuntu1
[ Kees Cook ]
* debian/control:
  - add libgtkspell-dev build-dep to gain GtkSpell features (LP: #183547).
  - update Standards version (no changes needed).
  - add Vcs and Homepage fields.
  - switch to new python-lxml dep.
* debian/{control,rules}: switch from dpatch to quilt for more sanity.
* debian/patches/20_fix_glib_and_gxx43_ftbfs.patch:
  - merged against upstream fixes.
  - added additional fixes for newly written code.
* debian/rules: enable parallel building.

[ Ted Gould ]
* Updating POTFILES.in to make it so things build correctly.
* debian/control:
  - add ImageMagick++ and libboost-dev to build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
6
 */
 
7
 
 
8
#ifdef HAVE_CONFIG_H
 
9
# include "config.h"
 
10
#endif
 
11
 
 
12
#include <gtkmm/adjustment.h>
 
13
#include <gtkmm/box.h>
 
14
#include <gtkmm/spinbutton.h>
 
15
 
 
16
#include <xml/node.h>
 
17
 
 
18
#include "extension.h"
 
19
#include "paramfloat.h"
 
20
 
 
21
namespace Inkscape {
 
22
namespace Extension {
 
23
 
 
24
 
 
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)
 
28
{
 
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);
 
34
    }
 
35
 
 
36
    const char * maxval = xml->attribute("max");
 
37
    if (maxval != NULL)
 
38
        _max = atof(maxval);
 
39
 
 
40
    const char * minval = xml->attribute("min");
 
41
    if (minval != NULL)
 
42
        _min = atof(minval);
 
43
 
 
44
    _precision = 1;
 
45
    const char * precision = xml->attribute("precision");
 
46
    if (precision != NULL)
 
47
        _precision = atoi(precision);
 
48
 
 
49
    /* We're handling this by just killing both values */
 
50
    if (_max < _min) {
 
51
        _max = 10.0;
 
52
        _min = 0.0;
 
53
    }
 
54
 
 
55
    gchar * pref_name = this->pref_name();
 
56
    _value = prefs_get_double_attribute(PREF_DIR, pref_name, _value);
 
57
    g_free(pref_name);
 
58
 
 
59
    // std::cout << "New Float::  value: " << _value << "  max: " << _max << "  min: " << _min << std::endl;
 
60
 
 
61
    if (_value > _max) _value = _max;
 
62
    if (_value < _min) _value = _min;
 
63
 
 
64
    return;
 
65
}
 
66
 
 
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
 
71
 
 
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.
 
75
*/
 
76
float
 
77
ParamFloat::set (float in, SPDocument * doc, Inkscape::XML::Node * node)
 
78
{
 
79
    _value = in;
 
80
    if (_value > _max) _value = _max;
 
81
    if (_value < _min) _value = _min;
 
82
 
 
83
    gchar * prefname = this->pref_name();
 
84
    prefs_set_double_attribute(PREF_DIR, prefname, _value);
 
85
    g_free(prefname);
 
86
 
 
87
    return _value;
 
88
}
 
89
 
 
90
/** \brief  Return the value as a string */
 
91
Glib::ustring *
 
92
ParamFloat::string (void)
 
93
{
 
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);
 
97
    return mystring;
 
98
}
 
99
 
 
100
/** \brief  A class to make an adjustment that uses Extension params */
 
101
class ParamFloatAdjustment : public Gtk::Adjustment {
 
102
    /** The parameter to adjust */
 
103
    ParamFloat * _pref;
 
104
    SPDocument * _doc;
 
105
    Inkscape::XML::Node * _node;
 
106
    sigc::signal<void> * _changeSignal;
 
107
public:
 
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));
 
114
        return;
 
115
    };
 
116
 
 
117
    void val_changed (void);
 
118
}; /* class ParamFloatAdjustment */
 
119
 
 
120
/** \brief  A function to respond to the value_changed signal from the
 
121
            adjustment.
 
122
 
 
123
    This function just grabs the value from the adjustment and writes
 
124
    it to the parameter.  Very simple, but yet beautiful.
 
125
*/
 
126
void
 
127
ParamFloatAdjustment::val_changed (void)
 
128
{
 
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();
 
133
    }
 
134
    return;
 
135
}
 
136
 
 
137
/**
 
138
    \brief  Creates a Float Adjustment for a float parameter
 
139
 
 
140
    Builds a hbox with a label and a float adjustment in it.
 
141
*/
 
142
Gtk::Widget *
 
143
ParamFloat::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal)
 
144
{
 
145
    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
 
146
 
 
147
    Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
 
148
    label->show();
 
149
    hbox->pack_start(*label, true, true);
 
150
 
 
151
    ParamFloatAdjustment * fadjust = Gtk::manage(new ParamFloatAdjustment(this, doc, node, changeSignal));
 
152
    Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 0.1, _precision));
 
153
    spin->show();
 
154
    hbox->pack_start(*spin, false, false);
 
155
 
 
156
    hbox->show();
 
157
 
 
158
    return dynamic_cast<Gtk::Widget *>(hbox);
 
159
}
 
160
 
 
161
 
 
162
}  /* namespace Extension */
 
163
}  /* namespace Inkscape */