Inkscape
Vector Graphics Editor
|
A labelled text box, with spin buttons and optional icon, for entering the values of various unit types. More...
#include <scalar-unit.h>
Public Member Functions | |
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. | |
ScalarUnit (Glib::ustring const &label, Glib::ustring const &tooltip, ScalarUnit &take_unitmenu, Glib::ustring const &icon={}, bool mnemonic=true) | |
Construct a ScalarUnit. | |
void | initScalar (double min_value, double max_value) |
Initializes the scalar based on the settings in _unit_menu. | |
Unit const * | getUnit () const |
Gets the object for the currently selected unit. | |
UnitType | getUnitType () const |
Gets the UnitType ID for the unit. | |
double | getValue (Glib::ustring const &units) const |
Returns the value in the given unit system. | |
bool | setUnit (Glib::ustring const &units) |
Sets the unit for the ScalarUnit widget. | |
void | setUnitType (UnitType unit_type) |
Adds the unit type to the ScalarUnit widget. | |
void | resetUnitType (UnitType unit_type) |
Resets the unit type for the ScalarUnit widget. | |
void | setAlignment (double xalign) |
allow align text in entry. | |
void | setValue (double number, Glib::ustring const &units) |
Sets the number and unit system. | |
void | setValueKeepUnit (double number, Glib::ustring const &units) |
Convert and sets the number only and keeps the current unit. | |
void | setValue (double number) |
Sets the number only. | |
void | grabFocusAndSelectEntry () |
Grab focus, and select the text that is in the entry field. | |
void | setHundredPercent (double number) |
void | setAbsoluteIsIncrement (bool value) |
void | setPercentageIsIncrement (bool value) |
double | PercentageToAbsolute (double value) |
Convert value from % to absolute, using _hundred_percent and *_is_increment flags. | |
double | AbsoluteToPercentage (double value) |
Convert value from absolute to %, using _hundred_percent and *_is_increment flags. | |
double | getAsPercentage () |
Assuming the current unit is absolute, get the corresponding % value. | |
void | setFromPercentage (double value) |
Assuming the current unit is absolute, set the value corresponding to a given %. | |
void | on_unit_changed () |
Signal handler for updating the value when unit is changed. | |
![]() | |
Scalar (Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &icon={}, bool mnemonic=true) | |
Construct a Scalar Widget. | |
Scalar (Glib::ustring const &label, Glib::ustring const &tooltip, unsigned digits, Glib::ustring const &icon={}, bool mnemonic=true) | |
Construct a Scalar Widget. | |
Scalar (Glib::ustring const &label, Glib::ustring const &tooltip, Glib::RefPtr< Gtk::Adjustment > const &adjust, unsigned digits=0, Glib::ustring const &icon={}, bool mnemonic=true) | |
Construct a Scalar Widget. | |
unsigned | getDigits () const |
Fetches the precision of the spin button. | |
double | getStep () const |
Gets the current step increment used by the spin button. | |
double | getPage () const |
Gets the current page increment used by the spin button. | |
double | getRangeMin () const |
Gets the minimum range value allowed for the spin button. | |
double | getRangeMax () const |
Gets the maximum range value allowed for the spin button. | |
bool | getSnapToTicks () const |
double | getValue () const |
Get the value in the spin_button. | |
int | getValueAsInt () const |
Get the value spin_button represented as an integer. | |
void | setDigits (unsigned digits) |
Sets the precision to be displayed by the spin button. | |
void | setIncrements (double step, double page) |
Sets the step and page increments for the spin button. | |
void | setRange (double min, double max) |
Sets the minimum and maximum range allowed for the spin button. | |
void | setValue (double value, bool setProg=true) |
Sets the value of the spin button. | |
void | setWidthChars (unsigned chars) |
Sets the width of the spin button by number of characters. | |
void | update () |
Manually forces an update of the spin button. | |
void | addSlider () |
Adds a slider (HScale) to the left of the spinbox. | |
void | setNoLeadingZeros () |
remove leading zeros fron widget. | |
bool | setNoLeadingZerosOutput () |
void | setWidthChars (gint width_chars) |
Set the number of set width chars of entry. | |
Glib::SignalProxy< void()> | signal_value_changed () |
Signal raised when the spin button's value changes. | |
void | hide_label () |
SpinButton const & | getSpinButton () const |
SpinButton & | getSpinButton () |
![]() | |
Labelled (Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Widget *widget, Glib::ustring const &icon={}, bool mnemonic=true) | |
Construct a Labelled Widget. | |
Gtk::Widget const * | getWidget () const |
Gtk::Widget * | getWidget () |
Gtk::Label const * | getLabel () const |
Gtk::Label * | getLabel () |
Protected Attributes | |
UnitMenu * | _unit_menu |
double | _hundred_percent |
bool | _absolute_is_increment |
bool | _percentage_is_increment |
Glib::ustring | lastUnits |
Additional Inherited Members | |
![]() | |
bool | setProgrammatically |
true if the value was set by setValue, not changed by the user; if a callback checks it, it must reset it back to false. | |
A labelled text box, with spin buttons and optional icon, for entering the values of various unit types.
A ScalarUnit is a control for entering, viewing, or manipulating numbers with units. This differs from ordinary numbers like 2 or 3.14 because the number portion of a scalar only has meaning when considered with its unit type. For instance, 12 m and 12 in have very different actual values, but 1 m and 100 cm have the same value. The ScalarUnit allows us to abstract the presentation of the scalar to the user from the internal representations used by the program.
Definition at line 34 of file scalar-unit.h.
Inkscape::UI::Widget::ScalarUnit::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.
label | Label, as per the Labelled base class. |
tooltip | Tooltip, as per the Labelled base class. |
unit_type | Unit type (defaults to UNIT_TYPE_LINEAR). |
icon | Icon name, placed before the label (defaults to empty). |
unit_menu | UnitMenu drop down; if not specified, one will be created and displayed after the widget (defaults to NULL). |
mnemonic | Mnemonic toggle; if true, an underscore (_) in the label indicates the next character should be used for the mnemonic accelerator key (defaults to true). |
Definition at line 22 of file scalar-unit.cpp.
References _unit_menu, Inkscape::UI::Widget::Scalar::getSpinButton(), Inkscape::UI::Widget::UnitMenu::getUnitAbbr(), Inkscape::UI::Widget::Labelled::getWidget(), lastUnits, on_unit_changed(), Inkscape::UI::pack_start(), remove(), Inkscape::UI::Widget::SpinButton::setUnitMenu(), Inkscape::UI::Widget::UnitMenu::setUnitType(), Inkscape::UI::shrink, and Inkscape::UI::Widget::UnitMenu::signal_changed().
Inkscape::UI::Widget::ScalarUnit::ScalarUnit | ( | Glib::ustring const & | label, |
Glib::ustring const & | tooltip, | ||
ScalarUnit & | take_unitmenu, | ||
Glib::ustring const & | icon = {} , |
||
bool | mnemonic = true |
||
) |
Construct a ScalarUnit.
label | Label, as per the Labelled base class. |
tooltip | Tooltip, as per the Labelled base class. |
take_unitmenu | Use the unitmenu from this parameter. |
icon | Icon name, placed before the label (defaults to empty). |
mnemonic | Mnemonic toggle; if true, an underscore (_) in the label indicates the next character should be used for the mnemonic accelerator key (defaults to true). |
Definition at line 58 of file scalar-unit.cpp.
double Inkscape::UI::Widget::ScalarUnit::AbsoluteToPercentage | ( | double | value | ) |
Convert value from absolute to %, using _hundred_percent and *_is_increment flags.
Definition at line 181 of file scalar-unit.cpp.
References _absolute_is_increment, _hundred_percent, _percentage_is_increment, _unit_menu, Inkscape::UI::Widget::UnitMenu::getConversion(), and lastUnits.
Referenced by getAsPercentage(), and on_unit_changed().
double Inkscape::UI::Widget::ScalarUnit::getAsPercentage | ( | ) |
Assuming the current unit is absolute, get the corresponding % value.
Definition at line 202 of file scalar-unit.cpp.
References AbsoluteToPercentage(), and Inkscape::UI::Widget::Scalar::getValue().
Referenced by Inkscape::UI::Dialog::Transformation::onScaleXValueChanged(), and Inkscape::UI::Dialog::Transformation::onScaleYValueChanged().
Unit const * Inkscape::UI::Widget::ScalarUnit::getUnit | ( | ) | const |
Gets the object for the currently selected unit.
Definition at line 96 of file scalar-unit.cpp.
References _unit_menu, and Inkscape::UI::Widget::UnitMenu::getUnit().
Referenced by Inkscape::UI::Widget::PrefSpinUnit::on_my_value_changed(), and Inkscape::UI::Dialog::GuidelinePropertiesDialog::~GuidelinePropertiesDialog().
UnitType Inkscape::UI::Widget::ScalarUnit::getUnitType | ( | ) | const |
Gets the UnitType ID for the unit.
Definition at line 101 of file scalar-unit.cpp.
References _unit_menu, and Inkscape::UI::Widget::UnitMenu::getUnitType().
double Inkscape::UI::Widget::ScalarUnit::getValue | ( | Glib::ustring const & | units | ) | const |
Returns the value in the given unit system.
Definition at line 128 of file scalar-unit.cpp.
References _unit_menu, Inkscape::UI::Widget::UnitMenu::getConversion(), and Inkscape::UI::Widget::Scalar::getValue().
Referenced by Inkscape::UI::Dialog::GuidelinePropertiesDialog::_onOKimpl(), Inkscape::UI::Dialog::Transformation::applyPageMove(), Inkscape::UI::Dialog::Transformation::applyPageRotate(), Inkscape::UI::Dialog::Transformation::applyPageScale(), Inkscape::UI::Dialog::Transformation::applyPageSkew(), Inkscape::UI::Dialog::Transformation::applyPageTransform(), Inkscape::UI::Dialog::GridArrangeTab::arrange(), Inkscape::UI::Dialog::PolarArrangeTab::arrange(), Inkscape::UI::Dialog::GridArrangeTab::on_xpad_spinbutton_changed(), Inkscape::UI::Dialog::GridArrangeTab::on_ypad_spinbutton_changed(), Inkscape::UI::Dialog::Transformation::onMoveRelativeToggled(), Inkscape::UI::Dialog::Transformation::onReplaceMatrixToggled(), Inkscape::UI::Dialog::Transformation::onScaleXValueChanged(), and Inkscape::UI::Dialog::Transformation::onScaleYValueChanged().
void Inkscape::UI::Widget::ScalarUnit::grabFocusAndSelectEntry | ( | ) |
Grab focus, and select the text that is in the entry field.
Definition at line 139 of file scalar-unit.cpp.
References Inkscape::UI::Widget::Scalar::getSpinButton().
Referenced by Inkscape::UI::Dialog::GuidelinePropertiesDialog::_setup().
void Inkscape::UI::Widget::ScalarUnit::initScalar | ( | double | min_value, |
double | max_value | ||
) |
Initializes the scalar based on the settings in _unit_menu.
Requires that _unit_menu has already been initialized.
Definition at line 66 of file scalar-unit.cpp.
References _unit_menu, Inkscape::UI::Widget::UnitMenu::getDefaultDigits(), Inkscape::UI::Widget::UnitMenu::getDefaultPage(), Inkscape::UI::Widget::UnitMenu::getDefaultStep(), Inkscape::UI::Widget::Scalar::setDigits(), Inkscape::UI::Widget::Scalar::setIncrements(), and Inkscape::UI::Widget::Scalar::setRange().
Referenced by Inkscape::UI::Dialog::Transformation::layoutPageMove(), Inkscape::UI::Dialog::Transformation::layoutPageRotate(), Inkscape::UI::Dialog::Transformation::layoutPageScale(), Inkscape::UI::Dialog::Transformation::layoutPageSkew(), and Inkscape::UI::Widget::RegisteredScalarUnit::RegisteredScalarUnit().
void Inkscape::UI::Widget::ScalarUnit::on_unit_changed | ( | ) |
Signal handler for updating the value when unit is changed.
Definition at line 214 of file scalar-unit.cpp.
References _unit_menu, AbsoluteToPercentage(), Inkscape::Util::UnitTable::get(), Inkscape::UI::Widget::UnitMenu::getConversion(), Inkscape::UI::Widget::UnitMenu::getUnitAbbr(), Inkscape::UI::Widget::Scalar::getValue(), lastUnits, PercentageToAbsolute(), Inkscape::UI::Widget::Scalar::setValue(), and Inkscape::Util::Unit::type.
Referenced by ScalarUnit().
double Inkscape::UI::Widget::ScalarUnit::PercentageToAbsolute | ( | double | value | ) |
Convert value from % to absolute, using _hundred_percent and *_is_increment flags.
Definition at line 167 of file scalar-unit.cpp.
References _absolute_is_increment, _hundred_percent, _percentage_is_increment, _unit_menu, and Inkscape::UI::Widget::UnitMenu::getConversion().
Referenced by on_unit_changed(), and setFromPercentage().
void Inkscape::UI::Widget::ScalarUnit::resetUnitType | ( | UnitType | unit_type | ) |
Resets the unit type for the ScalarUnit widget.
Definition at line 90 of file scalar-unit.cpp.
References _unit_menu, Inkscape::UI::Widget::UnitMenu::getUnitAbbr(), lastUnits, and Inkscape::UI::Widget::UnitMenu::resetUnitType().
Referenced by Inkscape::UI::Widget::PrefSpinUnit::init().
void Inkscape::UI::Widget::ScalarUnit::setAbsoluteIsIncrement | ( | bool | value | ) |
Definition at line 157 of file scalar-unit.cpp.
References _absolute_is_increment.
Referenced by Inkscape::UI::Dialog::Transformation::layoutPageScale().
void Inkscape::UI::Widget::ScalarUnit::setAlignment | ( | double | xalign | ) |
allow align text in entry.
Definition at line 146 of file scalar-unit.cpp.
References Inkscape::UI::Widget::Scalar::getSpinButton().
Referenced by Inkscape::UI::Dialog::GuidelinePropertiesDialog::_setup().
void Inkscape::UI::Widget::ScalarUnit::setFromPercentage | ( | double | value | ) |
Assuming the current unit is absolute, set the value corresponding to a given %.
Definition at line 208 of file scalar-unit.cpp.
References absolute(), PercentageToAbsolute(), and Inkscape::UI::Widget::Scalar::setValue().
Referenced by Inkscape::UI::Dialog::Transformation::onScaleXValueChanged(), and Inkscape::UI::Dialog::Transformation::onScaleYValueChanged().
void Inkscape::UI::Widget::ScalarUnit::setHundredPercent | ( | double | number | ) |
Definition at line 152 of file scalar-unit.cpp.
References _hundred_percent.
Referenced by Inkscape::UI::Dialog::Transformation::updatePageScale(), and Inkscape::UI::Dialog::Transformation::updatePageSkew().
void Inkscape::UI::Widget::ScalarUnit::setPercentageIsIncrement | ( | bool | value | ) |
Definition at line 162 of file scalar-unit.cpp.
References _percentage_is_increment.
Referenced by Inkscape::UI::Dialog::Transformation::layoutPageScale().
bool Inkscape::UI::Widget::ScalarUnit::setUnit | ( | Glib::ustring const & | units | ) |
Sets the unit for the ScalarUnit widget.
Definition at line 74 of file scalar-unit.cpp.
References _unit_menu, lastUnits, and Inkscape::UI::Widget::UnitMenu::setUnit().
Referenced by Inkscape::UI::Dialog::GuidelinePropertiesDialog::_setup(), Inkscape::UI::Widget::PrefSpinUnit::init(), and Inkscape::UI::Widget::RegisteredScalarUnit::RegisteredScalarUnit().
void Inkscape::UI::Widget::ScalarUnit::setUnitType | ( | UnitType | unit_type | ) |
Adds the unit type to the ScalarUnit widget.
Definition at line 84 of file scalar-unit.cpp.
References _unit_menu, Inkscape::UI::Widget::UnitMenu::getUnitAbbr(), lastUnits, and Inkscape::UI::Widget::UnitMenu::setUnitType().
void Inkscape::UI::Widget::ScalarUnit::setValue | ( | double | number | ) |
Sets the number only.
Definition at line 123 of file scalar-unit.cpp.
References Inkscape::UI::Widget::Scalar::setValue().
void Inkscape::UI::Widget::ScalarUnit::setValue | ( | double | number, |
Glib::ustring const & | units | ||
) |
Sets the number and unit system.
Definition at line 106 of file scalar-unit.cpp.
References _unit_menu, Inkscape::UI::Widget::UnitMenu::setUnit(), and Inkscape::UI::Widget::Scalar::setValue().
Referenced by Inkscape::UI::Dialog::GuidelinePropertiesDialog::_modeChanged(), Inkscape::UI::Dialog::GridArrangeTab::GridArrangeTab(), Inkscape::UI::Widget::PrefSpinUnit::init(), Inkscape::UI::Dialog::Transformation::layoutPageScale(), Inkscape::UI::Dialog::Transformation::layoutPageTransform(), Inkscape::UI::Dialog::Transformation::onClear(), Inkscape::UI::Dialog::Transformation::onMoveRelativeToggled(), Inkscape::UI::Dialog::Transformation::onReplaceMatrixToggled(), Inkscape::UI::Dialog::Transformation::onScaleXValueChanged(), Inkscape::UI::Dialog::Transformation::onScaleYValueChanged(), Inkscape::UI::Dialog::PolarArrangeTab::PolarArrangeTab(), Inkscape::UI::Dialog::Transformation::updatePageMove(), and Inkscape::UI::Dialog::Transformation::updatePageTransform().
void Inkscape::UI::Widget::ScalarUnit::setValueKeepUnit | ( | double | number, |
Glib::ustring const & | units | ||
) |
Convert and sets the number only and keeps the current unit.
Definition at line 112 of file scalar-unit.cpp.
References _unit_menu, Inkscape::UI::Widget::UnitMenu::getConversion(), and Inkscape::UI::Widget::Scalar::setValue().
Referenced by Inkscape::UI::Dialog::GuidelinePropertiesDialog::_modeChanged().
|
protected |
Definition at line 169 of file scalar-unit.h.
Referenced by AbsoluteToPercentage(), PercentageToAbsolute(), and setAbsoluteIsIncrement().
|
protected |
Definition at line 167 of file scalar-unit.h.
Referenced by AbsoluteToPercentage(), PercentageToAbsolute(), and setHundredPercent().
|
protected |
Definition at line 170 of file scalar-unit.h.
Referenced by AbsoluteToPercentage(), PercentageToAbsolute(), and setPercentageIsIncrement().
|
protected |
Definition at line 165 of file scalar-unit.h.
Referenced by AbsoluteToPercentage(), getUnit(), getUnitType(), getValue(), initScalar(), on_unit_changed(), PercentageToAbsolute(), resetUnitType(), ScalarUnit(), setUnit(), setUnitType(), setValue(), and setValueKeepUnit().
|
protected |
Definition at line 173 of file scalar-unit.h.
Referenced by AbsoluteToPercentage(), on_unit_changed(), resetUnitType(), ScalarUnit(), setUnit(), and setUnitType().