summaryrefslogtreecommitdiffstats
path: root/src/sp-guide.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp-guide.cpp')
-rw-r--r--src/sp-guide.cpp111
1 files changed, 76 insertions, 35 deletions
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 4e1c5913d..17a1a9ff1 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -26,6 +26,7 @@
#include "display/sp-canvas.h"
#include "display/guideline.h"
#include "svg/svg.h"
+#include "svg/svg-color.h"
#include "svg/stringstream.h"
#include "attributes.h"
#include "sp-guide.h"
@@ -42,6 +43,7 @@
#include <2geom/angle.h>
#include "document.h"
#include "document-undo.h"
+#include "helper-fns.h"
#include "verbs.h"
using Inkscape::DocumentUndo;
@@ -50,7 +52,7 @@ using std::vector;
SPGuide::SPGuide()
: SPObject()
, label(NULL)
- , views(NULL)
+ , locked(0)
, normal_to_line(Geom::Point(0.,1.))
, point_on_line(Geom::Point(0.,0.))
, color(0x0000ff7f)
@@ -61,8 +63,8 @@ void SPGuide::setColor(guint32 c)
{
color = c;
- for (GSList *l = this->views; l != NULL; l = l->next) {
- sp_guideline_set_color(SP_GUIDELINE(l->data), this->color);
+ for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ sp_guideline_set_color(*it, this->color);
}
}
@@ -70,7 +72,9 @@ void SPGuide::build(SPDocument *document, Inkscape::XML::Node *repr)
{
SPObject::build(document, repr);
+ this->readAttr( "inkscape:color" );
this->readAttr( "inkscape:label" );
+ this->readAttr( "inkscape:locked" );
this->readAttr( "orientation" );
this->readAttr( "position" );
@@ -80,10 +84,10 @@ void SPGuide::build(SPDocument *document, Inkscape::XML::Node *repr)
void SPGuide::release()
{
- while (this->views) {
- sp_guideline_delete(SP_GUIDELINE(this->views->data));
- this->views = g_slist_remove(this->views, this->views->data);
+ for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ sp_guideline_delete(*it);
}
+ this->views.clear();
if (this->document) {
// Unregister ourselves
@@ -95,9 +99,14 @@ void SPGuide::release()
void SPGuide::set(unsigned int key, const gchar *value) {
switch (key) {
+ case SP_ATTR_INKSCAPE_COLOR:
+ if (value) {
+ this->setColor(sp_svg_read_color(value, 0x0000ff00) | 0x7f);
+ }
+ break;
case SP_ATTR_INKSCAPE_LABEL:
- if (this->label) g_free(this->label);
-
+ // this->label already freed in sp_guideline_set_label (src/display/guideline.cpp)
+ // see bug #1498444, bug #1469514
if (value) {
this->label = g_strdup(value);
} else {
@@ -106,6 +115,12 @@ void SPGuide::set(unsigned int key, const gchar *value) {
this->set_label(this->label, false);
break;
+ case SP_ATTR_INKSCAPE_LOCKED:
+ this->locked = helperfns_read_bool(value, false);
+ if (value) {
+ this->set_locked(this->locked, false);
+ }
+ break;
case SP_ATTR_ORIENTATION:
{
if (value && !strcmp(value, "horizontal")) {
@@ -249,10 +264,11 @@ void sp_guide_create_guides_around_page(SPDesktop *dt)
void sp_guide_delete_all_guides(SPDesktop *dt)
{
SPDocument *doc=dt->getDocument();
- const GSList *current;
- while ( (current = doc->getResourceList("guide")) ) {
- SPGuide* guide = SP_GUIDE(current->data);
+ std::set<SPObject *> current = doc->getResourceList("guide");
+ while (!current.empty()){
+ SPGuide* guide = SP_GUIDE(*(current.begin()));
sp_guide_remove(guide);
+ current = doc->getResourceList("guide");
}
DocumentUndo::done(doc, SP_VERB_NONE, _("Delete All Guides"));
@@ -265,14 +281,19 @@ void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler)
g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this);
- views = g_slist_prepend(views, item);
+ views.push_back(SP_GUIDELINE(item));
}
void SPGuide::showSPGuide()
{
- for (GSList *v = views; v != NULL; v = v->next) {
- sp_canvas_item_show(SP_CANVAS_ITEM(v->data));
- sp_canvas_item_show(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin));
+ for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ sp_canvas_item_show(SP_CANVAS_ITEM(*it));
+ if((*it)->origin) {
+ sp_canvas_item_show(SP_CANVAS_ITEM((*it)->origin));
+ } else {
+ //reposition to same place to show knots
+ sp_guideline_set_position(*it, point_on_line);
+ }
}
}
@@ -280,11 +301,10 @@ void SPGuide::hideSPGuide(SPCanvas *canvas)
{
g_assert(canvas != NULL);
g_assert(SP_IS_CANVAS(canvas));
-
- for (GSList *l = views; l != NULL; l = l->next) {
- if (canvas == SP_CANVAS_ITEM(l->data)->canvas) {
- sp_guideline_delete(SP_GUIDELINE(l->data));
- views = g_slist_remove(views, l->data);
+ for(std::vector<SPGuideLine *>::iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ if (canvas == SP_CANVAS_ITEM(*it)->canvas) {
+ sp_guideline_delete(*it);
+ views.erase(it);
return;
}
}
@@ -294,9 +314,11 @@ void SPGuide::hideSPGuide(SPCanvas *canvas)
void SPGuide::hideSPGuide()
{
- for (GSList *v = views; v != NULL; v = v->next) {
- sp_canvas_item_hide(SP_CANVAS_ITEM(v->data));
- sp_canvas_item_hide(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin));
+ for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ sp_canvas_item_hide(SP_CANVAS_ITEM(*it));
+ if ((*it)->origin) {
+ sp_canvas_item_hide(SP_CANVAS_ITEM((*it)->origin));
+ }
}
}
@@ -305,9 +327,9 @@ void SPGuide::sensitize(SPCanvas *canvas, bool sensitive)
g_assert(canvas != NULL);
g_assert(SP_IS_CANVAS(canvas));
- for (GSList *l = views; l != NULL; l = l->next) {
- if (canvas == SP_CANVAS_ITEM(l->data)->canvas) {
- sp_guideline_set_sensitive(SP_GUIDELINE(l->data), sensitive);
+ for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ if (canvas == SP_CANVAS_ITEM(*it)->canvas) {
+ sp_guideline_set_sensitive(*it, sensitive);
return;
}
}
@@ -332,8 +354,11 @@ double SPGuide::getDistanceFrom(Geom::Point const &pt) const
*/
void SPGuide::moveto(Geom::Point const point_on_line, bool const commit)
{
- for (GSList *l = views; l != NULL; l = l->next) {
- sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line);
+ if(this->locked) {
+ return;
+ }
+ for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ sp_guideline_set_position(*it, point_on_line);
}
/* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit
@@ -378,8 +403,11 @@ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit)
*/
void SPGuide::set_normal(Geom::Point const normal_to_line, bool const commit)
{
- for (GSList *l = this->views; l != NULL; l = l->next) {
- sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line);
+ if(this->locked) {
+ return;
+ }
+ for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) {
+ sp_guideline_set_normal(*it, normal_to_line);
}
/* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit
@@ -404,8 +432,8 @@ void SPGuide::set_color(const unsigned r, const unsigned g, const unsigned b, bo
{
this->color = (r << 24) | (g << 16) | (b << 8) | 0x7f;
- if (views) {
- sp_guideline_set_color(SP_GUIDELINE(views->data), this->color);
+ if (! views.empty()) {
+ sp_guideline_set_color(views[0], this->color);
}
if (commit) {
@@ -416,10 +444,22 @@ void SPGuide::set_color(const unsigned r, const unsigned g, const unsigned b, bo
}
}
+void SPGuide::set_locked(const bool locked, bool const commit)
+{
+ this->locked = locked;
+ if ( !views.empty() ) {
+ sp_guideline_set_locked(views[0], locked);
+ }
+
+ if (commit) {
+ getRepr()->setAttribute("inkscape:locked", g_strdup(locked ? "true" : "false"));
+ }
+}
+
void SPGuide::set_label(const char* label, bool const commit)
{
- if (views) {
- sp_guideline_set_label(SP_GUIDELINE(views->data), label);
+ if (!views.empty()) {
+ sp_guideline_set_label(views[0], label);
}
if (commit) {
@@ -461,7 +501,7 @@ char* SPGuide::description(bool const verbose) const
descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str);
} else {
double const radians = this->angle();
- double const degrees = Geom::rad_to_deg(radians);
+ double const degrees = Geom::deg_from_rad(radians);
int const degrees_int = (int) round(degrees);
descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"),
degrees_int, position_string_x->str, position_string_y->str);
@@ -475,6 +515,7 @@ char* SPGuide::description(bool const verbose) const
descr = g_strconcat(oldDescr, shortcuts, NULL);
g_free(oldDescr);
}
+
g_free(shortcuts);
}