c99161dad88dbcf166342a28ed5b9a9c1ec191a4
1 /**
2 * \brief Scalar Unit Widget - A labelled text box, with spin buttons and
3 * optional icon or suffix, for entering the values of various unit
4 * types.
5 *
6 * Authors:
7 * Bryce Harrington <bryce@bryceharrington.org>
8 * Derek P. Moore <derekm@hackunix.org>
9 * buliabyak@gmail.com
10 *
11 * Copyright (C) 2004-2005 Authors
12 *
13 * Released under GNU GPL. Read the file 'COPYING' for more information.
14 */
16 #ifndef INKSCAPE_UI_WIDGET_SCALAR_UNIT_H
17 #define INKSCAPE_UI_WIDGET_SCALAR_UNIT_H
19 #include "scalar.h"
20 #include "unit-menu.h"
22 namespace Inkscape {
23 namespace UI {
24 namespace Widget {
26 class ScalarUnit : public Scalar
27 {
28 public:
29 ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip,
30 UnitType unit_type = UNIT_TYPE_LINEAR,
31 Glib::ustring const &suffix = "",
32 Glib::ustring const &icon = "",
33 UnitMenu *unit_menu = NULL,
34 bool mnemonic = true);
36 void initScalar(double min_value, double max_value);
38 Unit getUnit() const;
39 UnitType getUnitType() const;
40 double getValue(Glib::ustring const &units) const;
42 bool setUnit(Glib::ustring const &units);
43 void setValue(double number, Glib::ustring const &units);
44 void setValue(double number);
46 void setHundredPercent(double number);
47 void setAbsoluteIsIncrement(bool value);
48 void setPercentageIsIncrement(bool value);
50 double PercentageToAbsolute(double value);
51 double AbsoluteToPercentage(double value);
53 double getAsPercentage();
54 void setFromPercentage(double value);
56 void on_unit_changed();
58 protected:
59 UnitMenu *_unit_menu;
61 double _hundred_percent; // the length that corresponds to 100%, in px, for %-to/from-absolute conversions
63 bool _absolute_is_increment; // if true, 120% with _hundred_percent=100px gets converted to/from 20px; otherwise, to/from 120px
64 bool _percentage_is_increment; // if true, 120px with _hundred_percent=100px gets converted to/from 20%; otherwise, to/from 120%
65 // if both are true, 20px is converted to/from 20% if _hundred_percent=100px
67 Glib::ustring lastUnits; // previously selected unit, for conversions
68 };
70 } // namespace Widget
71 } // namespace UI
72 } // namespace Inkscape
74 #endif // INKSCAPE_UI_WIDGET_SCALAR_UNIT_H
76 /*
77 Local Variables:
78 mode:c++
79 c-file-style:"stroustrup"
80 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
81 indent-tabs-mode:nil
82 fill-column:99
83 End:
84 */
85 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :