measure-toolbar.cpp revision 4c117d2c20c4b9d75d57fb640d76768159357cb4
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen/**
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * @file
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Measure aux toolbar
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen */
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen/* Authors:
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 *
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 *
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Released under GNU GPL, read the file 'COPYING' for more information
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen */
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#ifdef HAVE_CONFIG_H
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen# include "config.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#endif
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen#include <glibmm/i18n.h>
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "measure-toolbar.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "desktop.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "inkscape.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "message-stack.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "document-undo.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "widgets/ege-adjustment-action.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "widgets/ege-output-action.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "preferences.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "toolbox.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "widgets/ink-action.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "ui/icon-names.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "ui/tools/measure-tool.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen#include "ui/widget/unit-tracker.h"
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenusing Inkscape::UI::Widget::UnitTracker;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenusing Inkscape::Util::Unit;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenusing Inkscape::DocumentUndo;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenusing Inkscape::UI::ToolboxFactory;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenusing Inkscape::UI::PrefPusher;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenusing Inkscape::UI::Tools::MeasureTool;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen//########################
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen//## Measure Toolbox ##
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen//########################
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen/** Temporary hack: Returns the node tool in the active desktop.
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen * Will go away during tool refactoring. */
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic MeasureTool *get_measure_tool()
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen MeasureTool *tool = 0;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (SP_ACTIVE_DESKTOP ) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (SP_IS_MEASURE_CONTEXT(ec)) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen tool = static_cast<MeasureTool*>(ec);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen return tool;
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen}
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelensp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
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 Engelen gtk_adjustment_get_value(adj));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen MeasureTool *mt = get_measure_tool();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (mt) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen mt->showCanvasItems();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen}
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelensp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
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 Engelen gtk_adjustment_get_value(adj));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen MeasureTool *mt = get_measure_tool();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (mt) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen mt->showCanvasItems();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen}
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelensp_measure_precision_value_changed(GtkAdjustment *adj, GObject *tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
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 Engelen gtk_adjustment_get_value(adj));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen MeasureTool *mt = get_measure_tool();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (mt) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen mt->showCanvasItems();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen}
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void measure_unit_changed(GtkAction* /*act*/, GObject* tbl)
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
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);
ea7d8c8f5752fe8fe4f814fc01baf6f250825817Johan Engelen MeasureTool *mt = get_measure_tool();
ea7d8c8f5752fe8fe4f814fc01baf6f250825817Johan Engelen if (mt) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen mt->showCanvasItems();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen}
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data )
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
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 if ( active ) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures inactive."));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen } else {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures active."));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen MeasureTool *mt = get_measure_tool();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (mt) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen mt->showCanvasItems();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
b49365c42b99e3cc135dcde0077aad31d930f6c1Johan B. C. Engelen}
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void toggle_all_layers( GtkToggleAction* act, gpointer data )
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
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 if ( active ) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use all layers in the measure."));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen } else {
b49365c42b99e3cc135dcde0077aad31d930f6c1Johan B. C. Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use current layer in the measure."));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen MeasureTool *mt = get_measure_tool();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen if (mt) {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen mt->showCanvasItems();
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen}
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelenstatic void toggle_show_in_between( GtkToggleAction* act, gpointer data )
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen{
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 if ( active ) {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute all elements."));
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen } else {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute max lenght."));
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen MeasureTool *mt = get_measure_tool();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen if (mt) {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen mt->showCanvasItems();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen}
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelenstatic void sp_reverse_knots(void){
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen MeasureTool *mt = get_measure_tool();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen if (mt) {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen mt->reverseKnots();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen}
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelenstatic void sp_to_mark_dimension(void){
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen MeasureTool *mt = get_measure_tool();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen if (mt) {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen mt->toMarkDimension();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen}
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelenstatic void sp_to_guides(void){
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen MeasureTool *mt = get_measure_tool();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen if (mt) {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen mt->toGuides();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen}
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelenstatic void sp_to_item(void){
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelen MeasureTool *mt = get_measure_tool();
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelen if (mt) {
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelen mt->toItem();
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen }
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelen}
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelen
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelenvoid sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder)
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen{
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());
26467da82c920aae52b2c00844c12f9ea236b480Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen g_object_set_data( holder, "tracker", tracker );
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen EgeAdjustmentAction *eact = 0;
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen /* Font Size */
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen eact = create_adjustment_action( "MeasureFontSizeAction",
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen _("Font Size"), _("Font Size:"),
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen _("The font size to be used in the measurement labels"),
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen "/tools/measure/fontsize", 0.0,
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen 1, 36, 1.0, 4.0,
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen 0, 0, 0,
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 }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen // units label
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen {
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 }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen // units menu
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen {
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 }
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen /* Precission */
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen {
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen eact = create_adjustment_action( "MeasurePrecisionAction",
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Precision"), _("Precision:"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Decimal precision of measure"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen "/tools/measure/precision", 2,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen 0, 10, 1, 0,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen 0, 0, 0,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen sp_measure_precision_value_changed, NULL, 0 ,0);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gtk_action_group_add_action( mainActions, GTK_ACTION(eact));
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen
742a1b08138aef8fc3c19730ae48e5477ee43fc5Johan B. C. Engelen /* Offset */
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen eact = create_adjustment_action( "MeasureOffsetAction",
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Offset"), _("Offset:"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("The offset size"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen "/tools/measure/offset", 30.0,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen 0.0, 90000.0, 1.0, 4.0,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen 0, 0, 0,
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen sp_measure_offset_value_changed, NULL, 0 , 2);
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen }
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen // ignore_1st_and_last
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen {
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen InkToggleAction* act = ink_toggle_action_new( "MeasureIgnore1stAndLast",
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Ignore first and last"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen _("Ignore first and last"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen INKSCAPE_ICON("draw-geometry-line-segment"),
4fd537e3c7f3fb1b0013f94688e95b0c3ef6649cJohan Engelen secondarySize );
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_action_group_add_action( mainActions, GTK_ACTION(act) );
}
// measure imbetweens
{
InkToggleAction* act = ink_toggle_action_new( "MeasureInBettween",
_("Show measures between items"),
_("Show measures between items"),
INKSCAPE_ICON("distribute-randomize"),
secondarySize );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/show_in_between", true) );
g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_in_between), desktop) ;
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
// measure only current layer
{
InkToggleAction* act = ink_toggle_action_new( "MeasureAllLayers",
_("Measure all layers"),
_("Measure all layers"),
INKSCAPE_ICON("dialog-layers"),
secondarySize );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/all_layers", true) );
g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_all_layers), desktop) ;
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//toogle start end
{
InkAction* act = ink_action_new( "MeasureReverse",
_("Reverse measure"),
_("Reverse measure"),
INKSCAPE_ICON("draw-geometry-mirror"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_reverse_knots), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//to guides
{
InkAction* act = ink_action_new( "MeasureToGuides",
_("To guides"),
_("To guides"),
INKSCAPE_ICON("guides"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_guides), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//to mark dimensions
{
InkAction* act = ink_action_new( "MeasureMarkDimension",
_("Mark Dimension"),
_("Mark Dimension"),
INKSCAPE_ICON("tool-pointer"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_mark_dimension), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
//to item
{
InkAction* act = ink_action_new( "MeasureToItem",
_("Convert to item"),
_("Convert to item"),
INKSCAPE_ICON("path-reverse"),
secondarySize );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_item), 0 );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
}
} // end of sp_measure_toolbox_prep()
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :