diff options
| author | Matthew Petroff <matthew@mpetroff.net> | 2013-08-06 18:54:40 +0000 |
|---|---|---|
| committer | Matthew Petroff <matthew@mpetroff.net> | 2013-08-06 18:54:40 +0000 |
| commit | bb88a2cb94ec34ee838a972bab17ca05ba92d1da (patch) | |
| tree | 4b4580dbe1bec0968254d1b362611ab57ad3c223 /src/widgets | |
| parent | init SPStyle better: fixes a bunch of bugs resulting from improper re-init of... (diff) | |
| parent | Fixed bug in page sizer. (diff) | |
| download | inkscape-bb88a2cb94ec34ee838a972bab17ca05ba92d1da.tar.gz inkscape-bb88a2cb94ec34ee838a972bab17ca05ba92d1da.zip | |
Merge Google Summer of Code unit refactor.
(bzr r12471)
Diffstat (limited to 'src/widgets')
31 files changed, 223 insertions, 381 deletions
diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 809050ad9..42f696bec 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -56,14 +56,10 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-ellipse.h" #include "../mod360.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -341,7 +337,7 @@ void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObjec _("Start"), _("Start:"), _("The angle (in degrees) from the horizontal to the arc's start point"), "/tools/shapes/arc/start", 0.0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-arc", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-arc", -360.0, 360.0, 1.0, 10.0, 0, 0, 0, sp_arctb_start_value_changed); @@ -354,7 +350,7 @@ void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObjec _("End"), _("End:"), _("The angle (in degrees) from the horizontal to the arc's end point"), "/tools/shapes/arc/end", 0.0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -360.0, 360.0, 1.0, 10.0, 0, 0, 0, sp_arctb_end_value_changed); diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp index e8b330375..91d4ebdec 100644 --- a/src/widgets/box3d-toolbar.cpp +++ b/src/widgets/box3d-toolbar.cpp @@ -58,16 +58,11 @@ #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" - #include "../pen-context.h" #include "../box3d-context.h" #include "../box3d.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -321,7 +316,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject // Translators: PL is short for 'perspective line' _("Angle of PLs in X direction"), "/tools/shapes/3dbox/box3d_angle_x", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-box3d", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-box3d", -360.0, 360.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), box3d_angle_x_value_changed ); @@ -361,7 +356,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject // Translators: PL is short for 'perspective line' _("Angle of PLs in Y direction"), "/tools/shapes/3dbox/box3d_angle_y", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -360.0, 360.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), box3d_angle_y_value_changed ); @@ -400,7 +395,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject // Translators: PL is short for 'perspective line' _("Angle of PLs in Z direction"), "/tools/shapes/3dbox/box3d_angle_z", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -360.0, 360.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), box3d_angle_z_value_changed ); diff --git a/src/widgets/calligraphy-toolbar.cpp b/src/widgets/calligraphy-toolbar.cpp index 4cb4813b5..1f91b9fe2 100644 --- a/src/widgets/calligraphy-toolbar.cpp +++ b/src/widgets/calligraphy-toolbar.cpp @@ -56,13 +56,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -451,7 +447,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Width"), _("Width:"), _("The width of the calligraphic pen (relative to the visible canvas area)"), "/tools/calligraphic/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-calligraphy", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-calligraphy", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_width_value_changed, 1, 0 ); @@ -468,7 +464,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Stroke Thinning"), _("Thinning:"), _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"), "/tools/calligraphic/thinning", 10, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -100, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_velthin_value_changed, 1, 0); @@ -484,7 +480,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Angle"), _("Angle:"), _("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)"), "/tools/calligraphic/angle", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "calligraphy-angle", + GTK_WIDGET(desktop->canvas), holder, TRUE, "calligraphy-angle", -90.0, 90.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_angle_value_changed, 1, 0 ); @@ -502,7 +498,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Fixation"), _("Fixation:"), _("Angle behavior (0 = nib always perpendicular to stroke direction, 100 = fixed angle)"), "/tools/calligraphic/flatness", 90, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_flatness_value_changed, 1, 0); @@ -519,7 +515,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Cap rounding"), _("Caps:"), _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"), "/tools/calligraphic/cap_rounding", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 5.0, 0.01, 0.1, labels, values, G_N_ELEMENTS(labels), sp_ddc_cap_rounding_value_changed, 0.01, 2 ); @@ -535,7 +531,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Stroke Tremor"), _("Tremor:"), _("Increase to make strokes rugged and trembling"), "/tools/calligraphic/tremor", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_tremor_value_changed, 1, 0); @@ -553,7 +549,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Wiggle"), _("Wiggle:"), _("Increase to make the pen waver and wiggle"), "/tools/calligraphic/wiggle", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_wiggle_value_changed, 1, 0); @@ -570,7 +566,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Mass"), _("Mass:"), _("Increase to make the pen drag behind, as if slowed by inertia"), "/tools/calligraphic/mass", 2.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_mass_value_changed, 1, 0); diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 7c72f8e0c..54344e446 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -55,9 +55,6 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../conn-avoid-ref.h" @@ -66,7 +63,6 @@ #include "../sp-path.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -365,7 +361,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, _("Connector Curvature"), _("Curvature:"), _("The amount of connectors curvature"), "/tools/connector/curvature", defaultConnCurvature, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-curvature", + GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-curvature", 0, 100, 1.0, 10.0, 0, 0, 0, connector_curvature_changed, 1, 0 ); @@ -376,7 +372,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, _("Connector Spacing"), _("Spacing:"), _("The amount of space left around objects by auto-routing connectors"), "/tools/connector/spacing", defaultConnSpacing, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-spacing", + GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-spacing", 0, 100, 1.0, 10.0, 0, 0, 0, connector_spacing_changed, 1, 0 ); @@ -398,7 +394,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, _("Connector Length"), _("Length:"), _("Ideal length for connectors when layout is applied"), "/tools/connector/length", 100, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-length", + GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-length", 10, 1000, 10.0, 100.0, 0, 0, 0, connector_length_changed, 1, 0 ); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index c1214c1a4..6493da84d 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -43,8 +43,8 @@ #include "file.h" #include "helper/action.h" #include "helper/action-context.h" -#include "helper/units.h" -#include "helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "inkscape-private.h" #include "interface.h" #include "macros.h" @@ -79,10 +79,11 @@ using Inkscape::round; #endif -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::UI::ToolboxFactory; using ege::AppearTimeTracker; +using Inkscape::Util::unit_table; enum { ACTIVATE, @@ -393,8 +394,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) GtkWidget *eventbox = gtk_event_box_new (); dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL); dtw->hruler_box = eventbox; - sp_ruler_set_unit(SP_RULER(dtw->hruler), SP_PT); - gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT)))); + Inkscape::Util::Unit pt = unit_table.getUnit("pt"); + sp_ruler_set_unit(SP_RULER(dtw->hruler), pt); + gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(pt.name_plural.c_str())); gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler); g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw); g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw); @@ -422,8 +424,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) eventbox = gtk_event_box_new (); dtw->vruler = sp_ruler_new(GTK_ORIENTATION_VERTICAL); dtw->vruler_box = eventbox; - sp_ruler_set_unit (SP_RULER (dtw->vruler), SP_PT); - gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT)))); + sp_ruler_set_unit (SP_RULER (dtw->vruler), pt); + gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(pt.name_plural.c_str())); gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler)); #if GTK_CHECK_VERSION(3,0,0) @@ -1674,7 +1676,7 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) { SPDesktopWidget *dtw = static_cast<SPDesktopWidget*>(g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL)); - dtw->dt2r = 1.0 / namedview->doc_units->unittobase; + dtw->dt2r = 1. / namedview->doc_units->factor; dtw->ruler_origin = Geom::Point(0,0); //namedview->gridorigin; Why was the grid origin used here? @@ -1746,11 +1748,11 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) SPNamedView *nv=SP_NAMEDVIEW(obj); if (flags & SP_OBJECT_MODIFIED_FLAG) { - this->dt2r = 1.0 / nv->doc_units->unittobase; + this->dt2r = 1. / nv->doc_units->factor; this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? - sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultMetric()); - sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultMetric()); + sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultUnit()); + sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultUnit()); /* This loops through all the grandchildren of aux toolbox, * and for each that it finds, it performs an sp_search_by_data_recursive(), @@ -1786,8 +1788,8 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) } // children } // if aux_toolbox is a container - gtk_widget_set_tooltip_text(this->hruler_box, gettext(sp_unit_get_plural (nv->doc_units))); - gtk_widget_set_tooltip_text(this->vruler_box, gettext(sp_unit_get_plural (nv->doc_units))); + gtk_widget_set_tooltip_text(this->hruler_box, gettext(nv->doc_units->name_plural.c_str())); + gtk_widget_set_tooltip_text(this->vruler_box, gettext(nv->doc_units->name_plural.c_str())); sp_desktop_widget_update_rulers(this); ToolboxFactory::updateSnapToolbox(this->desktop, 0, this->snap_toolbox); diff --git a/src/widgets/dropper-toolbar.cpp b/src/widgets/dropper-toolbar.cpp index cf58aa507..054955d8f 100644 --- a/src/widgets/dropper-toolbar.cpp +++ b/src/widgets/dropper-toolbar.cpp @@ -54,13 +54,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../tools-switch.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index aca960c00..3f5e60780 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -55,13 +55,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -149,7 +145,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb _("Pen Width"), _("Width:"), _("The width of the eraser pen (relative to the visible canvas area)"), "/tools/eraser/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-eraser", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-eraser", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_erc_width_value_changed, 1, 0); diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index 7fa848f1e..5f9098d44 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -33,7 +33,6 @@ #include "desktop.h" #include "widgets/font-selector.h" #include "preferences.h" -#include "unit-constants.h" /* SPFontSelector */ diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index ea125a380..c1eb13ceb 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -1171,7 +1171,7 @@ void sp_gradient_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, eact = create_adjustment_action( "GradientEditOffsetAction", _("Offset"), _("Offset:"), _("Offset of selected stop"), "/tools/gradient/stopoffset", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 1.0, 0.01, 0.1, 0, 0, 0, gr_stop_offset_adjustment_changed diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp index c7659ab42..55cce90cd 100644 --- a/src/widgets/lpe-toolbar.cpp +++ b/src/widgets/lpe-toolbar.cpp @@ -57,9 +57,8 @@ #include "../ui/icon-names.h" #include "../helper/action.h" #include "../helper/action-context.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../tools-switch.h" @@ -67,7 +66,9 @@ #include "../live_effects/lpe-angle_bisector.h" #include "../lpe-tool-context.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -197,9 +198,9 @@ static void lpetool_toggle_show_measuring_info(GtkToggleAction *act, GObject *tb static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker")); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt("/tools/lpetool/unitid", unit->unit_id); + prefs->setString("/tools/lpetool/unit", unit.abbr); SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); if (SP_IS_LPETOOL_CONTEXT(desktop->event_context)) { @@ -295,13 +296,13 @@ static void lpetool_open_lpe_dialog(GtkToggleAction *act, gpointer data) void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { - UnitTracker* tracker = new UnitTracker(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units); g_object_set_data(holder, "tracker", tracker); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt("/tools/lpetool/unitid", unit->unit_id); + prefs->setString("/tools/lpetool/unit", unit.abbr); /** Automatically create a list of LPEs that get added to the toolbar **/ { diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 21df4c6d9..53ed2d275 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -52,13 +52,12 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" +#include "ui/widget/unit-tracker.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -83,15 +82,17 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker")); - SPUnit const *unit = tracker->getActiveUnit(); + Glib::ustring const unit = tracker->getActiveUnit().abbr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt("/tools/measure/unitid", unit->unit_id); + prefs->setString("/tools/measure/unit", unit); } void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) { - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + tracker->setActiveUnitByAbbr(prefs->getString("/tools/measure/unit").c_str()); + g_object_set_data( holder, "tracker", tracker ); EgeAdjustmentAction *eact = 0; @@ -102,7 +103,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G _("Font Size"), _("Font Size:"), _("The font size to be used in the measurement labels"), "/tools/measure/fontsize", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 10, 36, 1.0, 4.0, 0, 0, 0, sp_measure_fontsize_value_changed); diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 99a34fbda..37763ab34 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -262,7 +262,7 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj eact = create_adjustment_action( "MeshRowAction", _("Rows"), _("Rows:"), _("Number of rows in new mesh"), "/tools/mesh/mesh_rows", 1, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 1, 20, 1, 1, labels, values, G_N_ELEMENTS(labels), ms_row_changed, @@ -278,7 +278,7 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj eact = create_adjustment_action( "MeshColumnAction", _("Columns"), _("Columns:"), _("Number of columns in new mesh"), "/tools/mesh/mesh_cols", 1, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 1, 20, 1, 1, labels, values, G_N_ELEMENTS(labels), ms_col_changed, diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index 849de874d..a9e298f1d 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -58,17 +58,19 @@ #include "../ui/tool/node-tool.h" #include "../ui/tool/multi-path-manipulator.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../lpe-tool-context.h" #include "../sp-namedview.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::Util::unit_table; //#################################### //# node editing callbacks @@ -238,7 +240,7 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb if (!tracker) { return; } - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); InkNodeTool *nt = get_node_tool(); if (!nt || nt->_selected_nodes->empty()) { @@ -248,15 +250,15 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb } else { gtk_action_set_sensitive(xact, TRUE); gtk_action_set_sensitive(yact, TRUE); - Geom::Coord oldx = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit); - Geom::Coord oldy = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit); + Geom::Coord oldx = Quantity::convert(gtk_adjustment_get_value(xadj), unit, "px"); + Geom::Coord oldy = Quantity::convert(gtk_adjustment_get_value(yadj), unit, "px"); Geom::Point mid = nt->_selected_nodes->pointwiseBounds()->midpoint(); if (oldx != mid[Geom::X]) { - gtk_adjustment_set_value(xadj, sp_pixels_get_units(mid[Geom::X], *unit)); + gtk_adjustment_set_value(xadj, Quantity::convert(mid[Geom::X], "px", unit)); } if (oldy != mid[Geom::Y]) { - gtk_adjustment_set_value(yadj, sp_pixels_get_units(mid[Geom::Y], *unit)); + gtk_adjustment_set_value(yadj, Quantity::convert(mid[Geom::Y], "px", unit)); } } @@ -272,11 +274,11 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D if (!tracker) { return; } - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"), - sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit)); + Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } // quit if run by the attr_changed listener @@ -289,7 +291,7 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D InkNodeTool *nt = get_node_tool(); if (nt && !nt->_selected_nodes->empty()) { - double val = sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit); + double val = Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"); double oldval = nt->_selected_nodes->pointwiseBounds()->midpoint()[d]; Geom::Point delta(0,0); delta[d] = val - oldval; @@ -339,8 +341,9 @@ static void sp_node_toolbox_sel_modified(Inkscape::Selection *selection, guint / void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + Unit doc_units = *sp_desktop_namedview(desktop)->doc_units; + tracker->setActiveUnit(&doc_units); g_object_set_data( holder, "tracker", tracker ); Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); @@ -589,7 +592,7 @@ void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "NodeXAction", _("X coordinate:"), _("X:"), _("X coordinate of selected node(s)"), "/tools/nodes/Xcoord", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-nodes", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-nodes", -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_node_path_x_value_changed ); @@ -607,7 +610,7 @@ void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "NodeYAction", _("Y coordinate:"), _("Y:"), _("Y coordinate of selected node(s)"), "/tools/nodes/Ycoord", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_node_path_y_value_changed ); diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index 73815b86d..7c23379cd 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -54,9 +54,8 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../flood-context.h" @@ -64,11 +63,12 @@ #include <gtk/gtk.h> -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::Util::unit_table; @@ -97,13 +97,13 @@ static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl) { UnitTracker* tracker = static_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" )); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // Don't adjust the offset value because we're saving the // unit and it'll be correctly handled on load. prefs->setDouble("/tools/paintbucket/offset", (gdouble)gtk_adjustment_get_value(adj)); - prefs->setString("/tools/paintbucket/offsetunits", sp_unit_get_abbreviation(unit)); + prefs->setString("/tools/paintbucket/offsetunits", unit.abbr); } static void paintbucket_defaults(GtkWidget *, GObject *tbl) @@ -165,7 +165,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions "ThresholdAction", _("Fill Threshold"), _("Threshold:"), _("The maximum allowed difference between the clicked pixel and the neighboring pixels to be counted in the fill"), - "/tools/paintbucket/threshold", 5, GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, + "/tools/paintbucket/threshold", 5, GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:paintbucket-threshold", 0, 100.0, 1.0, 10.0, 0, 0, 0, paintbucket_threshold_changed, 1, 0 ); @@ -175,10 +175,11 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions } // Create the units menu. - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits"); if (!stored_unit.empty()) { - tracker->setActiveUnit(sp_unit_get_by_abbreviation(stored_unit.data())); + Unit u = unit_table.getUnit(stored_unit); + tracker->setActiveUnit(&u); } g_object_set_data( holder, "tracker", tracker ); { @@ -192,7 +193,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions "OffsetAction", _("Grow/shrink by"), _("Grow/shrink by:"), _("The amount to grow (positive) or shrink (negative) the created fill path"), - "/tools/paintbucket/offset", 0, GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, + "/tools/paintbucket/offset", 0, GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:paintbucket-offset", -1e4, 1e4, 0.1, 0.5, 0, 0, 0, paintbucket_offset_changed, 1, 2); diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index e0cf67bd0..851ad7134 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -67,15 +67,10 @@ //#include "../ui/tool/multi-path-manipulator.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" - #include "../pen-context.h" //#include "../sp-namedview.h" #include "../tools-switch.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -307,7 +302,7 @@ void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb _("How much smoothing (simplifying) is applied to the line"), "/tools/freehand/pencil/tolerance", 3.0, - GTK_WIDGET(desktop->canvas), NULL, + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-pencil", 1, 100.0, 0.5, 1.0, labels, values, G_N_ELEMENTS(labels), diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 8c1a735c5..6dfd9cfcb 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -53,18 +53,20 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../sp-rect.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; +using Inkscape::Util::unit_table; //######################## @@ -91,12 +93,12 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" )); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name, - sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit)); + Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } // quit if run by the attr_changed listener @@ -113,7 +115,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * if (SP_IS_RECT(items->data)) { if (gtk_adjustment_get_value(adj) != 0) { setter(SP_RECT(items->data), - sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit)); + Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } else { SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); } @@ -184,32 +186,32 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) ); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); gpointer item = g_object_get_data( tbl, "item" ); if (item && SP_IS_RECT(item)) { { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) ); gdouble rx = sp_rect_get_visible_rx(SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(rx, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(rx, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) ); gdouble ry = sp_rect_get_visible_ry(SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(ry, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(ry, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) ); gdouble width = sp_rect_get_visible_width (SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(width, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(width, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) ); gdouble height = sp_rect_get_visible_height (SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(height, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(height, "px", unit)); } } @@ -301,7 +303,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje } // rx/ry units menu: create - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); //tracker->addUnit( SP_UNIT_PERCENT, 0 ); // fixme: add % meaning per cent of the width/height tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); @@ -314,7 +316,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RectWidthAction", _("Width"), _("W:"), _("Width of rectangle"), "/tools/shapes/rect/width", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-rect", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-rect", 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_width_value_changed ); @@ -331,7 +333,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RectHeightAction", _("Height"), _("H:"), _("Height of rectangle"), "/tools/shapes/rect/height", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_height_value_changed ); @@ -348,7 +350,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RadiusXAction", _("Horizontal radius"), _("Rx:"), _("Horizontal radius of rounded corners"), "/tools/shapes/rect/rx", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_rx_value_changed); @@ -363,7 +365,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RadiusYAction", _("Vertical radius"), _("Ry:"), _("Vertical radius of rounded corners"), "/tools/shapes/rect/ry", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_ry_value_changed); diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index c1f9be2a5..e4e72d86e 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -33,9 +33,9 @@ #include "widget-sizes.h" #include "ruler.h" -#include "unit-constants.h" #include "round.h" #include <glibmm/i18n.h> +#include "util/units.h" #define ROUND(x) ((int) ((x) + 0.5)) @@ -44,6 +44,7 @@ #define DEFAULT_RULER_FONT_SCALE PANGO_SCALE_X_SMALL #define MINIMUM_INCR 5 +using Inkscape::Util::unit_table; enum { PROP_0, @@ -62,7 +63,7 @@ enum { typedef struct { GtkOrientation orientation; - SPMetric unit; + Inkscape::Util::Unit *unit; gdouble lower; gdouble upper; gdouble position; @@ -196,11 +197,10 @@ sp_ruler_class_init (SPRulerClass *klass) /* FIXME: Should probably use g_param_spec_enum */ g_object_class_install_property (object_class, PROP_UNIT, - g_param_spec_uint ("unit", + g_param_spec_string ("unit", _("Unit"), _("Unit of the ruler"), - 0, 8, - SP_PX, + "px", static_cast<GParamFlags>(GTK_PARAM_READWRITE))); g_object_class_install_property (object_class, @@ -260,7 +260,7 @@ sp_ruler_init (SPRuler *ruler) gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); priv->orientation = GTK_ORIENTATION_HORIZONTAL; - priv->unit = SP_PX; + priv->unit = new Inkscape::Util::Unit(unit_table.getUnit("px")); priv->lower = 0; priv->upper = 0; priv->position = 0; @@ -387,7 +387,7 @@ sp_ruler_set_property (GObject *object, break; case PROP_UNIT: - sp_ruler_set_unit (ruler, static_cast<SPMetric>(g_value_get_int (value))); + sp_ruler_set_unit (ruler, unit_table.getUnit(g_value_get_string (value))); break; case PROP_LOWER: @@ -436,7 +436,7 @@ sp_ruler_get_property (GObject *object, break; case PROP_UNIT: - g_value_set_int (value, priv->unit); + g_value_set_string (value, priv->unit->abbr.c_str()); break; case PROP_LOWER: g_value_set_double (value, priv->lower); @@ -1071,15 +1071,15 @@ sp_ruler_remove_track_widget (SPRuler *ruler, */ void sp_ruler_set_unit (SPRuler *ruler, - SPMetric unit) + const Inkscape::Util::Unit &unit) { SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); g_return_if_fail (SP_IS_RULER (ruler)); - if (priv->unit != unit) + if (*priv->unit != unit) { - priv->unit = unit; + priv->unit = new Inkscape::Util::Unit(unit); g_object_notify(G_OBJECT(ruler), "unit"); gtk_widget_queue_draw (GTK_WIDGET (ruler)); @@ -1092,11 +1092,9 @@ sp_ruler_set_unit (SPRuler *ruler, * * Return value: the unit currently used in the @ruler widget. **/ -SPMetric +Inkscape::Util::Unit* sp_ruler_get_unit (SPRuler *ruler) { - g_return_val_if_fail(SP_IS_RULER(ruler), static_cast<SPMetric>(0)); - return SP_RULER_GET_PRIVATE (ruler)->unit; } @@ -1184,7 +1182,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) gint text_size; gint pos; gdouble max_size; - SPMetric unit; + Inkscape::Util::Unit *unit; SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ PangoLayout *layout; PangoRectangle logical_rect, ink_rect; @@ -1300,7 +1298,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) /* Inkscape change to ruler: Use a 1,2,4,8... scale for inches * or a 1,2,5,10... scale for everything else */ - if (sp_ruler_get_unit (ruler) == SP_IN) + if (*sp_ruler_get_unit (ruler) == unit_table.getUnit("in")) ruler_metric = ruler_metric_inches; for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++) @@ -1319,7 +1317,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) gdouble subd_incr; /* hack to get proper subdivisions at full pixels */ - if (unit == SP_PX && scale == 1 && i == 1) + if (*unit == unit_table.getUnit("px") && scale == 1 && i == 1) subd_incr = 1.0; else subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h index f0d866fff..08760f584 100644 --- a/src/widgets/ruler.h +++ b/src/widgets/ruler.h @@ -14,10 +14,15 @@ */ #include <gtk/gtk.h> -#include "sp-metric.h" #include <iostream> #include <glib.h> +namespace Inkscape { + namespace Util { + class Unit; + } +} + G_BEGIN_DECLS #define SP_TYPE_RULER (sp_ruler_get_type ()) @@ -51,8 +56,8 @@ void sp_ruler_remove_track_widget (SPRuler *ruler, GtkWidget *widget); void sp_ruler_set_unit (SPRuler *ruler, - SPMetric unit); -SPMetric sp_ruler_get_unit (SPRuler *ruler); + const Inkscape::Util::Unit &unit); +Inkscape::Util::Unit *sp_ruler_get_unit (SPRuler *ruler); void sp_ruler_set_position (SPRuler *ruler, gdouble set_position); gdouble sp_ruler_get_position (SPRuler *ruler); diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 1bfc841e3..e4a5a2905 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -39,8 +39,7 @@ #include <glibmm/i18n.h> #include "helper/action.h" #include "helper/action-context.h" -#include "helper/unit-menu.h" -#include "helper/units.h" +#include "util/units.h" #include "inkscape.h" #include "verbs.h" #include "selection.h" @@ -48,7 +47,7 @@ #include "sp-item-transform.h" #include "message-stack.h" #include "display/sp-canvas.h" -#include "helper/unit-tracker.h" +#include "ui/widget/unit-tracker.h" #include "ege-adjustment-action.h" #include "ege-output-action.h" #include "ink-action.h" @@ -56,8 +55,11 @@ #include "ui/icon-names.h" #include "select-toolbar.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; static void sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) @@ -78,7 +80,7 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) Geom::OptRect const bbox(sel->bounds(bbox_type)); if ( bbox ) { UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker")); - SPUnit const &unit = *tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); struct { char const *key; double val; } const keyval[] = { { "X", bbox->min()[X] }, @@ -87,8 +89,8 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) { "height", bbox->dimensions()[Y] } }; - if (unit.base == SP_UNIT_DIMENSIONLESS) { - double const val = 1. / unit.unittobase; + if (unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { + double const val = unit.factor * 100; for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); gtk_adjustment_set_value(a, val); @@ -97,7 +99,7 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) } else { for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); - gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit)); + gtk_adjustment_set_value(a, Quantity::convert(keyval[i].val, "px", unit)); } } } @@ -183,28 +185,28 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) gdouble y1 = 0; gdouble xrel = 0; gdouble yrel = 0; - SPUnit const &unit = *tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) ); GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) ); GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) ); GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) ); - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { - x0 = sp_units_get_pixels (gtk_adjustment_get_value (a_x), unit); - y0 = sp_units_get_pixels (gtk_adjustment_get_value (a_y), unit); - x1 = x0 + sp_units_get_pixels (gtk_adjustment_get_value (a_w), unit); - xrel = sp_units_get_pixels (gtk_adjustment_get_value (a_w), unit) / bbox_user->dimensions()[Geom::X]; - y1 = y0 + sp_units_get_pixels (gtk_adjustment_get_value (a_h), unit); - yrel = sp_units_get_pixels (gtk_adjustment_get_value (a_h), unit) / bbox_user->dimensions()[Geom::Y]; + if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) { + x0 = Quantity::convert(gtk_adjustment_get_value(a_x), unit, "px"); + y0 = Quantity::convert(gtk_adjustment_get_value(a_y), unit, "px"); + x1 = x0 + Quantity::convert(gtk_adjustment_get_value(a_w), unit, "px"); + xrel = Quantity::convert(gtk_adjustment_get_value(a_w), unit, "px") / bbox_user->dimensions()[Geom::X]; + y1 = y0 + Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px");; + yrel = Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px") / bbox_user->dimensions()[Geom::Y]; } else { - double const x0_propn = gtk_adjustment_get_value (a_x) * unit.unittobase; + double const x0_propn = gtk_adjustment_get_value (a_x) / 100 / unit.factor; x0 = bbox_user->min()[Geom::X] * x0_propn; - double const y0_propn = gtk_adjustment_get_value (a_y) * unit.unittobase; + double const y0_propn = gtk_adjustment_get_value (a_y) / 100 / unit.factor; y0 = y0_propn * bbox_user->min()[Geom::Y]; - xrel = gtk_adjustment_get_value (a_w) * unit.unittobase; + xrel = gtk_adjustment_get_value (a_w) / (100 / unit.factor); x1 = x0 + xrel * bbox_user->dimensions()[Geom::X]; - yrel = gtk_adjustment_get_value (a_h) * unit.unittobase; + yrel = gtk_adjustment_get_value (a_h) / (100 / unit.factor); y1 = y0 + yrel * bbox_user->dimensions()[Geom::Y]; } @@ -225,11 +227,11 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) double sv = fabs(y1 - bbox_user->max()[Geom::Y]); // unless the unit is %, convert the scales and moves to the unit - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { - mh = sp_pixels_get_units (mh, unit); - sh = sp_pixels_get_units (sh, unit); - mv = sp_pixels_get_units (mv, unit); - sv = sp_pixels_get_units (sv, unit); + if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) { + mh = Quantity::convert(mh, "px", unit); + sh = Quantity::convert(sh, "px", unit); + mv = Quantity::convert(mv, "px", unit); + sv = Quantity::convert(sv, "px", unit); } // do the action only if one of the scales/moves is greater than half the last significant @@ -488,8 +490,8 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb gtk_container_add(GTK_CONTAINER(spw), vb); // Create the units menu. - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->addUnit( SP_UNIT_PERCENT, 0 ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + tracker->addUnit(unit_table.getUnit("%")); tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( G_OBJECT(spw), "tracker", tracker ); diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 08d26f3d1..cccaf5154 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -53,13 +53,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-spiral.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -263,7 +259,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb eact = create_adjustment_action( "SpiralRevolutionAction", _("Number of turns"), _("Turns:"), _("Number of revolutions"), "/tools/shapes/spiral/revolution", 3.0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spiral", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-spiral", 0.01, 1024.0, 0.1, 1.0, labels, values, G_N_ELEMENTS(labels), sp_spl_tb_revolution_value_changed, 1, 2); @@ -277,7 +273,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb eact = create_adjustment_action( "SpiralExpansionAction", _("Divergence"), _("Divergence:"), _("How much denser/sparser are outer revolutions; 1 = uniform"), "/tools/shapes/spiral/expansion", 1.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 1000.0, 0.01, 1.0, labels, values, G_N_ELEMENTS(labels), sp_spl_tb_expansion_value_changed); @@ -291,7 +287,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb eact = create_adjustment_action( "SpiralT0Action", _("Inner radius"), _("Inner radius:"), _("Radius of the innermost revolution (relative to the spiral size)"), "/tools/shapes/spiral/t0", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 0.999, 0.01, 1.0, labels, values, G_N_ELEMENTS(labels), sp_spl_tb_t0_value_changed); diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 06850d261..fe221f695 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -52,13 +52,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../spray-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -131,7 +127,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "SprayWidthAction", _("Width"), _("Width:"), _("The width of the spray area (relative to the visible canvas area)"), "/tools/spray/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spray", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-spray", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_width_value_changed, 1, 0 ); @@ -147,7 +143,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "SprayMeanAction", _("Focus"), _("Focus:"), _("0 to spray a spot; increase to enlarge the ring radius"), "/tools/spray/mean", 0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-mean", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-mean", 0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_mean_value_changed, 1, 0 ); @@ -163,7 +159,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "SprayStandard_deviationAction", C_("Spray tool", "Scatter"), C_("Spray tool", "Scatter:"), _("Increase to scatter sprayed objects"), "/tools/spray/standard_deviation", 70, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-standard_deviation", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-standard_deviation", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_standard_deviation_value_changed, 1, 0 ); @@ -224,7 +220,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Amount"), _("Amount:"), _("Adjusts the number of items sprayed per click"), "/tools/spray/population", 70, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-population", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-population", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_population_value_changed, 1, 0 ); @@ -255,7 +251,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj // xgettext:no-c-format _("Variation of the rotation of the sprayed objects; 0% for the same rotation than the original object"), "/tools/spray/rotation_variation", 0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-rotation", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-rotation", 0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_rotation_value_changed, 1, 0 ); @@ -273,7 +269,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj // xgettext:no-c-format _("Variation in the scale of the sprayed objects; 0% for the same scale than the original object"), "/tools/spray/scale_variation", 0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-scale", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-scale", 0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_scale_value_changed, 1, 0 ); diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index 87ca80f2f..d0a3ed1c5 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -32,7 +32,6 @@ #include "selection.h" -#include "helper/unit-menu.h" #include "spw-utilities.h" #include <gtk/gtk.h> @@ -231,51 +230,6 @@ spw_dropdown(GtkWidget * dialog, GtkWidget * table, return selector; } -/** - * Creates a unit selector widget, used for selecting whether one wishes - * to measure screen elements in millimeters, points, etc. This is a - * compound unit that includes a label as well as the dropdown selector. - */ -GtkWidget * -spw_unit_selector(GtkWidget * dialog, GtkWidget * table, - const gchar * label_text, gchar * key, int row, - GtkWidget * us, GCallback cb, bool can_be_negative) -{ - g_assert(dialog != NULL); - g_assert(table != NULL); - g_assert(us != NULL); - - spw_label_old(table, label_text, 0, row); - -#if GTK_CHECK_VERSION(3,0,0) - GtkAdjustment * a = gtk_adjustment_new(0.0, can_be_negative?-1e6:0, 1e6, 1.0, 10.0, 10.0); -#else - GtkObject * a = gtk_adjustment_new(0.0, can_be_negative?-1e6:0, 1e6, 1.0, 10.0, 10.0); -#endif - - g_assert(a != NULL); - g_object_set_data (G_OBJECT (a), "key", key); - g_object_set_data (G_OBJECT (a), "unit_selector", us); - g_object_set_data (G_OBJECT (dialog), key, a); - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (us), GTK_ADJUSTMENT (a)); - GtkWidget * sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 4); - g_assert(sb != NULL); - gtk_widget_show (sb); - -#if GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_halign(sb, GTK_ALIGN_FILL); - gtk_widget_set_hexpand(sb, TRUE); - gtk_widget_set_valign(sb, GTK_ALIGN_CENTER); - gtk_grid_attach(GTK_GRID(table), sb, 1, row, 1, 1); -#else - gtk_table_attach (GTK_TABLE (table), sb, 1, 2, row, row+1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 0, 0); -#endif - - g_signal_connect (G_OBJECT (a), "value_changed", cb, dialog); - return sb; -} - static void sp_set_font_size_recursive (GtkWidget *w, gpointer font) { diff --git a/src/widgets/spw-utilities.h b/src/widgets/spw-utilities.h index fb8c04ebf..d52cbd888 100644 --- a/src/widgets/spw-utilities.h +++ b/src/widgets/spw-utilities.h @@ -56,11 +56,6 @@ spw_dropdown(GtkWidget *dialog, GtkWidget *table, GtkWidget *selector ); -GtkWidget * -spw_unit_selector(GtkWidget *dialog, GtkWidget *table, - gchar const *label, gchar *key, int row, - GtkWidget *us, GCallback cb, bool can_be_negative = false); - void sp_set_font_size (GtkWidget *w, guint font); void sp_set_font_size_smaller (GtkWidget *w); diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 8c07c6473..9f7dd95e0 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -53,14 +53,10 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-star.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -505,7 +501,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "MagnitudeAction", _("Corners"), _("Corners:"), _("Number of corners of a polygon or star"), "/tools/shapes/star/magnitude", 3, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 3, 1024, 1, 5, labels, values, G_N_ELEMENTS(labels), sp_stb_magnitude_value_changed, @@ -524,7 +520,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje // Base radius is the same for the closest handle. _("Base radius to tip radius ratio"), "/tools/shapes/star/proportion", 0.5, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.01, 1.0, 0.01, 0.1, labels, values, G_N_ELEMENTS(labels), sp_stb_proportion_value_changed ); @@ -545,7 +541,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RoundednessAction", _("Rounded"), _("Rounded:"), _("How much rounded are the corners (0 for sharp)"), "/tools/shapes/star/rounded", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -10.0, 10.0, 0.01, 0.1, labels, values, G_N_ELEMENTS(labels), sp_stb_rounded_value_changed ); @@ -560,7 +556,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RandomizationAction", _("Randomized"), _("Randomized:"), _("Scatter randomly the corners and angles"), "/tools/shapes/star/randomized", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -10.0, 10.0, 0.001, 0.01, labels, values, G_N_ELEMENTS(labels), sp_stb_randomized_value_changed, 0.1, 3 ); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 0a5b3781b..12d4002b8 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -22,8 +22,11 @@ #include "sp-gradient.h" #include "sp-stop.h" #include "svg/svg-color.h" +#include "util/units.h" +#include "ui/widget/unit-menu.h" using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; /** * Creates a new widget for the line stroke paint. @@ -189,22 +192,22 @@ StrokeStyle::StrokeStyle() : sp_dialog_defocus_on_enter_cpp(widthSpin); hb->pack_start(*widthSpin, false, false, 0); - unitSelector = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - Gtk::Widget *us = manage(Glib::wrap(unitSelector)); + unitSelector = new Inkscape::UI::Widget::UnitMenu(); + unitSelector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); + Gtk::Widget *us = manage(unitSelector); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(desktop)->doc_units); - sp_unit_selector_add_unit(SP_UNIT_SELECTOR(unitSelector), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0); - g_signal_connect ( G_OBJECT (unitSelector), "set_unit", G_CALLBACK (StrokeStyle::setStrokeWidthUnit), this ); + unitSelector->addUnit(unit_table.getUnit("%")); + if (desktop) { + unitSelector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); + _old_unit = new Inkscape::Util::Unit(*sp_desktop_namedview(desktop)->doc_units); + } + _old_unit = new Inkscape::Util::Unit(unitSelector->getUnit()); + widthSpin->setUnitMenu(unitSelector); + unitChangedConn = unitSelector->signal_changed().connect(sigc::mem_fun(*this, &StrokeStyle::unitChangedCB)); + us->show(); -#if WITH_GTKMM_3_0 - sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(unitSelector), GTK_ADJUSTMENT((*widthAdj)->gobj()) ); -#else - sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(unitSelector), GTK_ADJUSTMENT(widthAdj->gobj()) ); -#endif - hb->pack_start(*us, FALSE, FALSE, 0); #if WITH_GTKMM_3_0 @@ -519,75 +522,17 @@ void StrokeStyle::updateMarkerHist(SPMarkerLoc const which) } /** - * Sets the stroke width units for all selected items. - * Also handles absolute and dimensionless units. + * Callback for when UnitMenu widget is modified. + * Triggers update action. */ -gboolean StrokeStyle::setStrokeWidthUnit(SPUnitSelector *, - SPUnit const *old, - SPUnit const *new_units, - StrokeStyle *spw) +void StrokeStyle::unitChangedCB() { - if (spw->update) { - return FALSE; - } - - if (!spw->desktop) { - return FALSE; + Inkscape::Util::Unit new_unit = unitSelector->getUnit(); + if (new_unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { + widthSpin->set_value(100); } - - Inkscape::Selection *selection = sp_desktop_selection (spw->desktop); - - if (selection->isEmpty()) - return FALSE; - - GSList const *objects = selection->itemList(); - - if ((old->base == SP_UNIT_ABSOLUTE || old->base == SP_UNIT_DEVICE) && - (new_units->base == SP_UNIT_DIMENSIONLESS)) { - - /* Absolute to percentage */ - spw->update = true; - -#if WITH_GTKMM_3_0 - float w = sp_units_get_pixels( (*spw->widthAdj)->get_value(), *old); -#else - float w = sp_units_get_pixels(spw->widthAdj->get_value(), *old); -#endif - - gdouble average = stroke_average_width (objects); - - if ((average == Geom::infinity()) || (average < 1e-8)){ //less than 1e-8: to campare against zero, while taking numeric accuracy into account - return FALSE; - } - -#if WITH_GTKMM_3_0 - (*spw->widthAdj)->set_value(100.0 * w / average); -#else - spw->widthAdj->set_value(100.0 * w / average); -#endif - - spw->update = false; - return TRUE; - - } else if ((old->base == SP_UNIT_DIMENSIONLESS) && - (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) { - - /* Percentage to absolute */ - spw->update = true; - - gdouble average = stroke_average_width (objects); - -#if WITH_GTKMM_3_0 - (*spw->widthAdj)->set_value (sp_pixels_get_units (0.01 * (*spw->widthAdj)->get_value() * average, *new_units)); -#else - spw->widthAdj->set_value (sp_pixels_get_units (0.01 * spw->widthAdj->get_value() * average, *new_units)); -#endif - - spw->update = false; - return TRUE; - } - - return FALSE; + widthSpin->set_value(Inkscape::Util::Quantity::convert(widthSpin->get_value(), *_old_unit, new_unit)); + _old_unit = new Inkscape::Util::Unit(new_unit); } /** @@ -877,21 +822,21 @@ StrokeStyle::updateLine() } else { table->set_sensitive(true); - SPUnit const *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector)); + Inkscape::Util::Unit const *unit = new Inkscape::Util::Unit(unitSelector->getUnit()); if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) { - sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), &sp_unit_get_by_id(SP_UNIT_PERCENT)); + unitSelector->setUnit("%"); } else { // same width, or only one object; no sense to keep percent, switch to absolute - if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) { - sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { + unitSelector->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); } } - unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector)); + unit = new Inkscape::Util::Unit(unitSelector->getUnit()); - if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) { - double avgwidth = sp_pixels_get_units (query->stroke_width.computed, *unit); + if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { + double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *unit); #if WITH_GTKMM_3_0 (*widthAdj)->set_value(avgwidth); #else @@ -1017,7 +962,7 @@ StrokeStyle::scaleLine() double const miterlimit = miterLimitAdj->get_value(); #endif - SPUnit const *const unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector)); + Inkscape::Util::Unit const *const unit = new Inkscape::Util::Unit(unitSelector->getUnit()); double *dash, offset; int ndash; @@ -1026,8 +971,8 @@ StrokeStyle::scaleLine() for (GSList const *i = items; i != NULL; i = i->next) { /* Set stroke width */ double width; - if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) { - width = sp_units_get_pixels (width_typed, *unit); + if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { + width = Inkscape::Util::Quantity::convert(width_typed, *unit, "px"); } else { // percentage gdouble old_w = SP_OBJECT(i->data)->style->stroke_width.computed; width = old_w * width_typed / 100; @@ -1053,7 +998,7 @@ StrokeStyle::scaleLine() g_free(dash); - if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) { + if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { // reset to 100 percent #if WITH_GTKMM_3_0 (*widthAdj)->set_value(100.0); diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index fd9940db1..440881c6d 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -40,8 +40,6 @@ #include "document-undo.h" #include "gradient-chemistry.h" #include "helper/stock-items.h" -#include "helper/unit-menu.h" -#include "helper/units.h" #include "inkscape.h" #include "io/sys.h" #include "marker.h" @@ -77,6 +75,17 @@ class Widget; class Container; } +namespace Inkscape { + namespace Util { + class Unit; + } + namespace UI { + namespace Widget { + class UnitMenu; + } + } +} + struct { gchar const *key; gint value; } const SPMarkerNames[] = { {"marker-all", SP_MARKER_LOC}, {"marker-start", SP_MARKER_LOC_START}, @@ -162,17 +171,13 @@ private: StrokeStyleButtonType button_type, gchar const *stroke_style); - static gboolean setStrokeWidthUnit(SPUnitSelector *, - SPUnit const *old, - SPUnit const *new_units, - StrokeStyle *spw); - // Callback functions void selectionModifiedCB(guint flags); void selectionChangedCB(); void widthChangedCB(); void miterLimitChangedCB(); void lineDashChangedCB(); + void unitChangedCB(); static void markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, SPMarkerLoc const which); static void buttonToggledCB(StrokeStyleButton *tb, StrokeStyle *spw); @@ -191,7 +196,7 @@ private: #endif Inkscape::UI::Widget::SpinButton *miterLimitSpin; Inkscape::UI::Widget::SpinButton *widthSpin; - GtkWidget *unitSelector; + Inkscape::UI::Widget::UnitMenu *unitSelector; StrokeStyleButton *joinMiter; StrokeStyleButton *joinRound; StrokeStyleButton *joinBevel; @@ -207,6 +212,9 @@ private: sigc::connection startMarkerConn; sigc::connection midMarkerConn; sigc::connection endMarkerConn; + sigc::connection unitChangedConn; + + Inkscape::Util::Unit *_old_unit; }; } // namespace Inkscape diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 87cb54d10..7554f4faf 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -56,9 +56,6 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../svg/css-ostringstream.h" @@ -72,7 +69,6 @@ #include "widgets/font-selector.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -1217,11 +1213,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); - // Is this used? - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); - g_object_set_data( holder, "tracker", tracker ); - /* Font family */ { // Font list @@ -1462,7 +1453,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/lineheight", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1493,7 +1483,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/wordspacing", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1524,7 +1513,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/letterspacing", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1555,7 +1543,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/dx", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1586,7 +1573,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/dy", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1617,7 +1603,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/rotation", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 98a0ff51e..f3a83e84a 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -49,9 +49,6 @@ #include "../graphlayout.h" #include "../helper/action.h" #include "../helper/action-context.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "icon.h" #include "../ink-action.h" #include "../ink-comboboxentry-action.h" @@ -101,7 +98,6 @@ //#define DEBUG_TEXT -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::PrefPusher; @@ -1031,7 +1027,6 @@ EgeAdjustmentAction * create_adjustment_action( gchar const *name, gchar const *label, gchar const *shortLabel, gchar const *tooltip, Glib::ustring const &path, gdouble def, GtkWidget *focusTarget, - GtkWidget *us, GObject *dataKludge, gboolean altx, gchar const *altx_mark, gdouble lower, gdouble upper, gdouble step, gdouble page, @@ -1048,9 +1043,6 @@ EgeAdjustmentAction * create_adjustment_action( gchar const *name, Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( prefs->getDouble(path, def) * factor, lower, upper, step, page, 0 ) ); - if (us) { - sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us), adj ); - } g_signal_connect( G_OBJECT(adj), "value-changed", G_CALLBACK(callback), dataKludge ); diff --git a/src/widgets/toolbox.h b/src/widgets/toolbox.h index 9c839a8fe..197f0fb5e 100644 --- a/src/widgets/toolbox.h +++ b/src/widgets/toolbox.h @@ -118,7 +118,6 @@ void delete_connection(GObject * /*obj*/, sigc::connection *connection); gchar const *label, gchar const *shortLabel, gchar const *tooltip, Glib::ustring const &path, gdouble def, GtkWidget *focusTarget, - GtkWidget *us, GObject *dataKludge, gboolean altx, gchar const *altx_mark, gdouble lower, gdouble upper, gdouble step, gdouble page, diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp index beb527a17..d5fe67ef7 100644 --- a/src/widgets/tweak-toolbar.cpp +++ b/src/widgets/tweak-toolbar.cpp @@ -52,13 +52,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../tweak-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -145,7 +141,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "TweakWidthAction", _("Width"), _("Width:"), _("The width of the tweak area (relative to the visible canvas area)"), "/tools/tweak/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-tweak", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-tweak", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_tweak_width_value_changed, 0.01, 0, 100 ); @@ -162,7 +158,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "TweakForceAction", _("Force"), _("Force:"), _("The force of the tweak action"), "/tools/tweak/force", 20, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-force", + GTK_WIDGET(desktop->canvas), holder, TRUE, "tweak-force", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_tweak_force_value_changed, 0.01, 0, 100 ); @@ -371,7 +367,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Fidelity"), _("Fidelity:"), _("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes"), "/tools/tweak/fidelity", 50, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-fidelity", + GTK_WIDGET(desktop->canvas), holder, TRUE, "tweak-fidelity", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_tweak_fidelity_value_changed, 0.01, 0, 100 ); diff --git a/src/widgets/zoom-toolbar.cpp b/src/widgets/zoom-toolbar.cpp index 7d7f2c774..9cdbc3d6a 100644 --- a/src/widgets/zoom-toolbar.cpp +++ b/src/widgets/zoom-toolbar.cpp @@ -51,14 +51,10 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../tweak-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; |
