summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-07-17 13:53:18 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-07-17 13:53:18 +0000
commit10067e713619333f20201c7d01c99e302464f6b2 (patch)
treedba02600760724653c45c48b36c414a247bca456 /src/widgets
parentFixed botched merge. (diff)
downloadinkscape-10067e713619333f20201c7d01c99e302464f6b2.tar.gz
inkscape-10067e713619333f20201c7d01c99e302464f6b2.zip
Port remaining files away from "helper/unit-tracker.h".
(bzr r12380.1.19)
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/desktop-widget.cpp8
-rw-r--r--src/widgets/lpe-toolbar.cpp21
-rw-r--r--src/widgets/rect-toolbar.cpp32
-rw-r--r--src/widgets/select-toolbar.cpp62
-rw-r--r--src/widgets/toolbox.cpp3
5 files changed, 68 insertions, 58 deletions
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index fbef9bbce..1c6852f35 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,7 +79,7 @@
using Inkscape::round;
#endif
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::UI::ToolboxFactory;
using ege::AppearTimeTracker;
@@ -1780,7 +1780,7 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags)
if (tracker == NULL) // it's null when inkscape is first opened
continue;
- // tracker->setActiveUnit( nv->doc_units );
+ tracker->setActiveUnit( nv->doc_units );
} // grandchildren
} // if child is a container
} // children
diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp
index 65bb46e32..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);
- //tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units);
+ 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/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp
index 5fa96289f..359bc48e0 100644
--- a/src/widgets/rect-toolbar.cpp
+++ b/src/widgets/rect-toolbar.cpp
@@ -54,17 +54,19 @@
#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;
//########################
@@ -91,12 +93,14 @@ 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();
+ Inkscape::Util::UnitTable unit_table;
+ Unit const px = unit_table.getUnit("px");
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 +117,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 +188,34 @@ 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();
+ Inkscape::Util::UnitTable unit_table;
+ Unit const px = unit_table.getUnit("px");
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,10 +307,10 @@ 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 );
+ tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
g_object_set_data( holder, "tracker", tracker );
/* W */
diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp
index c0018751c..ffab3deab 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,7 +55,9 @@
#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;
static void
@@ -78,7 +79,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,17 +88,19 @@ 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;
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);
tracker->setFullVal( a, keyval[i].val );
}
} else {
+ Inkscape::Util::UnitTable unit_table;
+ Unit px = unit_table.getUnit("px");
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 +186,31 @@ 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];
+ Inkscape::Util::UnitTable unit_table;
+ Unit px = unit_table.getUnit("px");
+
+ 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) * 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) * 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) * 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) * unit.factor;
y1 = y0 + yrel * bbox_user->dimensions()[Geom::Y];
}
@@ -225,11 +231,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,9 +494,9 @@ 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 );
- //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
+ //tracker->addUnit( SP_UNIT_PERCENT, 0 );
+ tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
g_object_set_data( G_OBJECT(spw), "tracker", tracker );
g_signal_connect( G_OBJECT(spw), "destroy", G_CALLBACK(destroy_tracker), spw );
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index ca593976f..687f62420 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -50,8 +50,6 @@
#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 +99,6 @@
//#define DEBUG_TEXT
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::PrefPusher;