Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-namedview.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * <sodipodi:namedview> implementation
4 *
5 * Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * bulia byak <buliabyak@users.sf.net>
8 * Jon A. Cruz <jon@joncruz.org>
9 * Abhishek Sharma
10 *
11 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
12 * Copyright (C) 1999-2013 Authors
13 * Copyright (C) 2000-2001 Ximian, Inc.
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#include "sp-namedview.h"
19
20#include <cstring>
21#include <string>
22
23#include <2geom/transforms.h>
24
25#include <gtkmm/window.h>
26
27#include "attributes.h"
28#include "colors/manager.h"
29#include "conn-avoid-ref.h" // for defaultConnSpacing.
30#include "desktop.h"
31#include "document-undo.h"
32#include "document.h"
33#include "enums.h"
34#include "event-log.h"
35#include "inkscape-window.h"
36#include "layer-manager.h"
37#include "page-manager.h"
38#include "preferences.h"
39#include "sp-guide.h"
40#include "sp-grid.h"
41#include "sp-page.h"
42#include "sp-item-group.h"
43#include "sp-root.h"
44
47#include "ui/monitor.h"
48#include "ui/widget/canvas.h"
51#include "util/units.h"
52
55
57 snap_manager(this, get_snapping_preferences()),
58 _viewport{new Inkscape::CanvasPage()}
59{
61
62 _viewport->hide();
63}
64
67
70
111
112 /* Construct guideline and pages list */
113 for (auto &child : children) {
114 if (auto guide = cast<SPGuide>(&child)) {
115 guides.push_back(guide);
116 guide->setColor(getGuideColor().toRGBA());
117 guide->setHiColor(getGuideHiColor().toRGBA());
118 guide->readAttr(SPAttr::INKSCAPE_COLOR);
119 }
120 if (auto page = cast<SPPage>(&child)) {
122 }
123 if (auto grid = cast<SPGrid>(&child)) {
124 grids.emplace_back(grid);
125 }
126 }
127}
128
130 guides.clear();
131 grids.clear();
132
134}
135
137 if (desktop) {
139 }
140}
141
142static auto const default_desk_color = Inkscape::Colors::Color{0xd1d1d1, false};
143static auto const default_guide_color = Inkscape::Colors::Color{0x0086e5, false};
144static auto const default_guide_hi_color = Inkscape::Colors::Color{0xff0000, false};
145
150
152{
153 auto copy = _guide_color.value_or(default_guide_color);
154 copy.addOpacity(_guide_opacity);
155 return copy;
156}
157
159{
160 auto copy = _guide_hi_color.value_or(default_guide_hi_color);
161 copy.addOpacity(_guide_hi_opacity);
162 return copy;
163}
164
166 if (desktop) {
167 auto dkcolor = getDeskColor();
168 dkcolor.setOpacity(desk_checkerboard ? 0.0 : 1.0);
169 desktop->getCanvas()->set_desk(dkcolor.toRGBA());
170 // Update pages, whose colours sometimes change whe the desk color changes.
172 }
173}
174
175void SPNamedView::modified(unsigned int flags)
176{
177 // Copy the page style for the default viewport attributes
178 auto &page_manager = document->getPageManager();
179 if (flags & SP_OBJECT_MODIFIED_FLAG) {
180 page_manager.setDefaultAttributes(_viewport.get());
182 // Pass modifications to the page manager to update the page items.
183 for (auto &page : page_manager.getPages()) {
184 page->setDefaultAttributes();
185 }
186 // Update unit action group
187 auto action = document->getActionGroup()->lookup_action("set-display-unit");
188 if (auto saction = std::dynamic_pointer_cast<Gio::SimpleAction>(action)) {
189 Glib::VariantType String(Glib::VARIANT_TYPE_STRING);
190 saction->change_state(getDisplayUnit()->abbr);
191 }
192
193 updateGuides();
194 }
195 // Add desk color and checkerboard pattern to desk view
196 for (auto desktop : views) {
199 if (desktop) {
201 }
202 }
203
204 for (auto child : childList(false)) {
205 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
206 child->emitModified(flags & SP_OBJECT_MODIFIED_CASCADE);
207 }
208 }
209}
210
214void SPNamedView::update(SPCtx *ctx, guint flags)
215{
216 if (flags & SP_OBJECT_MODIFIED_FLAG) {
217 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
218 }
219
220 flags &= SP_OBJECT_MODIFIED_CASCADE;
221
222 for (auto child : childList(false)) {
223 if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
224 child->updateDisplay(ctx, flags);
225 }
226 }
227}
228
230 /* The default display unit if the document doesn't override this: e.g. for files saved as
231 * `plain SVG', or non-inkscape files, or files created by an inkscape 0.40 &
232 * earlier.
233 *
234 * Note that these units are not the same as the units used for the values in SVG!
235 *
236 * We default to `px'.
237 */
238 auto const &unit_table = UnitTable::get();
239 auto new_unit = unit_table.getUnit("px");
240
241 if (value) {
242 Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value);
243 if ( !unit_table.hasUnit(value) ) {
244 g_warning("Unrecognized unit `%s'", value);
245 /* fixme: Document errors should be reported in the status bar or
246 * the like (e.g. as per
247 * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
248 * should be only for programmer errors. */
249 } else if ( req_unit->isAbsolute() ) {
250 new_unit = req_unit;
251 } else {
252 g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'", value);
253 /* fixme: Don't use g_log (see above). */
254 }
255 }
256
257 return new_unit;
258}
259
260void SPNamedView::set(SPAttr key, const gchar* value) {
261 // Send page attributes to the page manager.
262 if (document->getPageManager().subset(key, value)) {
263 requestModified(SP_OBJECT_MODIFIED_FLAG);
264 return;
265 }
266
267 auto update_guides = [this]() {
268 for(auto guide : guides) {
269 guide->setColor(getGuideColor().toRGBA());
270 guide->setHiColor(getGuideHiColor().toRGBA());
271 guide->readAttr(SPAttr::INKSCAPE_COLOR);
272 }
273 };
274
275 switch (key) {
276 case SPAttr::VIEWONLY:
277 editable = (!value);
278 break;
280 showguides.readOrUnset(value);
281 break;
283 lockguides.readOrUnset(value);
284 break;
287 updateGrids();
288 break;
290 snap_manager.snapprefs.setGridTolerance(value ? g_ascii_strtod(value, nullptr) : 10);
291 break;
293 snap_manager.snapprefs.setGuideTolerance(value ? g_ascii_strtod(value, nullptr) : 20);
294 break;
296 snap_manager.snapprefs.setObjectTolerance(value ? g_ascii_strtod(value, nullptr) : 20);
297 break;
299 snap_manager.snapprefs.setAlignementTolerance(value ? g_ascii_strtod(value, nullptr) : 5);
300 break;
302 snap_manager.snapprefs.setDistributionTolerance(value ? g_ascii_strtod(value, nullptr) : 5);
303 break;
305 _guide_color = Inkscape::Colors::Color::parse(value);
306 update_guides();
307 break;
309 _guide_opacity = value ? g_ascii_strtod(value, nullptr) : 0.6;
310 update_guides();
311 break;
313 _guide_hi_color = Inkscape::Colors::Color::parse(value);
314 update_guides();
315 break;
317 _guide_hi_opacity = value ? g_ascii_strtod(value, nullptr) : 0.5;
318 update_guides();
319 break;
321 _desk_color = Inkscape::Colors::Color::parse(value);
322 break;
325 break;
327 zoom = value ? g_ascii_strtod(value, nullptr) : 0; // zero means not set
328 break;
330 rotation = value ? g_ascii_strtod(value, nullptr) : 0; // zero means not set
331 break;
333 cx = value ? g_ascii_strtod(value, nullptr) : HUGE_VAL; // HUGE_VAL means not set
334 break;
336 cy = value ? g_ascii_strtod(value, nullptr) : HUGE_VAL; // HUGE_VAL means not set
337 break;
339 window_width = value? atoi(value) : -1; // -1 means not set
340 break;
342 window_height = value ? atoi(value) : -1; // -1 means not set
343 break;
345 window_x = value ? atoi(value) : 0;
346 break;
348 window_y = value ? atoi(value) : 0;
349 break;
351 window_maximized = value ? atoi(value) : 0;
352 break;
354 default_layer_id = value ? g_quark_from_string(value) : 0;
355 break;
357 connector_spacing = value ? g_ascii_strtod(value, nullptr) : defaultConnSpacing;
358 break;
361 break;
364 break;
367 break;
368 /*
369 case SPAttr::UNITS: {
370 // Only used in "Custom size" section of Document Properties dialog
371 Inkscape::Util::Unit const *new_unit = nullptr;
372
373 if (value) {
374 Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value);
375 if ( !unit_table.hasUnit(value) ) {
376 g_warning("Unrecognized unit `%s'", value);
377 / * fixme: Document errors should be reported in the status bar or
378 * the like (e.g. as per
379 * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
380 * should be only for programmer errors. * /
381 } else if ( req_unit->isAbsolute() ) {
382 new_unit = req_unit;
383 } else {
384 g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",
385 value);
386 / * fixme: Don't use g_log (see above). * /
387 }
388 }
389 this->page_size_units = new_unit;
390 break;
391 } */
394 break;
397 break;
398 default:
399 SPObjectGroup::set(key, value);
400 return;
401 }
402
403 requestModified(SP_OBJECT_MODIFIED_FLAG);
404}
405
411{
412 auto box = document->preferredBounds();
413 if (auto page = document->getPageManager().getPageAt(box->corner(0))) {
414 // An existing page is set as the main page, so hide th viewport canvas item.
415 _viewport->hide();
416 // This means the page is in the middle of being moved, so please don't move.
417 if (page->isViewportPage()) {
418 page->setDesktopRect(*box);
419 }
420 } else {
421 // Otherwise we are showing the viewport item.
422 _viewport->show();
423 _viewport->update(*box, {}, {}, nullptr, document->getPageManager().hasPages(), document->is_yaxisdown());
424 }
425}
426
429
431 if (!no)
432 return;
433
434 if (auto grid = cast<SPGrid>(no)) {
435 grids.emplace_back(grid);
436 for (auto view : views) {
437 grid->show(view);
438 }
439 } else if (!strcmp(child->name(), "inkscape:page")) {
440 if (auto page = cast<SPPage>(no)) {
442 for (auto view : views) {
443 page->showPage(view->getCanvasPagesBg(), view->getCanvasPagesFg());
444 }
445 }
446 } else {
447 if (auto g = cast<SPGuide>(no)) {
448 guides.push_back(g);
449
450 //g_object_set(G_OBJECT(g), "color", this->guidecolor, "hicolor", this->guidehicolor, NULL);
451 g->setColor(getGuideColor().toRGBA());
452 g->setHiColor(getGuideHiColor().toRGBA());
453 g->readAttr(SPAttr::INKSCAPE_COLOR);
454
455 if (editable) {
456 for(auto view : views) {
457 g->SPGuide::showSPGuide(view->getCanvasGuides());
458
459 if (view->guides_active) {
460 g->sensitize(view->getCanvas(), TRUE);
461 }
462
464 }
465 }
466 }
467 }
468}
469
471 if (!strcmp(child->name(), "inkscape:page")) {
473 } else if (!strcmp(child->name(), "inkscape:grid")) {
474 for (auto it = grids.begin(); it != grids.end(); ++it) {
475 auto grid = *it;
476 if (grid->getRepr() == child) {
477 for (auto view : views) {
478 grid->hide(view);
479 }
480 grids.erase(it);
481 break;
482 }
483 }
484 } else {
485 for (auto it = guides.begin(); it != guides.end(); ++it) {
486 if ((*it)->getRepr() == child) {
487 guides.erase(it);
488 break;
489 }
490 }
491 }
492
494}
495
497 Inkscape::XML::Node *new_repr)
498{
499 SPObjectGroup::order_changed(child, old_repr, new_repr);
500 if (!strcmp(child->name(), "inkscape:page")) {
502 }
503}
504
506 if ( ( flags & SP_OBJECT_WRITE_EXT ) &&
507 repr != this->getRepr() )
508 {
509 if (repr) {
510 repr->mergeFrom(this->getRepr(), "id");
511 } else {
512 repr = this->getRepr()->duplicate(xml_doc);
513 }
514 }
515
516 return repr;
517}
518
520{
521 for (auto guide : guides) {
522 guide->showSPGuide( desktop->getCanvasGuides() );
523
524 if (desktop->guides_active) {
525 guide->sensitize(desktop->getCanvas(), TRUE);
526 }
527 setShowGuideSingle(guide);
528 }
529
530 for (auto grid : grids) {
531 grid->show(desktop);
532 }
533
534 auto box = document->preferredBounds();
538
539 for (auto page : document->getPageManager().getPages()) {
541 }
542
543 views.push_back(desktop);
544}
545
546/*
547 * Restores window geometry from the document settings or defaults in prefs
548 */
550{
553 int window_geometry = prefs->getInt("/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_NONE);
554 int default_size = prefs->getInt("/options/defaultwindowsize/value", PREFS_WINDOW_SIZE_NATURAL);
555 bool new_document = (nv->window_width <= 0) || (nv->window_height <= 0);
556
557 // restore window size and position stored with the document
558 auto win = desktop->getInkscapeWindow();
559 g_assert(win);
560
561 if (window_geometry == PREFS_WINDOW_GEOMETRY_LAST) {
562 gint pw = prefs->getInt("/desktop/geometry/width", -1);
563 gint ph = prefs->getInt("/desktop/geometry/height", -1);
564 gint px = prefs->getInt("/desktop/geometry/x", -1);
565 gint py = prefs->getInt("/desktop/geometry/y", -1);
566 gint full = prefs->getBool("/desktop/geometry/fullscreen");
567 gint maxed = prefs->getBool("/desktop/geometry/maximized");
568 if (pw>0 && ph>0) {
569
570 Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_at_point(px, py);
571 pw = std::min(pw, monitor_geometry.get_width());
572 ph = std::min(ph, monitor_geometry.get_height());
573 desktop->setWindowSize({pw, ph});
574 }
575 if (maxed) {
576 win->maximize();
577 }
578 if (full) {
579 win->fullscreen();
580 }
581 } else if ((window_geometry == PREFS_WINDOW_GEOMETRY_FILE && nv->window_maximized) ||
582 ((new_document || window_geometry == PREFS_WINDOW_GEOMETRY_NONE) &&
583 default_size == PREFS_WINDOW_SIZE_MAXIMIZED)) {
584 win->maximize();
585 } else {
586 const int MIN_WINDOW_SIZE = 600;
587
588 int w = prefs->getInt("/template/base/inkscape:window-width", 0);
589 int h = prefs->getInt("/template/base/inkscape:window-height", 0);
590 bool move_to_screen = false;
591 if (window_geometry == PREFS_WINDOW_GEOMETRY_FILE && !new_document) {
592 Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_at_point(nv->window_x, nv->window_y);
593 w = MIN(monitor_geometry.get_width(), nv->window_width);
594 h = MIN(monitor_geometry.get_height(), nv->window_height);
595 move_to_screen = true;
596 } else if (default_size == PREFS_WINDOW_SIZE_LARGE) {
597 Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_at_surface(win->get_surface());
598 w = MAX(0.75 * monitor_geometry.get_width(), MIN_WINDOW_SIZE);
599 h = MAX(0.75 * monitor_geometry.get_height(), MIN_WINDOW_SIZE);
600 } else if (default_size == PREFS_WINDOW_SIZE_SMALL) {
601 w = h = MIN_WINDOW_SIZE;
602 } else if (default_size == PREFS_WINDOW_SIZE_NATURAL) {
603 // don't set size (i.e. keep the gtk+ default, which will be the natural size)
604 w = h = 0;
605 // unless gtk+ decided it would be a good idea to show a window that is larger than the screen
606 Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_at_surface(win->get_surface());
607 int monitor_width = monitor_geometry.get_width();
608 int monitor_height = monitor_geometry.get_height();
609 int window_width = win->get_width();
610 int window_height = win->get_height();
611 if (window_width > monitor_width || window_height > monitor_height) {
612 w = std::min(monitor_width, window_width);
613 h = std::min(monitor_height, window_height);
614 }
615 }
616 if (w > 0 && h > 0) {
617 desktop->setWindowSize({w, h});
618 }
619 }
620
621 // Cancel any history of transforms up to this point (must be before call to zoom).
623}
624
625/*
626 * Restores zoom and view from the document settings
627 */
629{
631 if (nv->zoom != 0 && nv->zoom != HUGE_VAL && !std::isnan(nv->zoom)
632 && nv->cx != HUGE_VAL && !std::isnan(nv->cx)
633 && nv->cy != HUGE_VAL && !std::isnan(nv->cy)) {
634 desktop->zoom_absolute( Geom::Point(nv->cx, nv->cy), nv->zoom, false );
635 } else if (auto document = desktop->getDocument()) {
636 // document without saved zoom, zoom to its page
637 document->getPageManager().zoomToSelectedPage(desktop);
638 }
639 if (nv->rotation != 0 && nv->rotation != HUGE_VAL && !std::isnan(nv->rotation)) {
640 Geom::Point p;
641 if (nv->cx != HUGE_VAL && !std::isnan(nv->cx) && nv->cy != HUGE_VAL && !std::isnan(nv->cy)) {
642 p = Geom::Point(nv->cx, nv->cy);
643 }else{
644 p = desktop->current_center();
645 }
646 desktop->rotate_absolute_keep_point(p, nv->rotation * M_PI / 180.0);
647 }
648}
649
651{
652 SPObject *layer = nullptr;
653 SPDocument *document = desktop->doc();
655 if ( nv->default_layer_id != 0 ) {
656 layer = document->getObjectById(g_quark_to_string(nv->default_layer_id));
657 }
658 // don't use that object if it's not at least group
659 if ( !layer || !is<SPGroup>(layer) ) {
660 layer = nullptr;
661 }
662 // if that didn't work out, look for the topmost layer
663 if (!layer) {
664 for (auto& iter: document->getRoot()->children) {
665 if (desktop->layerManager().isLayer(&iter)) {
666 layer = &iter;
667 }
668 }
669 }
670 if (layer) {
672 }
673
674 // FIXME: find a better place to do this
675 document->get_event_log()->updateUndoVerbs();
676}
677
679{
681 int window_geometry = prefs->getInt("/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_NONE);
682 bool save_geometry_in_file = window_geometry == PREFS_WINDOW_GEOMETRY_FILE;
683 bool save_viewport_in_file = prefs->getBool("/options/savedocviewport/value", true);
685
686 // saving window geometry is not undoable
687 DocumentUndo::ScopedInsensitive _no_undo(desktop->getDocument());
688
689 if (save_viewport_in_file) {
690 view->setAttributeSvgDouble("inkscape:zoom", desktop->current_zoom());
691 double rotation = std::round(Geom::deg_from_rad(desktop->current_rotation().angle()));
692 view->setAttributeSvgNonDefaultDouble("inkscape:rotation", rotation, 0.0);
694 view->setAttributeSvgDouble("inkscape:cx", center.x());
695 view->setAttributeSvgDouble("inkscape:cy", center.y());
696 }
697
698 if (save_geometry_in_file) {
699 auto const [w, h] = desktop->getWindowSize();
700 view->setAttributeInt("inkscape:window-width", w);
701 view->setAttributeInt("inkscape:window-height", h);
702 view->setAttributeInt("inkscape:window-maximized", desktop->is_maximized());
703 }
704
705 view->setAttribute("inkscape:current-layer", desktop->layerManager().currentLayer()->getId());
706}
707
709{
710 g_assert(desktop != nullptr);
711 g_assert(std::find(views.begin(),views.end(),desktop)!=views.end());
712 for (auto guide : guides) {
713 guide->hideSPGuide(desktop->getCanvas());
714 }
715 for (auto grid : grids) {
716 grid->hide(desktop);
717 }
718 _viewport->remove(desktop->getCanvas());
719 for (auto page : document->getPageManager().getPages()) {
720 page->hidePage(desktop->getCanvas());
721 }
722 views.erase(std::remove(views.begin(),views.end(),desktop),views.end());
723}
724
732void SPNamedView::setDefaultAttribute(std::string attribute, std::string preference, std::string fallback)
733{
734 if (!getAttribute(attribute.c_str())) {
735 std::string value = "";
736 if (!preference.empty()) {
737 value = Preferences::get()->getString(preference);
738 }
739 if (value.empty() && !fallback.empty()) {
740 value = fallback;
741 }
742 if (!value.empty()) {
743 setAttribute(attribute, value);
744 }
745 }
746}
747
748void SPNamedView::activateGuides(void* desktop, bool active)
749{
750 g_assert(desktop != nullptr);
751 g_assert(std::find(views.begin(),views.end(),desktop)!=views.end());
752
753 SPDesktop *dt = static_cast<SPDesktop*>(desktop);
754 for(auto & guide : guides) {
755 guide->sensitize(dt->getCanvas(), active);
756 }
757}
758
759gchar const *SPNamedView::getName() const
760{
761 return getAttribute("id");
762}
763
764std::vector<SPDesktop *> const SPNamedView::getViewList() const
765{
766 return views;
767}
768
773
778
783
785{
786 {
788
789 if (v && grids.empty())
791
792 getRepr()->setAttributeBoolean("showgrid", v);
793 }
794 requestModified(SP_OBJECT_MODIFIED_FLAG);
795}
796
798{
799 return grids_visible;
800}
801
803{
804 if (auto repr = getRepr()) {
805 {
807 repr->setAttributeBoolean("showguides", v);
808 }
809 requestModified(SP_OBJECT_MODIFIED_FLAG);
810 }
811}
812
814{
815 if (auto repr = getRepr()) {
816 {
818 repr->setAttributeBoolean("inkscape:lockguides", v);
819 }
820 requestModified(SP_OBJECT_MODIFIED_FLAG);
821 }
822}
823
825{
826 if (getShowGuides())
827 guide->showSPGuide();
828 else
829 guide->hideSPGuide();
830}
831
833{
834 if (auto repr = getRepr()) {
835 // show guides if not specified, for backwards compatibility
836 return repr->getAttributeBoolean("showguides", true);
837 }
838
839 return false;
840}
841
843{
844 if (auto repr = getRepr()) {
845 return repr->getAttributeBoolean("inkscape:lockguides");
846 }
847
848 return false;
849}
850
852 if (grids_visible) return;
853
854 _sync_grids = false;
855 setShowGrids(true);
856 _sync_grids = true;
857}
858
860{
861 if (auto saction = std::dynamic_pointer_cast<Gio::SimpleAction>(
862 document->getActionGroup()->lookup_action("show-grids"))) {
863
864 saction->change_state(getShowGrids());
865 }
866 if (_sync_grids) {
868 for (auto grid : grids) {
869 grid->setVisible(getShowGrids());
870 }
871 }
872}
873
875{
876 bool const shown = getShowGuides();
877 bool const locked = getLockGuides();
878
879 if (auto saction = std::dynamic_pointer_cast<Gio::SimpleAction>(
880 document->getActionGroup()->lookup_action("show-all-guides")))
881 {
882 saction->set_state(Glib::Variant<bool>::create(shown));
883 }
884
885 if (auto saction = std::dynamic_pointer_cast<Gio::SimpleAction>(
886 document->getActionGroup()->lookup_action("lock-all-guides")))
887 {
888 saction->set_state(Glib::Variant<bool>::create(locked));
889 }
890
891 for (auto guide : guides) {
892 setShowGuideSingle(guide);
893 guide->set_locked(locked, true);
894 }
895}
896
902{
903 return display_units ? display_units : UnitTable::get().getUnit("px");
904}
905
909void SPNamedView::setDisplayUnit(std::string unit)
910{
911 setDisplayUnit(UnitTable::get().getUnit(unit));
912}
913
915{
916 // If this is unset, it will be returned as px by getDisplayUnit
917 display_units = unit;
918 getRepr()->setAttributeOrRemoveIfEmpty("inkscape:document-units",
919 unit ? unit->abbr.c_str() : nullptr);
920}
921
926{
927 for (auto grid : grids) {
928 if (grid->isEnabled())
929 return grid;
930 }
931
932 return nullptr;
933}
934
936 for(auto & it : guides) {
937 SPGuide &guide = *it;
938 Geom::Point point_on_line = guide.getPoint();
939 point_on_line *= tr;
940 guide.moveto(point_on_line, true);
941 }
942}
943
946 for (auto grid : grids) {
947 grid->setOrigin( grid->getOrigin() * scale * tr * scale.inverse());
948 }
949}
950
951void SPNamedView::scrollAllDesktops(double dx, double dy) {
952 for(auto & view : views) {
953 view->scroll_relative_in_svg_coords(dx, dy);
954 }
955}
956
957void SPNamedView::change_color(SPAttr color_key, SPAttr opacity_key, Inkscape::Colors::Color const &color) {
958 if (color.hasOpacity())
960 getRepr()->setAttribute(sp_attribute_name(color_key), color.toString(false));
961}
962
964 const char* str_value = nullptr;
966 str_value = value ? "auto" : "crispEdges";
967 } else if (key == SPAttr::PAGELABELSTYLE) {
968 str_value = value ? "below" : "default";
969 } else {
970 str_value = value ? "true" : "false";
971 }
973}
974
975// show/hide guide lines without modifying view; used to quickly and temporarily hide them and restore them
977 // hide grid and guides
978 for (auto guide : guides) {
979 show ? guide->showSPGuide() : guide->hideSPGuide();
980 }
981
982 // hide page margin and bleed lines
983 for (auto page : document->getPageManager().getPages()) {
984 page->set_guides_visible(show);
985 }
986}
987
989 if (auto repr = getRepr()) {
990 repr->setAttributeBoolean("origin-correction", on);
991 requestModified(SP_OBJECT_MODIFIED_FLAG);
992 }
993}
994
996 if (auto repr = getRepr()) {
997 repr->setAttributeBoolean("y-axis-down", down);
998 requestModified(SP_OBJECT_MODIFIED_FLAG);
999 }
1000}
1001
1003 for (auto guide : guides) {
1004 guide->fix_orientation();
1005 }
1006}
1007
1008/*
1009 Local Variables:
1010 mode:c++
1011 c-file-style:"stroustrup"
1012 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1013 indent-tabs-mode:nil
1014 fill-column:99
1015 End:
1016*/
1017// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
double scale
Definition aa.cpp:228
SnapPreferences & get_snapping_preferences()
gchar const * sp_attribute_name(SPAttr id)
Get attribute name by id.
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
@ INKSCAPE_WINDOW_X
@ INKSCAPE_DOCUMENT_UNITS
@ INKSCAPE_WINDOW_Y
@ INKSCAPE_DESK_COLOR
@ BORDERCOLOR
@ INKSCAPE_CONNECTOR_SPACING
@ GUIDEHICOLOR
@ INKSCAPE_ANTIALIAS_RENDERING
@ ALIGNMENTTOLERANCE
@ OBJECTTOLERANCE
@ INKSCAPE_DESK_CHECKERBOARD
@ GUIDEOPACITY
@ SHOWPAGESHADOW
@ INKSCAPE_CY
@ BORDEROPACITY
@ GUIDETOLERANCE
@ INKSCAPE_LOCKGUIDES
@ INKSCAPE_WINDOW_HEIGHT
@ SHOWGUIDES
@ SHAPE_RENDERING
@ DISTRIBUTIONTOLERANCE
@ INKSCAPE_ZOOM
@ INKSCAPE_CLIP_TO_PAGE_RENDERING
@ INKSCAPE_COLOR
@ SHOWBORDER
@ GRIDTOLERANCE
@ BORDERLAYER
@ INKSCAPE_CX
@ INKSCAPE_WINDOW_MAXIMIZED
@ INKSCAPE_Y_AXIS_DOWN
@ INKSCAPE_ROTATION
@ INKSCAPE_WINDOW_WIDTH
@ PAGELABELSTYLE
@ GUIDECOLOR
@ INKSCAPE_PAGESHADOW
@ GUIDEHIOPACITY
@ INKSCAPE_ORIGIN_CORRECTION
@ INKSCAPE_CURRENT_LAYER
Rewrite of code originally in desktop-widget.cpp.
uint64_t page
Definition canvas.cpp:171
Inkscape canvas widget.
Two-dimensional point that doubles as a vector.
Definition point.h:66
constexpr Coord y() const noexcept
Definition point.h:106
constexpr Coord x() const noexcept
Definition point.h:104
Coord angle() const
Definition transforms.h:204
Translation by a vector.
Definition transforms.h:115
std::string toString(bool opacity=true) const
Format the color as a css string and return it.
Definition color.cpp:106
bool hasOpacity() const
Returns true if there is an opacity channel in this color.
Definition color.cpp:398
double getOpacity() const
Get the opacity in this color, if it's stored.
Definition color.cpp:407
RAII-style mechanism for creating a temporary undo-insensitive context.
void setCurrentLayer(SPObject *object, bool clear=false)
Sets the current layer of the desktop.
SPGroup * currentLayer() const
Returns current top layer.
bool isLayer(SPObject *object) const
True if object is a layer.
bool setDefaultAttributes(CanvasPage *item)
Update the canvas item with the default display attributes.
void reorderPage(Inkscape::XML::Node *child)
Reorder page within the internal list to keep it up to date.
void addPage(SPPage *page)
Add a page to this manager, called from namedview parent.
bool subset(SPAttr key, const gchar *value)
Manage the page subset of attributes from sp-namedview and store them.
const std::vector< SPPage * > & getPages() const
SPPage * getPageAt(Geom::Point pos) const
Get a page at a specific starting location.
void removePage(Inkscape::XML::Node *child)
Remove a page from this manager, called from namedview parent.
Preference storage class.
Definition preferences.h:66
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
static Preferences * get()
Access the singleton Preferences object.
int getInt(Glib::ustring const &pref_path, int def=0)
Retrieve an integer.
void setGridTolerance(double val)
void setObjectTolerance(double val)
void setGuideTolerance(double val)
void setAlignementTolerance(double val)
void setDistributionTolerance(double val)
void set_antialiasing_enabled(bool enabled)
Definition canvas.cpp:1782
void set_clip_to_page_mode(bool clip)
Definition canvas.cpp:1790
void set_desk(uint32_t rgba)
Set the desk colour.
Definition canvas.cpp:1723
static UnitTable & get()
Definition units.cpp:441
bool isAbsolute() const
Definition units.h:64
Glib::ustring abbr
Definition units.h:81
Interface for refcounted XML nodes.
Definition node.h:80
void setAttributeOrRemoveIfEmpty(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:167
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
bool setAttributeInt(Util::const_char_ptr key, int val)
Definition node.cpp:92
virtual Node * duplicate(Document *doc) const =0
Create a duplicate of this node.
bool setAttributeSvgNonDefaultDouble(Util::const_char_ptr key, double val, double default_value)
Definition node.cpp:122
virtual void mergeFrom(Node const *src, char const *key, bool extension=false, bool clean=false)=0
Merge all children of another node with the current.
bool setAttributeCssDouble(Util::const_char_ptr key, double val)
Set a property attribute to val [slightly rounded], in the format required for CSS properties: in par...
Definition node.cpp:102
bool setAttributeBoolean(Util::const_char_ptr key, bool val)
Definition node.cpp:86
bool setAttributeSvgDouble(Util::const_char_ptr key, double val)
For attributes where an exponent is allowed.
Definition node.cpp:111
bool getAttributeBoolean(Util::const_char_ptr key, bool default_value=false) const
Parses the boolean value of an attribute "key" in repr and sets val accordingly, or to false if the a...
Definition node.cpp:49
To do: update description of desktop.
Definition desktop.h:149
Inkscape::UI::Widget::Canvas * getCanvas() const
Definition desktop.h:190
double current_zoom() const
Definition desktop.h:335
Inkscape::CanvasItemGroup * getCanvasGuides() const
Definition desktop.h:200
Geom::Point current_center() const
Definition desktop.cpp:660
SPDocument * getDocument() const
Definition desktop.h:189
InkscapeWindow const * getInkscapeWindow() const
Definition desktop.cpp:975
SPNamedView * getNamedView() const
Definition desktop.h:191
void setWindowSize(Geom::IntPoint const &size)
Definition desktop.cpp:965
bool guides_active
Definition desktop.h:235
Geom::Rotate const & current_rotation() const
Definition desktop.h:366
void rotate_absolute_keep_point(Geom::Point const &c, double rotate)
Set new rotation, keeping the point 'c' fixed in the desktop window.
Definition desktop.cpp:742
SPDocument * doc() const
Definition desktop.h:159
Geom::IntPoint getWindowSize() const
Definition desktop.cpp:960
Inkscape::CanvasItemGroup * getCanvasPagesFg() const
Definition desktop.h:198
bool is_maximized() const
Definition desktop.cpp:924
Inkscape::CanvasItemGroup * getCanvasPagesBg() const
Definition desktop.h:197
void clear_transform_history()
Clear transform lists.
Definition desktop.cpp:437
Inkscape::LayerManager & layerManager()
Definition desktop.h:287
void zoom_absolute(Geom::Point const &c, double zoom, bool keep_point=true)
Zoom to the given absolute zoom level.
Definition desktop.cpp:538
Typed SVG document implementation.
Definition document.h:101
Glib::RefPtr< Gio::SimpleActionGroup > getActionGroup()
Definition document.h:371
SPRoot * getRoot()
Returns our SPRoot.
Definition document.h:200
SPObject * getObjectById(std::string const &id) const
Inkscape::EventLog * get_event_log()
Definition document.h:160
Geom::OptRect preferredBounds() const
Definition document.cpp:963
Inkscape::PageManager & getPageManager()
Definition document.h:162
bool is_yaxisdown() const
True if the desktop Y-axis points down, false if it points up.
Definition document.h:274
SPObject * getObjectByRepr(Inkscape::XML::Node *repr) const
Geom::Scale getDocumentScale(bool computed=true) const
Returns document scale as defined by width/height (in pixels) and viewBox (real world to user-units).
Definition document.cpp:758
static void create_new(SPDocument *doc, Inkscape::XML::Node *parent, GridType type)
Definition sp-grid.cpp:57
void showSPGuide(Inkscape::CanvasItemGroup *group)
Definition sp-guide.cpp:303
void moveto(Geom::Point const point_on_line, bool const commit)
Definition sp-guide.cpp:367
Geom::Point getPoint() const
Definition sp-guide.h:54
void hideSPGuide(Inkscape::UI::Widget::Canvas *canvas)
Definition sp-guide.cpp:328
double _guide_opacity
char const * getName() const
void modified(unsigned int flags) override
~SPNamedView() override
void release() override
void set_y_axis_down(bool down)
SVGBool desk_checkerboard
bool getShowGrids()
bool getShowGuides()
void scrollAllDesktops(double dx, double dy)
void setDefaultAttribute(std::string attribute, std::string preference, std::string fallback)
Set an attribute in the named view to the value in this preference, or use the fallback.
std::optional< Colors::Color > _guide_color
SVGBool lockguides
void newGridCreated()
void toggleLockGuides()
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
void set(SPAttr key, char const *value) override
void setShowGuideSingle(SPGuide *guide)
SVGBool grids_visible
std::optional< Colors::Color > _desk_color
void show(SPDesktop *desktop)
void temporarily_show_guides(bool show)
void fix_guidelines()
std::vector< SPDesktop * > const getViewList() const
std::unique_ptr< Inkscape::CanvasPage > _viewport
std::optional< Colors::Color > _guide_hi_color
double rotation
void translateGrids(Geom::Translate const &translation)
void order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node *old_repr, Inkscape::XML::Node *new_repr) override
void remove_child(Inkscape::XML::Node *child) override
void set_clip_to_page(SPDesktop *desktop, bool enable)
SVGBool _origin_correction
SnapManager snap_manager
std::vector< SPGuide * > guides
SPGrid * getFirstEnabledGrid()
Returns the first grid it could find that isEnabled().
void toggleShowGuides()
void toggleShowGrids()
void child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) override
void setLockGuides(bool v)
Colors::Color getGuideHiColor() const
SVGBool _y_axis_down
void activateGuides(void *desktop, bool active)
Inkscape::Util::Unit const * display_units
void setShowGrids(bool v)
Colors::Color getGuideColor() const
std::vector< SPDesktop * > views
double _guide_hi_opacity
Colors::Color getDeskColor() const
GQuark default_layer_id
void updateGuides()
void set_origin_follows_page(bool on)
SVGBool antialias_rendering
SVGBool clip_to_page
void change_bool_setting(SPAttr key, bool value)
Inkscape::Util::Unit const * getDisplayUnit() const
Returns namedview's default unit.
void build(SPDocument *document, Inkscape::XML::Node *repr) override
void set_desk_color(SPDesktop *desktop)
SVGBool showguides
bool getLockGuides()
int window_maximized
void change_color(SPAttr color_key, SPAttr opacity_key, Colors::Color const &color)
void setDisplayUnit(std::string unit)
Set the display unit to the given value.
void setShowGuides(bool v)
std::vector< SPGrid * > grids
void hide(SPDesktop const *desktop)
double connector_spacing
void updateViewPort()
Update the visibility of the viewport space.
void update(SPCtx *ctx, unsigned int flags) override
Propergate the update to the child nodes so they can be updated correctly.
void translateGuides(Geom::Translate const &translation)
void order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node *old, Inkscape::XML::Node *new_repr) override
void remove_child(Inkscape::XML::Node *child) override
void child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) override
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * repr
Definition sp-object.h:193
void setAttribute(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
std::vector< SPObject * > childList(bool add_ref, Action action=ActionGeneral)
Retrieves the children as a std vector object, optionally ref'ing the children in the process,...
SPDocument * document
Definition sp-object.h:188
virtual void set(SPAttr key, const char *value)
char const * getId() const
Returns the objects current ID string.
virtual void release()
void readAttr(char const *key)
Read value of key attribute from XML node into object.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
char const * getAttribute(char const *name) const
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
ChildrenList children
Definition sp-object.h:907
void readOrUnset(gchar const *str)
Definition svg-bool.cpp:42
Inkscape::SnapPreferences & snapprefs
Definition snap.h:342
const double w
Definition conic-4.cpp:19
A class for handling shape interaction with libavoid.
static const double defaultConnSpacing
A class to hold:
Editable view implementation.
TODO: insert short description here.
@ PREFS_WINDOW_GEOMETRY_NONE
Definition enums.h:119
@ PREFS_WINDOW_GEOMETRY_LAST
Definition enums.h:121
@ PREFS_WINDOW_GEOMETRY_FILE
Definition enums.h:120
@ PREFS_WINDOW_SIZE_SMALL
Definition enums.h:158
@ PREFS_WINDOW_SIZE_NATURAL
Definition enums.h:157
@ PREFS_WINDOW_SIZE_MAXIMIZED
Definition enums.h:160
@ PREFS_WINDOW_SIZE_LARGE
Definition enums.h:159
Inkscape - An SVG editor.
helper functions for retrieving monitor geometry, etc.
Gdk::Rectangle get_monitor_geometry_at_surface(Glib::RefPtr< Gdk::Surface > const &surface)
get monitor geometry of monitor containing largest part of surface
Definition monitor.cpp:71
Gdk::Rectangle get_monitor_geometry_at_point(int x, int y)
get monitor geometry of monitor at (or closest to) point on combined screen area
Definition monitor.cpp:82
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
Singleton class to access the preferences file in a convenient way.
Ocnode * child[8]
Definition quantize.cpp:33
Ocnode ** ref
Definition quantize.cpp:32
SPGuide – a guideline.
void sp_namedview_zoom_and_view_from_document(SPDesktop *desktop)
static auto const default_guide_hi_color
void sp_namedview_document_from_window(SPDesktop *desktop)
static auto const default_guide_color
void sp_namedview_window_from_document(SPDesktop *desktop)
void sp_namedview_update_layers_from_document(SPDesktop *desktop)
const Inkscape::Util::Unit * sp_parse_document_units(const char *value)
static auto const default_desk_color
const Inkscape::Util::Unit * sp_parse_document_units(const char *unit)
SPPage – a page object.
SPRoot: SVG <svg> implementation.
Interface for XML documents.
Definition document.h:43
Unused.
Definition sp-object.h:94
SPDesktop * desktop
Affine transformation classes.