Code

Fix for 181663 by The Adib. Yay for working Italics button on the toolbar!
[inkscape.git] / src / desktop.cpp
index 85c53be6fe91d8fe96de847cd4d2b85a1979384c..f7ef1a8cdb79c6d9a02d6a6aef7be6aaf58c5906 100644 (file)
@@ -104,7 +104,6 @@ static void _layer_hierarchy_changed(SPObject *top, SPObject *bottom, SPDesktop
 static void _reconstruction_start(SPDesktop * desktop);
 static void _reconstruction_finish(SPDesktop * desktop);
 static void _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop);
-static void _update_snap_distances (SPDesktop *desktop);
 
 /**
  * Return new desktop object.
@@ -149,7 +148,6 @@ SPDesktop::SPDesktop() :
     _layer_hierarchy( 0 ),
     _reconstruction_old_layer_id( 0 ),
     _display_mode(Inkscape::RENDERMODE_NORMAL),
-    _saved_display_mode(Inkscape::RENDERMODE_NORMAL),
     _widget( 0 ),
     _inkscape( 0 ),
     _guides_message_context( 0 ),
@@ -227,11 +225,18 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
         setDisplayModeNormal();
     }
 
+    // The order in which these canvas items are added determines the z-order. It's therefore
+    // important to add the tempgroup (which will contain the snapindicator) before adding the
+    // controls. Only this way one will be able to quickly (before the snap indicator has
+    // disappeared) reselect a node after snapping it. If the z-order is wrong however, this
+    // will not work (the snap indicator is on top of the node handler; is the snapindicator
+    // being selected? or does it intercept some of the events that should have gone to the
+    // node handler? see bug https://bugs.launchpad.net/inkscape/+bug/414142)
     gridgroup = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
     guides = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
     sketch = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
-    controls = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
     tempgroup = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
+    controls = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
 
     /* Push select tool to the bottom of stack */
     /** \todo
@@ -438,18 +443,21 @@ void SPDesktop::_setDisplayMode(Inkscape::RenderMode mode) {
     SP_CANVAS_ARENA (drawing)->arena->rendermode = mode;
     canvas->rendermode = mode;
     _display_mode = mode;
-    if (mode != Inkscape::RENDERMODE_OUTLINE) {
-        _saved_display_mode = _display_mode;
-    }
     sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (main), _d2w); // redraw
     _widget->setTitle(SP_DOCUMENT_NAME(sp_desktop_document(this)));
 }
 
 void SPDesktop::displayModeToggle() {
-    if (_display_mode == Inkscape::RENDERMODE_OUTLINE) {
-        _setDisplayMode(_saved_display_mode);
-    } else {
+    switch (_display_mode) {
+    case Inkscape::RENDERMODE_NORMAL:
+        _setDisplayMode(Inkscape::RENDERMODE_NO_FILTERS);
+        break;
+    case Inkscape::RENDERMODE_NO_FILTERS:
         _setDisplayMode(Inkscape::RENDERMODE_OUTLINE);
+        break;
+    case Inkscape::RENDERMODE_OUTLINE:
+    default:
+        _setDisplayMode(Inkscape::RENDERMODE_NORMAL);
     }
 }
 
@@ -869,7 +877,7 @@ SPDesktop::next_zoom()
     \param  enable  Whether we're going in or out of quick zoom
 
 */
-void 
+void
 SPDesktop::zoom_quick (bool enable)
 {
     if (enable == _quick_zoom_enabled) {
@@ -883,56 +891,57 @@ SPDesktop::zoom_quick (bool enable)
         if (!zoomed) {
             SPItem * singleItem = selection->singleItem();
             if (singleItem != NULL && tools_isactive(this, TOOLS_NODES)) {
-                SPNodeContext * ncontext = SP_NODE_CONTEXT(event_context);
 
-                Inkscape::NodePath::Path * nodepath = ncontext->shape_editor->get_nodepath();
+                Inkscape::NodePath::Path * nodepath = event_context->shape_editor->get_nodepath();
                 // printf("I've got a nodepath, crazy\n");
 
-                Geom::Rect nodes;
-                bool firstnode = true;
-
-                if (nodepath->selected) {
-                    for (GList *spl = nodepath->subpaths; spl != NULL; spl = spl->next) {
-                       Inkscape::NodePath::SubPath *subpath = (Inkscape::NodePath::SubPath *) spl->data;
-                        for (GList *nl = subpath->nodes; nl != NULL; nl = nl->next) {
-                           Inkscape::NodePath::Node *node = (Inkscape::NodePath::Node *) nl->data;
-                            if (node->selected) {
-                                // printf("\tSelected node\n");
-                                if (firstnode) {
-                                    nodes = Geom::Rect(node->pos, node->pos);
-                                    firstnode = false;
-                                } else {
-                                    nodes.expandTo(node->pos);
-                                }
-
-                                if (node->p.other != NULL) {
-                                    /* Include previous node pos */
-                                    nodes.expandTo(node->p.other->pos);
-
-                                    /* Include previous handle */
-                                    if (!sp_node_side_is_line(node, &node->p)) {
-                                        nodes.expandTo(node->p.pos);
-                                    }
-                                }
-
-                                if (node->n.other != NULL) {
-                                    /* Include previous node pos */
-                                    nodes.expandTo(node->n.other->pos);
-
-                                    /* Include previous handle */
-                                    if (!sp_node_side_is_line(node, &node->n)) {
-                                        nodes.expandTo(node->n.pos);
-                                    }
-                                }
-                            }
-                        }
-                    }
-
-                    if (!firstnode && nodes.area() * 2.0 < _quick_zoom_stored_area.area()) {
-                        set_display_area(nodes, 10);
-                        zoomed = true;
-                    }
-                }
+                               if (nodepath) {
+                                       Geom::Rect nodes;
+                                       bool firstnode = true;
+
+                                       if (nodepath->selected) {
+                                               for (GList *spl = nodepath->subpaths; spl != NULL; spl = spl->next) {
+                                                  Inkscape::NodePath::SubPath *subpath = (Inkscape::NodePath::SubPath *) spl->data;
+                                                       for (GList *nl = subpath->nodes; nl != NULL; nl = nl->next) {
+                                                          Inkscape::NodePath::Node *node = (Inkscape::NodePath::Node *) nl->data;
+                                                               if (node->selected) {
+                                                                       // printf("\tSelected node\n");
+                                                                       if (firstnode) {
+                                                                               nodes = Geom::Rect(node->pos, node->pos);
+                                                                               firstnode = false;
+                                                                       } else {
+                                                                               nodes.expandTo(node->pos);
+                                                                       }
+
+                                                                       if (node->p.other != NULL) {
+                                                                               /* Include previous node pos */
+                                                                               nodes.expandTo(node->p.other->pos);
+
+                                                                               /* Include previous handle */
+                                                                               if (!sp_node_side_is_line(node, &node->p)) {
+                                                                                       nodes.expandTo(node->p.pos);
+                                                                               }
+                                                                       }
+
+                                                                       if (node->n.other != NULL) {
+                                                                               /* Include previous node pos */
+                                                                               nodes.expandTo(node->n.other->pos);
+
+                                                                               /* Include previous handle */
+                                                                               if (!sp_node_side_is_line(node, &node->n)) {
+                                                                                       nodes.expandTo(node->n.pos);
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+
+                                               if (!firstnode && nodes.area() * 2.0 < _quick_zoom_stored_area.area()) {
+                                                       set_display_area(nodes, 10);
+                                                       zoomed = true;
+                                               }
+                                       }
+                               }
             }
         }
 
@@ -941,7 +950,7 @@ SPDesktop::zoom_quick (bool enable)
             if (d && d->area() * 2.0 < _quick_zoom_stored_area.area()) {
                 set_display_area(*d, 10);
                 zoomed = true;
-            } 
+            }
         }
 
         if (!zoomed) {
@@ -1326,7 +1335,7 @@ SPDesktop::shutdown()
 
 bool SPDesktop::onDeleteUI (GdkEventAny*)
 {
-    if(shutdown()) 
+    if(shutdown())
         return true;
 
     destroyWidget();
@@ -1449,7 +1458,7 @@ void SPDesktop::showGrids(bool show, bool dirty_document)
     }
 }
 
-void SPDesktop::toggleSnapping()
+void SPDesktop::toggleSnapGlobal()
 {
     bool v = namedview->snap_manager.snapprefs.getSnapEnabledGlobally();
     Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview);
@@ -1699,12 +1708,6 @@ _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop)
 
     if (flags & SP_OBJECT_MODIFIED_FLAG) {
 
-        /* Recalculate snap distances */
-        /* FIXME: why is the desktop getting involved in setting up something
-        ** that is entirely to do with the namedview?
-        */
-        _update_snap_distances (desktop);
-
         /* Show/hide page background */
         if (nv->pagecolor & 0xff) {
             sp_canvas_item_show (desktop->table);
@@ -1759,33 +1762,6 @@ _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop)
     }
 }
 
-/**
- * Callback to reset snapper's distances.
- */
-static void
-_update_snap_distances (SPDesktop *desktop)
-{
-    SPUnit const &px = sp_unit_get_by_id(SP_UNIT_PX);
-
-    SPNamedView &nv = *desktop->namedview;
-
-    //tell all grid snappers
-    for ( GSList const *l = nv.grids; l != NULL; l = l->next) {
-        Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data;
-        grid->snapper->setSnapperTolerance(sp_convert_distance_full(nv.gridtolerance,
-                                                                      *nv.gridtoleranceunit,
-                                                                      px));
-    }
-
-    nv.snap_manager.guide.setSnapperTolerance(sp_convert_distance_full(nv.guidetolerance,
-                                                                       *nv.guidetoleranceunit,
-                                                                       px));
-    nv.snap_manager.object.setSnapperTolerance(sp_convert_distance_full(nv.objecttolerance,
-                                                                        *nv.objecttoleranceunit,
-                                                                        px));
-}
-
-
 Geom::Matrix SPDesktop::w2d() const
 {
     return _w2d;