Inkscape
Vector Graphics Editor
scalar-unit.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * Bryce Harrington <bryce@bryceharrington.org>
5 * Derek P. Moore <derekm@hackunix.org>
6 * buliabyak@gmail.com
7 *
8 * Copyright (C) 2004-2005 Authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef INKSCAPE_UI_WIDGET_SCALAR_UNIT_H
14#define INKSCAPE_UI_WIDGET_SCALAR_UNIT_H
15
16#include "scalar.h"
17#include "unit-menu.h"
18
19namespace Inkscape::UI::Widget {
20
34class ScalarUnit : public Scalar
35{
36public:
50 ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip,
51 UnitType unit_type = UNIT_TYPE_LINEAR,
52 Glib::ustring const &icon = {},
53 UnitMenu *unit_menu = nullptr,
54 bool mnemonic = true);
55
67 ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip,
68 ScalarUnit &take_unitmenu,
69 Glib::ustring const &icon = {},
70 bool mnemonic = true);
71
76 void initScalar(double min_value, double max_value);
77
81 Unit const * getUnit() const;
82
86 UnitType getUnitType() const;
87
91 double getValue(Glib::ustring const &units) const;
92
96 bool setUnit(Glib::ustring const &units);
97
101 void setUnitType(UnitType unit_type);
102
106 void resetUnitType(UnitType unit_type);
107
111 void setAlignment(double xalign);
112
116 void setValue(double number, Glib::ustring const &units);
117
121 void setValueKeepUnit(double number, Glib::ustring const &units);
122
126 void setValue(double number);
127
132
133 void setHundredPercent(double number);
134
135 void setAbsoluteIsIncrement(bool value);
136
137 void setPercentageIsIncrement(bool value);
138
142 double PercentageToAbsolute(double value);
143
147 double AbsoluteToPercentage(double value);
148
152 double getAsPercentage();
153
157 void setFromPercentage(double value);
158
162 void on_unit_changed();
163
164protected:
166
167 double _hundred_percent; // the length that corresponds to 100%, in px, for %-to/from-absolute conversions
168
169 bool _absolute_is_increment; // if true, 120% with _hundred_percent=100px gets converted to/from 20px; otherwise, to/from 120px
170 bool _percentage_is_increment; // if true, 120px with _hundred_percent=100px gets converted to/from 20%; otherwise, to/from 120%
171 // if both are true, 20px is converted to/from 20% if _hundred_percent=100px
172
173 Glib::ustring lastUnits; // previously selected unit, for conversions
174};
175
176} // namespace Inkscape::UI::Widget
177
178#endif // INKSCAPE_UI_WIDGET_SCALAR_UNIT_H
179
180/*
181 Local Variables:
182 mode:c++
183 c-file-style:"stroustrup"
184 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
185 indent-tabs-mode:nil
186 fill-column:99
187 End:
188*/
189// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
A labelled text box, with spin buttons and optional icon, for entering the values of various unit typ...
Definition: scalar-unit.h:35
void setValue(double number, Glib::ustring const &units)
Sets the number and unit system.
double PercentageToAbsolute(double value)
Convert value from % to absolute, using _hundred_percent and *_is_increment flags.
void setUnitType(UnitType unit_type)
Adds the unit type to the ScalarUnit widget.
Definition: scalar-unit.cpp:84
double AbsoluteToPercentage(double value)
Convert value from absolute to %, using _hundred_percent and *_is_increment flags.
void grabFocusAndSelectEntry()
Grab focus, and select the text that is in the entry field.
bool setUnit(Glib::ustring const &units)
Sets the unit for the ScalarUnit widget.
Definition: scalar-unit.cpp:74
void setAlignment(double xalign)
allow align text in entry.
void resetUnitType(UnitType unit_type)
Resets the unit type for the ScalarUnit widget.
Definition: scalar-unit.cpp:90
void setValueKeepUnit(double number, Glib::ustring const &units)
Convert and sets the number only and keeps the current unit.
Unit const * getUnit() const
Gets the object for the currently selected unit.
Definition: scalar-unit.cpp:96
void setAbsoluteIsIncrement(bool value)
void initScalar(double min_value, double max_value)
Initializes the scalar based on the settings in _unit_menu.
Definition: scalar-unit.cpp:66
ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, UnitType unit_type=UNIT_TYPE_LINEAR, Glib::ustring const &icon={}, UnitMenu *unit_menu=nullptr, bool mnemonic=true)
Construct a ScalarUnit.
Definition: scalar-unit.cpp:22
void setPercentageIsIncrement(bool value)
void on_unit_changed()
Signal handler for updating the value when unit is changed.
UnitType getUnitType() const
Gets the UnitType ID for the unit.
void setFromPercentage(double value)
Assuming the current unit is absolute, set the value corresponding to a given %.
void setHundredPercent(double number)
double getAsPercentage()
Assuming the current unit is absolute, get the corresponding % value.
A labelled text box, with spin buttons and optional icon, for entering arbitrary number values.
Definition: scalar.h:34
double getValue() const
Get the value in the spin_button.
Definition: scalar.cpp:83
A drop down menu for choosing unit types.
Definition: unit-menu.h:31
Custom widgets.
Definition: desktop.h:127
@ UNIT_TYPE_LINEAR
Definition: units.h:34