diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/sp-guide.cpp | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/sp-guide.cpp')
| -rw-r--r-- | src/sp-guide.cpp | 282 |
1 files changed, 134 insertions, 148 deletions
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 6a71cf4f0..a0aa9692e 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -35,7 +35,6 @@ #include <glibmm/i18n.h> #include <xml/repr.h> #include <remove-last.h> -#include "sp-metrics.h" #include "inkscape.h" #include "desktop.h" #include "sp-namedview.h" @@ -47,169 +46,158 @@ using Inkscape::DocumentUndo; using std::vector; -enum { - PROP_0, - PROP_COLOR, - PROP_HICOLOR -}; +//enum { +// PROP_0, +// PROP_COLOR, +// PROP_HICOLOR +//}; +// +//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void sp_guide_class_init(SPGuideClass *gc); -static void sp_guide_init(SPGuide *guide); -static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +#include "sp-factory.h" -static void sp_guide_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static void sp_guide_release(SPObject *object); -static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value); +namespace { + SPObject* createGuide() { + return new SPGuide(); + } -static SPObjectClass *parent_class; - -GType sp_guide_get_type(void) -{ - static GType guide_type = 0; - - if (!guide_type) { - GTypeInfo guide_info = { - sizeof(SPGuideClass), - NULL, NULL, - (GClassInitFunc) sp_guide_class_init, - NULL, NULL, - sizeof(SPGuide), - 16, - (GInstanceInitFunc) sp_guide_init, - NULL, /* value_table */ - }; - guide_type = g_type_register_static(SP_TYPE_OBJECT, "SPGuide", &guide_info, (GTypeFlags) 0); - } - - return guide_type; + bool guideRegistered = SPFactory::instance().registerObject("sodipodi:guide", createGuide); } -static void sp_guide_class_init(SPGuideClass *gc) -{ - GObjectClass *gobject_class = (GObjectClass *) gc; - SPObjectClass *sp_object_class = (SPObjectClass *) gc; - - parent_class = (SPObjectClass*) g_type_class_ref(SP_TYPE_OBJECT); - - gobject_class->set_property = sp_guide_set_property; - gobject_class->get_property = sp_guide_get_property; - - sp_object_class->build = sp_guide_build; - sp_object_class->release = sp_guide_release; - sp_object_class->set = sp_guide_set; - - g_object_class_install_property(gobject_class, - PROP_COLOR, - g_param_spec_uint("color", "Color", "Color", - 0, - 0xffffffff, - 0xff000000, - (GParamFlags) G_PARAM_READWRITE)); - - g_object_class_install_property(gobject_class, - PROP_HICOLOR, - g_param_spec_uint("hicolor", "HiColor", "HiColor", - 0, - 0xffffffff, - 0xff000000, - (GParamFlags) G_PARAM_READWRITE)); +//static void sp_guide_class_init(SPGuideClass *gc) +//{ +// GObjectClass *gobject_class = (GObjectClass *) gc; +// +// gobject_class->set_property = sp_guide_set_property; +// gobject_class->get_property = sp_guide_get_property; +// +// g_object_class_install_property(gobject_class, +// PROP_COLOR, +// g_param_spec_uint("color", "Color", "Color", +// 0, +// 0xffffffff, +// 0xff000000, +// (GParamFlags) G_PARAM_READWRITE)); +// +// g_object_class_install_property(gobject_class, +// PROP_HICOLOR, +// g_param_spec_uint("hicolor", "HiColor", "HiColor", +// 0, +// 0xffffffff, +// 0xff000000, +// (GParamFlags) G_PARAM_READWRITE)); +//} +// CPPIFY: properties! + +SPGuide::SPGuide() : SPObject() { + this->label = NULL; + this->views = NULL; + + this->normal_to_line = Geom::Point(0.,1.); + this->point_on_line = Geom::Point(0.,0.); + this->color = 0x0000ff7f; + this->hicolor = 0xff00007f; } -static void sp_guide_init(SPGuide *guide) -{ - guide->normal_to_line = Geom::Point(0.,1.); - guide->point_on_line = Geom::Point(0.,0.); - guide->color = 0x0000ff7f; - guide->hicolor = 0xff00007f; +SPGuide::~SPGuide() { } -static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec */*pspec*/) -{ - SPGuide &guide = *SP_GUIDE(object); - - switch (prop_id) { - case PROP_COLOR: - guide.color = g_value_get_uint(value); - for (GSList *l = guide.views; l != NULL; l = l->next) { - sp_guideline_set_color(SP_GUIDELINE(l->data), guide.color); - } - break; +guint32 SPGuide::getColor() const { + return color; +} - case PROP_HICOLOR: - guide.hicolor = g_value_get_uint(value); - break; - } +guint32 SPGuide::getHiColor() const { + return hicolor; } -static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec */*pspec*/) -{ - SPGuide const &guide = *SP_GUIDE(object); +void SPGuide::setColor(guint32 c) { + color = c; - switch (prop_id) { - case PROP_COLOR: - g_value_set_uint(value, guide.color); - break; - case PROP_HICOLOR: - g_value_set_uint(value, guide.hicolor); - break; - } + for (GSList *l = this->views; l != NULL; l = l->next) { + sp_guideline_set_color(SP_GUIDELINE(l->data), this->color); + } } -static void sp_guide_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) (parent_class))->build) { - (* ((SPObjectClass *) (parent_class))->build)(object, document, repr); - } +void SPGuide::setHiColor(guint32 h) { + this->hicolor = h; +} - object->readAttr( "inkscape:label" ); - object->readAttr( "orientation" ); - object->readAttr( "position" ); +//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec */*pspec*/) +//{ +// SPGuide &guide = *SP_GUIDE(object); +// +// switch (prop_id) { +// case PROP_COLOR: +// guide.color = g_value_get_uint(value); +// for (GSList *l = guide.views; l != NULL; l = l->next) { +// sp_guideline_set_color(SP_GUIDELINE(l->data), guide.color); +// } +// break; +// +// case PROP_HICOLOR: +// guide.hicolor = g_value_get_uint(value); +// break; +// } +//} +// +//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec */*pspec*/) +//{ +// SPGuide const &guide = *SP_GUIDE(object); +// +// switch (prop_id) { +// case PROP_COLOR: +// g_value_set_uint(value, guide.color); +// break; +// case PROP_HICOLOR: +// g_value_set_uint(value, guide.hicolor); +// break; +// } +//} + +void SPGuide::build(SPDocument *document, Inkscape::XML::Node *repr) { + SPObject::build(document, repr); + + this->readAttr( "inkscape:label" ); + this->readAttr( "orientation" ); + this->readAttr( "position" ); /* Register */ - document->addResource("guide", object); + document->addResource("guide", this); } -static void sp_guide_release(SPObject *object) -{ - SPGuide *guide = (SPGuide *) object; - - while (guide->views) { - sp_guideline_delete(SP_GUIDELINE(guide->views->data)); - guide->views = g_slist_remove(guide->views, guide->views->data); +void SPGuide::release() { + while (this->views) { + sp_guideline_delete(SP_GUIDELINE(this->views->data)); + this->views = g_slist_remove(this->views, this->views->data); } - if (object->document) { + if (this->document) { // Unregister ourselves - object->document->removeResource("guide", object); + this->document->removeResource("guide", this); } - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); - } + SPObject::release(); } -static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) -{ - SPGuide *guide = SP_GUIDE(object); - +void SPGuide::set(unsigned int key, const gchar *value) { switch (key) { case SP_ATTR_INKSCAPE_LABEL: if (value) { - guide->label = g_strdup(value); + this->label = g_strdup(value); } else { - guide->label = NULL; + this->label = NULL; } - sp_guide_set_label(*guide, guide->label, false); + sp_guide_set_label(*this, this->label, false); break; case SP_ATTR_ORIENTATION: { if (value && !strcmp(value, "horizontal")) { /* Visual representation of a horizontal line, constrain vertically (y coordinate). */ - guide->normal_to_line = Geom::Point(0., 1.); + this->normal_to_line = Geom::Point(0., 1.); } else if (value && !strcmp(value, "vertical")) { - guide->normal_to_line = Geom::Point(1., 0.); + this->normal_to_line = Geom::Point(1., 0.); } else if (value) { gchar ** strarray = g_strsplit(value, ",", 2); double newx, newy; @@ -219,16 +207,16 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) if (success == 2 && (fabs(newx) > 1e-6 || fabs(newy) > 1e-6)) { Geom::Point direction(newx, newy); direction.normalize(); - guide->normal_to_line = direction; + this->normal_to_line = direction; } else { // default to vertical line for bad arguments - guide->normal_to_line = Geom::Point(1., 0.); + this->normal_to_line = Geom::Point(1., 0.); } } else { // default to vertical line for bad arguments - guide->normal_to_line = Geom::Point(1., 0.); + this->normal_to_line = Geom::Point(1., 0.); } - sp_guide_set_normal(*guide, guide->normal_to_line, false); + sp_guide_set_normal(*this, this->normal_to_line, false); } break; case SP_ATTR_POSITION: @@ -240,29 +228,27 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) success += sp_svg_number_read_d(strarray[1], &newy); g_strfreev (strarray); if (success == 2) { - guide->point_on_line = Geom::Point(newx, newy); + this->point_on_line = Geom::Point(newx, newy); } else if (success == 1) { // before 0.46 style guideline definition. - const gchar *attr = object->getRepr()->attribute("orientation"); + const gchar *attr = this->getRepr()->attribute("orientation"); if (attr && !strcmp(attr, "horizontal")) { - guide->point_on_line = Geom::Point(0, newx); + this->point_on_line = Geom::Point(0, newx); } else { - guide->point_on_line = Geom::Point(newx, 0); + this->point_on_line = Geom::Point(newx, 0); } } } else { // default to (0,0) for bad arguments - guide->point_on_line = Geom::Point(0,0); + this->point_on_line = Geom::Point(0,0); } // update position in non-committing way // fixme: perhaps we need to add an update method instead, and request_update here - sp_guide_moveto(*guide, guide->point_on_line, false); + sp_guide_moveto(*this, this->point_on_line, false); } break; default: - if (((SPObjectClass *) (parent_class))->set) { - ((SPObjectClass *) (parent_class))->set(object, key, value); - } + SPObject::set(key, value); break; } } @@ -301,14 +287,14 @@ sp_guide_create_guides_around_page(SPDesktop *dt) { std::list<std::pair<Geom::Point, Geom::Point> > pts; Geom::Point A(0, 0); - Geom::Point C(doc->getWidth(), doc->getHeight()); + Geom::Point C(doc->getWidth().value("px"), doc->getHeight().value("px")); Geom::Point B(C[Geom::X], 0); Geom::Point D(0, C[Geom::Y]); - pts.push_back(std::make_pair<Geom::Point, Geom::Point>(A, B)); - pts.push_back(std::make_pair<Geom::Point, Geom::Point>(B, C)); - pts.push_back(std::make_pair<Geom::Point, Geom::Point>(C, D)); - pts.push_back(std::make_pair<Geom::Point, Geom::Point>(D, A)); + pts.push_back(std::pair<Geom::Point, Geom::Point>(A, B)); + pts.push_back(std::pair<Geom::Point, Geom::Point>(B, C)); + pts.push_back(std::pair<Geom::Point, Geom::Point>(C, D)); + pts.push_back(std::pair<Geom::Point, Geom::Point>(D, A)); sp_guide_pt_pairs_to_guides(doc, pts); @@ -484,14 +470,14 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) char *descr = 0; if ( !guide->document ) { // Guide has probably been deleted and no longer has an attached namedview. - descr = g_strdup_printf(_("Deleted")); + descr = g_strdup_printf("%s", _("Deleted")); } else { SPNamedView *namedview = sp_document_namedview(guide->document, NULL); - GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], - namedview->getDefaultMetric()); - GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], - namedview->getDefaultMetric()); + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px"); + GString *position_string_x = g_string_new(x_q.string(namedview->doc_units).c_str()); + GString *position_string_y = g_string_new(y_q.string(namedview->doc_units).c_str()); gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete")); |
