measure-toolbar.cpp revision 4c117d2c20c4b9d75d57fb640d76768159357cb4
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Measure aux toolbar
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * MenTaLguY <mental@rydia.net>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Lauris Kaplinski <lauris@kaplinski.com>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * bulia byak <buliabyak@users.sf.net>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Frank Felfe <innerspace@iname.com>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * John Cliff <simarilius@yahoo.com>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * David Turner <novalis@gnu.org>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Josh Andler <scislac@scislac.com>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Jon A. Cruz <jon@joncruz.org>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Maximilian Albert <maximilian.albert@gmail.com>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Tavmjong Bah <tavmjong@free.fr>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Abhishek Sharma
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Kris De Gussem <Kris.DeGussem@gmail.com>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Copyright (C) 2004 David Turner
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Copyright (C) 2003 MenTaLguY
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Copyright (C) 1999-2011 authors
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Copyright (C) 2001-2002 Ximian, Inc.
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Released under GNU GPL, read the file 'COPYING' for more information
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen//########################
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen//## Measure Toolbox ##
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen//########################
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen/** Temporary hack: Returns the node tool in the active desktop.
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Will go away during tool refactoring. */
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelensp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen prefs->setInt(Glib::ustring("/tools/measure/fontsize"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelensp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen prefs->setInt(Glib::ustring("/tools/measure/offset"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelensp_measure_precision_value_changed(GtkAdjustment *adj, GObject *tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen prefs->setInt(Glib::ustring("/tools/measure/precision"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void measure_unit_changed(GtkAction* /*act*/, GObject* tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Glib::ustring const unit = tracker->getActiveUnit()->abbr;
ea7d8c8f5752fe8fe4f814fc01baf6f250825817Johan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
ea7d8c8f5752fe8fe4f814fc01baf6f250825817Johan Engelen prefs->setString("/tools/measure/unit", unit);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data )
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gboolean active = gtk_toggle_action_get_active(act);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen prefs->setInt("/tools/measure/ignore_1st_and_last", active);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(data);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures inactive."));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures active."));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void toggle_all_layers( GtkToggleAction* act, gpointer data )
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gboolean active = gtk_toggle_action_get_active(act);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen prefs->setInt("/tools/measure/all_layers", active);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(data);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use all layers in the measure."));
b49365c42b99e3cc135dcde0077aad31d930f6c1Johan B. C. Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use current layer in the measure."));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void toggle_show_in_between( GtkToggleAction* act, gpointer data )
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gboolean active = gtk_toggle_action_get_active(act);
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen prefs->setInt("/tools/measure/show_in_between", active);
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen SPDesktop *desktop = static_cast<SPDesktop *>(data);
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute all elements."));
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute max lenght."));
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelenstatic void sp_reverse_knots(void){
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelenstatic void sp_to_guides(void){
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelenstatic void sp_to_item(void){
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelenvoid sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder)
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen tracker->setActiveUnitByAbbr(prefs->getString("/tools/measure/unit").c_str());
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen g_object_set_data( holder, "tracker", tracker );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen /* Font Size */
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen eact = create_adjustment_action( "MeasureFontSizeAction",
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen _("The font size to be used in the measurement labels"),
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen sp_measure_fontsize_value_changed, NULL, 0 , 2);
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen gtk_action_group_add_action( mainActions, GTK_ACTION(eact));
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen // units label
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen EgeOutputAction* act = ege_output_action_new( "measure_units_label", _("Units:"), _("The units to be used for the measurements"), 0 );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen ege_output_action_set_use_markup( act, TRUE );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen g_object_set( act, "visible-overflown", FALSE, NULL );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements") );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen gtk_action_group_add_action( mainActions, act );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen /* Precission */
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen eact = create_adjustment_action( "MeasurePrecisionAction",
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Decimal precision of measure"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen sp_measure_precision_value_changed, NULL, 0 ,0);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gtk_action_group_add_action( mainActions, GTK_ACTION(eact));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen eact = create_adjustment_action( "MeasureOffsetAction",
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("The offset size"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen sp_measure_offset_value_changed, NULL, 0 , 2);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen // ignore_1st_and_last
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen InkToggleAction* act = ink_toggle_action_new( "MeasureIgnore1stAndLast",
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Ignore first and last"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Ignore first and last"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/ignore_1st_and_last", true) );
g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_ignore_1st_and_last), desktop) ;
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/show_in_between", true) );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/all_layers", true) );