Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
spinbutton.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Author:
4 * Johan B. C. Engelen
5 *
6 * Copyright (C) 2011 Author
7 *
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10
11#ifndef INKSCAPE_UI_WIDGET_SPINBUTTON_H
12#define INKSCAPE_UI_WIDGET_SPINBUTTON_H
13
14#include <glibmm/refptr.h>
15#include <glibmm/ustring.h>
16#include <gtkmm/spinbutton.h>
17
18#include "ui/popup-menu.h"
20
21namespace Gtk {
22class Builder;
23class EventControllerKey;
24} // namespace Gtk
25
26namespace Inkscape::UI { class DefocusTarget; }
27
28namespace Inkscape::UI::Widget {
29
30class UnitMenu;
31class UnitTracker;
32
36class MathSpinButton : public Gtk::SpinButton
37{
38public:
39 MathSpinButton(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refGlade);
40
41private:
42 int on_input(double &newvalue);
43};
44
51class SpinButton : public Gtk::SpinButton
52{
53public:
54 using NumericMenuData = std::map<double, Glib::ustring>;
55 // We canʼt inherit ctors as if we declare SpinButton(), inherited ctors donʼt call it. Really!
56 template <typename ...Args>
57 SpinButton(Args &&...args)
58 : Gtk::SpinButton(std::forward<Args>(args)...)
59 { _construct(); } // Do the non-templated stuff
60
61 SpinButton(BaseObjectType *cobject, Glib::RefPtr<Gtk::Builder> const &)
62 : Gtk::SpinButton(cobject)
63 { _construct(); }
64
65 ~SpinButton() override;
66
67 void setUnitMenu(UnitMenu* unit_menu) { _unit_menu = unit_menu; };
69
70 // TODO: Might be better to just have a default value and a reset() method?
71 inline void set_zeroable(const bool zeroable = true) { _zeroable = zeroable; }
72 inline void set_oneable(const bool oneable = true) { _oneable = oneable; }
73
74 inline bool get_zeroable() const { return _zeroable; }
75 inline bool get_oneable() const { return _oneable; }
76
77 void defocus();
78
79 // set key up/down increment to override spin button adjustment step setting
80 void set_increment(double delta);
81
82private:
83 UnitMenu *_unit_menu = nullptr;
85 double _on_focus_in_value = 0.;
87 bool _zeroable = false;
88 bool _oneable = false;
89 bool _dont_evaluate = false;
91 bool _custom_popup = false;
92 double _increment = 0.0; // if > 0, key up/down will increment/decrement current value by this amount
93 std::unique_ptr<UI::Widget::PopoverMenu> _popover_menu;
94
95 void _construct();
96
104 int on_input(double &newvalue);
105
112 bool on_key_pressed(Gtk::EventControllerKey const &controller,
113 unsigned keyval, unsigned keycode, Gdk::ModifierType state);
114
116 void create_popover_menu();
117 void on_numeric_menu_item_activate(double value);
118
122 void undo();
123
124 void _unparentChildren();
125
126public:
127 inline void setDefocusTarget(decltype(_defocus_target) target) { _defocus_target = target; }
128 inline void set_dont_evaluate(bool flag) { _dont_evaluate = flag; }
129
130 void set_custom_numeric_menu_data(NumericMenuData &&custom_menu_data);
131};
132
133} // namespace Inkscape::UI::Widget
134
135#endif // INKSCAPE_UI_WIDGET_SPINBUTTON_H
136
137/*
138 Local Variables:
139 mode:c++
140 c-file-style:"stroustrup"
141 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
142 indent-tabs-mode:nil
143 fill-column:99
144 End:
145*/
146// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Interface for objects that would like to be informed when another widget loses focus.
A spin button for use with builders.
Definition spinbutton.h:37
SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMen...
Definition spinbutton.h:52
bool _oneable
Reset-value should be one.
Definition spinbutton.h:88
NumericMenuData _custom_menu_data
Definition spinbutton.h:90
void set_oneable(const bool oneable=true)
Definition spinbutton.h:72
void undo()
Undo the editing, by resetting the value upon when the spinbutton got focus.
void setUnitMenu(UnitMenu *unit_menu)
Definition spinbutton.h:67
void set_zeroable(const bool zeroable=true)
Definition spinbutton.h:71
UnitTracker * _unit_tracker
Linked unit tracker for unit conversion in entered expressions.
Definition spinbutton.h:84
bool _dont_evaluate
Don't attempt to evaluate expressions.
Definition spinbutton.h:89
void addUnitTracker(UnitTracker *ut)
Definition spinbutton.h:68
bool on_key_pressed(Gtk::EventControllerKey const &controller, unsigned keyval, unsigned keycode, Gdk::ModifierType state)
Handle specific keypress events, like Ctrl+Z.
std::map< double, Glib::ustring > NumericMenuData
Definition spinbutton.h:54
void setDefocusTarget(decltype(_defocus_target) target)
Definition spinbutton.h:127
int on_input(double &newvalue)
This callback function should try to convert the entered text to a number and write it to newvalue.
bool _zeroable
Reset-value should be zero.
Definition spinbutton.h:87
SpinButton(BaseObjectType *cobject, Glib::RefPtr< Gtk::Builder > const &)
Definition spinbutton.h:61
UnitMenu * _unit_menu
Linked unit menu for unit conversion in entered expressions.
Definition spinbutton.h:83
std::unique_ptr< UI::Widget::PopoverMenu > _popover_menu
Definition spinbutton.h:93
void on_numeric_menu_item_activate(double value)
Inkscape::UI::DefocusTarget * _defocus_target
Widget that should be informed when the spinbutton defocuses.
Definition spinbutton.h:86
bool on_popup_menu(PopupMenuOptionalClick)
void set_custom_numeric_menu_data(NumericMenuData &&custom_menu_data)
A drop down menu for choosing unit types.
Definition unit-menu.h:31
Definition desktop.h:50
Custom widgets.
Definition desktop.h:126
User interface code.
Definition desktop.h:113
std::optional< PopupMenuClick > PopupMenuOptionalClick
Optional: not present if popup wasnʼt triggered by click.
Definition popup-menu.h:41
STL namespace.
A replacement for GTK3ʼs Gtk::Menu, as removed in GTK4.
Helpers to connect signals to events that popup a menu in both GTK3 and GTK4.
int delta