27#include <glibmm/i18n.h>
28#include <glibmm/regex.h>
29#include <gdkmm/general.h>
30#include <gtkmm/drawingarea.h>
31#include <gtkmm/gridview.h>
32#include <gtkmm/image.h>
33#include <gtkmm/menubutton.h>
34#include <gtkmm/popover.h>
35#include <gtkmm/signallistitemfactory.h>
36#include <gtkmm/singleselection.h>
48constexpr auto DRAWING_AREA_WIDTH = 100;
49constexpr auto DRAWING_AREA_HEIGHT = 16;
51std::vector<std::vector<double>> get_dash_patterns()
53 std::vector<std::vector<double>> dash_patterns;
56 auto const dash_prefs = prefs->getAllDirs(
"/palette/dashes");
60 for (
auto const &dash_pref : dash_prefs) {
72class DashPattern :
public Glib::Object
79 return Glib::make_refptr_for_instance<DashPattern>(
new DashPattern(std::move(
dash_pattern)));
91 :
Gtk::Box(
Gtk::Orientation::HORIZONTAL, 4)
93 set_name(
"DashSelector");
96 set_valign(Gtk::Align::CENTER);
99 auto dash_patterns = get_dash_patterns();
107 custom_pattern->custom =
true;
108 liststore->insert(1, custom_pattern);
115 auto gridview = Gtk::make_managed<Gtk::GridView>(
selection, factory);
116 gridview->set_min_columns(2);
117 gridview->set_max_columns(2);
118 gridview->set_single_click_activate(
true);
119 gridview->signal_activate().connect(sigc::bind<0>(sigc::mem_fun(*
this, &
DashSelector::activate), gridview));
121 popover = Gtk::make_managed<Gtk::Popover>();
130 auto menubutton = Gtk::make_managed<Gtk::MenuButton>();
132 gtk_menu_button_set_always_show_arrow(menubutton->gobj(),
true);
133 menubutton->set_popover(*
popover);
139 adjustment->signal_value_changed().connect([
this] {
143 auto spinbutton = Gtk::make_managed<Inkscape::UI::Widget::SpinButton>(
adjustment, 0.1, 2);
144 spinbutton->set_tooltip_text(_(
"Dash pattern offset"));
145 spinbutton->set_width_chars(5);
159 double const delta = std::accumulate(new_dash_pattern.begin(), new_dash_pattern.end(), 0.0)
160 / (10000.0 * (new_dash_pattern.empty() ? 1.0 : new_dash_pattern.size()));
163 auto const item_count =
selection->get_n_items();
164 for (
int index = 0; index < item_count; ++index) {
165 auto const &
item =
dynamic_cast<DashPattern &
>(*
selection->get_object(index));
166 if (
std::equal(new_dash_pattern.begin(), new_dash_pattern.end(),
item.dash_pattern.begin(),
item.dash_pattern.end(),
167 [=] (
double a,
double b) {
return Geom::are_near(a, b, delta); }))
181 auto &
item =
dynamic_cast<DashPattern &
>(*
selection->get_object(position));
182 item.dash_pattern.assign(new_dash_pattern.begin(), new_dash_pattern.end());
209 auto &model =
dynamic_cast<Gtk::SingleSelection &
>(*grid->get_model());
210 auto const &
item =
dynamic_cast<DashPattern &
>(*model.get_selected_item());
222 auto drawing_area = Gtk::make_managed<Gtk::DrawingArea>();
230 auto const &
dash_pattern =
dynamic_cast<DashPattern &
>(*list_item->get_item());
231 auto &
drawing_area =
dynamic_cast<Gtk::DrawingArea &
>(*list_item->get_child());
242 std::vector<double>
const &pattern)
244 cr->set_line_width(2);
246 cr->set_dash(pattern, 0);
256 cr->select_font_face(
"Sans", Cairo::ToyFontFace::Slant::NORMAL, Cairo::ToyFontFace::Weight::NORMAL);
257 cr->set_font_size(12);
259 cr->move_to(16.0, (
height + 12) / 2.0);
260 cr->show_text(_(
"Custom"));
static Preferences * get()
Access the singleton Preferences object.
T< SPAttr::STROKE_DASHARRAY, SPIDashArray > stroke_dasharray
stroke-dasharray
void readFromPrefs(Glib::ustring const &path)
Read style properties from preferences.
Integral and real coordinate types and some basic utilities.
std::vector< double > dash_pattern
A widget for selecting dash patterns and setting the dash offset.
void sp_dialog_defocus_on_enter(Gtk::Entry *e)
Event handler for dialog windows.
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
bool equal(std::optional< std::string > const &a, char const *b)
static void append(std::vector< T > &target, std::vector< T > &&source)
Singleton class to access the preferences file in a convenient way.
SPStyle - a style object for SPItem objects.