18#include <glibmm/i18n.h>
19#include <giomm/menu.h>
20#include <giomm/simpleactiongroup.h>
21#include <gtkmm/builder.h>
22#include <gtkmm/button.h>
23#include <gtkmm/flowbox.h>
24#include <gtkmm/gestureclick.h>
25#include <gtkmm/popover.h>
26#include <gtkmm/togglebutton.h>
27#include <gtkmm/scrolledwindow.h>
28#include <gtkmm/separator.h>
43 : _context_menu{makeContextMenu(window)}
45 set_name(
"ToolToolbar");
48 auto &tool_toolbar = UI::get_widget<Gtk::ScrolledWindow>(
builder,
"tool-toolbar");
49 tool_toolbar.set_halign(Gtk::Align::FILL);
68 int buttons_before_separator = 0;
69 Gtk::Widget* last_sep =
nullptr;
70 Gtk::FlowBox* last_box =
nullptr;
75 if (
auto const flowbox =
dynamic_cast<Gtk::FlowBox *
>(&widget)) {
76 flowbox->set_visible(
true);
77 flowbox->set_max_children_per_line(1);
79 }
else if (
auto const btn =
dynamic_cast<Gtk::Button *
>(&widget)) {
82 auto const parent = btn->get_parent();
85 ++buttons_before_separator;
87 last_box->set_max_children_per_line(buttons_before_separator);
90 parent->set_visible(
false);
92 }
else if (
auto const sep =
dynamic_cast<Gtk::Separator *
>(&widget)) {
93 if (buttons_before_separator <= 0) {
94 sep->set_visible(
false);
96 sep->set_visible(
true);
97 buttons_before_separator = 0;
106 last_sep->set_visible(
false);
113 Glib::ustring icon_name;
115 if (prefs->
getInt(
"/theme/menuIcons",
true)) {
116 icon_name =
"preferences-system";
119 auto &
item = *Gtk::make_managed<UI::Widget::PopoverMenuItem>(_(
"Open tool preferences"),
false, icon_name);
120 item.signal_activate().connect([=,
this] {
125 auto menu = std::make_unique<UI::Widget::PopoverMenu>(Gtk::PositionType::BOTTOM);
145 for (
auto &
object :
builder->get_objects()) {
146 auto const radio =
dynamic_cast<Gtk::ToggleButton *
>(
object.get());
151 Glib::VariantBase action_target;
152 radio->get_property(
"action-target", action_target);
153 if (!action_target.is_of_type(Glib::VARIANT_TYPE_STRING)) {
157 auto tool_name = Glib::ustring((gchar
const *)action_target.get_data());
159 (Gtk::GestureClick
const &click,
160 int const n_press,
double ,
double )
163 auto const button = click.get_current_button();
164 if (button == 1 && n_press == 2) {
166 return Gtk::EventSequenceState::CLAIMED;
170 return Gtk::EventSequenceState::CLAIMED;
172 return Gtk::EventSequenceState::NONE;
175 const auto click = Gtk::GestureClick::create();
176 click->set_button(0);
178 radio->add_controller(click);
Preference storage class.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
static Preferences * get()
Access the singleton Preferences object.
int getInt(Glib::ustring const &pref_path, int def=0)
Retrieve an integer.
std::unique_ptr< PreferencesObserver > createObserver(Glib::ustring path, std::function< void(const Preferences::Entry &new_value)> callback)
Create an observer watching preference 'path' and calling provided function when preference changes.
Utilities to more easily use Gtk::EventController & subclasses like Gesture.
static char const *const parent
Inkscape - An SVG editor.
auto use_state(Slot &&slot)
static void on_click_pressed(int n_press, double x, double y, Gtk::GestureClick &click, PopupMenuSlot const &slot)
Gtk::Widget * for_each_descendant(Gtk::Widget &widget, Func &&func)
Like for_each_child() but also tests the initial widget & recurses through childrenʼs children.
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
static void append(std::vector< T > &target, std::vector< T > &&source)
Glib::ustring sp_get_action_target(Gtk::Widget *widget)
Get string action target, if available.
Glib::RefPtr< Gtk::Builder > builder