Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
page-manager.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Inkscape::PageManager - Multi-Page management.
4 *
5 * Copyright 2021 Martin Owens <doctormo@geek-2.com>
6 *
7 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
8 */
9
10#ifndef SEEN_INKSCAPE_PAGE_MANAGER_H
11#define SEEN_INKSCAPE_PAGE_MANAGER_H
12
13#include <vector>
14#include <optional>
15
16#include "document.h"
17#include "object/sp-namedview.h"
18#include "svg/svg-bool.h"
19
20class SPDesktop;
21class SPPage;
22
23namespace Inkscape {
24class Selection;
25class ObjectSet;
26class CanvasPage;
27namespace UI {
28namespace Dialog {
29class DocumentProperties;
30}
31} // namespace UI
32namespace Colors {
33class Color;
34}
35
37{
38public:
39 PageManager(SPDocument *document);
41
42 static bool move_objects();
43 const std::vector<SPPage *> &getPages() const { return pages; }
44 std::vector<SPPage *> getPages(const std::string &pages, bool inverse) const;
45 std::vector<SPPage *> getPages(std::set<unsigned int> indexes, bool inverse = false) const;
46
47 void addPage(SPPage *page);
50
51 // Returns None if no page selected
52 SPPage *getSelected() const { return _selected_page; }
53 SPPage *getPage(int index) const;
54 SPPage *getPageAt(Geom::Point pos) const;
55 SPPage *getFirstPage() const { return getPage(0); }
56 SPPage *getLastPage() const { return getPage(pages.size() - 1); }
57 SPPage *getViewportPage() const;
58 std::vector<SPPage *> getPagesFor(SPItem *item, bool contains) const;
59 SPPage *getPageFor(SPItem *item, bool contains) const;
61 bool hasPages() const { return !pages.empty(); }
62 int getPageCount() const { return pages.size(); }
63 int getPageIndex(const SPPage *page) const;
64 int getSelectedPageIndex() const;
68 SPPage *findPageAt(Geom::Point pos) const;
69
70 void enablePages();
71 void disablePages();
72 void pagesChanged();
73 bool selectPage(SPPage *page);
74 bool selectPage(SPItem *item, bool contains);
75 bool selectPage(int index) { return selectPage(getPage(index)); }
78 bool hasNextPage() const { return getSelectedPageIndex() + 1 < pages.size(); }
79 bool hasPrevPage() const { return getSelectedPageIndex() - 1 >= 0; }
80
82
83 // TODO: move these functions out of here and into the Canvas or InkscapeWindow
84 void zoomToPage(SPDesktop *desktop, SPPage *page, bool width_only = false);
85 void zoomToSelectedPage(SPDesktop *desktop, bool width_only = false) { zoomToPage(desktop, _selected_page, width_only); };
88
89 SPPage *newPage();
90 SPPage *newPage(double width, double height);
91 SPPage *newPage(Geom::Rect rect, bool first_page = false);
92 SPPage *newDesktopPage(Geom::Rect rect, bool first_page = false);
93 SPPage *newDocumentPage(Geom::Rect rect, bool first_page = false);
94 void deletePage(SPPage *page, bool contents = false);
95 void deletePage(bool contents = false);
96 void resizePage(double width, double height);
97 void resizePage(SPPage *page, double width, double height);
98 void scalePages(Geom::Scale const &scale);
99 void rotatePage(int turns);
100 void changeOrientation();
101 void fitToSelection(ObjectSet *selection, bool add_margins = true);
102 void fitToRect(Geom::OptRect box, SPPage *page, bool add_margins = false);
103
104 bool subset(SPAttr key, const gchar *value);
106 bool showDefaultLabel() const { return label_style == "below"; }
107 std::string getSizeLabel(SPPage *page = nullptr);
108 std::string getSizeLabel(double width, double height);
109
110 static void enablePages(SPDocument *document) { document->getPageManager().enablePages(); }
111 static void disablePages(SPDocument *document) { document->getPageManager().disablePages(); }
112 static SPPage *newPage(SPDocument *document) { return document->getPageManager().newPage(); }
113
114 sigc::connection connectPageSelected(const sigc::slot<void (SPPage *)> &slot)
115 {
116 return _page_selected_signal.connect(slot);
117 }
118 sigc::connection connectPageModified(const sigc::slot<void (SPPage *)> &slot)
119 {
120 return _page_modified_signal.connect(slot);
121 }
122 sigc::connection connectPagesChanged(const sigc::slot<void ()> &slot)
123 {
124 return _pages_changed_signal.connect(slot);
125 }
126
128 Colors::Color const &getMarginColor() const { return margin_color; }
129 Colors::Color const &getBleedColor() const { return bleed_color; }
130 Colors::Color const &getBorderColor() const { return border_color; }
131
132 void movePages(Geom::Affine tr);
133 std::vector<SPItem *> getOverlappingItems(SPDesktop *desktop, SPPage *page, bool hidden = true, bool in_bleed = false, bool in_layers = true);
134
135protected:
137
138 // Default settings from sp-namedview
143
144 std::string label_style = "default";
145
146private:
149 std::vector<SPPage *> pages;
150
151 sigc::signal<void (SPPage *)> _page_selected_signal;
152 sigc::signal<void (SPPage *)> _page_modified_signal;
153 sigc::signal<void ()> _pages_changed_signal;
154
156
161};
162
163} // namespace Inkscape
164
165#endif
166/*
167 Local Variables:
168 mode:c++
169 c-file-style:"stroustrup"
170 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
171 indent-tabs-mode:nil
172 fill-column:99
173 End:
174*/
175// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
SPAttr
Definition attributes.h:27
uint32_t Color
uint64_t page
Definition canvas.cpp:171
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
Scaling from the origin.
Definition transforms.h:150
sigc::connection connectPagesChanged(const sigc::slot< void()> &slot)
static void enablePages(SPDocument *document)
Colors::Color const & getMarginColor() const
bool setDefaultAttributes(CanvasPage *item)
Update the canvas item with the default display attributes.
void disablePages()
Disables multi page supply by removing all the page objects.
void changeOrientation()
Change page orientation, landscape to portrait and back.
Geom::Affine getSelectedPageAffine() const
sigc::signal< void(SPPage *)> _page_selected_signal
void centerToPage(SPDesktop *desktop, SPPage *page)
Center without zooming on the given page.
Colors::Color const & getBorderColor() const
SPPage * getFirstPage() const
bool hasNextPage() const
void scalePages(Geom::Scale const &scale)
Change page size, margins and bleeds by a set amount.
std::vector< SPPage * > getPagesFor(SPItem *item, bool contains) const
Return a list of pages this item is on.
void zoomToSelectedPage(SPDesktop *desktop, bool width_only=false)
sigc::connection connectPageSelected(const sigc::slot< void(SPPage *)> &slot)
sigc::signal< void()> _pages_changed_signal
void enablePages()
Enables multi page support by turning the document viewBox into the first page.
Colors::Color border_color
void zoomToPage(SPDesktop *desktop, SPPage *page, bool width_only=false)
Center/zoom on the given page.
SPPage * getLastPage() const
void fitToSelection(ObjectSet *selection, bool add_margins=true)
Resize the page to the given selection.
int getPageCount() const
SPPage * findPageAt(Geom::Point pos) const
This provides a simple way of selecting a page based on their layering Pages which are entirely conta...
SPPage * getPageFor(SPItem *item, bool contains) const
Return the first page that contains the given item.
SPPage * newPage()
Add a new page of the default size, this will be either the size of the viewBox if no pages exist,...
void reorderPage(Inkscape::XML::Node *child)
Reorder page within the internal list to keep it up to date.
bool selectPage(int index)
Colors::Color background_color
bool hasPrevPage() const
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.
std::string getSizeLabel(SPPage *page=nullptr)
Return a page's size label, or match via width and height.
sigc::signal< void(SPPage *)> _page_modified_signal
const std::vector< SPPage * > & getPages() const
void centerToSelectedPage(SPDesktop *desktop)
Colors::Color const & getBleedColor() const
bool selectPage(SPPage *page)
Set the given page as the selected page.
SPPage * getPage(int index) const
Get the page at the given position or return nullptr if out of range.
Geom::Rect getSelectedPageRect() const
Returns the selected page rect, OR the viewbox rect.
static void disablePages(SPDocument *document)
SPPage * getSelected() const
SPPage * getPageAt(Geom::Point pos) const
Get a page at a specific starting location.
Geom::Point nextPageLocation() const
Return the location of the next created page.
int getSelectedPageIndex() const
Return the index of the page in the index.
void movePages(Geom::Affine tr)
Called when the viewbox is resized.
void deletePage(SPPage *page, bool contents=false)
Delete the given page.
Colors::Color const & getBackgroundColor() const
SPPage * newDesktopPage(Geom::Rect rect, bool first_page=false)
Create a new page, resizing the rectangle from desktop coordinates.
bool showDefaultLabel() const
Colors::Color margin_color
SPPage * getViewportPage() const
Returns the page attached to the viewport, or nullptr if no pages or none of the pages are the viewpo...
void fitToRect(Geom::OptRect box, SPPage *page, bool add_margins=false)
Fit the selected page to the given rectangle.
void rotatePage(int turns)
Rotate the selected page by the given number of 90 degree rotations.
std::vector< SPItem * > getOverlappingItems(SPDesktop *desktop, SPPage *page, bool hidden=true, bool in_bleed=false, bool in_layers=true)
Return a list of objects touching this page, or viewbox (of single page document)
sigc::connection _page_modified_connection
static bool move_objects()
bool hasPages() const
void removePage(Inkscape::XML::Node *child)
Remove a page from this manager, called from namedview parent.
void pagesChanged()
Called when the pages vector is updated, either page deleted or page created (but not if the page is ...
Colors::Color const & getDefaultBackgroundColor() const
int getPageIndex(const SPPage *page) const
Get page index, returns -1 if the page is not found in this document.
void resizePage(double width, double height)
Colors::Color bleed_color
std::vector< SPPage * > pages
Geom::OptRect getDesktopRect() const
Returns the total area of all the pages in desktop units.
SPPage * newDocumentPage(Geom::Rect rect, bool first_page=false)
Create a new page, using document coordinates.
sigc::connection connectPageModified(const sigc::slot< void(SPPage *)> &slot)
static SPPage * newPage(SPDocument *document)
Interface for refcounted XML nodes.
Definition node.h:80
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:103
Inkscape::PageManager & getPageManager()
Definition document.h:164
Base class for visual SVG elements.
Definition sp-item.h:109
SPItem * item
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
Ocnode * child[8]
Definition quantize.cpp:33
int index
SPDesktop * desktop
double height
double width