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) {
63 for (
auto const &v : style.stroke_dasharray.values) {
72class DashPattern :
public Glib::Object
78 static Glib::RefPtr<DashPattern>
create(std::vector<double> dash_pattern) {
79 return Glib::make_refptr_for_instance<DashPattern>(
new DashPattern(std::move(
dash_pattern)));
83 DashPattern(std::vector<double> dash_pattern)
93 set_name(
"DashSelector");
95 set_halign(Gtk::Align::FILL);
96 set_valign(Gtk::Align::CENTER);
99 auto dash_patterns = get_dash_patterns();
106 auto custom_pattern = DashPattern::create({1, 2, 1, 4});
107 custom_pattern->custom =
true;
108 liststore->insert(1, custom_pattern);
110 selection = Gtk::SingleSelection::create(liststore);
111 auto factory = Gtk::SignalListItemFactory::create();
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>();
123 popover->add_css_class(
"menu");
132 auto menubutton = Gtk::make_managed<Gtk::MenuButton>();
134 gtk_menu_button_set_always_show_arrow(menubutton->gobj(),
true);
135 menubutton->set_popover(*
popover);
140 adjustment = Gtk::Adjustment::create(0.0, 0.0, 1000.0, 0.1, 1.0, 0.0);
141 adjustment->signal_value_changed().connect([
this] {
145 auto spinbutton = Gtk::make_managed<Inkscape::UI::Widget::SpinButton>(
adjustment, 0.1, 2);
146 spinbutton->set_tooltip_text(_(
"Dash pattern offset"));
147 spinbutton->set_width_chars(5);
161 double const delta = std::accumulate(new_dash_pattern.begin(), new_dash_pattern.end(), 0.0)
162 / (10000.0 * (new_dash_pattern.empty() ? 1.0 : new_dash_pattern.size()));
165 auto const item_count =
selection->get_n_items();
168 if (std::equal(new_dash_pattern.begin(), new_dash_pattern.end(),
item.dash_pattern.begin(),
item.dash_pattern.end(),
183 auto &
item =
dynamic_cast<DashPattern &
>(*
selection->get_object(position));
184 item.dash_pattern.assign(new_dash_pattern.begin(), new_dash_pattern.end());
211 auto &model =
dynamic_cast<Gtk::SingleSelection &
>(*grid->get_model());
212 auto const &
item =
dynamic_cast<DashPattern &
>(*model.get_selected_item());
224 auto drawing_area = Gtk::make_managed<Gtk::DrawingArea>();
232 auto const &
dash_pattern =
dynamic_cast<DashPattern &
>(*list_item->get_item());
233 auto &
drawing_area =
dynamic_cast<Gtk::DrawingArea &
>(*list_item->get_child());
244 std::vector<double>
const &pattern)
246 cr->set_line_width(2);
248 cr->set_dash(pattern, 0);
249 Gdk::Cairo::set_source_rgba(cr, get_color());
258 cr->select_font_face(
"Sans", Cairo::ToyFontFace::Slant::NORMAL, Cairo::ToyFontFace::Weight::NORMAL);
259 cr->set_font_size(12);
260 Gdk::Cairo::set_source_rgba(cr, get_color());
261 cr->move_to(16.0, (
height + 12) / 2.0);
262 cr->show_text(_(
"Custom"));
static Preferences * get()
Access the singleton Preferences object.
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)
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.