summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter/unit.cpp
blob: 65a939b7e118a62d84c64339b1c4e05ab8643f67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "ui/widget/registered-widget.h"
#include <glibmm/i18n.h>

#include "live_effects/parameter/unit.h"
#include "live_effects/effect.h"
#include "verbs.h"
#include "util/units.h"

using Inkscape::Util::unit_table;

namespace Inkscape {

namespace LivePathEffect {


UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip,
                              const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
                              Effect* effect, Glib::ustring default_unit)
    : Parameter(label, tip, key, wr, effect)
{
    defunit = unit_table.getUnit(default_unit);
    unit = defunit;
}

UnitParam::~UnitParam()
= default;

bool
UnitParam::param_readSVGValue(const gchar * strvalue)
{
    if (strvalue) {
        param_set_value(*unit_table.getUnit(strvalue));
        return true;
    }
    return false;
}

Glib::ustring
UnitParam::param_getSVGValue() const
{
    return unit->abbr;
}

Glib::ustring
UnitParam::param_getDefaultSVGValue() const
{
    return defunit->abbr;
}

void
UnitParam::param_set_default()
{
    param_set_value(*defunit);
}

void 
UnitParam::param_update_default(const gchar * default_unit)
{
    defunit = unit_table.getUnit((Glib::ustring)default_unit);
}

void
UnitParam::param_set_value(Inkscape::Util::Unit const &val)
{
    param_effect->refresh_widgets = true;
    unit = new Inkscape::Util::Unit(val);
}

const gchar *
UnitParam::get_abbreviation() const
{
    return unit->abbr.c_str();
}

Gtk::Widget *
UnitParam::param_newWidget()
{
    Inkscape::UI::Widget::RegisteredUnitMenu* unit_menu = Gtk::manage(
        new Inkscape::UI::Widget::RegisteredUnitMenu(param_label,
                                                     param_key,
                                                     *param_wr,
                                                     param_effect->getRepr(),
                                                     param_effect->getSPDoc()));

    unit_menu->setUnit(unit->abbr);
    unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter"));
    
    return dynamic_cast<Gtk::Widget *> (unit_menu);
}

} /* namespace LivePathEffect */
} /* namespace Inkscape */

/*
  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 :