Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::UI::Widget::SpinButton Class Reference

SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMenu), and allows entry of both '. More...

#include <spinbutton.h>

Inheritance diagram for Inkscape::UI::Widget::SpinButton:
Inkscape::UI::Widget::PrefSpinButton

Public Types

using NumericMenuData = std::map< double, Glib::ustring >
 

Public Member Functions

template<typename ... Args>
 SpinButton (Args &&...args)
 
 SpinButton (BaseObjectType *cobject, Glib::RefPtr< Gtk::Builder > const &)
 
 ~SpinButton () override
 
void setUnitMenu (UnitMenu *unit_menu)
 
void addUnitTracker (UnitTracker *ut)
 
void set_zeroable (const bool zeroable=true)
 
void set_oneable (const bool oneable=true)
 
bool get_zeroable () const
 
bool get_oneable () const
 
void defocus ()
 
void set_increment (double delta)
 
void setDefocusTarget (decltype(_defocus_target) target)
 
void set_dont_evaluate (bool flag)
 
void set_custom_numeric_menu_data (NumericMenuData &&custom_menu_data)
 

Private Member Functions

void _construct ()
 
int on_input (double &newvalue)
 This callback function should try to convert the entered text to a number and write it to newvalue.
 
bool on_key_pressed (Gtk::EventControllerKey const &controller, unsigned keyval, unsigned keycode, Gdk::ModifierType state)
 Handle specific keypress events, like Ctrl+Z.
 
bool on_popup_menu (PopupMenuOptionalClick)
 
void create_popover_menu ()
 
void on_numeric_menu_item_activate (double value)
 
void undo ()
 Undo the editing, by resetting the value upon when the spinbutton got focus.
 
void _unparentChildren ()
 

Private Attributes

UnitMenu_unit_menu = nullptr
 Linked unit menu for unit conversion in entered expressions.
 
UnitTracker_unit_tracker = nullptr
 Linked unit tracker for unit conversion in entered expressions.
 
double _on_focus_in_value = 0.
 
Inkscape::UI::DefocusTarget_defocus_target = nullptr
 Widget that should be informed when the spinbutton defocuses.
 
bool _zeroable = false
 Reset-value should be zero.
 
bool _oneable = false
 Reset-value should be one.
 
bool _dont_evaluate = false
 Don't attempt to evaluate expressions.
 
NumericMenuData _custom_menu_data
 
bool _custom_popup = false
 
double _increment = 0.0
 
std::unique_ptr< UI::Widget::PopoverMenu_popover_menu
 

Detailed Description

SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMenu), and allows entry of both '.

' and ',' for the decimal, even when in numeric mode.

Calling "set_numeric()" effectively disables the expression parsing. If no unit menu is linked, all unitlike characters are ignored.

Definition at line 51 of file spinbutton.h.

Member Typedef Documentation

◆ NumericMenuData

using Inkscape::UI::Widget::SpinButton::NumericMenuData = std::map<double, Glib::ustring>

Definition at line 54 of file spinbutton.h.

Constructor & Destructor Documentation

◆ SpinButton() [1/2]

template<typename ... Args>
Inkscape::UI::Widget::SpinButton::SpinButton ( Args &&...  args)
inline

Definition at line 57 of file spinbutton.h.

References _construct().

◆ SpinButton() [2/2]

Inkscape::UI::Widget::SpinButton::SpinButton ( BaseObjectType *  cobject,
Glib::RefPtr< Gtk::Builder > const &   
)
inline

Definition at line 61 of file spinbutton.h.

References _construct().

◆ ~SpinButton()

Inkscape::UI::Widget::SpinButton::~SpinButton ( )
override

Definition at line 242 of file spinbutton.cpp.

References _unparentChildren().

Member Function Documentation

◆ _construct()

void Inkscape::UI::Widget::SpinButton::_construct ( )
private

◆ _unparentChildren()

void Inkscape::UI::Widget::SpinButton::_unparentChildren ( )
private

Definition at line 235 of file spinbutton.cpp.

References _popover_menu.

Referenced by _construct(), and ~SpinButton().

◆ addUnitTracker()

◆ create_popover_menu()

void Inkscape::UI::Widget::SpinButton::create_popover_menu ( )
private

◆ defocus()

void Inkscape::UI::Widget::SpinButton::defocus ( )

◆ get_oneable()

bool Inkscape::UI::Widget::SpinButton::get_oneable ( ) const
inline

Definition at line 75 of file spinbutton.h.

References _oneable.

◆ get_zeroable()

bool Inkscape::UI::Widget::SpinButton::get_zeroable ( ) const
inline

Definition at line 74 of file spinbutton.h.

References _zeroable.

◆ on_input()

int Inkscape::UI::Widget::SpinButton::on_input ( double &  newvalue)
private

This callback function should try to convert the entered text to a number and write it to newvalue.

It calls a method to evaluate the (potential) mathematical expression.

Return values
falseNo conversion done, continue with default handler.
trueConversion successful, don't call default handler.

Definition at line 76 of file spinbutton.cpp.

References _dont_evaluate, _unit_menu, _unit_tracker, Inkscape::Util::ExpressionEvaluator::evaluate(), Inkscape::UI::Widget::get_text(), Inkscape::UI::Widget::UnitTracker::getActiveUnit(), Inkscape::UI::Widget::UnitMenu::getUnit(), result, Inkscape::Util::EvaluatorQuantity::value, and Inkscape::Util::EvaluatorException::what().

Referenced by _construct().

◆ on_key_pressed()

bool Inkscape::UI::Widget::SpinButton::on_key_pressed ( Gtk::EventControllerKey const &  controller,
unsigned  keyval,
unsigned  keycode,
Gdk::ModifierType  state 
)
private

Handle specific keypress events, like Ctrl+Z.

Return values
falsecontinue with default handler.
truedon't call default handler.

Definition at line 106 of file spinbutton.cpp.

References _increment, defocus(), Inkscape::UI::Tools::get_latin_keyval(), Inkscape::UI::Controller::has_flag(), and undo().

Referenced by _construct().

◆ on_numeric_menu_item_activate()

void Inkscape::UI::Widget::SpinButton::on_numeric_menu_item_activate ( double  value)
private

Definition at line 168 of file spinbutton.cpp.

Referenced by create_popover_menu().

◆ on_popup_menu()

bool Inkscape::UI::Widget::SpinButton::on_popup_menu ( PopupMenuOptionalClick  )
private

Definition at line 173 of file spinbutton.cpp.

References _custom_popup, _popover_menu, and create_popover_menu().

Referenced by _construct().

◆ set_custom_numeric_menu_data()

◆ set_dont_evaluate()

void Inkscape::UI::Widget::SpinButton::set_dont_evaluate ( bool  flag)
inline

Definition at line 128 of file spinbutton.h.

References _dont_evaluate.

Referenced by Inkscape::UI::Widget::StatusBar::StatusBar().

◆ set_increment()

void Inkscape::UI::Widget::SpinButton::set_increment ( double  delta)

Definition at line 266 of file spinbutton.cpp.

References _increment, and delta.

Referenced by Inkscape::UI::Toolbar::SelectToolbar::setup_derived_spin_button().

◆ set_oneable()

void Inkscape::UI::Widget::SpinButton::set_oneable ( const bool  oneable = true)
inline

Definition at line 72 of file spinbutton.h.

References _oneable.

◆ set_zeroable()

void Inkscape::UI::Widget::SpinButton::set_zeroable ( const bool  zeroable = true)
inline

Definition at line 71 of file spinbutton.h.

References _zeroable.

◆ setDefocusTarget()

◆ setUnitMenu()

void Inkscape::UI::Widget::SpinButton::setUnitMenu ( UnitMenu unit_menu)
inline

◆ undo()

void Inkscape::UI::Widget::SpinButton::undo ( )
private

Undo the editing, by resetting the value upon when the spinbutton got focus.

Definition at line 230 of file spinbutton.cpp.

References _on_focus_in_value.

Referenced by on_key_pressed().

Member Data Documentation

◆ _custom_menu_data

NumericMenuData Inkscape::UI::Widget::SpinButton::_custom_menu_data
private

Definition at line 90 of file spinbutton.h.

Referenced by create_popover_menu(), and set_custom_numeric_menu_data().

◆ _custom_popup

bool Inkscape::UI::Widget::SpinButton::_custom_popup = false
private

Definition at line 91 of file spinbutton.h.

Referenced by on_popup_menu(), and set_custom_numeric_menu_data().

◆ _defocus_target

Inkscape::UI::DefocusTarget* Inkscape::UI::Widget::SpinButton::_defocus_target = nullptr
private

Widget that should be informed when the spinbutton defocuses.

Definition at line 86 of file spinbutton.h.

Referenced by defocus(), and setDefocusTarget().

◆ _dont_evaluate

bool Inkscape::UI::Widget::SpinButton::_dont_evaluate = false
private

Don't attempt to evaluate expressions.

Definition at line 89 of file spinbutton.h.

Referenced by on_input(), and set_dont_evaluate().

◆ _increment

double Inkscape::UI::Widget::SpinButton::_increment = 0.0
private

Definition at line 92 of file spinbutton.h.

Referenced by on_key_pressed(), and set_increment().

◆ _on_focus_in_value

double Inkscape::UI::Widget::SpinButton::_on_focus_in_value = 0.
private

Definition at line 85 of file spinbutton.h.

Referenced by _construct(), and undo().

◆ _oneable

bool Inkscape::UI::Widget::SpinButton::_oneable = false
private

Reset-value should be one.

Definition at line 88 of file spinbutton.h.

Referenced by get_oneable(), and set_oneable().

◆ _popover_menu

std::unique_ptr<UI::Widget::PopoverMenu> Inkscape::UI::Widget::SpinButton::_popover_menu
private

Definition at line 93 of file spinbutton.h.

Referenced by _unparentChildren(), create_popover_menu(), and on_popup_menu().

◆ _unit_menu

UnitMenu* Inkscape::UI::Widget::SpinButton::_unit_menu = nullptr
private

Linked unit menu for unit conversion in entered expressions.

Definition at line 83 of file spinbutton.h.

Referenced by on_input(), and setUnitMenu().

◆ _unit_tracker

UnitTracker* Inkscape::UI::Widget::SpinButton::_unit_tracker = nullptr
private

Linked unit tracker for unit conversion in entered expressions.

Definition at line 84 of file spinbutton.h.

Referenced by addUnitTracker(), and on_input().

◆ _zeroable

bool Inkscape::UI::Widget::SpinButton::_zeroable = false
private

Reset-value should be zero.

Definition at line 87 of file spinbutton.h.

Referenced by get_zeroable(), and set_zeroable().


The documentation for this class was generated from the following files: